引導語;預定義的巨集不採用任何引數,並且不能重新定義。以下是本站小編分享給大家的.C語言預定義巨集用法,歡迎閱讀!
預定義巨集
__DATE__進行預處理的日期(“Mmm dd yyyy”形式的字串文字)
__FILE__代表當前源程式碼檔名的字串文字
__BASE_FILE__獲取正在編譯的原始檔名
__LINE__代表當前原始碼檔案中的行號的整數常量
__TIME__原始檔編譯時間,格式為“hh: mm: ss”
__STDC__設定為 1時,表示該實現遵循 C標準
__STDC_HOSTED__為本機環境設定為 1,否則設為 0
__STDC_VERSION__為C99時設定為199901L
__FUNCTION__或者 __func__ 獲取所在的函式名(預定義識別符號,而非預定義巨集)
#include
int main (void)
{
printf ("The file is %sn", __FILE__);
printf ("The base_file is %sn", __BASE_FILE__);
printf ("The line is %dn", __LINE__);
printf ("The function is %sn", __FUNCTION__);
printf ("The func is %sn", __func__);
printf ("The date is %sn", __DATE__);
printf ("The time is %sn", __TIME__);
return 0;
}
輸出結果:
The file is part.c
The base_file is part.c
The line is 6
The function is main
The func is main
The date is Nov 22 2016
The time is 15:46:30