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

查看:322
本文介绍了__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 __ code> __ 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 effect performance in any way.

这篇关于__FILE__,__LINE__和__FUNCTION__在C ++中的用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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