sizeof a struc field

mcdonald at uxe.cso.uiuc.edu mcdonald at uxe.cso.uiuc.edu
Sat Oct 28 01:42:00 AEST 1989



>However, the argument is persuasive only because the constant 0 has a
>special meaning in C.  We know a null pointer does not point to an
>object.  But what happens if we do the following?

>        sizeof ((type *)1)->member
            

How about
/* suitable definition of type and member here */
void *a;

size_t b = sizeof(((type *)a)->member);

type *c;
a = malloc(b);  
c = (type * )a;
Somehow this begins to look awfully legal to me. What if the malloc
was in another source file that was not linked in?

Doug McDonald   



More information about the Comp.lang.c mailing list