假设您的 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__ 是非标准的,__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 affect performance in any way.
这篇关于__FILE__、__LINE__ 和 __FUNCTION__ 在 C++ 中的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
为什么两个函数的地址相同?Why do two functions have the same address?(为什么两个函数的地址相同?)
为什么 std::function 的初始化程序必须是可复制构Why the initializer of std::function has to be CopyConstructible?(为什么 std::function 的初始化程序必须是可复制构造的?)
混合模板与多态性mixing templates with polymorphism(混合模板与多态性)
我什么时候应该使用关键字“typename"?使用模When should I use the keyword quot;typenamequot; when using templates(我什么时候应该使用关键字“typename?使用模板时)
依赖名称解析命名空间 std/标准库Dependent name resolution amp; namespace std / Standard Library(依赖名称解析命名空间 std/标准库)
gcc 可以编译可变参数模板,而 clang 不能gcc can compile a variadic template while clang cannot(gcc 可以编译可变参数模板,而 clang 不能)