Last active
September 11, 2023 18:10
Revisions
-
osalbahr revised this gist
Sep 11, 2023 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,20 @@ uninitialized.c:5:7: note: 'x' was declared here | ^ ``` ## Or.... [adding one more non-warning flag](https://stackoverflow.com/questions/30578625/why-is-there-not-any-warning-on-a-declaration-without-initialization-in-a-for-lo)??? ```console $ CC='gcc-13' CFLAGS='-O' make uninitialized gcc-13 -O uninitialized.c -o uninitialized $ rm uninitialized $ CC='gcc-13' CFLAGS='-Wall -O' make uninitialized gcc-13 -Wall -O uninitialized.c -o uninitialized uninitialized.c: In function 'main': uninitialized.c:5:7: warning: 'x' is used uninitialized [-Wuninitialized] 5 | int x; | ^ ``` # With `clang` ```console -
osalbahr revised this gist
Sep 11, 2023 . 1 changed file with 4 additions and 24 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,8 @@ int main() x += 1; printf("%d\n", x); } $ CC='gcc-13' CFLAGS='-std=c99 -Wall -Wextra -Wpedantic' make uninitialized gcc-13 -std=c99 -Wall -Wextra -Wpedantic uninitialized.c -o uninitialized $ # No warning ``` @@ -29,8 +29,8 @@ int main() // x += 1; printf("%d\n", x); } $ CC='gcc-13' CFLAGS='-std=c99 -Wall' make uninitialized gcc-13 -std=c99 -Wall uninitialized.c -o uninitialized uninitialized.c: In function 'main': uninitialized.c:8:3: warning: 'x' is used uninitialized [-Wuninitialized] 8 | printf("%d\n", x); @@ -54,23 +54,3 @@ uninitialized.c:5:8: note: initialize the variable 'x' to silence this warning = 0 1 warning generated. ``` -
osalbahr revised this gist
Sep 11, 2023 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -53,4 +53,24 @@ uninitialized.c:5:8: note: initialize the variable 'x' to silence this warning ^ = 0 1 warning generated. ``` - - - Edit: Ok, `-Wpedantic` does it, nvm ```console $ CFLAGS='-std=c99 -Wall -Wextra -Wpedantic' make uninitialized cc -std=c99 -Wall -Wextra -Wpedantic uninitialized.c -o uninitialized uninitialized.c:3:9: warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes] int main() ^ void uninitialized.c:7:5: warning: variable 'x' is uninitialized when used here [-Wuninitialized] x += 1; ^ uninitialized.c:5:8: note: initialize the variable 'x' to silence this warning int x; ^ = 0 2 warnings generated. ``` -
osalbahr renamed this gist
Sep 11, 2023 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,8 @@ gcc-13 -std=c99 -Wall -Wextra uninitialized.c -o uninitialized $ # No warning ``` ## Commenting-out the loop ```console $ cat uninitialized.c #include <stdio.h> @@ -41,7 +43,8 @@ uninitialized.c:5:7: note: 'x' was declared here # With `clang` ```console CC='clang' CFLAGS='-std=c99 -Wall' make uninitialized clang -std=c99 -Wall uninitialized.c -o uninitialized uninitialized.c:7:5: warning: variable 'x' is uninitialized when used here [-Wuninitialized] x += 1; ^ -
osalbahr revised this gist
Sep 11, 2023 . 2 changed files with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,4 +4,10 @@ gcc-13 (Homebrew GCC 13.2.0) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ clang --version Apple clang version 14.0.3 (clang-1403.0.22.14.1) Target: x86_64-apple-darwin22.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # With `gcc` (GNU) ```console $ cat uninitialized.c #include <stdio.h> @@ -34,4 +36,18 @@ uninitialized.c:8:3: warning: 'x' is used uninitialized [-Wuninitialized] uninitialized.c:5:7: note: 'x' was declared here 5 | int x; | ^ ``` # With `clang` ```console $ clang -Wall uninitialized.c uninitialized.c:7:5: warning: variable 'x' is uninitialized when used here [-Wuninitialized] x += 1; ^ uninitialized.c:5:8: note: initialize the variable 'x' to silence this warning int x; ^ = 0 1 warning generated. ``` -
osalbahr revised this gist
Sep 11, 2023 . 1 changed file with 14 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,20 @@ ```console $ cat uninitialized.c #include <stdio.h> int main() { int x; for (int i = 0; i < 5; i++) x += 1; printf("%d\n", x); } $ CC='gcc-13' CFLAGS='-std=c99 -Wall -Wextra' make uninitialized gcc-13 -std=c99 -Wall -Wextra uninitialized.c -o uninitialized $ # No warning ``` ```console $ cat uninitialized.c #include <stdio.h> -
osalbahr revised this gist
Sep 11, 2023 . 1 changed file with 9 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ #include <stdio.h> int main() { int x; for (int i = 0; i < 5; i++) x += 1; printf("%d\n", x); } -
osalbahr created this gist
Sep 11, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ ```console $ gcc-13 -std=c99 -Wall -Wextra $ CC='gcc-13' CFLAGS='-std=c99 -Wall -Wextra' make uninitialized gcc-13 -std=c99 -Wall -Wextra uninitialized.c -o uninitialized $ vim uninitialized.c $ cat uninitialized.c #include <stdio.h> int main() { int x; // for (int i = 0; i < 5; i++) // x += 1; printf("%d\n", x); } $ CC='gcc-13' CFLAGS='-std=c99 -Wall -Wextra' make uninitialized gcc-13 -std=c99 -Wall -Wextra uninitialized.c -o uninitialized uninitialized.c: In function 'main': uninitialized.c:8:3: warning: 'x' is used uninitialized [-Wuninitialized] 8 | printf("%d\n", x); | ^~~~~~~~~~~~~~~~~ uninitialized.c:5:7: note: 'x' was declared here 5 | int x; | ^ ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ ```console $ gcc-13 --version gcc-13 (Homebrew GCC 13.2.0) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ```