#include<stdio.h>
#include<stdlib.h>
int main()
{
#ifdef DEBUG
printf("Compiled: " __DATE__ " at " __TIME__"\n" );
printf("This is line %d of file %s\n",__LINE__,__FILE__);
#endif
printf("Hello world\n");
return 0;
}
gcc -o debug_info -DDEBUG debug_info.c
Compiled: May 29 2016 at 21:52:49
This is line 7 of file debug_info.c
Hello world
###可变参数打印函数
#define va_list char*
#define va_start(ap,arg) (ap =(va_list)&arg + sizeof(arg))
#define va_arg(ap,t) ( * (t*)( (ap += sizeof(t)) - sizeof(t) ))
#define va_end(ap) (ap =(va_list)0)
具体参考 程序员的自我修养—链接 装载与库一书
#include <stdarg.h>
void R_OUTPUT(int dwRTSwitch, int dwDebugLevel, char* pchDebugInfo, ...)
{
static char achBuf[1024];
va_list ArgList;
if ((dwRTSwitch & dwDebugLevel) != 0)
{
(void)va_start(ArgList, pchDebugInfo);
(void)vsprintf(achBuf, pchDebugInfo,ArgList);
va_end(ArgList);
printf((char *)achBuf);
}
}