作为一个例子, 假设用 calls 处理下面的程序:
#include <stdio.h>
static void my_print (char *);
static void my_print2 (char *);
main ()
{
char my_string[] = "hello world!";
my_print (my_string);
my_print2 (my_string);
my_print (my_string);
}
void count_sum()
{
int i,sum=0;
for(i=0; i<1000000; i++)
sum += i;
}
void my_print (char *string)
{
count_sum();
printf ("The string is %s\n", string);
}
void my_print2 (char *string)
{
char *string2;
int size, i,sum =0;
count_sum();
size = strlen (string);
string2 = (char *) malloc (size + 1);
for (i = 0; i < size; i++) string2[size -1 - i] = string;
string2[size] = 0;
for(i=0; i<5000000; i++)
sum += i;
printf ("The string printed backward is %s\n", string2);
}
将产生如下的输出:
1 __underflow [hello.c]
2 main
3 my_print [hello.c]
4 count_sum [hello.c]
5 printf
6 my_print2 [hello.c]
7 count_sum
8 strlen
9 malloc
10 printf
calls 有很多命令行选项来设置不同的输出格式, 有关这些选项的更多信息请参考 cal
ls 的指南页. 方法是在命令行上键入 calls -h .
calltree
calltree与calls类似,初了输出函数调用树图外,还有其它详细的信息。
可以从sunsite.unc.edu FTP 站点用下面的路径:/pub/Linux/devel/lang/c/calltree.
tar.gz得到calltree.
cproto
cproto 读入 C 源程序文件并自动为每个函数产生原型申明. 用 cproto 可以在写程序
时为你节省大量用来定义函数原型的时间.
如果你让 cproto 处理下面的代码(cproto hello.c):
#include <stdio.h>
static void my_print (char *);
static void my_print2 (char *);
main ()
{
char my_string[] = "hello world!";
my_print (my_string);
my_print2 (my_string);
}
void my_print (char *string)
{
printf ("The string is %s\n", string);
}
void my_print2 (char *string)
{
char *string2;
int size, i;
size = strlen (string);
string2 = (char *) malloc (size + 1);
for (i = 0; i < size; i++)
string2[size -1 - i] = string;
string2[size] = 0;
printf ("The string printed backward is %s\n", string2);
}
你将得到下面的输出:
/* hello.c */
int main(void);
int my_print(char *string);
int my_print2(char *string);
这个输出可以重定向到一个定义函数原型的包含文件里.
indent
indent 实用程序是 Linux 里包含的另一个编程实用工具. 这个工具简单的说就为你的
代码产生美观的缩进的格式. indent 也有很多选项来指定如何格式化你的源代码.这些
选项的更多信息请看indent 的指南页, 在命令行上键入 indent -h .
下面的例子是 indent 的缺省输出:
运行 indent 以前的 C 代码:
#include <stdio.h>
static void my_print (char *);
static void my_print2 (char *);
main ()
{
char my_string[] = "hello world!";
my_print (my_string);
my_print2 (my_string);
}
void my_print (char *string)
{
printf ("The string is %s\n", string);
}
void my_print2 (char *string)