3 ms·
Would a memcpy into a uint16_t be less fragile?
by cesarb 8y ago
Would a memcpy into a uint16_t be less fragile?
- pjscott 8y agoJust tried this with godbolt.org and yes, the memcpy() thing is consistently good while the shift-and-or version often gets an unoptimized implementation (depending on compiler and version).
- beached_whale 8y agoIn C++, not necessarily C, memcpy is how you type pun. Seeing as they often are the same compiler it's probably the fastest way.
- amluto 8y agoIIRC memcpy is borderline UB here. It also has the same endianness problem.