c/9058: structure with flexible array member: offsetof() != sizeof()
Manfred Spraul
manfred@colorfullife.com
Thu Dec 26 15:46:00 GMT 2002
The following reply was made to PR c/9058; it has been noted by GNATS.
From: Manfred Spraul <manfred@colorfullife.com>
To: "Joseph S. Myers" <jsm28@cam.ac.uk>
Cc: gcc-gnats@gcc.gnu.org, gcc-bugs@gcc.gnu.org
Subject: Re: c/9058: structure with flexible array member: offsetof() != sizeof()
Date: Fri, 27 Dec 2002 00:37:54 +0100
Joseph S. Myers wrote:
>On Thu, 26 Dec 2002, Manfred Spraul wrote:
>
>
>
>>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]);
>>
>>
>
>You mean offsetof(struct a, c) + nr_entries * sizeof(short).
>
>
No, I meant what I wrote - is that valid? It would be less error prone,
e.g. if the type of the flexible array member is changed.
linux kernel, i.e gcc portability across platforms.
--
Manfred
More information about the Gcc-prs
mailing list