@@ -2955,19 +2955,38 @@ $(H3 $(LNAME2 anonymous, Anonymous Functions and Anonymous Delegates))
2955
2955
$(H2 $(LNAME2 main, $(D main()) Function))
2956
2956
2957
2957
$(P For console programs, $(D main()) serves as the entry point.
2958
- It gets called after all the module initializers are run, and
2959
- after any unittests are run.
2958
+ It gets called after all the $(DDSUBLINK spec/ module, staticorder, module initializers)
2959
+ are run, and after any $(DDLINK spec/unittest, Unit Tests, unittests) are run.
2960
2960
After it returns, all the module destructors are run.
2961
- $(D main()) must be declared using one of the following forms:
2961
+ $(D main()) must be declared as follows:
2962
+ )
2963
+
2964
+ $(GRAMMAR
2965
+ $(GNAME MainFunction):
2966
+ $(GLINK MainReturnDecl) $(D main$(LPAREN)$(RPAREN)) $(GLINK2 statement, BlockStatement)
2967
+ $(GLINK MainReturnDecl) $(D main$(LPAREN)string[]) $(GLINK_LEX Identifier)$(D $(RPAREN)) $(GLINK2 statement, BlockStatement)
2968
+
2969
+ $(GNAME MainReturnDecl):
2970
+ $(D void)
2971
+ $(D int)
2972
+ $(GLINK2 type, noreturn)
2973
+ $(RELATIVE_LINK2 auto-functions, $(D auto))
2962
2974
)
2963
2975
2964
2976
$(UL
2965
- $(LI `void main() { ... }`)
2966
- $(LI `void main(string[] args) { ... }`)
2967
- $(LI `int main() { ... }`)
2968
- $(LI `int main(string[] args) { ... }`)
2977
+ $(LI If `main` returns `void`, the OS will receive a zero value on success.)
2978
+ $(LI If `main` returns `void` or `noreturn`, the OS will receive a non-zero
2979
+ value on abnormal termination, such as an uncaught exception.)
2980
+ $(LI If `main` is declared as `auto`, the inferred return type must be
2981
+ one of `void`, `int` and `noreturn`.)
2969
2982
)
2970
2983
2984
+ $(P If the $(D string[]) parameter is declared, the parameter will hold
2985
+ arguments passed to the program by the OS. The first argument is typically
2986
+ the executable name, followed by any command-line arguments.)
2987
+
2988
+ $(NOTE The runtime can remove any arguments prefixed `--DRT-`.)
2989
+
2971
2990
$(P The main function must have D linkage.)
2972
2991
2973
2992
$(P Attributes may be added as needed, e.g. `@safe`, `@nogc`, `nothrow`, etc.)
0 commit comments