What are primitive types default-initialized to in C++?

You are not correct. The object is not default-initialized but value-initialized. And its value is well-defined

int = 0, 
bool = false, 
float = 0.0f,  
enum = (enum type)0, 
pointer = null pointer
pointer to member = null member pointer

Note that zero is in the range of values for any enumeration, even if it doesn’t contain an explicit enumerator with that vaue, so it’s safe to initialize an enumeration variable to that value.

In particular for pointer to data members, the representation used in practice is not all-zero bits. In the so-called C++ Itanium ABI used by at least GCC and Clang, pointer to data members have an all-one bits null representation.

Leave a Comment