Skip to content

Instantly share code, notes, and snippets.

@nibrahim
Created August 19, 2013 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nibrahim/6265814 to your computer and use it in GitHub Desktop.
Save nibrahim/6265814 to your computer and use it in GitHub Desktop.
gcc failing to give warnings
#include <stdio.h>
void test()
{
int iters;
while(iters++ <= 100) {
printf("%d\n", iters);
}
}
int main()
{
test();
return 0;
}
# 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