Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

offsetof -macro

2 views
Skip to first unread message

Kristo Helasvuo

unread,
Feb 12, 2001, 10:09:25 AM2/12/01
to

Hi!

I have Metrowerks CodeWarrior Lite for Palm and when I'm using offsetof() I
get error:

Error : function has no prototype
MemoPad.c line 1458 DmWrite(s, offsetof(PackedProduct, amount),
&product->amount, sizeof(product->amount));


Is that not a standard function, or should I include something to get this
to work?

I deeply appreciate your efforts to answer this question, thank you!

Kristo


Ben Combee

unread,
Feb 12, 2001, 2:47:32 PM2/12/01
to
> If CodeWarrior for Palm OS won't let you #include <stddef.h> like that
> then it's not even a conforming freestanding implementation of Standard C.
> If that's the case, it's pathetic.

Actually, it does with no problem. The only issue is adding the access path
to see the Metrowerks Standard Library. As long as you stick to the
freestanding subset of the library, MSL works great with PalmOS.

> Once upon a time, an engineer at Palm who only uses CodeWarrior added an
> offsetof() macro to PalmTypes.h. I told him that he'd have to work a bit
> harder to avoid conflicting with the macro provided by various compilers'
> stddef.h headers. Instead of working harder, he changed the
capitalisation.
> PalmTypes.h says OffsetOf not by design, but by accident.

Yow! ...all this time, I thought it had been a Blessed creation, along with
MemSet and StrLen.

> I regret that I didn't take it upon myself to fix this before the 3.5 SDK
> left the building. Along with not campaigning harder for us to use the
> C99 standard's uint32_t instead of UInt32, etc, I consider this one of my
> greatest personal failures while I've been working on the SDK.

Using stdint.h would have rocked. Too bad; I guess a general rule for SDK
design is to look at the practices of Microsoft and the Win32 SDK and do the
opposite. At least WORD and DWORD are gone.

--
Ben Combee
Veriprise Wireless <http://www.veriprise.com>


Ben Combee

unread,
Feb 12, 2001, 1:14:02 PM2/12/01
to
"Kristo Helasvuo" <kristo-nospam@-remove-kaapeli.fi> wrote in message
news:3OhSOXQ...@www.massena.com...

>
> Hi!
>
> I have Metrowerks CodeWarrior Lite for Palm and when I'm using offsetof()
I
> get error:
>
> Error : function has no prototype
> MemoPad.c line 1458 DmWrite(s, offsetof(PackedProduct, amount),
> &product->amount, sizeof(product->amount));
>
>
> Is that not a standard function, or should I include something to get this
> to work?

offsetof is not Palm standard. The PalmOS headers supply the replacement
called "OffsetOf". Notice the capitalization.

John Marshall

unread,
Feb 12, 2001, 2:32:31 PM2/12/01
to
Ben Combee <com...@techwood.org> wrote:

> "Kristo Helasvuo" <kristo-nospam@-remove-kaapeli.fi> wrote:
>> I have Metrowerks CodeWarrior Lite for Palm and when I'm using offsetof() I
>> get error:
[...]

> offsetof is not Palm standard. The PalmOS headers supply the replacement
> called "OffsetOf". Notice the capitalization.

It never ceases to amaze me that people can say this with a straight face.

I've been programming in C for over ten years. Why would I want to use
OffsetOf on one particular system when offsetof is what I've been using
everywhere else all that time? Should I spell sizeof as SizeOf if Palm
were to tell me to?

With m68k-palmos-gcc you can write

#include <PalmOS.h>
#include <stddef.h>

... code using offsetof() ...

just as you would expect. Just because PalmTypes.h pollutes your
namespace with OffsetOf() doesn't mean you have to use it.

If CodeWarrior for Palm OS won't let you #include <stddef.h> like that
then it's not even a conforming freestanding implementation of Standard C.
If that's the case, it's pathetic.

Once upon a time, an engineer at Palm who only uses CodeWarrior added an


offsetof() macro to PalmTypes.h. I told him that he'd have to work a bit
harder to avoid conflicting with the macro provided by various compilers'
stddef.h headers. Instead of working harder, he changed the capitalisation.
PalmTypes.h says OffsetOf not by design, but by accident.

I regret that I didn't take it upon myself to fix this before the 3.5 SDK


left the building. Along with not campaigning harder for us to use the
C99 standard's uint32_t instead of UInt32, etc, I consider this one of my
greatest personal failures while I've been working on the SDK.

John "pedantic standards freak"

John Marshall

unread,
Feb 12, 2001, 2:56:49 PM2/12/01
to
Ben Combee <com...@techwood.org> wrote:
>> If CodeWarrior for Palm OS won't let you #include <stddef.h> like that
[...]

