在代码中写入
不用debug的结果(死循环)
#ifdef DEBUG
#endif
编译时用 gcc –DDEBUG –g –o *** ***.c 此时运行的结果是有debug信息的 , gcc –o *** ***.c 无debug 信息 ,如
# include <stdio.h>
int main ()
{ int i=0 ;
while (1) {
printf ("hello world\t") ;
i++ ;
printf ("time=%d\n",i);
#ifdef DEBUG
if (i>10)
break ;
#endif
}
return 0 ;
}
/*
打开debug 的结果
gcc -DDEBUG -o debug debug.c

gcc -o debug debug.c

本文介绍如何使用GCC编译器通过定义DEBUG宏来控制程序中的调试信息。当编译时加入-DDEBUG标志,程序会在运行到指定条件时退出,避免无限循环,便于调试。

273

被折叠的 条评论
为什么被折叠?



