|
|
|
|
|
by Joker_vD
893 days ago
|
|
double transmute_int_to_double(int x) {
double result = 0;
memcpy(&result, &x, sizeof(int) < sizeof(double) ? sizeof(int) : sizeof(double));
return result;
}
is not a UB, and it doesn't even necessarily touch any memory: transmute_int_to_double:
movd xmm0, edi
ret
[0] https://godbolt.org/z/czM3eh8er |
|
Not by my interpretation of n3096 (April 2023 ISO C draft).
> doesn't even necessarily touch any memory
The abstract semantics calls for memory being touched. Data flows that go through memory in the abstract semantics can be optimized not to go through memory. UB can do anything at all.