Skip to content

Commit c30f5e7

Browse files
committed
fix: update main_function.mdx
1 parent 8163b7d commit c30f5e7

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/content/docs/cpp/language/basic_concepts/main_function.mdx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The C++ standard recommends implementation-defined main functions to place the e
5454
Non-negative value representing the number of arguments passed to the program from the environment in which the program is run.
5555
</ParamDoc>
5656
<ParamDoc name="argv">
57-
Pointer to the first element of an array of `argc + 1` pointers, of which the last one is null and the previous ones, if any, point to <Missing>null-terminated multibyte strings</Missing> that represent the arguments passed to the program from the execution environment. If `argv[0]` is not a null pointer (or, equivalently, if `argc > 0`), it points to a string that represents the name used to invoke the program, or to an empty string.
57+
Pointer to the first element of an array of `argc + 1` pointers, of which the last one is null and the previous ones, if any, point to <DocLink dest="/cpp/library/text/multibyte">null-terminated multibyte strings</DocLink> that represent the arguments passed to the program from the execution environment. If `argv[0]` is not a null pointer (or, equivalently, if `argc > 0`), it points to a string that represents the name used to invoke the program, or to an empty string.
5858
</ParamDoc>
5959
<ParamDoc name="body">
6060
The body of the `main` function.
@@ -63,30 +63,30 @@ The C++ standard recommends implementation-defined main functions to place the e
6363

6464
## Explanation
6565

66-
The `main` function is called at program startup after <Missing>initialization</Missing> of the non-local objects with static storage duration. It is the designated entry point to a program that is executed in <Missing>hosted</Missing> environment (that is, with an operating system). The entry points to <Missing>freestanding</Missing> programs (boot loaders, OS kernels, etc) are implementation-defined.
66+
The `main` function is called at program startup after <DocLink dest="/cpp/language/initialization">initialization</DocLink> of the non-local objects with static <DocLink dest="/cpp/language/declarations/storage_duration">storage duration</DocLink>. It is the designated entry point to a program that is executed in <DocLink dest="/cpp/library/freestanding">hosted</DocLink> environment (that is, with an operating system). The entry points to <DocLink dest="/cpp/library/freestanding">freestanding</DocLink> programs (boot loaders, OS kernels, etc) are <Behavior type="impl-def">implementation-defined</Behavior>.
6767

68-
The parameters of the two-parameter form of the `main` function allow arbitrary multibyte character strings to be passed from the execution environment (these are typically known as _command line arguments_), the pointers [`argv[1]`, `argv[argc - 1]`] point at the first characters in each of these strings. `argv[0]` (if non-null) is the pointer to the initial character of a null-terminated multibyte string that represents the name used to invoke the program itself (or an empty string `""` if this is not supported by the execution environment). The strings are modifiable, although these modifications do not propagate back to the execution environment: they can be used, for example, with <Missing>`std::strtok`</Missing>. The size of the array pointed to by `argv` is at least `argc + 1`, and the last element, `argv[argc]`, is guaranteed to be a null pointer.
68+
The parameters of the two-parameter form of the `main` function allow arbitrary multibyte character strings to be passed from the execution environment (these are typically known as _command line arguments_), the pointers [`argv[1]`, `argv[argc - 1]`] point at the first characters in each of these strings. `argv[0]` (if non-null) is the pointer to the initial character of a null-terminated multibyte string that represents the name used to invoke the program itself (or an empty string `""` if this is not supported by the execution environment). The strings are modifiable, although these modifications do not propagate back to the execution environment: they can be used, for example, with <DocLink dest="/cpp/library/text/byte/strtok">`std::strtok`</DocLink>. The size of the array pointed to by `argv` is at least `argc + 1`, and the last element, `argv[argc]`, is guaranteed to be a null pointer.
6969

7070
The `main` function has the following several special properties:
7171

72-
- The body of the `main` function does not need to contain the <Missing>`return` statement</Missing>: if control reaches the end of main without encountering a `return` statement, the effect is that of executing `return 0;`.
73-
- Execution of the return (or the implicit return upon reaching the end of main) is equivalent to first leaving the function normally (which destroys the objects with automatic storage duration <Revision since="C++26">and evaluates any <Missing>postcondition assertions</Missing> of main</Revision>) and then calling <Missing>`std::exit`</Missing> with the same argument as the argument of the return (<Missing>`std::exit`</Missing> then destroys static objects and terminates the program).
72+
- The body of the `main` function does not need to contain the <DocLink dest="/cpp/language/statements/return">`return` statement</DocLink>: if control reaches the end of main without encountering a `return` statement, the effect is that of executing `return 0;`.
73+
- Execution of the return (or the implicit return upon reaching the end of main) is equivalent to first leaving the function normally (which destroys the objects with automatic storage duration<Revision since="C++26"> and evaluates any <DocLink dest="/cpp/language/functions/function" section="postcondition-assertions">postcondition assertions</DocLink> of main</Revision>) and then calling <DocLink dest="/cpp/library/utility/program/exit">`std::exit`</DocLink> with the same argument as the argument of the <DocLink dest="/cpp/language/statements/return">return</DocLink> (<DocLink dest="/cpp/library/utility/program/exit">`std::exit`</DocLink> then destroys static objects and terminates the program).
7474

