[ub] Type punning to avoid copying

Ion Gaztañaga igaztanaga at gmail.com
Fri Jul 26 00:06:44 CEST 2013


El 25/07/2013 17:45, Gabriel Dos Reis escribió:
> If that analysis is correct, I would welcome a rule in the language that
> says that memcpy() into an object of type that admits no trap
> representation is equivalent to initialization with value obtained from
> appropriate interpretation of the value representation bits of the
> "initializing byte" sequence.

Why can't we memcpy to a type that admits a trap representation (say, a 
float with a signaling NaN value)? If we know about that representation 
is in our system, the programmer should be responsible for not creating 
such bit pattern before copying it to the destination. Couldn't we write:

float f_uninitialized;
std::memcpy(&f_uninitialized, &i32, sizeof(i32));

?

Best,

Ion


More information about the ub mailing list