码迷,mamicode.com
首页 > 系统相关 > 详细

幾種方法實現C語言Macro for debug

时间:2016-07-08 00:07:42      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

1、

#include <stdio.h>
#include <stdlib.h>

#define DEBUG 1
#ifdef DEBUG
    #define DEBUG_PRINT(fmt, args...) fprintf(stdout, fmt, ##args) 
#else
    #define DEBUG_PRINT(fmt, args...)
#endif


void main()
{
    DEBUG_PRINT("China. File:%s, Line:%d\n",__FILE__,__LINE__);

    return;
}

 參考:C #define macro for debug

2、

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <stdarg.h>
 4 
 5 #define DEBUG 1
 6 //#undef DEBUG
 7 
 8 #define DEBUG_PRINT( ...)  9     do {if (DEBUG) fprintf(stdout, ##__VA_ARGS__); } while(0)
10 
11 
12 void main()
13 {
14     DEBUG_PRINT("China.\n");
15 
16     return;
17 }

參考:C #define macro for debugging

 

這兩個均是在GCC編譯環境下進行的。

 

幾種方法實現C語言Macro for debug

标签:

原文地址:http://www.cnblogs.com/xuanyuanchen/p/5651822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!