Questions tagged [standard-layout]
42 questions
1
vote
1 answer
"Merge" PODs into one
Is there a way to compose (or merge, aggregate) PODs between them ? One intuitive solution:
struct Base1 { int i; };
struct Base2 { char c; };
struct Derived : Base1, Base2 {};
// in a more generalized way
// template struct…

Arthur R.
- 323
- 2
- 7
1
vote
0 answers
Why does C++ StandardLayout disallow mixed access specifiers?
I hear often this is for backward compatibility with C. But C does not have access specifiers, so how can they break compatibility?
And a related question, why do mixed access specifiers allow the compiler to change the order of the members of a…

Patrick Fromberg
- 1,313
- 11
- 37
1
vote
0 answers
C++ types with standard layout in the context of interprocess communication
The standard states that
Standard layout types are useful for communicating with code written
in other programming languages.
But for interprocess communication on the same machine this is only true if the same member alignments are used, e.g.…

Patrick Fromberg
- 1,313
- 11
- 37
1
vote
0 answers
c++ - is there a way to have "inline" structs (similar to inline namespaces)
If I have two structs:
struct Base {
int a;
};
struct Derived : Base {
int b;
};
then with an instance Derived d, I can directly access a and b as d.a and d.b.
However with this setup, Derived isn't a standard layout type.
If I wanted to…

user1000039
- 785
- 1
- 7
- 19
1
vote
1 answer
Member of Union has User-Defined Constructor
For the following code:
class Foo{
int foo;
public:
Foo() : foo(13) {}
int getFoo() const { return foo; }
};
union Bar{
Foo fBar;
double dBar;
};
I believe this is fully legal in C++.…

Jonathan Mee
- 37,899
- 23
- 129
- 288
1
vote
0 answers
ABI-compatible shared_ptr implementation
I am working on a COM-style complier cross-compatible plugin framework relying on compatible virtual table implementations for ABI compatibility.
I define interfaces containing only pure virtual member functions and an overridden delete operator to…

Mart
- 135
- 1
- 10
1
vote
1 answer
Does a class need to be a standard layout type to be sure of the memory offsets of its members?
Lets say I want to write an intrusive list. I have an intrusive list class template that takes the type and a pointer to the member to use as the node. It looks roughly like this:
// This needs to be a member of anything the intrusive list is going…

Alex
- 14,973
- 13
- 59
- 94
1
vote
1 answer
Why are unions which have members with differing access control not standard-layout?
§9.0
7. A class S is a standard-layout class if it:
(7.3)
has the same access control (Clause
11
) for all non-static data members,
8
A
standard-layout struct
is a standard-layout class defined with the
class-key
struct
or the
…

OmnipotentEntity
- 16,531
- 6
- 62
- 96
1
vote
1 answer
C++ - standard-layout
According to the current C++ standard draft, a standard-layout class
either has no non-static data members in the most derived class and at most one base class with non-static data members, or has no base classes with non-static data members
I…

Hristo Venev
- 972
- 5
- 17
1
vote
0 answers
Effect of C++11 standard layout violation
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,…

Claas
- 389
- 1
- 3
- 5
0
votes
0 answers
POD-types and inheritance in c++11: Why is it not possible to inherit and extend, and still be a POD-type
I think this is best explained with an example:
#include
struct A
{
int a;
};
struct B
{
A a;
int b;
};
struct C: A
{
int c;
};
static inline std::ostream& operator<< (std::ostream& os, const A& a)
{ return os <<…

Troels Blum
- 823
- 8
- 17
0
votes
1 answer
Why is a class with multiple public access specifiers standard_layout?
I was just playing around with g++, and I found that
#include
class Foo {
public: int x;
public: char y;
public: double z;
};
static_assert(std::is_standard_layout::value, "Foo is not standard layout");
int main() {}
Compiles…

math4tots
- 8,540
- 14
- 58
- 95