Question about type punning: why does this code break strict aliasing rules:
int main()
{
int a = 1;
short j;
printf("%i
", j = *((short*)&a));
return 0;
}
and this is not:
int main()
{
int a = 1;
short j;
int *p;
p=&a;
printf("%i
", j = *((short*)p));
return 0;
}
Build by gcc -fstrict-aliasing
.
Thank you!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…