layout compatible question

A

Adrian Hawryluk

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/]______\/
 
V

Victor Bazarov

Adrian said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top