sizeof a struc field

Dr. T. Andrews tanner at cdis-1.uucp
Mon Sep 18 06:56:41 AEST 1989


In article <11086 at smoke.BRL.MIL>, gwyn at smoke.BRL.MIL (Doug Gwyn) writes:
) [ [ #define SIZEGHI sizeof(((struct abc *)0)->ghi) ]...
) doesn't necessarily work. ]
Since you're not de-referencing the null pointer, you're going to
have a very hard time convincing me that there's an excuse for the
above to fail.

The same argument applies to the obvious "OFFSET_OF" implementation.

) Review the interminable discussions about use of null pointers.
Most of the discussions about NULL pointers have warned of the evils
of dereferencing them.

It has been noted that a particular object need not actually exist
for sizeof() to work.

) #define SIZEGHI (sizeof ((struct abc *)malloc(sizeof(struct abc)))->ghi)
And, why not use "blunge()" instead of malloc?  We're not going to
call malloc() in the sizeof() context.  Ah, yes, and we can
#define	 blunge(XX)	((char *)0)	/* malloc may return NULL */
and of course we're right back to where we were at the start...
-- 
...!bikini.cis.ufl.edu!ki4pv!cdis-1!tanner  ...!bpa!cdin-1!cdis-1!tanner
or...  {allegra attctc gatech!uflorida}!ki4pv!cdis-1!tanner



More information about the Comp.lang.c mailing list