This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: struct and members addresses
- From: Alexandre Courbot <Alexandre dot Courbot at lifl dot fr>
- To: Cédric Lucantis <cedric dot lucantis at caramail dot com>, gcc-help at gcc dot gnu dot org
- Date: Thu, 24 Apr 2003 13:16:23 +0200
- Subject: Re: struct and members addresses
- References: <1051182045025865@lycos-europe.com>
> 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.