Effect of C++11 standard layout violation

106 views Asked by At

Possible Duplicate:
Why can’t you use offsetof on non-POD strucutures in C++?

I have two classes:

struct A{
  double one;
  float two;
};

struct B : public A{
  float three;
};

If I interpretete the C++11 standard layout restrictions correctly, then B is not standard layout, because both B and A have non-static data members. I would like to use a construct like B in combination with HDF5, which requires the use of the offsetof macro, which (to my knowledge) is restricted to standard-layout objects. My question is, what could go wrong, with an expression like

offsetof(B, three)

It works fine with gcc-4.6, but has anybody ever encountered unexpected behaviour in a similar situation? If so, which one and with which compiler? What is the worst case scenario?

Regards Claas

0

There are 0 answers