-
-
Save nibrahim/6265814 to your computer and use it in GitHub Desktop.
gcc failing to give warnings
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> | |
void test() | |
{ | |
int iters; | |
while(iters++ <= 100) { | |
printf("%d\n", iters); | |
} | |
} | |
int main() | |
{ | |
test(); | |
return 0; | |
} |
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
# With gcc | |
noufal@sanitarium% CFLAGS=-Wall make foo | |
cc -Wall foo.c -o foo | |
# With clang | |
noufal@sanitarium% CFLAGS=-Wall CC==clang make foo | |
/home/noufal/local/bin//clang -Wall foo.c -o foo | |
foo.c:7:9: warning: variable 'iters' is uninitialized when used here [-Wuninitialized] | |
while(iters++ <= 100) { | |
^~~~~ | |
foo.c:5:12: note: initialize the variable 'iters' to silence this warning | |
int iters; | |
^ | |
= 0 | |
1 warning generated. | |
# Using valgrind | |
noufal@sanitarium% valgrind ./foo | |
==15231== Memcheck, a memory error detector | |
==15231== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. | |
==15231== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info | |
==15231== Command: ./foo | |
==15231== | |
==15231== Conditional jump or move depends on uninitialised value(s) | |
==15231== at 0x40050B: test (in /tmp/foo) | |
==15231== by 0x400553: main (in /tmp/foo) | |
==15231== | |
. | |
. | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment