** help...
Bruce Worden
bruce at seismo.gps.caltech.edu
Fri Aug 31 05:15:33 AEST 1990
In article <1912 at islay.tcom.stc.co.uk> rmj at htc1.UUCP (Rhodri James) writes:
[material deleted]
>The crux of the potential health hazard comes with the definition of
>sizeof, which K&R2 says (section 6.3) gives a size_t result equal to the
>size of the specified object or type in bytes. Nothing here guarentees
>that the *end* of the object will be such that another object straight
>after it in memory (which is what the multiplication implies) will be
>correctly aligned. Many structs would give appropriately odd lengths;
>I'm sure you don't need examples.
Actually, examples would be nice, since I don't see what you mean.
On a machine requiring alignment:
struct thingy {
char a;
}
sizeof(struct thingy) is 1.
struct thingy {
int i; /* four byte ints */
}
sizeof(struct thingy) is 4.
struct thingy {
int i;
char a;
}
sizeof(struct thingy) is 8. The structure is padded to insure that
alignment is maintained.
> ... Can anyone
>quote chapter and verse invalidating this argument (please)?
I don't know what the standard says about the issue (if anything), but it
is difficult to imagine a serious vendor shipping a system that required
more than single byte alignment and in which the structure in the last
example was size 5. It is not so much a question of the standard, but,
rather, one of functionality.
--------------------------------------------------------------------------
C. Bruce Worden bruce at seismo.gps.caltech.edu
252-21 Seismological Laboratory, Caltech, Pasadena, CA 91125
More information about the Comp.lang.c
mailing list