struct and members addresses

Agust Karlsson Gusti@pallas.dk
Thu Apr 24 11:18:00 GMT 2003


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@pallas.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.Courbot@lifl.fr]
> Sent:	Thursday, April 24, 2003 1:16 PM
> To:	Cédric Lucantis; gcc-help@gcc.gnu.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.
> 



More information about the Gcc-help mailing list