4 ms·
> Not by my interpretation of n3096 (April 2023 ISO C draft). What clause(s) support the claim that that example is UB? At least at first glance it looks prett
by aw1621107 3y ago
> Not by my interpretation of n3096 (April 2023 ISO C draft).
What clause(s) support the claim that that example is UB? At least at first glance it looks pretty similar to the sometimes-recommended way to perform safe type-punning in C, and the only way to "directly" invoke UB via memcpy (passing pointers to overlapping objects) isn't relevant here.
The only suspicious part to me is the size/number of bytes to copy, but I'm not sure that's outright UB?
- kazinator 3y agoWe have no idea whether the bytes that were copied into that object are a valid representation.
- aw1621107 3y agoAh, I didn't think of that. That being said, is there a representation for doubles that could be considered invalid? I thought all double bit patterns are interpretable as a "valid" double, even if you get NaNs.