From Jason Turner

[basic.start.main]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpf5gttma6/{from.md → to.md} +41 -38
tmp/tmpf5gttma6/{from.md → to.md} RENAMED
@@ -1,64 +1,67 @@
1
- ### `main` function <a id="basic.start.main">[[basic.start.main]]</a>
2
 
3
- A program shall contain a global function called `main`. Executing a
4
- program starts a main thread of execution ([[intro.multithread]],
5
- [[thread.threads]]) in which the `main` function is invoked, and in
6
- which variables of static storage duration might be initialized (
7
- [[basic.start.static]]) and destroyed ([[basic.start.term]]). It is
8
- *implementation-defined* whether a program in a freestanding environment
9
- is required to define a `main` function.
10
 
11
- [*Note 1*: In a freestanding environment, start-up and termination is
12
- *implementation-defined*; start-up contains the execution of
13
- constructors for objects of namespace scope with static storage
14
- duration; termination contains the execution of destructors for objects
15
- with static storage 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
26
- of exposition, the first function parameter is called `argc` and the
27
- second function parameter is called `argv`, where `argc` shall be the
28
- number of arguments passed to the program from the environment in which
29
- the program is run. If `argc` is nonzero these arguments shall be
30
- supplied in `argv[0]` through `argv[argc-1]` as pointers to the initial
31
- characters of null-terminated multibyte strings (NTMBS s) (
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 `main` function shall not be
44
- declared with a *linkage-specification* ([[dcl.link]]). A program that
45
- declares a variable `main` at global scope or that declares the name
46
- `main` with C language linkage (in any namespace) is ill-formed. The
47
- name `main` is not otherwise reserved.
 
 
48
 
49
  [*Example 1*: Member functions, classes, and enumerations can be called
50
  `main`, as can entities in other namespaces. — *end example*]
51
 
52
  Terminating the program without leaving the current block (e.g., by
53
- calling the function `std::exit(int)` ([[support.start.term]])) does
54
- not destroy any objects with automatic storage duration (
55
- [[class.dtor]]). If `std::exit` is called to end a program during the
56
- destruction of an object with static or thread storage duration, the
57
- program has undefined behavior.
58
 
59
- A return statement in `main` has the effect of leaving the main function
60
- (destroying any objects with automatic storage duration) and calling
61
- `std::exit` with the return value as the argument. If control flows off
62
- the end of the *compound-statement* of `main`, the effect is equivalent
63
- to a `return` with operand `0` (see also [[except.handle]]).
 
64
 
 
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
26
+ exposition, the first function parameter is called `argc` and the second
27
+ function parameter is called `argv`, where `argc` shall be the number of
28
+ arguments passed to the program from the environment in which the
29
+ program is run. If `argc` is nonzero these arguments shall be supplied
30
+ in `argv[0]` through `argv[argc-1]` as pointers to the initial
31
+ 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
65
+ effect is equivalent to a `return` with operand `0` (see also
66
+ [[except.handle]]).
67