On Wed, May 24, 2006 at 08:18:00PM +0200, Michael Kerrisk wrote:
> > > > 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.
Oops I meant to note that I found it (glibc doc, section on c language
foo).
On that note, would you be able to find out when
grep -r DEFAULT_CHECK_ACTION malloc/
changed from 1 to 3? (This for a work-in-process page on mallopt()
and friends). It was between glibc-2.3.2 and glibc-2.3.6..
Justin
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]