> > > Included is a manpage documenting the offsetof() macro; please
> > > consider including it.
> > 
> > Excellent idea!  Thanks for the page.  It will go in 2.34.
> It was my idea .. I guess I found it in undocumented.3.

Yep -- I removed it from undocumented.3 already.

[...]

> > >         printf("%d\n", offsetof(struct a, c));
> > >         exit(EXIT_SUCCESS);
> > > }
> > > .fi
> > > .SH NOTES
> > > \fBoffsetof\fP can be implemented as:
> > > .sp
> > > .nf
> > >         \fB#define offsetof(\fItype\fP, \fPmember\fP) \\
> > >           \fB&((type *)0)->\fImember\fP - (char *)((\fPtype\fP *)0)
> > > .fi
> > 
> > I'm inclined  to leave the above out (it could vary on some systems).  
> > But anyway, why do you write the above when glibc says:
> > 
> > #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
> Actually, I have:
> 
>   #define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER)
> 
> And in gcc-3.4 it is even uglier:
> 
> /* The cast to "char &" below avoids problems with user-defined
>    "operator &", which can appear in a POD type.  */
> #define offsetof(TYPE, MEMBER)                                  \
>   (__offsetof__ (reinterpret_cast <size_t>                      \
>                  (&reinterpret_cast <const volatile char &>     \
>                   (static_cast<TYPE *> (0)->MEMBER))))
> 
> But I don't know why it would be necessary to subtract the casted zero
> :)  At one point I had quite an amusing conversation about this.

Okay -- I will remove this definition from the man page,

> I wrote it myself so I wasn't copying libc (although my source was gcc
> anyway) and to make sure I still understood it.  Do you have a glibc
> source, too?

There are many glibc sources (different versions) -- I
have the source of a large number of them.

Cheers,

Michael
-- 
Michael Kerrisk
maintainer of Linux man pages Sections 2, 3, 4, 5, and 7 

Want to help with man page maintenance?  
Grab the latest tarball at
ftp://ftp.win.tue.nl/pub/linux-local/manpages/, 
read the HOWTOHELP file and grep the source 
files for 'FIXME'.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to