博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GNU :6.47 Function Names as Strings
阅读量:6916 次
发布时间:2019-06-27

本文共 1977 字,大约阅读时间需要 6 分钟。

链接:

GCC provides three magic variables that hold the name of the current function, as a string. The first of these is __func__, which is part of the C99 standard:The identifier __func__ is implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration     static const char __func__[] = "function-name";appeared, where function-name is the name of the lexically-enclosing function. This name is the unadorned name of the function.__FUNCTION__ is another name for __func__. Older versions of GCC recognize only this name. However, it is not standardized. For maximum portability, we recommend you use __func__, but provide a fallback definition with the preprocessor:     #if __STDC_VERSION__ < 199901L     # if __GNUC__ >= 2     #  define __func__ __FUNCTION__     # else     #  define __func__ "
" # endif #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.

 

 

转载于:https://www.cnblogs.com/lc-cnblong/p/3231884.html

你可能感兴趣的文章
最简单的视音频播放演示样例7:SDL2播放RGB/YUV
查看>>
vector draw 试用期结束的 激活方法
查看>>
Oracle数据库软件标准版的一个限制:仅仅能用一个rman channel
查看>>
docker官方文档中的dns,link,expose,publish
查看>>
使用 redis “捕捉” “用户登录过期” 事件
查看>>
MyEclipse 8.5安装Aptana
查看>>
C#动态对象(dynamic)示例(实现方法和属性的动态)
查看>>
Objective-C之成魔之路【8-訪问成员变量和属性】
查看>>
支付宝支付-常用支付API详解(查询、退款、提现等)
查看>>
windows下查看特定端口被什么程序占用
查看>>
JSON.parse()与JSON.stringify()的区别
查看>>
1032. Sharing (25)
查看>>
JSP的隐藏对象
查看>>
2014秋C++ 第8周项目 分支程序设计
查看>>
[pig] pig 基础使用
查看>>
java中的线程同步
查看>>
Does the parameter type of the setter match the return type of the getter?
查看>>
MongoDB count distinct group by JavaAPI查询
查看>>
Java多线程系列——原子类的实现(CAS算法)
查看>>
LibEvent代码阅读--多缓冲区和零拷贝技术
查看>>