@@ -3414,30 +3414,31 @@ $(H3 $(LNAME2 anonymous, Anonymous Functions and Anonymous Delegates))
3414
3414
$(P See $(GLINK2 expression, FunctionLiteral)s.
3415
3415
)
3416
3416
3417
- $(H2 $(LNAME2 main, $(D main() ) Function))
3417
+ $(H2 $(LNAME2 main, The $(D main) Function))
3418
3418
3419
- $(P For console programs, $(D main()) serves as the entry point.
3419
+ $(P For console programs, the $(D main) function serves as the entry point.
3420
3420
It gets called after all the $(DDSUBLINK spec/module, staticorder, module initializers)
3421
3421
are run, and after any $(DDLINK spec/unittest, Unit Tests, unittests) are run.
3422
3422
After it returns, all the module destructors are run.
3423
- $(D main()) must be declared as follows:
3423
+ The $(D main) function typically is declared as follows:
3424
3424
)
3425
3425
3426
- $(GRAMMAR
3427
- $(GNAME MainFunction):
3428
- $(GLINK MainReturnDecl) $(D main$(LPAREN)$(RPAREN)) $(GLINK2 statement, MainFunctionBody )
3429
- $(GLINK MainReturnDecl) $(D main$(LPAREN)string[ ]) $(GLINK_LEX Identifier)$(D $(RPAREN)) $(GLINK2 statement, MainFunctionBody )
3426
+ $(INFORMATIVE_GRAMMAR
3427
+ $(GNAME MainFunction):
3428
+ $(GLINK MainReturnDecl) $(D main) $(LPAREN) $(RPAREN) $(GLINK FunctionBody )
3429
+ $(GLINK MainReturnDecl) $(D main) $(LPAREN) $(D string) $(D [) $(D ]) $(GLINK_LEX Identifier)$(OPT) $(RPAREN) $(GLINK FunctionBody )
3430
3430
3431
- $(GNAME MainReturnDecl):
3432
- $(D void)
3433
- $(D int)
3434
- $(GLINK2 type, noreturn)
3435
- $(RELATIVE_LINK2 auto-functions, $(D auto))
3431
+ $(GNAME MainReturnDecl):
3432
+ $(D void)
3433
+ $(D int)
3434
+ $(GLINK2 type, noreturn)
3435
+ $(RELATIVE_LINK2 auto-functions, $(D auto))
3436
+ $(GLINK_LEX Identifier)
3436
3437
3437
- $(GNAME MainFunctionBody):
3438
- $(GLINK ShortenedFunctionBody)
3439
- $(GLINK SpecifiedFunctionBody)
3440
- )
3438
+ $(GNAME MainFunctionBody):
3439
+ $(GLINK ShortenedFunctionBody)
3440
+ $(GLINK SpecifiedFunctionBody)
3441
+ )
3441
3442
3442
3443
$(UL
3443
3444
$(LI If `main` returns `void`, the OS will receive a zero value on success.)
@@ -3447,35 +3448,36 @@ $(H2 $(LNAME2 main, $(D main()) Function))
3447
3448
one of `void`, `int` and `noreturn`.)
3448
3449
)
3449
3450
3450
- $(P If the $(D string[]) parameter is declared, the parameter will hold
3451
- arguments passed to the program by the OS. The first argument is typically
3451
+ $(P If the parameter is declared, it will hold
3452
+ arguments passed to the program by the OS. The index-0 element is typically
3452
3453
the executable name, followed by any command-line arguments.)
3453
3454
3454
3455
$(NOTE The runtime can remove any arguments prefixed `--DRT-`.)
3455
3456
3456
- $(NOTE The aforementioned return / parameter types may be annotated with $(D const),
3457
- $(D immutable). They may also be replaced by $(D enum)'s with matching base types.)
3457
+ $(NOTE The aforementioned return / parameter types may be annotated with $(D const) or
3458
+ $(D immutable), or carry $(GLINK ParameterAttributes).
3459
+ They may also be replaced by $(D enum) types with matching base types.)
3458
3460
3459
3461
$(P The main function must have D linkage.)
3460
3462
3461
3463
$(P Attributes may be added as needed, e.g. `@safe`, `@nogc`, `nothrow`, etc.)
3462
3464
3463
- $(H3 $(LNAME2 betterc-main, $(D extern(C) main() ) Function))
3465
+ $(H2 $(LNAME2 betterc-main, $(D extern(C)) $(D main ) Function))
3464
3466
3465
3467
$(P Programs may define an $(D extern(C) main) function as an alternative to the
3466
3468
standard $(RELATIVE_LINK2 main, entry point). This form is required for
3467
3469
$(DDLINK spec/betterc, Better C, $(B BetterC)) programs.)
3468
3470
3469
- $(P A C $(D main) function must be declared as follows:)
3471
+ $(P A C $(D main) function is typically declared as follows:)
3470
3472
3471
- $(GRAMMAR
3472
- $(GNAME CMainFunction):
3473
- $(D extern (C)) $(GLINK MainReturnDecl) $(D main$(LPAREN)$(GLINK CmainParameters )$(OPT)$(RPAREN) ) $(GLINK2 statement, BlockStatement)
3473
+ $(INFORMATIVE_GRAMMAR
3474
+ $(GNAME CMainFunction):
3475
+ $(D extern) $(LPAREN) $(D C) $(RPAREN) $(GLINK MainReturnDecl) $(D main) $(LPAREN) $(GLINK CMainParameters )$(OPT) $(RPAREN) $(GLINK2 statement, BlockStatement)
3474
3476
3475
- $(GNAME CmainParameters ):
3476
- $(D int) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier)
3477
- $(D int) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier), $(D char**) $(GLINK_LEX Identifier)
3478
- )
3477
+ $(GNAME CMainParameters ):
3478
+ $(D int) $(GLINK_LEX Identifier)$(OPT) $(D ,) $(D char**) $(GLINK_LEX Identifier)$(OPT )
3479
+ $(D int) $(GLINK_LEX Identifier)$(OPT) $(D ,) $(D char**) $(GLINK_LEX Identifier)$(OPT) $(D ,) $(D char**) $(GLINK_LEX Identifier)$(OPT )
3480
+ )
3479
3481
3480
3482
$(P When defined, the first two parameters denote a C-style array (length + pointer)
3481
3483
that holds the arguments passed to the program by the OS. The third parameter is a POSIX
0 commit comments