From c9e0845c7f4b55597349ed2d3de57646fa680aeb Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 23 Nov 2015 15:15:41 -0500 Subject: [PATCH] Aliasing through a union member is valid. Take back my previous TODO. --- source/endian.cpp | 4 +++- test/UnitSPIRV.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/endian.cpp b/source/endian.cpp index 39ecbcc..8c39f29 100644 --- a/source/endian.cpp +++ b/source/endian.cpp @@ -33,7 +33,9 @@ enum { I32_ENDIAN_BIG = 0x00010203ul, }; -// TODO(dneto): This relies on undefined behaviour. Fix that. +// This constant value allows the detection of the host machine's endianness. +// Accessing it through the "value" member is valid due to C++11 section 3.10 +// paragraph 10. static const union { unsigned char bytes[4]; uint32_t value; diff --git a/test/UnitSPIRV.h b/test/UnitSPIRV.h index 1545915..808ad5e 100644 --- a/test/UnitSPIRV.h +++ b/test/UnitSPIRV.h @@ -61,8 +61,6 @@ enum { I32_ENDIAN_BIG = 0x00010203ul, }; -// TODO(dneto): Using a union this way relies on undefined behaviour. -// Replace this with uses of BitwiseCast from util/bitutils.h static const union { unsigned char bytes[4]; uint32_t value; -- 2.7.4