物探论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1091|回复: 0

[Envi] C++库研究笔记——函数名的宏定义

[复制链接]
发表于 2013-8-12 11:31:15 | 显示全部楼层 |阅读模式
     #endifIn C, __PRETTY_FUNCTION__ is yet another name for __func__. However, in C++, __PRETTY_FUNCTION__ contains the type signature of the function as well as its bare name. For example, this program:     extern "C" {     extern int printf (char *, ...);     }          class a {      public:       void sub (int i)         {           printf ("__FUNCTION__ = %s\n", __FUNCTION__);           printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);         }     };          int     main (void)     {       a ax;       ax.sub (0);       return 0;     }gives this output:     __FUNCTION__ = sub     __PRETTY_FUNCTION__ = void a::sub(int)These identifiers are not preprocessor macros. In GCC 3.3 and earlier, in C only, __FUNCTION__ and __PRETTY_FUNCTION__ were treated as string literals; they could be used to initialize char arrays, and they could be concatenated with other string literals. GCC 3.4 and later treat them as variables, like __func__. In C++, __FUNCTION__ and __PRETTY_FUNCTION__ have always been variables.
但是,根据,__FUNCTION__更保险?Macro / keyword which can be used to print out method name?
On GCC you can use __FUNCTION__ and __PRETTY_FUNCTION__.On MSVC you can use __FUNCSIG__ and __FUNCTION__.simple.c: In function `main':simple.c:8: warning: concatenation of string literals with__FUNCTION__ is deprecatedPrint the function name using __FUNCTION__ macro
总结各资料:最好使用__func__?注:__func__是内直变量??
Since __func__ is not a string literal, you can't concatenate it withanother string literal, but what you can do is
printf("%s %s\n", __func__, __FILE__);

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|物探论坛 ( 鄂ICP备12002012号 微信号:iwutan )

GMT+8, 2024-4-19 07:34 , Processed in 0.065713 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表