This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: attribute data structure rewrite
Gabriel Dos Reis wrote:
> We used to accept it because we did not implement offsetof correctly.
> For example, the following variation should be rejected (in C89 an C++
> mode)
>
> struct A { char foo[10]; };
> void bar(void) {
> int i;
> for (int i = 0; i < 10; ++i)
> {
> char ary[offsetof(struct A, foo[i] + 1);
> }
> }
I don't understand your example because I don't think the +1 there is valid.
Unless you meant:
char ary[offsetof(struct A, foo[i])+1];
Anyway, what about this in C99? We don't need a constant expression in this
context, and even if offsetof is always a constant expression we could still
accept it as an extension. In other words, we could transform it to
offsetof(struct A, foo)+i*sizeof(foo[0]) in contexts that don't require a
constant expression.
Giovanni Bajo