__FILE__,__LINE__和__FUNCTION__在C ++中的用法 [英] __FILE__, __LINE__, and __FUNCTION__ usage in C++

查看:114
本文介绍了__FILE__,__LINE__和__FUNCTION__在C ++中的用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