3 ms·
lol, how the compiler didn't warn about uninitialized variable
by piadodjanho 6y ago
lol, how the compiler didn't warn about uninitialized variable
- sigjuice 6y agoCompiler warnings are not straightforward and depend on many things; compiler version, optimization settings, warning settings. $ gcc-9 -Wuninitialized -O0 float.c # NO WARNINGS!!! $ gcc-9 -O1 float.c # NO WARNINGS!!! $ gcc-9 -Wuninitialized -O1 float.c float.c: In function 'main': float.c:9:5: warning: 'i' is used uninitialized in this function [-Wuninitialized] 9 | for (size_t i; i < (1ul << 33); i++) { | ^~~
- piadodjanho 6y agoWeirdly, those two codes behaves differently: $ gcc hn.c -O0 -o hn for (size_t i; i < (1ul<<46); i++) { printf ("%zd\n",i); acc += x; break; } Without break: $ gcc hn.c -O0 -o hn for (size_t i; i < (1ul<<46); i++) { printf ("%zd\n",i); acc += x; }