$ 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.
$ 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
Last active
September 11, 2023 18:10
-
-
Save osalbahr/796919bebe1d8960803c2a66f4d6ecfb to your computer and use it in GitHub Desktop.
`gcc-13` uninitialized value lack of warning after a loop?
$ 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 -Wpedantic' make uninitialized
gcc-13 -std=c99 -Wall -Wextra -Wpedantic uninitialized.c -o uninitialized
$ # No warning
$ 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' 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);
| ^~~~~~~~~~~~~~~~~
uninitialized.c:5:7: note: 'x' was declared here
5 | int x;
| ^
Or.... adding one more non-warning flag???
$ 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;
| ^
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;
^
uninitialized.c:5:8: note: initialize the variable 'x' to silence this warning
int x;
^
= 0
1 warning generated.
This file contains 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 characters
#include <stdio.h> | |
int main() | |
{ | |
int x; | |
for (int i = 0; i < 5; i++) | |
x += 1; | |
printf("%d\n", x); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the most surprising part, to me:
Bug 18501 goes a very long time ago: