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

Manfred Spraul manfred@colorfullife.com
Thu Dec 26 15:38:00 GMT 2002


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-bugs mailing list