Type: Note
Intro
C++ Macro 筆記
#define GetObjName(x) #x
#define DebugPrint(msg) printf("%s ; %s ; %s ; %d\n", #msg, __FILE__, __FUNCTION__, __LINE__)
#define Contact(x, y) x##y
int _tmain(int argc, _TCHAR* argv[])
{
printf("line: %d \n", __LINE__);
printf("file: %s \n", __FILE__);
printf("function: %s \n", __FUNCTION__);
//printf("function: %s \n", __func__);
printf("time: %s \n", __TIME__);
printf("date: %s \n", __DATE__);
//printf("STDC: %d \n", __STDC__);
//printf("STDC_HOSTED: %d \n", __STDC_HOSTED__);
//printf("VERSION: %s \n", __VERSION__);
printf("TIMESTAMP: %s \n", __TIMESTAMP__);
char* s = GetObjName(MyClass);
printf("%s \n", s);
Contact(pri, ntf) ("exec printf \n");
DebugPrint("Debug");
getchar();
return 0;
}
Macro中的# 代表取得variable名稱該變數可以是 class, function, ...
## 是將2個變數粘在一起, pri##ntf = printf
__FILE__ , __FUNCTION__, __LINE__, ... 是 Compiler 預先就定義好的變數
debug時, 可以print出來, 方便識別
沒有留言:
張貼留言