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: alias: Varying struct and fixed scalar question


Andreas Krebbel writes:
 > 
 > > struct foo { int n; };
 > > extern unsigned long c = 0;
 > > 
 > > {
 > >   int b;
 > > 
 > >   b = 2;
 > >   ((struct foo*)(&b + c))->n = 3;
 > > }
 > 
 > For having a true dependency the example should look like this:
 > 
 > struct foo { int n; };
 > extern unsigned long c = 0;
 > 
 > {
 >   int b;
 >   int d;
 > 
 >   b = 2;
 >   d = ((struct foo*)(&b + c))->n;
 > }

6.7.2.1:  A pointer to a struct object, suitably converted, points to
its initial member, and vice versa.

However, that doesn't imply that you can convert a pointer to an
arbitrary scalar to a pointer to a structure whose initial member has
the same type as the scalar.

Andrew.


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