在C ++中main的签名的参数有unsiged和const限定符吗? [英] Can the arguments of main's signature in C++ have the unsiged and const qualifiers?

查看:228
本文介绍了在C ++中main的签名的参数有unsiged和const限定符吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准明确说明 main 有两个有效(即保证工作)签名;即:

The standard explicitly states that main has two valid (i.e., guaranteed to work) signatures; namely:

int main();
int main(int, char*[]);

我的问题很简单,下面是合法的吗?

My question is simple, would something like the following be legal?

int main(const unsigned int, const char* const* argv);

我的测试说'yes',但我不确定答案,通过将 int 更改为 unsigned int 以及非top-level const -ness of argv?

My tests say 'yes', but I'm unsure of the answer because am I not overloading main by changing int to unsigned int as well as the non top-level const-ness of argv? If I am, then that's clearly prohibited.

那么,这些修改是否保证在符合标准的编译器上工作?

So, are these modifications guaranteed to work on a standards conforming compiler?

推荐答案

C ++ 98标准在第3.6.1节第2节中说明

The C++98 standard says in section 3.6.1 paragraph 2


实现不应预定义主要功能。此功能不应重载。它应该具有 int 类型的返回类型,否则其类型是实现定义的。所有实现应允许 main 的两个定义: int main() int main (int argc,char * argv [])

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 the following definitions of main: int main() and int main(int argc, char* argv[])

接受是可以接受的,但可以接受。

So it's not mandated by the standard that the env accepting main is acceptable but it is permissible.

经常提到,这里是前面的段落免除独立环境从任何,但记录他们的行为:

Because this is referred to often, here is the previous paragraph exempting freestanding environments from anything but documenting their behavior:


程序应包含一个全局函数main,这是程序的指定开始。它是
实现定义
是否需要在独立环境中的程序来定义主
函数。 [注意:在独立的环境中,启动
和终止是实现定义的;
startup
包含对具有静态存储持续时间的命名空间范围对象的构造函数的执行;终止
包含具有静态存储持续时间的对象的析构函数的执行。 ]

A program shall contain a global function called main, which is the designated start of the program. It is implementation defined whether a program in a freestanding environment is required to define a main function. [Note: in a freestanding environment, startup and termination is implementation defined; startup contains the execution of constructors for objects of namespace scope with static storage duration; termination contains the execution of destructors for objects with static storage duration. ]

这篇关于在C ++中main的签名的参数有unsiged和const限定符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