TC bug in sizeof()?

Barry.True btrue at emdeng.Dayton.NCR.COM
Sat Feb 17 01:03:48 AEST 1990


In article <1519 at maytag.waterloo.edu> dmurdoch at watstat.waterloo.edu (Duncan Murdoch) writes:
>
>[Stuff deleted about asking whether it is an error that sizeof rounds the]
>[following structure up one byte when in word but not alignment.]
>
>Sample program:
>
>struct test
>  { char a;
>    char b;
>    char c;
>  } structure;
>

IMHO (since I don't know that much about TC) the fact that you used word
alignment means that the compiler is going to try to align all multi-byte
data on a word boundary (i.e., four bytes). Since the above structure is
only three bytes long it is padded with an extra byte when stored so the
next data element will be aligned on an even word boundary. We used to have
the same problem with the C compiler on a SYSVR0 system running on an AT&T
3B5 system. I'm not sure if you will run into any problems using the length
return from sizeof(struct test) in something like strncpy() or memcpy() to
initialize the structure or not since you won't be overwriting into another
variable's data space. Any body else know?



More information about the Comp.lang.c mailing list