Does the following program invoke any undefined behavior? In particular, does it break any strict aliasing rules?
void zeroInt(unsigned char *mem) {
*reinterpret_cast<int *>(mem) = 0;
}
int main() {
int value;
zeroInt(reinterpret_cast<unsigned char *>(&value));
return value;
}
I compiled it with gcc using -O2 -Wstrict-aliasing=3
and it didn't complain, however the gcc docs say that it doesn't catch all cases.