Why wording declaring major changes between draft standards?

N3936 [basic.start.main]

2

The implementation does not have to predefine the function main

. This function should not be overloaded. It must have a declared return type int

, but otherwise its type is implementation-defined. the implementation should provide both

- a function ()

that returns int

and

- function ( int

, pointer to pointer to char

), returningint

N3337 [basic.start.main]

2

The implementation does not have to predefine the function main

. This function should not be overloaded. It must have a return type int

, but otherwise its type is implementation-defined. All implementations must admit both of the following definitions main

:

int main() { /* ...  */ }

      

and

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

      

What explains this change? The closest I can find is DR 1669 , in which the proposed wording already includes this change. We know that because of the "decay of a matrix into a pointer", char* argv[]

it becomes char** argv

.

std::cout << std::is_same<char**, std::decay<char*[]>::type>::value; // true

      

It doesn't really need to be rewritten - it's self-evident. So why change?

+3


source to share


1 answer


It's just more flexible in general since it doesn't hold back the syntax.
DR, which introduces the change, # 1003 :

A specification of the forms of definition main

that needs to be adopted so that it is clear in C99 that parameter names and the exact syntactic form of types can be different. While it is reasonable to assume that a C ++ implementation will accept the type definition

int main(int foo, char** bar) { /* ... */ }

      

instead of the canonical

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

      

it might be a good idea to clarify the intent using C99's similar wording.

The most common example is mentioned above:

int main(int argc, char** argv)

      



This is not guaranteed to work according to C ++ 11.

Trailing-return-types are another example. Think that a lot of people are using them exclusively now - and they write something in strings

auto main() -> int

      

We want these and similar definitions to be standard. Not defined for implementation.

+5


source







All Articles