Visual C++ equivalent of __FILE__ , __LINE__ and __PRETTY_FUNCTION__

后端 未结 8 2251
后悔当初
后悔当初 2020-12-14 08:50

GCC compiler gives me the following macros:

  • __FILE__ so that I can print out the file name + directory.
  • __LINE__ so that I c
8条回答
  •  庸人自扰
    2020-12-14 09:20

    In VS2008, this:

    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);
    }
    

    will print this:

    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.)

提交回复
热议问题