Object access using reinterpret_cast for “struct {double, int}”-like object
问题 Accessing objects via reinterpret_cast ed pointers and related UB has been extensively discussed here. After reading questions and answers, I'm still not sure about proper using uninitialized memory with POD types. Suppose I want to "emulate" struct { double d; int i; }; by manually allocating memory for data members and suppose (for simplicity) that no padding is needed before i . Now, I do this: // (V1) auto buff = reinterpret_cast<char*>(std::malloc(sizeof(double) + sizeof(int))); auto d