> What if we had this: > uint32_t u = 0x12345678; > upal_u32be_t tempb; > memcpy (&tempb, &u, sizeof(uint32_t)); > uint32_t bu = tempb.val; > > Is that valid? We still run into the wrong code with the above case. > memcpy here should be considered a byte-by-byte copy and therefor > should not have any type punning except for to bytes.
The usual trick of people doing type punning and pretending they don't. ;-) No, this cannot work as-is, although it's probably fixable by blocking the propagation through the memcpy in case the scalar order is flipped, unlike the previous example. -- Eric Botcazou