On a hosted environment, The signature of main
allows for two basic variants:
int main(void)
int main(int, char **) // or synonym like char *[]
Strictly speaking the return 0
is never required for main
, as the standard clearly states that 5.1.2.2.3:
If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument reaching the } that terminates the main function returns a value of 0. If the return type is not compatible with int, the termination status returned to the host environment is unspecified.
By long time established convention 0
means "no error" on such systems (that's the reason for the default result).
Said that, a bare metal controller is typically a freestanding environment. For such environments, the signature of main
is not specified. Actually not even which function is called as entry to the application program is not defined, but left to the environment. Using main
is just a common informative convention here. It often has a signature of
void main(void)
Even better, they define
_Noreturn void main(void)
That means main
shall never ever return.
However, some systems allow main
to return and flag for special actions, e.g. cold reset, hot reset, signal fatal failure (like busy-blink an LED), power off, etc. So you require one of the classic signatures here.
Note all this is beyond the standard and has to be defined by your execution environment.
Briefly: return 0
from int main(...)
is not required for a hosted environment, but it is good style to be explicitly state: "Yes, there is no error here". For a freestanding environment like your's Check the documentation and/or startup code for the correct signature and the allowed results.