By default, gcc
runs in a rather permissive mode. You can get a warning by adding, for example:
gcc -Wall -c yourfile.c
asking for all the main warnings. (There are more warnings you can asl for: -Wextra
adds a bunch.) You might also specify -std=c99
(and maybe -pedantic
) in order to get more warnings.
C99 requires functions to be defined or declared before they are used.
$ gcc -O3 -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition -c warn.c
warn.c:4:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
warn.c: In function ‘main’:
warn.c:4:5: warning: old-style function definition [-Wold-style-definition]
warn.c:9:4: warning: implicit declaration of function ‘isgraph’ [-Wimplicit-function-declaration]
warn.c:10:4: warning: implicit declaration of function ‘isupper’ [-Wimplicit-function-declaration]
warn.c:9:8: warning: unused variable ‘g’ [-Wunused-variable]
$
That's the output of GCC 4.7.1 (on Mac OS X 10.7.5) with the standard set of compilation options I use — run on your source code stashed in a file warn.c
.