相关疑难解决方法(0)

在C++中__FILE __,_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

假设您的C++编译器支持它们,是否有任何特殊原因使用__FILE__,__LINE__以及__FUNCTION__用于记录和调试目的?

我主要关注的是为用户提供误导性数据 - 例如,由于优化而报告错误的行号或功能,或者因此导致性能下降.

基本上,我可以信任__FILE__,__LINE____FUNCTION__永远做正确的事?

c++ debugging logging c-preprocessor

149
推荐指数
6
解决办法
23万
查看次数

_LINE__在内联函数中的行为

我有一个宏将行号和文件名传递给错误处理程序:

#define SYSTEM_FAILURE (error_code, comment) \
   System_Failure((error_code), (comment), __LINE__, __FILE__);
Run Code Online (Sandbox Code Playgroud)

__LINE__在内联函数中使用时如何解决?

file.h:
inline int divide(int x, int y)
{
    if (y == 0)
    {
        SYSTEM_FAILURE(ENUM_DIVIDE_BY_ZERO, "divide by zero error");
    }
    return x/y;
}
Run Code Online (Sandbox Code Playgroud)

__LINE__包含头文件中的行号,或调用内联函数的源文件的行号(假设编译器在源代码中执行"粘贴")?

c c++ inline line c-preprocessor

15
推荐指数
3
解决办法
4302
查看次数

标签 统计

c++ ×2

c-preprocessor ×2

c ×1

debugging ×1

inline ×1

line ×1

logging ×1