attribute data structure rewrite

Giovanni Bajo giovannibajo@libero.it
Fri Sep 24 14:45:00 GMT 2004


Joseph S. Myers wrote:


>> ----------------------------------------
>> #include <stddef.h>
>> #include <stdio.h>
>>
>> struct A { char foo[10]; };
>>
>> void bar(void) {
>>     int i;
>>     for (i=0;i<10;i++)
>>         printf("%d\n", offsetof(struct A, foo[i]));
>> }
>> --------------------------------------
>>
>> but we used to accept it.  Any idea about its legality? Workarounds?
>
> Compile-time undefined for both C and C++, no diagnostic required; one
> couldn't reasonably be given with the old macro implementations.

Yes. Actually, the old implementation just worked.

> Either diagnose the use of non-integer-constant-expressions in
> offsetof, or permit them but make them cause the result not to be an
> integer constant expression.


I think we currently go with the former. But I believe this to be a regression
in user experience. Using the external + sizeof(i)*blah is ugly. If it was
possible to build the result not being an integer constant expression before
4.0 it would be great. If you want, I can file a bug report to track this.

-- 
Giovanni Bajo




More information about the Gcc mailing list