int64_t v;
};
std::vector<char> buffer = stream.read(sizeof(A));//throws if unable to read requested amount
auto p = reinterpret_cast<A*>(buffer.data());
std::cout << p->v << std::endl;
есть тут UB или нет?
Есть. Можно насколько я понимаю в другую сторону - обратиться к готовому A через указатель на char.
оч сложный вопрос
короче: 1) For trivially copyable types, the value representation is a set of bits in the object representation that determines a value, which is one discrete element of an implementation-defined set of values. 2) For any object (other than a potentially-overlapping subobject) of trivially copyable type T, whether or not the object holds a valid value of type T, the underlying bytes ([intro.memory]) making up the object can be copied into an array of char, unsigned char, or std::byte ([cstddef.syn]).38 If the content of that array is copied back into the object, the object shall subsequently hold its original value. 3) For any trivially copyable type T, if two pointers to T point to distinct T objects obj1 and obj2, where neither obj1 nor obj2 is a potentially-overlapping subobject, if the underlying bytes ([intro.memory]) making up obj1 are copied into obj2,39 obj2 shall subsequently hold the same value as obj1.
Обсуждают сегодня