c++ - main() 中的无名参数是否严格符合要求?

标签 c++ program-entry-point language-lawyer

C++ 允许以下两种 main 定义:

int main() { }
int main(int argc, char* argv[]) { }

它还允许char*[] 被命名为char**argcargv无论程序员想要什么。但是,它是否也允许:

int main(int, char*[]) { }

这和上面的例子一样吗?是否严格符合?请注意,我不关心它是否可以在您最喜欢的编译器中编译,我只询问标准。

最佳答案

是的,正如@Captain Obvlious 所说,C++ 只关心参数的类型。 C++ 标准委员会公开发表的论文 here供大家引用。

3.6.1 主要功能

  1. An implementation shall not predefine the main function. This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined. All implementations shall allow both

— a function of () returning int and

— a function of (int, pointer to pointer to char) returning int

关于c++ - main() 中的无名参数是否严格符合要求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32194151/

相关文章:

c++ - Const C++ 函数中的赋值

c++ - 修复NamespaceComment 在 .clang-format 中无法按预期工作

java - 使用方法引用和原始类型的函数接口(interface)特化的重载解析

c++ - 将 char** 转换为 char[x][x]

c++ - 如何将多面体网格拆分为一组具有签名面的不同多面体?

java - 我们可以在一个接口(interface)中有一个 main() 并在实现这个接口(interface)的类中有不同的 main() 实现吗?

java:找不到主类:测试/测试。程序将会退出

java - 如何解决线程 "main"java.lang.NoSuchMethodError : main 中的异常

c++ - 是否有任何 C++11 线程安全保证适用于使用 C++11 编译/链接的第三方线程库?

c++ - 在现有对象上使用新放置时如何定义对象的内容