First of all let's clarify that because you refer to the main
function, obviously (but not for all seems) this answer assume that you are referring to an hosted environment, because for a freestanding environment (see ISO/IEC 9899:2011 "§5.1.2.1 Freestanding environment") there are no requirements at all and the name and type of the function called at program startup are implementation-defined.
Going back to the hosted environment, the standard that defines C language, in its more recent version ISO/IEC 9899:2011, for C11, describe the requirements for the program startup function in an enough strict way (§5.1.2.2.1 Program startup).
The points to be respected are essentially:
- The
main
function must return an int
.
- Only 2 variation of it are allowed:
- Without parameters as in :
int main(void) { /* ... */ }
- With 2 parameters a count of argument elements and the array of arguments as in :
int main(int argc, char *argv[]) { /* ... */ }
Some implementation variation are allowed, but only as different representation of same parameters (i.e. instead of char *argv[]
the equivalent char **argv
, or some typedef
for specific types resolving in an int
type for argc
).
The very common definition void main() { /* ... */ }
allowed in some major compiler producers (most often MS) are not strictly C99-C11 compliant.
In fact the use of empty parenthesis in function declarators is an obsolescent feature that could be removed in future standard revision as reported in "§6.11 Future language directions" (thanks to have reported me the imprecision). In fact many compilers C99-C11 compliant issue a warning.
So considering the before mentioned obsolescence would be a good habit to use a more standard declarations.
In conclusion your declaration is wrong because:
return;
You return no value
- Optionally consider that
main()
miss the void
(strict C99-C11)
What you return depends on what you want return. Let only say that a general convention commonly accepted is to return from main the value 0
(zero) for normal termination (no errors), any other value denotes an execution error.
Anyway for the sake of precision, for those who want go inside specs, I report below the exact text from specific paragraph
5.1.2.2.1 Program startup
The function called at program startup is named main.
The implementation declares no prototype for this
function. It shall be defined with a return type of int (emphasis mine, please see below the definition of the term shall in ISO document) and with no
parameters:
int main(void) { /* ... */ } or with two parameters
(referred to here as argc and argv, though any names may be used, as
they are local to the function in which they are declared):
int main(int argc, char *argv[]) { /* ... */ }
or equivalent;(see note below) or in some other implementation-defined manner.
The note for equivalent type says:
NOTE: Thus, int can be replaced by a typedef
name defined as int
, or the type of argv
can be written as char ** argv
, and so on
Last to remove any doubt about the meaning of the term "shall" the ISO/IEC 9899:2011 specification clearly define it on paragraph §4.0 Conformance at subpar. 1:
4.0 Conformance
1 In this International Standard, ‘‘shall’’ is to be interpreted as
a requirement on an implementation or on a program; conversely,
‘‘shall not’’ is to be interpreted as a prohibition.