Reputation: 2309
Given:
inline uint16_t Hash3_x86_16(const void* key, int len, uint32_t seed)
{
uint32_t hash32;
Hash3_x86_32(key, len, seed, &hash32);
return (reinterpret_cast<uint16_t*>(&hash32)[1] | reinterpret_cast<uint16_t*>(&hash32)[0]);
}
What is the correct/best fix to prevent GCC from giving the following warning?
warning: dereferencing type-punned pointer will break strict-aliasing rules
Upvotes: 2
Views: 97
Reputation: 38463
Bit shifting:
return static_cast<uint16_t>(hash32 | (hash32 >> 16));
Upvotes: 4