This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: struct and members addresses
- From: "Agust Karlsson" <Gusti at pallas dot dk>
- To: "Alexandre Courbot" <Alexandre dot Courbot at lifl dot fr>, Cédric Lucantis <cedric dot lucantis at caramail dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Thu, 24 Apr 2003 13:18:50 +0200
- Subject: RE: struct and members addresses
Or to be sure you could use
__attribute__ ((packed))
I.e.
struct foo
{
any_type first_member;
} __attribute__ ((packed)) ;
Gústi
--
Agust Karlsson mailto:gusti at pallas dot dk
Pallas Informatik A/S http://www.pallas.dk
Allerød Stationsvej 2D Tel.: +45 48 10 24 10
DK-3450 Allerød Fax.: +45 48 10 24 01
> -----Original Message-----
> From: Alexandre Courbot [SMTP:Alexandre dot Courbot at lifl dot fr]
> Sent: Thursday, April 24, 2003 1:16 PM
> To: Cédric Lucantis; gcc-help at gcc dot gnu dot org
> Subject: Re: struct and members addresses
>
>
> > struct foo
> > {
> > any_type first_member;
> > };
> >
> > struct foo my_struct;
> >
> > void * addr1 = &my_struct;
> > void * addr2 = &my_struct.first_member;
> >
> > /* ----------------------------------*/
> >
> > can I be sure that `addr1' will be equal to `addr2' ?
>
> In C, I think you can safely. In C++, if your struct has virtual methods, the
> adress won't be the same since I think GCC puts the vtable at the beginning
> of the struct. But as long as you don't use virtuals, it should be ok AFAIK.
>
> Alex.
>