什么是之间__ preTTY_FUNCTION__,__FUNCTION__,__func__区别? [英] What's the difference between __PRETTY_FUNCTION__, __FUNCTION__, __func__?
问题描述
有什么__功能的 __ preTTY_FUNCTION __
,的区别__
, __ FUNC __
,和他们在哪里记录?我该如何决定使用哪一个呢?
What's the difference between __PRETTY_FUNCTION__
, __FUNCTION__
, __func__
, and where are they documented? How do I decide which one to use?
推荐答案
__ FUNC __
是扩展到包含函数名称时,它是一个字符数组变量隐式声明的标识符一个函数的内部使用。它被添加到C C99。从 C99 的§6.4.2.2/ 1:
__func__
is an implicitly declared identifier that expands to a character array variable containing the function name when it is used inside of a function. It was added to C in C99. From C99 §6.4.2.2/1:
标识符 __ __ FUNC
被隐式由译者声明那样的话,紧随其后的每个函数定义的左大括号,声明
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.
请注意,这不是一个宏,它有preprocessing期间没有特殊含义。
Note that it is not a macro and it has no special meaning during preprocessing.
__ FUNC __
添加到C ++在C ++ 11,在那里它被指定为包含实现德科幻奈德字符串(C ++ 11§8.4.1[ dcl.fct.def.general] / 8),这是不是很在C规格(原来的建议添加有用 __ __ FUNC
来C ++是的 N1642 )。
__func__
was added to C++ in C++11, where it is specified as containing "an implementation-defined string" (C++11 §8.4.1[dcl.fct.def.general]/8), which is not quite as useful as the specification in C. (The original proposal to add __func__
to C++ was N1642).
__ __功能
为pre-标准的扩展,一些C编译器的支持(包括gcc和Visual C ++);在一般情况下,你应该使用 __ FUNC __
在那里支持,并且只使用 __功能__
如果您使用的编译器不支持它(例如,Visual C ++,它不支持C99和尚不支持所有的C ++ 0x的,不提供 __ FUNC __
)。
__FUNCTION__
is a pre-standard extension that some C compilers support (including gcc and Visual C++); in general, you should use __func__
where it is supported and only use __FUNCTION__
if you are using a compiler that does not support it (for example, Visual C++, which does not support C99 and does not yet support all of C++0x, does not provide __func__
).
__ preTTY_FUNCTION __
是gcc的一个扩展,主要是一样的 __功能__
,但对于C ++功能它包含包括函数的签名功能中的pretty的名称。 VISUAL C ++也有类似的(但不完全相同)扩展, __ __ FUNCSIG
。
__PRETTY_FUNCTION__
is a gcc extension that is mostly the same as __FUNCTION__
, except that for C++ functions it contains the "pretty" name of the function including the signature of the function. Visual C++ has a similar (but not quite identical) extension, __FUNCSIG__
.
对于非标准宏,你会想咨询你的编译器的文档。 Visual C ++的扩展名包括C ++编译器的的MSDN文档中的predefined宏。 GCC的文档扩展在GCC文档的网页。描述功能名称作为字符串。
For the nonstandard macros, you will want to consult your compiler's documentation. The Visual C++ extensions are included in the MSDN documentation of the C++ compiler's "Predefined Macros". The gcc documentation extensions are described in the gcc documentation page "Function Names as Strings."
这篇关于什么是之间__ preTTY_FUNCTION__,__FUNCTION__,__func__区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!