__FILE__,__LINE__和__FUNCTION__在C ++中的用法 [英] __FILE__, __LINE__, and __FUNCTION__ usage in C++
问题描述
__ FILE __
, __ LINE __
和 __ FUNCTION __
用于记录和调试目的? 我主要关心给用户误导性的数据 - 例如,作为优化的结果报告不正确的行号或功能 - 或者作为结果导致性能下降。
基本上,我可以相信 __ FILE __
, __ LINE __
和 __ FUNCTION __
to always 做正确的事情?
__ FUNCTION __
是非标准的, code> __ func __ 存在于C99 / C ++ 11中。其他( __ LINE __
和 __ FILE __
)很好。
它将始终报告正确的文件和行(如果您选择使用 __ FUNCTION __
/ __ func __
)。优化是一个非因素,因为它是一个编译时宏扩展; 永远不会以任何方式影响效果。
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.
Basically, can I trust __FILE__
, __LINE__
and __FUNCTION__
to always do the right thing?
__FUNCTION__
is non standard, __func__
exists in C99 / C++11. The others (__LINE__
and __FILE__
) are just fine.
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屋!