uint32_t Seed() {
uint64_t seed = GetSomeReasonable64BitIntegerSeed();
return *(uint32_t*)&seed ^ *((uint32_t*)&seed + 1);
}
Above is not real code, but that's basically what the real code does. I got a warning from g++ that it violates strict aliasing, googled it, and okay I want to fix it. I found this question, but it doesn't give a clear solution other than using memcpy
, or relying on undefined but practically-no-problem behaviour, that is to access an unset member of a union.
The current options I can think of are,
- Use
memcpy
. - Use a
union
and compile this part as C, where the language standard allows type punning via unions.