GCC: accuracy of strict aliasing warnings
问题 I'm trying to check some of my code for strict aliasing violations, but it looks like I've missed something while trying to understand the strict aliasing rule. Imagine the following code: #include <stdio.h> int main( void ) { unsigned long l; l = 0; *( ( unsigned short * )&l ) = 1; printf( "%lu\n", l ); return 0; } Classic and basic example. With GCC 4.9 ( -Wall -fstrict-aliasing -Wstrict-aliasing -O3 ), it actually reports the error: dereferencing type-punned pointer will break strict