This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: attribute data structure rewrite


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]