https://stackoverflow.com/questions/25664848/unions-and-type-punning
4. THE SAFE CASE: unsigned char
The only safe manner of using type punning is with unsigned char or well unsigned char arrays (because we know that members of array objects are strictly contiguous and there is not any padding bytes when their size is computed with sizeof()).
union {
TYPE data;
unsigned char type_punning[sizeof(TYPE)];
} xx;
Since we know that unsigned char is represented in strict binary form, without padding bits, the type punning can be used here to take a look to the binary represention of the member data.
This tool can be used to analyze how values of a given type are represented, in a particular implementation.
I am not able to see another safe and useful application of type punning under the standard specifications.
探検
C++相談室 part149
■ このスレッドは過去ログ倉庫に格納されています
429デフォルトの名無しさん
2020/03/02(月) 17:53:41.95ID:AN3bmLPv■ このスレッドは過去ログ倉庫に格納されています
