编译器内置宏与调试输出

ANSI C标准中有几个常用的标准预定义宏:

LINE:在源代码中插入当前源代码行号;

FILE:在源文件中插入当前源文件名;

DATE:在源文件中插入当前的编译日期

TIME:在源文件中插入当前编译时间;

STDC:当要求程序严格遵循ANSI C标准时该标识被赋值为1;

__cplusplus:当编写C++程序时该标识符被定义。

头文件 debug_macro.h

#ifndef DEBUG_MACRO_H
#define DEBUG_MACRO_H

#include <stdio.h>

#ifdef __DEBUG

#define DEBUG(formate, ...) fprintf(stderr,"FILE:"__FILE__"\nLINE%d:\n""error:"formate"\n", __LINE__, ##__VA_ARGS__)/*如果__VA_ARGS__为空则去掉逗号*/
#else

#endif

#endif

posted on 2016-06-06 22:26  shaolw  阅读(511)  评论(0编辑  收藏  举报

导航