在编程的过程中使用__FILE__ __LINE__ __DATE__ __TIME__可以更好的定位问题解决问题。
在vs2005中:
// macroTest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT (__DATE__"-"__TIME__"-"__FILE__ "-" TOSTRING(__LINE__))
#define chSTR2(x) #x
#define chSTR(x) chSTR2(x)
#define chMSG(desc) message(__FILE__ "(" chSTR(__LINE__) "):" #desc)
#pragma chMSG(Fix this later)
void error(const char *location, const char *msg)
{
printf("%s: %s\n", location, msg);
}
int _tmain(int argc, _TCHAR* argv[])
{
error(AT, "fake error");
return 0;
}
在vs2005中
在vc6中
由上可见在vc6中对于__LINE__还是有些问题。
在vs2010中,__FUNCTION__默认是可以用的。