Function Names as Strings
【Function Names as Strings】
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(old):
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(GCC2.0以上版本没有__func__,只有__FUNCTION__,2.0以下版本编译器不认识__FUNCTION__). However, it is not standardized. For maximum portability, we recommend you use __func__, but provide a fallback definition with the preprocessor(GCC2.0)(通过以下的宏使用__func__可以提供跨版本特性):
#if __STDC_VERSION__ < 199901L
# if __GNUC__ >= 2
# define __func__ __FUNCTION__
# else
# define __func__ "<unknown>"
# endif
#endif
In 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(C++中__PRETTY_FUNCTION__包含函数签名). 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__(GCC3.4以后版本,此2种东西均为变量). In C++, __FUNCTION__ and__PRETTY_FUNCTION__ have always been variables.
参考:http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html#Function-Names
Function Names as Strings的更多相关文章
- GNU :6.47 Function Names as Strings
链接:http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html#Function-Names GCC provides three magic var ...
- REST Representational state transfer REST Resource Naming Guide Never use CRUD function names in URIs
怎样用通俗的语言解释什么叫 REST,以及什么是 RESTful? - 知乎 https://www.zhihu.com/question/28557115 大家都知道"古代"网 ...
- C++库研究笔记——函数名的宏定义
6.47 Function Names as Strings:http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html GCC provides th ...
- 在golang中使用 cgo,如何让被嵌入的c语言代码调用golang
https://golang.org/misc/cgo/test/callback.go // Copyright 2011 The Go Authors. All rights reserved. ...
- 高性能python
参考来源:Python金融大数据分析第八章 提高性能有如下方法 1.Cython,用于合并python和c语言静态编译泛型 2.IPython.parallel,用于在本地或者集群上并行执行代码 3. ...
- Consuming JSON Strings in SQL Server
https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/ Consuming JS ...
- clean code meaningful names
---恢复内容开始--- Meaningful Names: use Intention-Revealing Names //nice,Everyone who reads your code (in ...
- Working with Strings(使用Oracle字符串)
Working with Strings By Steven Feuerstein Part 3 in a series of articles on understanding and using ...
- Named function expressions demystified
Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...
随机推荐
- C++ socket网络爬虫(1)
C++写的socket网络爬虫,代码会在最后一次讲解中提供给大家,同时我也会在写的同时不断的对代码进行完善与修改 我首先向大家讲解如何将网页中的内容,文本,图片等下载到电脑中. 我会教大家如何将百度首 ...
- [C/C++] C++ Primer学习笔记
记录下自己掌握不清楚的概念和用法... Day 1 endl:具有输出换行的效果,并刷新与设备相关联的缓冲区. 注:在调试程序过程中插入的输出语句都应刷新输出流,否则可能会造成程序崩溃,将会导致程序出 ...
- JAVA Junit4
JAVA Junit4 测试框架 序言 刚学Java的时候就听说过JUnit了,单元测试框架,很好用的测试框架,JUnit测试 ...
- FutureTask 源码解析
FutureTask 源码解析 版权声明:本文为本作者原创文章,转载请注明出处.感谢 码梦为生| 刘锟洋 的投稿 站在使用者的角度,future是一个经常在多线程环境下使用的Runnable,使用它的 ...
- 只会java,参加acm如何?
作者:董适链接:https://www.zhihu.com/question/31213070/answer/51054677来源:知乎著作权归作者所有,转载请联系作者获得授权. 当然合适,有什么不合 ...
- [AT2268] [agc008_f] Black Radius
题目链接 AtCoder:https://agc008.contest.atcoder.jp/tasks/agc008_f 洛谷:https://www.luogu.org/problemnew/sh ...
- Alpha 冲刺 —— 十分之九
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭鸭鸭鸭鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 多次测试软件运行 学习OPENMP ...
- kibana5画图
先展示一下我的Dashboard 1.Markdown文本 2.日志条数统计 3.访问IP前10柱状图 4.访问IP前10饼图 5.状态码饼图 6.状态码趋势图 7.状态码柱状叠加图 8.流量趋势图 ...
- fzyzojP3580 -- [校内训练-互测20180315]小基的高智商测试
题目还有一个条件是,x>y的y只会出现一次(每个数直接大于它的只有一个) n<=5000 是[HNOI2015]实验比较 的加强版 g(i,j,k)其实可以递推:g(i,j,k)=g(i- ...
- (转)java getResourceAsStream的使用方法
背景:对于java项目中配置文件加载时候的绝对路径和相对路径做一个清晰的认识! 1 分析路径 在Java项目中会经常用到getResourceAsStream这个函数获取一些配置文件,但是怎样正确使用 ...