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■ このスレッドは過去ログ倉庫に格納されています
ニュース
- 「中国側も日本機のレーダーを感知していた」 中国メディアが報道 [♪♪♪★]
- 【YouTuber】バイク事故で入院のゆたぼん、振込で「お見舞金」募る [muffin★]
- 高市早苗首相、消費税減税に後ろ向き 足かせはレジシステム? 「責任ある積極財政」期待高いが [蚤の市★]
- 堀江貴文、キャッシュレス非対応の店にモヤッ 『PayPay』立ち上げの人物にまさかの直談判「現金決済しかできないんだけど…」 [冬月記者★]
- 低所得層のマクドナルド離れが深刻に 広がる「ファストフード格差」の真相 米国 [少考さん★]
- バリ島で男子生徒ら集団万引きか、防犯カメラ映像が拡散 京都の大谷中学・高校が「窃盗行為」謝罪★7 [七波羅探題★]
- 防衛省、中国を完全論破www 「事前通告があったのは海自であって空自ではない」 高市早苗勝利 [175344491]
- 乳首触らんと立たないやつ
- 【悲報】JA「全然米が売れなくて倉庫を圧迫してる。助けて!」米卸売り業者「安売りしたら赤字になる…助けて!」 [802034645]
- アパートに無理Wi-Fi
- htrktkni
- 小学受験に失敗したら人生終わる?
