问题描述
假设您的 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设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)