c语言调试开关

上一篇转载的没看懂,参考别人的代码,自己又琢磨了一个调试技巧,挺好用,姑且就叫调试开关吧,欢迎指正!!!

/*功能:调试开关
 *描述:if条件成立,则打印调试信息,否则不打印()
 *
*/

#include<stdio.h>
#if 1           //为0时调试关闭, 为1时调试打开
#define DEBUG_OUT(fmt, args...)\
printf("file:%s func:%s line:%d\n", __FILE__, __func__, __LINE__)

#else
#define DEBUG_OUT(fmt, args...) ((void)0)
#endif
int main(void)
{
    int i;
    for(i = 0; i < 4; i++){
        printf("i = %d\n", i);
    }
    print();
    DEBUG_OUT();
    return 0;
}

int print(void)
{
    printf("hello world\n");
    DEBUG_OUT();
    return 0;
}
-- 插入

 

如上代码:

1__FILE__ 打印出调试信息所在的文件名;

2__func__ 将会打印出调试信息所在的函数名;

3__LINE__ 将会打印出调试信息所在文件的行号;

运行结果:

[root@embedclub test]# gcc -o debug debug.c
[root@embedclub test]# ./debug
i = 0
i = 1
i = 2
i = 3
hello world
file:debug.c func:print line:28
file:debug.c func:main line:21

转载于:https://www.cnblogs.com/flash610/p/debug_out.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值