Why wording declaring major changes between draft standards?
N3936 [basic.start.main]
2
The implementation does not have to predefine the functionmain
. This function should not be overloaded. It must have a declared return typeint
, but otherwise its type is implementation-defined. the implementation should provide both- a function
()
that returnsint
and- function (
int
, pointer to pointer tochar
), returningint
N3337 [basic.start.main]
2
The implementation does not have to predefine the functionmain
. This function should not be overloaded. It must have a return typeint
, but otherwise its type is implementation-defined. All implementations must admit both of the following definitionsmain
:
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?
source to share
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.
source to share