so how do I do it? (was Re: call to revolt)

Doug Gwyn gwyn at smoke.brl.mil
Fri Jun 28 06:20:01 AEST 1991


In article <1991Jun27.115736.18417 at tkou02.enet.dec.com> diamond at jit533.enet@tkou02.enet.dec.com (Norman Diamond) writes:
>>and then (struct foo *)p->c  or (struct foo *)p->u
>This is legal.

Actually, no.  ((struct foo *)p)->c is the way to write this.
You want to cast the pointer, not the char member.

>>this is nonportable, as to my understanding, as struct arrangements are not
>>guaranteed.
>Huh?  Oh, you mean that the buffer was laid out by some other entity
>than your C program.

I don't know exactly what he meant (could have been any of several things),
but the problems are:  (1) there might be padding between the struct members
and (2) the representation, especially of the unsigned member, may not agree
with the C implementation's.  The first problem is easy; the second one is
harder.



More information about the Comp.std.c mailing list