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


At 13.00 24/04/2003 +0100, Cédric Lucantis wrote:
Hello

   I would like to know if I can assume that a structure and its first member
will always have the same address. For instance, with the following code:

/* ----------------------------------*/

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' ?

thanks

I think so. IF yours is a simple struct, ie. no hereditaritey or any C++ thing.

You can check that offsetof (my_struct, first_member) is 0.

.fwyzard.


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