From Jason Turner

[basic.start.main]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpvdpmyxjv/{from.md → to.md} +27 -25
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 a global function called `main` attached to the
4
- global module. Executing a program starts a main thread of execution (
5
- [[intro.multithread]], [[thread.threads]]) in which the `main` function
6
- is invoked, and in which variables of static storage duration might be
7
- initialized [[basic.start.static]] and destroyed [[basic.start.term]].
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 of namespace scope with static storage duration; termination
14
- contains the execution of destructors for objects with static storage
15
  duration. — *end note*]
16
 
17
- An implementation shall not predefine the `main` function. This function
18
- shall not be overloaded. Its type shall have C++ language linkage and it
19
- shall have a declared return type of type `int`, but otherwise its type
20
- is *implementation-defined*. An implementation shall allow both
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
- [*Note 2*: It is recommended that any further (optional) parameters be
38
- added after `argv`. — *end note*]
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 `constexpr` is ill-formed. The function `main` shall not be
44
- a coroutine [[dcl.fct.def.coroutine]]. The `main` function shall not be
45
- declared with a *linkage-specification* [[dcl.link]]. A program that
46
- declares a variable `main` at global scope, or that declares a function
47
- `main` at global scope attached to a named module, or that declares the
48
- name `main` with C language linkage (in any namespace) is ill-formed.
49
- The name `main` is not otherwise reserved.
 
 
 
 
 
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 called to end a program during the destruction of an
58
- object with static or thread storage duration, the program has undefined
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