standard-layout Questions

1

Solved

In C++17 there is normative text [class.mem]/17: Non-static data members of a (non-union) class with the same access control (Clause 14) are allocated so that later members have higher addresse...
Breana asked 4/5, 2020 at 11:3

2

In C++20, the concept of POD is deprecated, supposedly because it is a meaningless composite trait of being trivial and standard-layout. However, the definition of POD in the C++20 draft is not exa...
Turanian asked 8/11, 2019 at 18:51

2

Solved

Consider the following simple struct: struct A { float data[16]; }; My question is: Assuming a platform where float is a 32-bit IEEE754 floating point number (if that matters at all), does the...
Mistral asked 12/4, 2019 at 11:38

5

Solved

David Hollman recently tweeted the following example (which I've slightly reduced): struct FooBeforeBase { double d; bool b[4]; }; struct FooBefore : FooBeforeBase { float value; }; static_as...
Alurd asked 18/12, 2018 at 16:32

6

This FAQ is about Aggregates and PODs and covers the following material: What are aggregates? What are PODs (Plain Old Data)? More recently, what are trivial or trivially copyable types? How are t...
Luciana asked 14/11, 2010 at 15:35

1

Look at this code: struct A { short s; int i; }; struct B { short s; int i; }; union U { A a; B b; }; int fn() { U u; u.a.i = 1; return u.b.i; } Is it guaranteed that fn() returns 1? ...
Bunt asked 29/10, 2018 at 17:45

1

Solved

std::is_pod has been deprecated in C++20. What's the reason for this choice? What should I use in place of std::is_pod to know if a type is actually a POD?
Unrivalled asked 12/1, 2018 at 11:46

3

Solved

Today I've encountered some code that roughly looks like the following snippet. Both valgrind and UndefinedBehaviorSanitizer detected reads of uninitialized data. template <typename T> void ...

2

Solved

The C++ standard specifies that mutex, atomics or conditinal_variable are of standard-layout type. What is the benefit of this specification? How a user can take advantage of this property? And i...
Culminant asked 27/9, 2017 at 13:20

3

Solved

C++11 allowed the use of standard layout types in a union: Member of Union has User-Defined Constructor My question then is: Am I guaranteed the custom destructor will be called, when the union go...
Kaifeng asked 18/10, 2016 at 11:24

1

Solved

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++. http...

3

While thinking of a counter-example for this question, I came up with: struct A { alignas(2) char byte; }; But if that's legal and standard-layout, is it layout-compatible to this struct B? st...
Salyers asked 1/2, 2014 at 15:33

1

Solved

I need to write to individual bytes of some integer types. Should I used reinterpret_cast, or should I use static_cast via void*? (a) unsigned short v16; char* p = static_cast<char*>(static...
Northwest asked 8/7, 2014 at 8:22

1

Solved

I'm writing a class that, assuming the answer to Are enumeration types layout compatible with their underlying type? is "yes", is layout-compatible struct kevent but uses enum classes for filter, f...
Elexa asked 22/2, 2014 at 15:30

1

From what I understand, standard layout allows three things: Empty base class optimization Backwards compatibility with C with certain pointer casts Use of offsetof Now, included in the library...
Anglaangle asked 13/4, 2013 at 23:58

1

Solved

According to the C++ standard: A standard-layout class is a class that: —has no non-static data members of type non-standard-layout class (or array of such types) or reference. What pr...
Paresh asked 13/4, 2013 at 23:24

1

Solved

A piece of code is worth a thousands words. #include <iostream> #include <type_traits> using namespace std; struct A { int a; }; struct B : A { int b; }; int main() { cout <&...
Study asked 16/12, 2012 at 10:32

1

Solved

I was going through great articles on C++ POD, Trivial and Standard Layout classes One property I haven't clearly understood about standard layout is the following:- A standard layout has no base...
Vip asked 2/7, 2012 at 20:6

4

Solved

I am wrapping a simple C++ inheritance hierarchy into "object-oriented" C. I'm trying to figure out if there any gotchas in treating the pointers to C++ objects as pointers to opaque C structs. In ...
Flowerless asked 6/2, 2012 at 22:50

3

Solved

The C++11 standard guarantees that byte-for-byte copies are always valid for POD types. But what about certain trivial types? Here's an example: struct trivial { int x; int y; trivial(int i) :...
Eisenhower asked 24/9, 2011 at 0:32

6

Solved

I'm looking into the new, relaxed POD definition in C++11 (section 9.7) A standard-layout class is a class that: has no non-static data members of type non-standard-layout class (or array o...
Putrid asked 23/8, 2011 at 12:16
1

© 2022 - 2024 — McMap. All rights reserved.