[GCC-XML] pragmas, preprocessor

Paul Suade paul.suade at laposte.net
Wed Sep 29 19:04:35 EDT 2004


----- Original Message ----- 
From: "Bjorn.Roald" <bjorn.roald at broadpark.no>
To: <gccxml at gccxml.org>
Sent: Wednesday, September 29, 2004 10:37 PM
Subject: Re: [GCC-XML] pragmas, preprocessor


> > struct {
> >     int a;
> >     struct U {
> >         int b;
> >     };
> > } X;

you must considerate that the fact you are using C++ : here you only declare
a struct U local to an anonymous struct instancied into X. But you are not
declaring a member, so you have 4 bytes as the whole size : sizeof(int).

> >
> > Changing the definition to either this
> >
> > struct {
> >     int a;
> >     struct U {
> >         int b;
> >     } u;
> > } X;

Not only you are still declaring a local structure but you declare a member
of this structure. So you get : sizeof(int) + sizeof(int), that is 8 bytes;

> >
> > or this
> >
> > struct {
> >     int a;
> >     struct {
> >         int b;
> >     };
> > } X;

now you declare a anonymous structure local to another, and still declaring
a member inside, so you get : sizeof(int) + sizeof(int), that is 8 bytes.
> >
> > gives the correct results.  I'm not sure the first definition is
> > valid C - but it is in MS header files (objidl.h, struct
_userSTGMEDIUM).
> >

well there is no reason it is not valid C, except the fact that it should
not be interpreted the same way since visual and watcom C compilers accepted
the direct use of X.b to access it. GCC didn't accept it until recently. So,
you should have a different result if generated with a C compiler, not a C++
compiler. You may need to check out.

regards




More information about the gccxml mailing list