matthew@seymour:~$ gcc -o tux tux.c
matthew@seymour:~$ ./tux
But the splint command might point out some serious problems with the
source:
Click here to view code image
matthew@seymour:~$ splint tux.c
Splint 3.1.2 -- 29 Apr 2009
tux.c: (in function main)
tux.c:2:19: Return value (type int) ignored: putchar(t[++j] -...
Result returned by function call is not used. If this is intended,
can cast
result to (void) to eliminate message. (Use -retvalint to inhibit
warning)
Finished checking -- 1 code warning
You can use the splint command’s -strict option, like this, to get a more
verbose report:
Click here to view code image
matthew@seymour:~$ splint -strict tux.c
gcc also supports diagnostics through the use of extensive warnings (through
the -Wall and -pedantic options):
Click here to view code image
matthew@seymour:~$ gcc -Wall tux.c
tux.c:1: warning: return type defaults to 'int'
tux.c: In function 'main':
tux.c:2: warning: implicit declaration of function 'putchar'
Using gprof to Track Function Time
You use the gprof (profile) command to study how a program is spending
its time. If a program is compiled and linked with -p as a flag, a mon.out
file is created when it executes, with data on how often each function is called
and how much time is spent in each function. gprof parses and displays this
data. An analysis of the output generated by gprof helps you determine
where performance bottlenecks occur. Using an optimizing compiler can
speed up a program, but taking the time to use gprof’s analysis and revising
bottleneck functions significantly improves program performance.