From Jason Turner

[basic.start.main]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp1enguaos/{from.md → to.md} +29 -21
tmp/tmp1enguaos/{from.md → to.md} RENAMED
@@ -1,20 +1,25 @@
1
- ### Main function <a id="basic.start.main">[[basic.start.main]]</a>
2
 
3
- A program shall contain a global function called `main`, which is the
4
- designated start of the program. It is *implementation-defined* whether
5
- a program in a freestanding environment is required to define a `main`
6
- function. In a freestanding environment, start-up and termination is
 
 
 
 
 
7
  *implementation-defined*; start-up contains the execution of
8
  constructors for objects of namespace scope with static storage
9
  duration; termination contains the execution of destructors for objects
10
- with static storage duration.
11
 
12
  An implementation shall not predefine the `main` function. This function
13
- shall not be overloaded. It shall have a declared return type of type
14
- `int`, but otherwise its type is *implementation-defined*. An
15
- implementation shall allow both
16
 
17
  - a function of `()` returning `int` and
18
  - a function of `(int`, pointer to pointer to `char)` returning `int`
19
 
20
  as the type of `main` ([[dcl.fct]]). In the latter form, for purposes
@@ -25,32 +30,35 @@ the program is run. If `argc` is nonzero these arguments shall be
25
  supplied in `argv[0]` through `argv[argc-1]` as pointers to the initial
26
  characters of null-terminated multibyte strings (NTMBS s) (
27
  [[multibyte.strings]]) and `argv[0]` shall be the pointer to the initial
28
  character of a NTMBSthat represents the name used to invoke the program
29
  or `""`. The value of `argc` shall be non-negative. The value of
30
- `argv[argc]` shall be 0. It is recommended that any further (optional)
31
- parameters be added after `argv`.
 
 
32
 
33
  The function `main` shall not be used within a program. The linkage (
34
  [[basic.link]]) of `main` is *implementation-defined*. A program that
35
  defines `main` as deleted or that declares `main` to be `inline`,
36
- `static`, or `constexpr` is ill-formed. The name `main` is not otherwise
37
- reserved. member functions, classes, and enumerations can be called
38
- `main`, as can entities in other namespaces.
 
 
 
 
 
39
 
40
  Terminating the program without leaving the current block (e.g., by
41
  calling the function `std::exit(int)` ([[support.start.term]])) does
42
  not destroy any objects with automatic storage duration (
43
  [[class.dtor]]). If `std::exit` is called to end a program during the
44
  destruction of an object with static or thread storage duration, the
45
  program has undefined behavior.
46
 
47
  A return statement in `main` has the effect of leaving the main function
48
  (destroying any objects with automatic storage duration) and calling
49
- `std::exit` with the return value as the argument. If control reaches
50
- the end of `main` without encountering a `return` statement, the effect
51
- is that of executing
52
-
53
- ``` cpp
54
- return 0;
55
- ```
56
 
 
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
 
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 NTMBSthat 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