__FILE__ 、 __LINE__ 和 __PRETTY_FUNCTION__ 的 Visual C++ 等效项 [英] Visual C++ equivalent of __FILE__ , __LINE__ and __PRETTY_FUNCTION__

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

问题描述

GCC 编译器为我提供了以下宏:

GCC compiler gives me the following macros:

  • __FILE__ 这样我就可以打印出文件名+目录了.
  • __LINE__ 这样我就可以打印出我正在打印的行号.
  • __PRETTY_FUNCTION__ 这样我就可以打印出漂亮的函数名了
  • __FILE__ so that I can print out the file name + directory.
  • __LINE__ so that I can print out the line number of where I'm printing from.
  • __PRETTY_FUNCTION__ so that I can print out the pretty function name

Visual C++ 是否有这些宏的等价物?附带的问题是,这些是 C++ 编译器的标准吗?

Does Visual C++ have the equivalent of these macros? A side question is, are these standard for C++ compilers?

推荐答案

在VS2008中:

struct A
{
    bool Test(int iDummyArg)
    {
        const char *szFile = __FILE__;
        int iLine = __LINE__;
        const char *szFunc = __FUNCTION__; // Func name
        const char *szFunD = __FUNCDNAME__; // Decorated
        const char *szFunS = __FUNCSIG__; // Signature

        printf("%s
", szFile);
        printf("%d
", iLine);
        printf("%s
", szFunc);
        printf("%s
", szFunD);
        printf("%s
", szFunS);

        return true;
    }
};

int wmain(int argc, TCHAR *lpszArgv[])
{
    A a;
    a.Test(10);
}

将打印这个:

c:source	est_projectslahlah.cpp
14
A::Test
?Test@A@@QAE_NH@Z
bool __thiscall A::Test(int)

(行号是错误的",因为我的文件顶部确实有一些额外的东西.)

(The line number is "wrong" since there was really some extra stuff at the top of my file.)

这篇关于__FILE__ 、 __LINE__ 和 __PRETTY_FUNCTION__ 的 Visual C++ 等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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