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

layout compatible question

P: n/a
I was wondering, does this meet the criteria for "layout compatible" in
the C++ specification?

struct A {
int a[5];
};

struct B {
A b[4];
};

B obj;
int (&array)[4][5] = reinterpret_cast<int (&)[4][5]>(obj);

Regards,
Adrian
--
__________________________________________________ ___________________
\/Adrian_Hawryluk BSc. - Specialties: UML, OOPD, Real-Time Systems\/
\ _---_ Q. What are you doing here? _---_ /
\ / | A. Just surf'n the net, teaching and | \ /
\__/___\___ learning, learning and teaching. You?_____/___\__/
\/______[blog:__http://adrians-musings.blogspot.com/]______\/
Mar 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Adrian Hawryluk wrote:
I was wondering, does this meet the criteria for "layout compatible"
in the C++ specification?

struct A {
int a[5];
};

struct B {
A b[4];
};

B obj;
int (&array)[4][5] = reinterpret_cast<int (&)[4][5]>(obj);

Regards,
I am not sure how to answer, but I am concerned that sizeof(A) is
not necessarily sizeof(int[5]), which means that sizeof(A[4]) is not
necessaruly sizeof(int[4][5]). An 'A' object can have padding added
to its 'a' member, while in an array of four arrays of five int there
will be no padding.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Mar 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.