Skip to content

Commit e5bdbb7

Browse files
authored
Document exceptions to the rules for parsing C arguments
This description was empirically wrong, which made it rather confusing to read and rely upon.
1 parent 1c2997d commit e5bdbb7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

docs/c-language/parsing-c-command-line-arguments.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Microsoft C startup code uses the following rules when interpreting arguments gi
2222

2323
- If an odd number of backslashes is followed by a double quotation mark, then one backslash (**\\**) is placed in the `argv` array for every pair of backslashes (**\\\\**) and the double quotation mark is interpreted as an escape sequence by the remaining backslash, causing a literal double quotation mark (**"**) to be placed in `argv`.
2424

25+
- A double quotation mark appearing after a closing double quotation mark, **"*""**, will be interpreted as a literal double quotation mark (**\*"**). It might also (depending on the target program) delimit the start of a new string region.
26+
2527
This list illustrates the rules above by showing the interpreted result passed to `argv` for several examples of command-line arguments. The output listed in the second, third, and fourth columns is from the ARGS.C program that follows the list.
2628

2729
|Command-Line Input|argv[1]|argv[2]|argv[3]|
@@ -31,6 +33,9 @@ This list illustrates the rules above by showing the interpreted result passed t
3133
|`a\\\b d"e f"g h`|`a\\\b`|`de fg`|`h`|
3234
|`a\\\"b c d`|`a\"b`|`c`|`d`|
3335
|`a\\\\"b c" d e`|`a\\b c`|`d`|`e`|
36+
|`a"b"" c d`|`ab"`|`c`|`d`|
37+
38+
Note that the command itself (**argv[0]**) may use different parsing rules, and often does not treat a backslash as an escape character.
3439

3540
## Example
3641

0 commit comments

Comments
 (0)