C語言預定義宏用法

來源:文萃谷 3.1W

引導語;預定義的宏不採用任何參數,並且不能重新定義。以下是本站小編分享給大家的.C語言預定義宏用法,歡迎閲讀!

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

熱門標籤