sizeof a struc field

David Adrien Tanguay datanguay at watmath.waterloo.edu
Thu Oct 19 20:25:37 AEST 1989


In article <1234 at crdos1.crd.ge.COM> davidsen at crdos1.UUCP (bill davidsen) writes:
]
]Here's what the standard says (3.3.3.4):
]	[quotes the standard]
]
]If the expression is not evaluated the pointer is not dereferenced and
]there is no problem as far as hypothetical hardware which checks for
]this. I see nothing which I can read to forbid the original construct
]or indicate that it might not be valid in this case. The meaning of an
]incomplete type is spelled out in 3.1.2.5 and a null pointer with a
]cast isn't shown. I therefore conclude that the construct of the
]original poster is valid C as specified by the standard.

See also section 3.3.2.3, on the '->' and '.' operators. It eventually
says "...designates a member of a structure or union object." and
"... is an lvalue.". ((struct foo *)0)->elem does not designate an
object. Is there a clearer indication elsewhere?

]I also really
]wonder why sizeof doesn't return "unsigned int" but I suspect i wouldn't
]like the answer.

Unsigned int might not be large enough to hold the size of an object.
E.g., an IBM PC with huge objects.

David Tanguay



More information about the Comp.lang.c mailing list