Visual C ++等同于__FILE__,__LINE__和__PRETTY_FUNCTION__ [英] Visual C++ equivalent of __FILE__ , __LINE__ and __PRETTY_FUNCTION__

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

问题描述

GCC编译器提供以下宏:

GCC compiler gives me the following macros:

 - __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

相当于这些宏?

推荐答案


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\n", szFile);
        printf("%d\n", iLine);
        printf("%s\n", szFunc);
        printf("%s\n", szFunD);
        printf("%s\n", szFunS);

        return true;
    }
};

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

将打印:

c:\source\test_projects\blah\blah.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.)

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

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