Portability using structures and malloc - Help
wendt at bocklin.UUCP
wendt at bocklin.UUCP
Fri Aug 2 04:55:17 AEST 1985
I'm wrong about sizeof(struct {char a;}), as Jerry Schwartz informs me.
> Using the size of a structure containing a single char to find
> out about alignment requirements is not portable. While many
> compilers will round up the size of such structures there
> is no guarantee that they will round to the maximum requirement.
> (E.g. they might round to 4 bytes on a machine that requires
> doubles to be aligned at 8 bytes)
What about sizeof(struct {char a; double b;}) - sizeof(double) .
This assumes that the alignment requirements for double are the most
stringent. The assumption could be removed by maximizing over all
types or something, but the result would probably break some preprocessors.
More information about the Comp.lang.c
mailing list