attribute data structure rewrite
Gabriel Dos Reis
gdr@cs.tamu.edu
Fri Sep 24 02:59:00 GMT 2004
"Giovanni Bajo" <giovannibajo@libero.it> writes:
| Gabriel Dos Reis wrote:
|
| > Currently, the compiler fails on any of the following fails,
| > complaining about non-"integral constant expression"-ness, which is
| > pure nonense.
| >
| > const int N = 4;
| > struct S {
| > enum { M = 4 };
| > float x __attibute__((__aligned__(N)));
| > float x __attibute__((__aligned__(M)));
| > };
| >
| > template<typename T, int N>
| > struct buffer {
| > typedef char U[sizeof(T)];
| > U data __attribute__((__aligned__(N)));
| > };
|
| Is there already a bug report about this?
Hmm, now that you're questioning I think we don't have a proper PR for
them.
| Anothing thing I have been shown today is that we currently reject this:
|
| ----------------------------------------
| #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?
My gut reaction is that "foo[i]" is not a data at compile-time
location; so, it does not qualify for use in offsetof.
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);
}
}
-- Gaby
More information about the Gcc
mailing list