Skip to content

Commit 275dcd4

Browse files
author
Colin Robertson
committed
Undo a bit
1 parent db8e10c commit 275dcd4

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

docs/cpp/main-function-command-line-args.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,25 @@ no-loc: [main, wmain, inline, static, _tmain, void, exit, argc, argv, envp, Crea
99

1010
All C++ programs must have a `main` function. If you try to compile a C++ *.exe* project without a main function, the compiler will raise an error. (Dynamic-link libraries and static libraries don't have a `main` function.) The `main` function is where your source code begins execution, but before a program enters the `main` function, all static class members without explicit initializers are set to zero. In Microsoft C++, global static objects are also initialized before entry to `main`. Several restrictions apply to the `main` function that do not apply to any other C++ functions. The `main` function:
1111

12-
- Can't be overloaded (see [Function Overloading](function-overloading.md)).
13-
- Can't be declared as **inline**.
14-
- Can't be declared as **static**.
15-
- Can't have its address taken.
16-
- Can't be called.
12+
- Cannot be overloaded (see [Function Overloading](function-overloading.md)).
13+
- Cannot be declared as **inline**.
14+
- Cannot be declared as **static**.
15+
- Cannot have its address taken.
16+
- Cannot be called.
1717

1818
The main function doesn't have a declaration, because it's built into the language. If it did, the declaration syntax for `main` would look like this:
1919

2020
```cpp
2121
int main();
22-
int main(int argc, char *argv[]);
2322
int main(int argc, char *argv[], char *envp[]);
2423
```
2524
2625
**Microsoft Specific**
2726
28-
If your source files use Unicode wide characters, you can use `wmain`, which is the wide-character version of `main`. The virtual declaration syntax for `wmain` is as follows:
27+
If your source files use Unicode wide characters, you can use `wmain`, which is the wide-character version of `main`. The declaration syntax for `wmain` is as follows:
2928
3029
```cpp
3130
int wmain( );
32-
int wmain(int argc, wchar_t *argv[]);
3331
int wmain(int argc, wchar_t *argv[], wchar_t *envp[]);
3432
```
3533

@@ -39,10 +37,15 @@ If no return value is specified, the compiler supplies a return value of zero. A
3937

4038
**END Microsoft Specific**
4139

42-
## Command-line arguments
40+
## Command line arguments
4341

4442
The arguments for `main` or `wmain` allow convenient command-line parsing of arguments and, optionally, access to environment variables. The types for `argc` and `argv` are defined by the language. The names `argc`, `argv`, and `envp` are traditional, but you can name them whatever you like.
4543

44+
```cpp
45+
int main(int argc, char *argv[], char *envp[]);
46+
int wmain(int argc, wchar_t *argv[], wchar_t *envp[]);
47+
```
48+
4649
The argument definitions are as follows:
4750
4851
*argc*<br/>
@@ -154,7 +157,7 @@ The following table shows example input and expected output, demonstrating the r
154157
155158
You can use wildcards — the question mark (?) and asterisk (*) — to specify filename and path arguments on the command line.
156159
157-
Command-line arguments are handled by a routine called `_setargv` (or `_wsetargv` in the wide-character environment), which by default does not expand wildcards into separate strings in the `argv` string array. For more information on enabling wildcard expansion, see [Expanding Wildcard Arguments](../c-language/expanding-wildcard-arguments.md).
160+
Command-line arguments are handled by a routine called `_setargv` (or `_wsetargv` in the wide-character environment), which by default does not expand wildcards into separate strings in the `argv` string array. For more information on enabling wildcard expansion, refer to [Expanding Wildcard Arguments](../c-language/expanding-wildcard-arguments.md).
158161
159162
**END Microsoft Specific**
160163
@@ -164,12 +167,12 @@ Command-line arguments are handled by a routine called `_setargv` (or `_wsetargv
164167
165168
If your program does not take command-line arguments, you can save a small amount of space by suppressing use of the library routine that performs command-line processing. This routine is called `_setargv` and is described in [Wildcard Expansion](../cpp/wildcard-expansion.md). To suppress its use, define a routine that does nothing in the file containing the `main` function, and name it `_setargv`. The call to `_setargv` is then satisfied by your definition of `_setargv`, and the library version is not loaded.
166169
167-
Similarly, if you never access the environment table through the `envp` argument, you can provide your own empty routine to be used in place of `_setenvp`, the environment-processing routine. Like the `_setargv` function, `_setenvp` must be declared as **extern "C"**.
170+
Similarly, if you never access the environment table through the `envp` argument, you can provide your own empty routine to be used in place of `_setenvp`, the environment-processing routine. Just as with the `_setargv` function, `_setenvp` must be declared as **extern "C"**.
168171
169172
Your program might make calls to the `spawn` or `exec` family of routines in the C run-time library. If it does, you shouldn't suppress the environment-processing routine, since this routine is used to pass an environment from the parent process to the child process.
170173
171174
**END Microsoft Specific**
172175
173176
## See also
174177
175-
[Basic concepts](../cpp/basic-concepts-cpp.md)
178+
[Basic Concepts](../cpp/basic-concepts-cpp.md)

0 commit comments

Comments
 (0)