On Sun, Nov 10, 2024 at 11:04 PM Brian Bi <bbi5291@gmail.com> wrote:
Unless I've misunderstood, the C23 draft appears to say that as soon as you write to any member of a struct, all padding bits are reset to unspecified values.
6.2.6.1/6: When a value is stored in an object of structure or union type, including in a member object, the bytes of the object representation that correspond to any padding bytes take unspecified values [...]
That seems to prevent the use of `memcmp` for comparing the values of struct objects in most cases.
Or is the C standard only talking about writes of struct type? (Which, as you probably know, don't exist in C++: an assignment operator, possibly a trivial one, is always called.)
--
Brian Bi
The number of cases for memcmp would be not as wide as one hoped, but still good enough. The way I read the C standard, it is also about member wise modifications as well, basically anything that changes the value, but not clear if they bless changing padding bits in the code - though for something like __builtin_clear_padding it has to be possible.
-Mykola