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 ...
随机推荐
- pxe前期网络准备
核心交换机:[H3C12510-HEXIN]vlan 3010 //如果存在则不需要创建[H3C12510-HEXIN]dis interface Bridge-Aggregation brief / ...
- @Dataprovider 和 @Factory 的使用
总结: 0.@Dataprovider 所修饰的方法必须 return Object[][] ; @Facotry 所修饰的方法必须return Object[] ; 1.在测试场景中经常会遇到一个 ...
- d指针在Qt上的应用及实现(有图,很清楚)
Qt为了使其动态库最大程度上实现二进制兼容,引入了d指针的概念.那么为什么d指针能实现二进制兼容呢?为了回答这个问题,首先弄清楚什么是二进制兼容?所谓二进制兼容动态库,指的是一个在老版本库下运行的程序 ...
- maven依赖jar包时版本冲突的解决
https://blog.csdn.net/sinat_39789638/article/details/78005945 共有四种解决方式: 1.第一声明优先原则: 在pom.xml配置文件中,如果 ...
- 计算机网络【4】—— TCP和UDP的区别
一.TCP/UDP优点和缺点 TCP的优点: 可靠,稳定 TCP的可靠体现在TCP在传递数据之前,会有三次握手来建立连接,而且在数据传递时,有确认.窗口.重传.拥塞控制机制,在数据传完后,还会断开连接 ...
- 【Nginx笔记】 fastcgi_param解释
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#脚本文件请求的路径 fastcgi_param QUERY_STRI ...
- Luogu4885 灭顶之灾
显然1的位置确定了整个矩阵,每一段连续的数即是对该位置的限制.化一下式子可以发现是一段区间或一段区间的补集,最后要求的是他们的交.看起来不太好求,于是转为求补集的并,那么排个序就完了. #includ ...
- P3758 [TJOI2017]可乐
题目描述 加里敦星球的人们特别喜欢喝可乐.因而,他们的敌对星球研发出了一个可乐机器人,并且放在了加里敦星球的1号城市上.这个可乐机器人有三种行为: 停在原地,去下一个相邻的城市,自爆.它每一秒都会随机 ...
- Paint Chain HDU - 3980(sg)
因为题中是个环, 所以我们可以首先拿出一组m 如果n<m 先手必输 否则的话跑sg函数 n = n-m #include <iostream> #include <cstdio ...
- 【算法复习】codevs1022 匈牙利算法
题目描述 Description 有一个N×M的单位方格中,其中有些方格是水塘,其他方格是陆地.如果要用1×2的矩阵区覆盖(覆盖过程不容许有任何部分重叠)这个陆地,那么最多可以覆盖多少陆地面积. ...