相当于__FILE__,__LINE__和__PRETTY_FUNCTION__的Visual C - 代码日志

相当于__FILE__,__LINE__和__PRETTY_FUNCTION__的Visual C

GCC编译器给了我以下宏:

 - __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编译器的标准?

在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\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)

(行号是“错误的”,因为我的文件顶部真的有一些额外的东西。)

http://stackoverflow.com/questions/4434282/visual-c-equivalent-of-file-line-and-pretty-function

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:相当于__FILE__,__LINE__和__PRETTY_FUNCTION__的Visual C