On Tue, 4 Apr 2006, Joerg Schilling wrote:

JS>Steve Bennett <[EMAIL PROTECTED]> wrote:
JS>
JS>> I don't think unspecified means irrelevant.
JS>>
JS>> > 
JS>> > struct test2 { 
JS>> >  char blerg[1]; 
JS>> >  char type[4]; 
JS>> >  char flibble[3]; 
JS>> >  char more[2]; 
JS>> >  char dummy[1]; 
                   ^^^

With the 1 there the compiler can pad at the end so that the sizes and 
offsets below are legal. If you put an empty [], then and only then the 
offset of dummy MUST be equal to the struct size (but there may be padding 
between more and dummy).

JS>> > }; 
JS>>
JS>> And the result:
JS>>
JS>> sizeof(test1) is 12
JS>> offsetof(test1, more) is 8
JS>> offsetof(test1, dummy) is 10
JS>>
JS>> > 
JS>> > Now, sizeof(test1) needs to be == offsetof(test2, dummy);
JS>> > 
JS>> > It seems that this is mot the case for GCC.
JS>>
JS>> So either this is the case because the you are misunderstanding
JS>> the spec or because the GCC arm guys are misunderstanding the spec.
JS>
JS>OK, now I have access to the printed standard at work....
JS>
JS>Working draft 1997-11-21:
JS>
JS>------->
JS>As a special case, the last element of a structure may be an incomplete type.
JS>This is called a flexible array member, and the size of the structure shall 
be
JS>equal to the offset of the last element of an otherwise identical structure 
that
JS>replaces the flexible array member with an array of one element.
JS><------
JS>
JS>It is obvious that the new version of the text has been made more universal 
JS>from a theoretical standpoint (the new text does not allow the compiler to 
JS>behave different in case that the size of the replaced last element differs
JS>from 1) but unfortunately this reduces readability for the first attempt 
JS>to read....
JS>
JS>The recent C-99 text basically says the same as the important part of 
JS>the new sentence is that the size of the structure shall be equal to 
JS>the offset of the flexible array member.
JS>
JS>However, I understand that it would take some time to fix the GCC and 
JS>to wait until the fixed gcc appears at end user systems.
JS>
JS>What the last 10 lines in mkisofs.h show is that it seems to be usual (not 
JS>only for GCC) to tail pad structures on some architectures.

I've not looked at the .h file, but if the last member of the struct is 
really [1] and not [], then gcc behaviour is correct.

harti

JS>We need to find a different way to solve your problem that is insensitive to
JS>compiler bugs.
JS>
JS>
JS>Thank you for pointing to this problem!
JS>
JS>J?rg
JS>
JS>


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to