为什么#ifndef __func__返回true
Why does #ifndef __func__ return true?
以下代码,
#include <iostream>
#ifndef __func__
# ifdef __FUNCTION__
# define __func__ __FUNCTION__
# else
//# error This compiler supports neither __func__ nor __FUNCTION__
# endif
#endif
int main(int argc, char **argv)
{
std::cout << __func__ << std::endl
<< __FUNCTION__ << std::endl
<< __PRETTY_FUNCTION__ << std::endl;
}
给出以下预期输出,
main
main
int main(int, char**)
但是,如果我散布else
条件,则汇编失败,因为__func__
和__FUNCTION__
均未定义。怎么会这样?显然,它们被定义为上述输出中所示。关于#ifdef
/#ifndef
,我在这里缺少一些简单的原则吗?
__func__
不是宏。它是一个魔术变量,__FUNCTION__
和__PRETTY_FUNCTION__
。
来自https://gcc.gnu.org/onlinedocs/gcc-4.9.0/gcc/function-names.html:
gcc提供了三个魔术变量,将当前函数的名称保存为字符串。其中的第一个是
__func__
,它是C99标准的一部分:标识符
__func__
被翻译人员隐式声明,好像在每个函数定义的开放式上立即声明,声明static const char __func__[] = "function-name";
...
__FUNCTION__
是__func__
的另一个名称。...
在C中,
__PRETTY_FUNCTION__
是__func__
的另一个名称。但是,在C 中,__PRETTY_FUNCTION__
包含该功能的类型签名以及其裸机。
相关文章:
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- C++如果使用 lambda 表达式的语句返回 true,但输出来自 false,为什么
- 测试用例状态为失败,但返回的值为 true
- MFC 的 OnInit() 函数中的返回 true 和返回 false 有什么区别
- 我正在尝试创建一个布尔函数,该函数计算字符并在字符为"()*-+"时返回 true
- 创建一个函数,如果元素在unordered_set中,则返回 true,如何处理模板
- QTimer isActive 返回 true,但 remainingTime 返回 -1
- 为什么在 IsValid(Object) 返回 true 后不能安全地使用 Object?
- 计算 <Classtype*> 向量中所有项的布尔值的最有效方法,如果全部为真则返回 true
- QDir mkpath 返回 true,但未创建目录
- std::is_array 当它应该返回 false 时返回 true
- 尝试创建一个评估字符的bool函数,如果字母数字为字母,则返回true
- 我想返回 True/False 关于值是否在一组值中
- 为什么我的布尔函数返回 true 会导致读取访问冲突?
- ifstream::is_open 返回 true,即使该位置不存在文件也是如此
- 是否有内置函数返回" the number of true value in a boolean vector "?
- 为什么包含指针的条件总是返回 true?
- 对于 ((无符号整数)0-1)返回 true>0
- 为什么#ifndef __func__返回true
- 我的bool函数一直返回true,我不知道为什么