> Actually, it does with no problem. The only issue is adding the access path
> to see the Metrowerks Standard Library.

Judging by number of times this comes up, I consider that too much of an
impediment. :-)

> Yow! ...all this time, I thought it had been a Blessed creation, along with
> MemSet and StrLen.

It's funny you should mentioned the &*#@&! blessedness of MemSet!

John

Keith Rollin

unread,
Feb 13, 2001, 3:47:46 AM2/13/01
to
"Warren Young" <tan...@cyberport.com> wrote in message
news:3A88862C...@cyberport.com...

> John Marshall wrote:
> >
> > > Yow! ...all this time, I thought it had been a Blessed creation,
along with
> > > MemSet and StrLen.
> >
> > It's funny you should mentioned the &*#@&! blessedness of MemSet!
>
> You have no idea how happy I am to know that there are people in Palm's
> development group who regret MemSet(). :)

Well, that would be most people. It's not like anyone here is a fan of it
either. MemSet was implemented when there were just a few people working
for Palm. There wasn't a whole lot of opportunity for peer review and
feedback. The guy who did MemSet just got it wrong. And once it got
shipped that way, it had to stay that way.

-- Keith Rollin
-- Palm OS Emulator engineer

Ben Combee

unread,
Feb 13, 2001, 4:20:09 AM2/13/01
to
"Kristo Helasvuo" <kristo-nospam@-remove-kaapeli.fi> wrote in message
news:X0h4LFZ...@www.massena.com...
>
> "Ben Combee" <com...@techwood.org> wrote in message
> news:7xK41wS...@www.massena.com...

> > > If CodeWarrior for Palm OS won't let you #include <stddef.h> like that
> > > then it's not even a conforming freestanding implementation of
Standard
> C.
> > > If that's the case, it's pathetic.
> >
> > Actually, it does with no problem. The only issue is adding the access
> path
> > to see the Metrowerks Standard Library. As long as you stick to the
> > freestanding subset of the library, MSL works great with PalmOS.
>
> This might be a RTFM, but could you advise where I can find MSL? Could it
be
> that Lite version does not include a standard lib...

CW Lite does not include MSL -- it was stripped out of the distribution
along with other parts in order to make the download as light as possible.

Kristo Helasvuo

unread,
Feb 13, 2001, 2:52:35 AM2/13/01
to

"Ben Combee" <com...@techwood.org> wrote in message
news:5lMMm8R...@www.massena.com...

> offsetof is not Palm standard. The PalmOS headers supply the replacement
> called "OffsetOf". Notice the capitalization.

I get the very same error msg that the function has no prototype even with
OffsetOf. Pilot.h is included.

Maybe they have shipped some weird old version of SDK with MW Palm Lite,
which btw does not include MW help and reference files at all...

Kristo


Warren Young

unread,
Feb 12, 2001, 7:56:12 PM2/12/01
to
John Marshall wrote:
>
> > Yow! ...all this time, I thought it had been a Blessed creation, along with
> > MemSet and StrLen.
>
> It's funny you should mentioned the &*#@&! blessedness of MemSet!

You have no idea how happy I am to know that there are people in Palm's


development group who regret MemSet(). :)

--
= Warren Young -- Maintainer of the Palm OS Programmer's FAQ at:
= http://www.cyberport.com/~tangent/palm/faq/
=
= ICBM Address: 36.8274040 N, 108.0204086 W, alt. 1714m

Kristo Helasvuo

unread,
Feb 13, 2001, 2:47:54 AM2/13/01
to

"Ben Combee" <com...@techwood.org> wrote in message
news:7xK41wS...@www.massena.com...

> > If CodeWarrior for Palm OS won't let you #include <stddef.h> like that
> > then it's not even a conforming freestanding implementation of Standard
C.
> > If that's the case, it's pathetic.
>
> Actually, it does with no problem. The only issue is adding the access
path
> to see the Metrowerks Standard Library. As long as you stick to the
> freestanding subset of the library, MSL works great with PalmOS.

This might be a RTFM, but could you advise where I can find MSL? Could it be

Heather KML Tufts

unread,
Feb 14, 2001, 11:12:52 AM2/14/01
to
> > offsetof is not Palm standard. The PalmOS headers supply the
replacement
> > called "OffsetOf". Notice the capitalization.
>
> I get the very same error msg that the function has no prototype even with
> OffsetOf. Pilot.h is included.
>
> Maybe they have shipped some weird old version of SDK with MW Palm Lite,
> which btw does not include MW help and reference files at all...

Lite ships with the 3.1 SDK (which was current at the time that Lite was
completed). OffsetOf is defined in the 3.5 SDK. Since the 3.5 SDK is not
available for the Lite version, you will need to get the full product to use
this macro.

-hkmlt


0 new messages