tmp/tmpvdpmyxjv/{from.md → to.md}
RENAMED
|
@@ -1,25 +1,23 @@
|
|
| 1 |
#### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
|
| 2 |
|
| 3 |
-
A program shall contain
|
| 4 |
-
global
|
| 5 |
-
[[intro.multithread]], [[thread.threads]]
|
| 6 |
-
is invoked
|
| 7 |
-
|
| 8 |
-
It is *implementation-defined* whether a program in a freestanding
|
| 9 |
-
environment is required to define a `main` function.
|
| 10 |
|
| 11 |
[*Note 1*: In a freestanding environment, startup and termination is
|
| 12 |
*implementation-defined*; startup contains the execution of constructors
|
| 13 |
-
for objects
|
| 14 |
-
|
| 15 |
duration. — *end note*]
|
| 16 |
|
| 17 |
-
An implementation shall not predefine the `main` function.
|
| 18 |
-
shall
|
| 19 |
-
|
| 20 |
-
|
| 21 |
|
| 22 |
- a function of `()` returning `int` and
|
| 23 |
- a function of `(int`, pointer to pointer to `char)` returning `int`
|
| 24 |
|
| 25 |
as the type of `main` [[dcl.fct]]. In the latter form, for purposes of
|
|
@@ -32,33 +30,37 @@ characters of null-terminated multibyte strings (NTMBSs)
|
|
| 32 |
[[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
|
| 33 |
character of a NTMBS that represents the name used to invoke the program
|
| 34 |
or `""`. The value of `argc` shall be non-negative. The value of
|
| 35 |
`argv[argc]` shall be 0.
|
| 36 |
|
| 37 |
-
|
| 38 |
-
added after `argv`.
|
| 39 |
|
| 40 |
The function `main` shall not be used within a program. The linkage
|
| 41 |
[[basic.link]] of `main` is *implementation-defined*. A program that
|
| 42 |
defines `main` as deleted or that declares `main` to be `inline`,
|
| 43 |
-
`static`, or `
|
| 44 |
-
a coroutine [[dcl.fct.def.coroutine]]. The `main` function
|
| 45 |
-
declared with a *linkage-specification* [[dcl.link]]. A
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
[*Example 1*: Member functions, classes, and enumerations can be called
|
| 52 |
`main`, as can entities in other namespaces. — *end example*]
|
| 53 |
|
| 54 |
Terminating the program without leaving the current block (e.g., by
|
| 55 |
calling the function `std::exit(int)` [[support.start.term]]) does not
|
| 56 |
destroy any objects with automatic storage duration [[class.dtor]]. If
|
| 57 |
-
`std::exit` is
|
| 58 |
-
|
| 59 |
-
behavior.
|
| 60 |
|
| 61 |
A `return` statement [[stmt.return]] in `main` has the effect of leaving
|
| 62 |
the main function (destroying any objects with automatic storage
|
| 63 |
duration) and calling `std::exit` with the return value as the argument.
|
| 64 |
If control flows off the end of the *compound-statement* of `main`, the
|
|
|
|
| 1 |
#### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
|
| 2 |
|
| 3 |
+
A program shall contain exactly one function called `main` that belongs
|
| 4 |
+
to the global scope. Executing a program starts a main thread of
|
| 5 |
+
execution [[intro.multithread]], [[thread.threads]] in which the `main`
|
| 6 |
+
function is invoked. It is *implementation-defined* whether a program in
|
| 7 |
+
a freestanding environment is required to define a `main` function.
|
|
|
|
|
|
|
| 8 |
|
| 9 |
[*Note 1*: In a freestanding environment, startup and termination is
|
| 10 |
*implementation-defined*; startup contains the execution of constructors
|
| 11 |
+
for non-local objects with static storage duration; termination contains
|
| 12 |
+
the execution of destructors for objects with static storage
|
| 13 |
duration. — *end note*]
|
| 14 |
|
| 15 |
+
An implementation shall not predefine the `main` function. Its type
|
| 16 |
+
shall have C++ language linkage and it shall have a declared return type
|
| 17 |
+
of type `int`, but otherwise its type is *implementation-defined*. An
|
| 18 |
+
implementation shall allow both
|
| 19 |
|
| 20 |
- a function of `()` returning `int` and
|
| 21 |
- a function of `(int`, pointer to pointer to `char)` returning `int`
|
| 22 |
|
| 23 |
as the type of `main` [[dcl.fct]]. In the latter form, for purposes of
|
|
|
|
| 30 |
[[multibyte.strings]] and `argv[0]` shall be the pointer to the initial
|
| 31 |
character of a NTMBS that represents the name used to invoke the program
|
| 32 |
or `""`. The value of `argc` shall be non-negative. The value of
|
| 33 |
`argv[argc]` shall be 0.
|
| 34 |
|
| 35 |
+
*Recommended practice:* Any further (optional) parameters should be
|
| 36 |
+
added after `argv`.
|
| 37 |
|
| 38 |
The function `main` shall not be used within a program. The linkage
|
| 39 |
[[basic.link]] of `main` is *implementation-defined*. A program that
|
| 40 |
defines `main` as deleted or that declares `main` to be `inline`,
|
| 41 |
+
`static`, `constexpr`, or `consteval` is ill-formed. The function `main`
|
| 42 |
+
shall not be a coroutine [[dcl.fct.def.coroutine]]. The `main` function
|
| 43 |
+
shall not be declared with a *linkage-specification* [[dcl.link]]. A
|
| 44 |
+
program that declares
|
| 45 |
+
|
| 46 |
+
- a variable `main` that belongs to the global scope, or
|
| 47 |
+
- a function `main` that belongs to the global scope and is attached to
|
| 48 |
+
a named module, or
|
| 49 |
+
- a function template `main` that belongs to the global scope, or
|
| 50 |
+
- an entity named `main` with C language linkage (in any namespace)
|
| 51 |
+
|
| 52 |
+
is ill-formed. The name `main` is not otherwise reserved.
|
| 53 |
|
| 54 |
[*Example 1*: Member functions, classes, and enumerations can be called
|
| 55 |
`main`, as can entities in other namespaces. — *end example*]
|
| 56 |
|
| 57 |
Terminating the program without leaving the current block (e.g., by
|
| 58 |
calling the function `std::exit(int)` [[support.start.term]]) does not
|
| 59 |
destroy any objects with automatic storage duration [[class.dtor]]. If
|
| 60 |
+
`std::exit` is invoked during the destruction of an object with static
|
| 61 |
+
or thread storage duration, the program has undefined behavior.
|
|
|
|
| 62 |
|
| 63 |
A `return` statement [[stmt.return]] in `main` has the effect of leaving
|
| 64 |
the main function (destroying any objects with automatic storage
|
| 65 |
duration) and calling `std::exit` with the return value as the argument.
|
| 66 |
If control flows off the end of the *compound-statement* of `main`, the
|