首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

_FILE_LINE_FUNCTION_变量?该如何处理

2012-05-07 
__FILE__,__LINE__,__FUNCTION__变量?最近在给程序加Log时,发现别人加的log时使用__FILE__,__LINE__,__FUN

__FILE__,__LINE__,__FUNCTION__变量?
最近在给程序加Log时,发现别人加的log时使用__FILE__,__LINE__,__FUNCTION__ 3个参数,
输出当前log行所在的文件\行数和函数,很方便.(环境是Linux C)

不知道这些变量(应该是系统级的吧)是在哪里定义的,
参数的类型是什么,还有多少类似这种功能的变量?



[解决办法]
http://longsy.iteye.com/blog/349417
[解决办法]
宏定义来的,在头文件stdio.h中。标准库中的assert宏就是用__FILE__宏和__LINE__宏来实现的。
[解决办法]
只不过是个宏而已,由预编译器展开
[解决办法]
__FILE__和__LINE__是ISO C通用的预定义宏。
ISO C11(N1570)
6.10.8.1 Mandatory macros
1 The following macro names shall be defined by the implementation:
__DATE__ The date of translation of the preprocessing translation unit: a character string literal of the form "Mmm dd yyyy", where the names of the months are the same as those generated by the asctime function, and the first character of dd is a space character if the value is less than 10. If the date of translation is not available, an implementation-defined valid date shall be supplied.
__FILE__ The presumed name of the current source file (a character string literal).177)
__LINE__ The presumed line number (within the current source file) of the current source line (an integer constant).177)
__STDC__ The integer constant 1, intended to indicate a conforming implementation.
__STDC_HOSTED__ The integer constant 1 if the implementation is a hosted implementation or the integer constant 0 if it is not.
176) See ‘‘future language directions’’ (6.11.9).
177) The presumed source file name and line number can be changed by the #line directive.
__STDC_VERSION__ The integer constant 201ymmL.178)
__TIME__ The time of translation of the preprocessing translation unit: a character string literal of the form "hh:mm:ss" as in the time generated by the asctime function. If the time of translation is not available, an implementation-defined valid time shall be supplied.
Forward references: the asctime function (7.27.3.1).
6.10.8.2 Environment macros
1 The following macro names are conditionally defined by the implementation:
__STDC_ISO_10646__ An integer constant of the form yyyymmL (for example, 199712L). If this symbol is defined, then every character in the Unicode required set, when stored in an object of type wchar_t, has the same value as the short identifier of that character. The Unicode required set consists of all the characters that are defined by ISO/IEC 10646, along with all amendments and technical corrigenda, as of the specified year and month. If some other encoding is used, the macro shall not be defined and the actual encoding used is implementation-defined.
__STDC_MB_MIGHT_NEQ_WC__ The integer constant 1, intended to indicate that, in the encoding for wchar_t, a member of the basic character set need not have a code value equal to its value when used as the lone character in an integer character constant.
__STDC_UTF_16__ The integer constant 1, intended to indicate that values of type char16_t are UTF?16 encoded. If some other encoding is used, the macro shall not be defined and the actual encoding used is implementationdefined.
__STDC_UTF_32__ The integer constant 1, intended to indicate that values of type char32_t are UTF?32 encoded. If some other encoding is used, the macro shall not be defined and the actual encoding used is implementationdefined.
Forward references: common definitions (7.19), unicode utilities (7.28).
178) This macro was not specified in ISO/IEC 9899:1990 and was specified as 199409L in ISO/IEC 9899/AMD1:1995 and as 199901L in ISO/IEC 9899:1999. The intention is that this will remain an integer constant of type long int that is increased with each revision of this International Standard.


__FUNCTION__是GCC等的扩展,见http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html。

热点排行