Tutorial by Examples

Whereas inside a Translation Unit, order of initialization of global variables is specified, order of initialization across Translation Units is unspecified. So program with following files foo.cpp #include <iostream> int dummyFoo = ((std::cout << "foo"), 0); b...
If a scoped enum is converted to an integral type that is too small to hold its value, the resulting value is unspecified. Example: enum class E { X = 1, Y = 1000, }; // assume 1000 does not fit into a char char c1 = static_cast<char>(E::X); // c1 is 1 char c2 = static_cast<c...
If a void* value is converted to a pointer to object type, T*, but is not properly aligned for T, the resulting pointer value is unspecified. Example: // Suppose that alignof(int) is 4 int x = 42; void* p1 = &x; // Do some pointer arithmetic... void* p2 = static_cast<char*>(p1) + 2; ...
The result of a reinterpret_cast from one function pointer type to another, or one function reference type to another, is unspecified. Example: int f(); auto fp = reinterpret_cast<int(*)(int)>(&f); // fp has unspecified value C++03 The result of a reinterpret_cast from one object poi...
If two pointers are compared using <, >, <=, or >=, the result is unspecified in the following cases: The pointers point into different arrays. (A non-array object is considered an array of size 1.) int x; int y; const bool b1 = &x < &y; // unspecified int ...
A reference is not an object, and unlike an object, it is not guaranteed to occupy some contiguous bytes of memory. The standard leaves it unspecified whether a reference requires any storage at all. A number of features of the language conspire to make it impossible to portably examine any storage ...
If a function has multiple arguments, it is unspecified what order they are evaluated in. The following code could print x = 1, y = 2 or x = 2, y = 1 but it is unspecified which. int f(int x, int y) { printf("x = %d, y = %d\n", x, y); } int get_val() { static int x = 0; r...
C++11 All standard library containers are left in a valid but unspecified state after being moved from. For example, in the following code, v2 will contain {1, 2, 3, 4} after the move, but v1 is not guaranteed to be empty. int main() { std::vector<int> v1{1, 2, 3, 4}; std::vector&l...

Page 1 of 1