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的更多相关文章

  1. GNU :6.47 Function Names as Strings

    链接:http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html#Function-Names GCC provides three magic var ...

  2. REST Representational state transfer REST Resource Naming Guide Never use CRUD function names in URIs

    怎样用通俗的语言解释什么叫 REST,以及什么是 RESTful? - 知乎  https://www.zhihu.com/question/28557115 大家都知道"古代"网 ...

  3. C++库研究笔记——函数名的宏定义

    6.47 Function Names as Strings:http://gcc.gnu.org/onlinedocs/gcc/Function-Names.html GCC provides th ...

  4. 在golang中使用 cgo,如何让被嵌入的c语言代码调用golang

    https://golang.org/misc/cgo/test/callback.go // Copyright 2011 The Go Authors. All rights reserved. ...

  5. 高性能python

    参考来源:Python金融大数据分析第八章 提高性能有如下方法 1.Cython,用于合并python和c语言静态编译泛型 2.IPython.parallel,用于在本地或者集群上并行执行代码 3. ...

  6. Consuming JSON Strings in SQL Server

    https://www.simple-talk.com/sql/t-sql-programming/consuming-json-strings-in-sql-server/ Consuming JS ...

  7. clean code meaningful names

    ---恢复内容开始--- Meaningful Names: use Intention-Revealing Names //nice,Everyone who reads your code (in ...

  8. Working with Strings(使用Oracle字符串)

    Working with Strings By Steven Feuerstein  Part 3 in a series of articles on understanding and using ...

  9. Named function expressions demystified

    Introduction Surprisingly, a topic of named function expressions doesn't seem to be covered well eno ...

随机推荐

  1. Beta阶段DAY2

    一.提供当天站立式会议照片一张 二.每个人的工作 1.讨论项目每个成员的昨天进展 刘阳航:删除多余按钮,调整界面. 林庭亦:删除麻烦的颜色设置. 郑子熙:添加新增按钮. 陈文俊:重新规划面板及功能. ...

  2. HDU 2103 Family planning

    http://acm.hdu.edu.cn/showproblem.php?pid=2103 Problem Description As far as we known,there are so m ...

  3. HDU 2140 Michael Scofield's letter

    http://acm.hdu.edu.cn/showproblem.php?pid=2140 Problem Description I believe many people are the fan ...

  4. area point sql

    UPDATE aa_info_area t,(SELECT areaId, areacenter,CONCAT('POINT(' ,substring_index(areacenter,',', 1) ...

  5. CSS 报错

  6. sublinme 快捷键格式

    {"keys": ["ctrl+shift+f"], "command": "reindent" , "arg ...

  7. Java变量初始化之后的默认值问题

    1) 局部变量初始化(局部变量:函数.语句中的变量,只在所属区域内有效)局部变量声明后,Java虚拟机不会自动给它初始化为默认值.因此对于局部变量,必须经过显示的初始化,才能使用它.如果使用一个没有被 ...

  8. 【Java】提取JSON数值时遇到数组集合时使用的K-V方式转换

    1.实体类转换方法 参照文章:http://www.cnblogs.com/dflmg/p/6933811.html 2.K-V方法(此方法比较笨,但是没有办法,我现在不知道有没有相关的简单API,只 ...

  9. BZOJ3246 IOI2013Dreaming

    如果将森林里每棵树都各自看做一个点,那么最后所连成的树应该是一颗菊花,否则将叶子节点父亲改为根不会更劣. 对于每个点所代表的树,其和根节点相连的点应该是到其他点距离最大值最小的点.这个点显然是直径的中 ...

  10. 修改grub需要修改权限命令

    Ubantu每次更新都会把用于引导的grub文件重置,导致开机后,又找不到系统,看来以后还是要备份一下grub文件.另外,这周开始学习python,先学习Linux系统的命令行操作,很多操作是相通的. ...