This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: c/9058: structure with flexible array member: offsetof() != sizeof()


Joseph S. Myers wrote:

On 26 Dec 2002 manfred@colorfullife.com wrote:


Now sizeof(struct x) is 8, offsetof(struct x, c) is 6. That seems to
contradice the C99 standard: section 6.7.2.1, constraint 16.

Please read the suggested TC in response to DR 282.  (See N983
<http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n983.htm> and the Santa Cruz
minutes <http://std.dkuug.dk/JTC1/SC22/WG14/www/docs/n987.htm> - the DR
log hasn't yet been updated.)

Thanks, I found the thread "C99 conformance bug in gcc-3.1" after filing the bug report.
What's the recommended approach to calculate the size for malloc calls? Is

struct a {int a; char b; short c[]; };

len = offsetof(struct a, c[nr_entries]);

valid and portable?

sizeof(struct a)+nr_entries*sizeof(short);

would waste 2 bytes.

--
Manfred


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]