By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,226 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,226 IT Pros & Developers. It's quick & easy.

allignment of structure

P: n/a
Hi,
I've got a question about the allignment of data in a structure.
What happens in memory when i declare the following

struct A
{
int x;
}
stuct B : public A
{
int y;
}

Is it compiler specific how the memory is alligned when I instance B?
Or can do something like this:

B b;
int* z = &(reinterpret_cast<int>(b)); //z point to x
z++; //z points to y

Or does the VTABLE pointer cause problems here?

Thanks in regard,
Anthony Lansbergen
Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Anthony" <an*****@EdAsys.E-is-A.A-is-E.nl> wrote...
I've got a question about the allignment of data in a structure.
What happens in memory when i declare the following

struct A
{
int x;
}
stuct B : public A
{
int y;
}

Is it compiler specific how the memory is alligned when I instance B?
Yes.
Or can do something like this:

B b;
int* z = &(reinterpret_cast<int>(b)); //z point to x
z++; //z points to y
Most likely you can't. The Standard imposes no requirement on
the behaviour of such code. It's called "undefined behaviour".

Or does the VTABLE pointer cause problems here?


There is no such thing in the language as "VTABLE pointer". If
you're talking of a very common way to implement virtual function
mechanism in the language, then what does it matter here? Your
structs have no virtual functions.

Victor
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.