__FILE__,__LINE__和__FUNCTION__在C ++中的用法 [英] __FILE__, __LINE__, and __FUNCTION__ usage in C++
问题描述
假设您的C ++编译器支持它们,是否有任何特殊原因不使用 __ FILE __
, __ LINE __
和
__ FUNCTION __
用于记录和调试目的?
Presuming that your C++ compiler supports them, is there any particular reason not to use __FILE__
, __LINE__
and __FUNCTION__
for logging and debugging purposes?
误导性数据 - 例如,作为优化的结果报告了不正确的行号或功能 - 或者将性能影响作为结果。
I'm primarily concerned with giving the user misleading data—for example, reporting the incorrect line number or function as a result of optimization—or taking a performance hit as a result.
基本上,我可以信任 __ FILE __
, __ LINE __
和 __ FUNCTION __
至 >
Basically, can I trust __FILE__
, __LINE__
and __FUNCTION__
to always do the right thing?
推荐答案
__ FUNCTION __
code> __ func __ 存在于C99 / C ++ 11中。其他人( __ LINE __
和 __ FILE __
)很好。
__FUNCTION__
is non standard, __func__
exists in C99 / C++11. The others (__LINE__
and __FILE__
) are just fine.
如果你选择使用 __ FUNCTION __
/ __ func __
)优化,它总是报告正确的文件和行是一个非因子因为它是一个编译时宏扩展。它将从不以任何方式影响效果。
It will always report the right file and line (and function if you choose to use __FUNCTION__
/__func__
) optimization is a non-factor since it is a compile time macro expansion. It will never effect performance in any way.
这篇关于__FILE__,__LINE__和__FUNCTION__在C ++中的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!