C++的函数宏

gcc支持__FUNCTION____func____PRETTY_FUNCTION__三个宏用以打印函数当前执行的函数名。 前两者等价,最后一个比较少用到,用于打印函数原型。

如下代码:

int test(int n)
{
    cout << __FUNCTION__ << endl;
    cout << __func__ << endl;
    cout << __PRETTY_FUNCTION__ << endl;
    return 0;
}

执行输出为:

test
test
int test(int)

通过如下gcc命令,可以查询gcc预定义的宏有哪些:

gcc -dM -E - < /dev/null

常见到的宏定义有如下一些:

#define __STDC__ 1
#define __VERSION__ "4.4.7"
#define __amd64__ 1
#define __x86_64__ 1
#define unix 1
#define __unix__ 1
#define linux 1
#define __linux__ 1
#define __MMX__ 1
#define __SSE__ 1
#define __SSE2__ 1

当要写跨平台代码时,这些宏会很实用。

发表于 2014年08月25日 17:39   评论:0   阅读:2045  



回到顶部

首页 | 关于我 | 关于本站 | 站内留言 | rss
python logo   django logo   tornado logo