c++ - `int main(int argc, char* argv<::>)` 如何成为 main 的有效签名?

标签 c++ c program-entry-point

<分区>

我在网站上看到 int main(int argc, char* argv<::>)也可以用作 main 的签名.令人惊讶的是,以下程序:

int main(int argc, char* argv<::>)
{
  return 0;
}

编译时会发出 GCC 中的任何警告以及 clang。它还在 C++ 中编译。

那么,int main(int argc, char* argv<::>) 是怎么回事?是 main 的有效签名?

最佳答案

char* argv<::>相当于char* argv[] . <::>这里使用的是二合字母。

C11: 6.4.6 (p3):

In all aspects of the language, the six tokens79)

<: :> <% %> %: %:%:

behave, respectively, the same as the six tokens

[ ] { } # ##

except for their spelling. 80)


脚注:
79) 这些标记有时被称为“二合字母”。
80)因此[<:在“字符串化”时表现不同(参见 6.10.3.2),但可以自由互换

一个例子:

%: define  stringize(a) printf("Digraph \"%s\" retains its spelling in case of stringization.\n", %:a)    

调用上面的宏

stringize( %:);  

将打印

Digraph "%:" retains its spelling in case of stringization.

关于c++ - `int main(int argc, char* argv<::>)` 如何成为 main 的有效签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29874677/

相关文章:

c - c程序中对角插入元素

java.lang.ClassNotFoundException : com. example.Main 在 intelliJ 和 Maven 构建中

Linux 文件属性/

c++ - void main() 有什么问题?

c++ - 指针成员未在复制构造函数中初始化

c++ - 将调用哪个重载模板?

c++ - 在 C++ 中初始化静态 std::map<int, int>

c - 如何增加指针值数组的索引?

c - GCC 的 -Wmaybe-uninitialized 是否为基于枚举的 switch 语句生成带有 -O1 的虚假警告?

c++ - C++ 中的屏蔽断言