This is the mail archive of the gcc-help@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: 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.


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