I have the following code, saved on Coding Ground here:
#include <stdio.h>
void foo(int const *x)
{
printf("Hello, %d!\n", *x);
}
int main()
{
int y;
foo(&y);
y = 3;
printf("Hello, World %d!\n", y);
return 0;
}
I compile with:
gcc -std=c99 -Wall -Wextra -Wuninitialized -o main *.c
However, I get no warning about taking a const pointer of an uninitialised variable, and I cannot find a suitable flag.
Note: pasting the code into Gimpel's Online Lint gives me the expected:
test.c 12 Warning 603: Symbol 'y' (line 10) not initialized
-Wuninitialized Warn whenever an automatic variable is used without first being initialized.
These warnings are possible only in optimizing compilation, because they require data-flow information that is computed only when optimizing. If you don't specify `-O', you simply won't get these warnings.
If you try to compile with:
gcc -std=c99 -Wall -Wextra -Wuninitialized -O2 -o main *.c
The warning will be:
pippo.c: In function ‘main’:
pippo.c:56:5: warning: ‘y’ is used uninitialized in this function [-Wuninitialized]
printf("Hello, %d!\n", *x);
^
pippo.c:61:9: note: ‘y’ was declared here
int y;
^