This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: [13278] sizeof and allignment on 32bit target
- From: "John Yates" <jyates at netezza dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Sat, 26 Jul 2003 11:04:24 -0400
- Subject: Re: [13278] sizeof and allignment on 32bit target
- References: <1059173250.4755.ezmlm@gcc.gnu.org>
Long ago I internalized the point that sizeof() does
not return the minimum number of bytes that need to
be copied in an aggregate assignment but rather the
spacing between elements in an array:
struct foo { ... };
foo a[2];
((char*)&a[0]) + sizeof(foo) equals ((char*)&a[1])
This is a bit of a hole in the language definition
since there really is no way to obtain that minimum
number. Hence using sizeof() as the length of a
memcpy() to set a freestanding risks trashing some
other object if the compiler has practiced any kind
storage packing.
/john