#include #include #ifndef MY_S_IS_LOCAL struct my_s { int a[128]; int b[128]; int c[128]; int d[128]; } my_s; #endif /* MY_S_IS_LOCAL */ int main(int ac, char *av[]) { #ifdef MY_S_IS_LOCAL struct my_s { int a[128]; int b[128]; int c[128]; int d[128]; } my_s; #endif /* MY_S_IS_LOCAL */ /* silence warnings about unused variables*/ (void)ac; (void)av; (void)my_s; for(int i=0; i< 256; i++) { my_s.b[i]=0xdeadbeef; } /* prevent optimiser from eliminating |my_s| */ (void)&my_s; return EXIT_SUCCESS; } ############################################## # warnings are generated for global variables... $ g++ -g -gdwarf-2 -O2 -Wall -Wextra -Waggressive-loop-optimizations x.cpp x.cpp: In function ‘int main(int, char**)’: x.cpp:33:23: warning: iteration 128u invokes undefined behavior [-Waggressive-loop-optimizations] my_s.b[i]=0xdeadbeef; ^ x.cpp:31:2: note: containing loop for(int i=0; i< 256; i++) ^ # ... but NO warnings are generated for local variables $ g++ -g -gdwarf-2 -DMY_S_IS_LOCAL -O2 -Wall -Wextra -Waggressive-loop-optimizations x.cpp $ # EOF.