__FILE__, __LINE__, and __FUNCTION__ usage in C++(__FILE__、__LINE__ 和 __FUNCTION__ 在 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__
是非标准的,__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++ 中的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:__FILE__、__LINE__ 和 __FUNCTION__ 在 C++ 中的用法


基础教程推荐
- 我有静态或动态 boost 库吗? 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01