offsets in structures.

Guido van Rossum guido at mcvax.UUCP
Thu Oct 11 04:17:40 AEST 1984


Watch out!  I did a similar thing to calculate the width of a structure:

	(int) ((struct foo *)0 + 1)

This would give me the sizeof a struct foo, ROUNDED UP to the necessary
alignment.  It worked fine, until one day, I ported my program to an
IBM PC with a Lattice C compiler.  There it would always evaluate to 1
(apparently the compiler cancelled the two casts against each other).

--
	Guido van Rossum, "Stamp Out BASIC" Committee, CWI, Amsterdam
	guido at mcvax.UUCP

"Immorality may be something, but it does not take the place of virtue
and three square meals a day."



More information about the Comp.lang.c mailing list