在内联函数中__LINE__的行为 [英] Behavior of __LINE__ in inline functions
问题描述
我有一个宏将行号和文件名传递给错误处理程序:
I have a macro that passes the line number and file name to an error handler:
#define SYSTEM_FAILURE (error_code, comment) \
System_Failure((error_code), (comment), __LINE__, __FILE__);
__ LINE __
在内联函数中?
file.h:
inline int divide(int x, int y)
{
if (y == 0)
{
SYSTEM_FAILURE(ENUM_DIVIDE_BY_ZERO, "divide by zero error");
}
return x/y;
}
将 __ LINE __
头文件中的行号或者调用内联函数的源文件的行号(假设编译器在源代码中做了粘贴)?
Will __LINE__
contain the line number within the header file, or the line number of the source file where the inline function is called (assuming compiler does a "paste" in the source code)?
推荐答案
在C和C ++中,宏不是(大部分)用实际代码的任何知识进行评估,并且在代码之前处理(因此名称为预处理器)。因此, __ FILE __
将计算为file.h, __ LINE __
将计算与该行对应的行号其中 SYSTEM_FAILURE
出现在file.h中。
In C and C++, macros aren't (for the most part) evaluated with any knowledge of the actual code and are processed before the code (hence the name "preprocessor"). Therefore, __FILE__
would evaluate to "file.h", and __LINE__
would evaluate to the line number corresponding to the line on which SYSTEM_FAILURE
appears in file.h.
这篇关于在内联函数中__LINE__的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!