This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: attribute data structure rewrite
"Giovanni Bajo" <giovannibajo@libero.it> writes:
| 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];
Yes, this is what I meant.
Sorry for the typo, and sending a testcase without compiling :-)
| Anyway, what about this in C99?
Even in strict C99 mode, it will not be valid. One could think of GNU
extensions that compute offsetof at run-time, but that is something
we've debated much in the past. I see the move to the new
implementation as a desire to keep away from that.
RTH might want to weight in.
| 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.
I agree that in C99, one does not need a constant expression to make
it work, but the offsetof-subexpression still will not be valid.
| 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.
That is a possibility. I'm not sure how serious the issue is.
-- Gaby