c++ - 零作为函数名

标签 c++ function visual-c++ compiler-construction

以下示例编译(虽然 VS2010 C++ 编译器发出警告 C4353)并且表达式 (*) 计算为 0:

#include <iostream>
#include <string>

int main()
{
   0(1, "test"); // (*) - any number and type of arguments allowed       
   int n = 0(1, "test"); // 0
   std::string str(0(1, "test")); // Debug assertion fails - 0 pointer passed
}

是否使用 0 作为 C++ 标准允许/规定的函数名称,或者它的解析是特定于编译器的?我正在查看 N3242 草案,但找不到任何内容与此有关。 Microsoft 编译器显然将此类构造(或带有 __noop 的构造)解析为值为 0 的整数。

警告 C4353:

warning C4353: nonstandard extension used: constant 0 as function expression. Use __noop function intrinsic instead

最佳答案

函数名是一个标识符,标识符需要以非数字开头(§2.11):

identifier:
    identifier-nondigit
    identifier identifier-nondigit
    identifier digit

关于c++ - 零作为函数名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10227997/

相关文章:

c++ - 插入跳过列表

javascript - 如何创建包含自定义变量的函数

function - 将函数作为参数传递的优点

c++ - 如何在 Visual Studio 汇编程序输出中分解名称?

c++ - 使用双击事件创建 QLabel 时出现链接器错误

C++:通过派生类调用重载虚拟,导致 NULL 调用/段错误

sql - 如何在postgresql中的单个函数中编写多个查询

c - 'asm','__ asm'和'__asm__'有什么区别?

c++ - vc++ 应用程序中的看门狗

c++ - OpenCV中的简单视频播放,C++