7575
The `main` function has several restrictions (violation of which renders the program <Behavior kind="ill-formed">ill-formed</Behavior>):
7676

77-
- It cannot be <Missing>named</Missing> anywhere in the program
77+
- It cannot be <DocLink dest="/cpp/language/basic_concepts/definition" section="naming-a-function">named</DocLink> anywhere in the program
7878
- in particular, it cannot be called recursively
7979
- its address cannot be taken
80-
- it cannot be used in a <Missing>`typeid`</Missing> expression <Revision since="C++11">or a <Missing>`decltype`</Missing> specifier</Revision>
81-
- It cannot be predefined and cannot be overloaded: effectively, the name `main` in the global namespace is reserved for functions (although it can be used to name classes, namespaces, enumerations, and any entity in a non-global namespace, except that an entity named `main` cannot be declared with C <Missing>language linkage</Missing> in any namespace).
82-
- It cannot be <Revision since="C++11">defined as deleted or</Revision> declared with any language linkage<Revision since="C++11">, <Missing>constexpr</Missing></Revision><Revision since="C++20">, <Missing>consteval</Missing></Revision>, <Missing>inline</Missing>, or <Missing>static</Missing>.
80+
- it cannot be used in a <DocLink dest="/cpp/language/expressions/typeid">`typeid`</DocLink> expression<Revision since="C++11"> or a <DocLink dest="/cpp/language/declarations/decltype">`decltype`</DocLink> specifier</Revision>
81+
- It cannot be predefined and cannot be overloaded: effectively, the name `main` in the global namespace is reserved for functions (although it can be used to name classes, namespaces, enumerations, and any entity in a non-global namespace, except that an entity named `main` cannot be declared with C <DocLink dest="/cpp/language/declarations/language_linkage">language linkage</DocLink> in any namespace).
82+
- It cannot be<Revision since="C++11"> defined as deleted or</Revision> declared with any language linkage<Revision since="C++11">, <DocLink dest="/cpp/language/declarations/constexpr">constexpr</DocLink></Revision><Revision since="C++20">, <DocLink dest="/cpp/language/declarations/consteval">consteval</DocLink></Revision>, <DocLink dest="/cpp/language/declarations/inline">inline</DocLink>, or <DocLink dest="/cpp/language/classes/static">static</DocLink>.
8383
- <Revision since="C++14">The return type of the `main` function cannot be deduced (`auto main() {...}` is not allowed).</Revision>
84-
- <Revision since="C++20">The `main` function cannot be a <Missing>coroutine</Missing>.</Revision>
85-
- <Revision since="C++20">The `main` function cannot attach to a named <Missing>module</Missing>.</Revision>
84+
- <Revision since="C++20">The `main` function cannot be a <DocLink dest="/cpp/language/functions/coroutines">coroutine</DocLink>.</Revision>
85+
- <Revision since="C++20">The `main` function cannot attach to a named <DocLink dest="/cpp/language/basic_concepts/modules">module</DocLink>.</Revision>
8686

8787
## Notes
8888

89-
If the `main` function is defined with a <Missing>function `try` block</Missing>, the exceptions thrown by the destructors of static objects (which are destroyed by the implied <Missing>`std::exit`</Missing>) are not <Missing>caught</Missing> by it.
89+
If the `main` function is defined with a <DocLink dest="/cpp/language/exceptions/try">function `try` block</DocLink>, the exceptions thrown by the destructors of static objects (which are destroyed by the implied <DocLink dest="/cpp/library/utility/program/exit">`std::exit`</DocLink>) are not <DocLink dest="/cpp/language/exceptions/catch">caught</DocLink> by it.
9090

9191
The manner in which the arguments given at the OS command line are converted into the multibyte character arrays referenced by `argv` may involve implementation-defined processing:
9292

@@ -187,6 +187,6 @@ The following behavior-changing defect reports were applied retroactively to pre
187187
188188
<DescList>
189189
<Desc>
190-
<DocLink slot="item" dest="/c/language/main_function"> C documentation</DocLink> for <span> **main function** </span>
190+
<DocLink slot="item" dest="/c/language/basic_concepts/main_function"> C documentation</DocLink> for <span> **main function** </span>
191191
</Desc>
192192
</DescList>

0 commit comments

Comments
 (0)