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 ...
随机推荐
- pixi.js 总结
我的博客简单简洁 可能表达不清. 如有想法, 敬请留言.谢谢! 群:881784250 https://github.com/ccaleb/endless-runner/tree/master/jav ...
- 在输入密码框中眼睛睁开可以看见数字,眼睛闭上看不见数字怎么用JS实现
无论做那个项目,登录注册页面总是避免不了的,那怎么用js来控制密码的显示和隐藏呢?先看一下效果图: HTML代码如下: <div> <label for=" ...
- 计算机网络【4】—— TCP和UDP的区别
一.TCP/UDP优点和缺点 TCP的优点: 可靠,稳定 TCP的可靠体现在TCP在传递数据之前,会有三次握手来建立连接,而且在数据传递时,有确认.窗口.重传.拥塞控制机制,在数据传完后,还会断开连接 ...
- js判断浏览器语言实现网站国际化
一般国际化的网站至少是有中.英文两种语言的,然后就是在不同的语言环境下使用不同的语言页面. 1.实现原理 一般实现这种功能的方法,无非就是两种, 第一种,判断浏览器语言类型: 第二种,判断ip所属国家 ...
- access数据库表导入到oracle
1.本机安装access数据库 25M左右2.创建ODBC数据源,要选择oracle C:\Windows\SysWOW64\odbcad32.exe 3.打开要导入的 .mdb文件 右键表--> ...
- Ansible基础概述
一.Ansible简介 Ansible基于Python语言实现,由paramiko和PyYAML两个关键模块构建.Ansible的编排引擎可以出色地完成配置管理,流程控制,资源部署等多方面工作.Ans ...
- sqoop 补充
1.用 sqoop 将MySQL中的数据导入hbase中 sqoop import \--connect jdbc:mysql://***.***.*.***:3306/mysql \--hbase- ...
- bzoj 2453 : 维护队列 带修莫队
2453: 维护队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 952 Solved: 432[Submit][Status][Discuss] ...
- fzyzojP2291 -- 小添添的庄园之道路修复
直接换根dp f[i]表示,i为根的子树的方案 f[i]=Π(f[son]+1)(就是考虑这个边修不修(不修,子树中只有一种方案)) 这里是乘法 换根的时候,直接算的话,为了消除x对fa的贡献,要乘上 ...
- python入门:求1-2+3-4+5...99的所有数的和
#!/usr/bin/env python # -*- coding:utf-8 -*- #求1-2+3-4+5...99的所有数的和 """ 给start赋值为1,su ...