jaysome said:
And so are a lot of embedded compiler vendors, who realize that
99.9999999% of their users write code like this:
void main(void)
{
/* loop forever */
for ( ; ; )
{
/* handle whatever */
}
}
I prefer a return type of void for main() in embedded (free-standing)
applications, provided the compiler supports it, of course.
Yes, the advice that main() always returns int really applies only to
hosted implementations, not to freestanding (typically embedded)
implementations. We usually assume here that we're talking about
hosted implementations unless explicitly stated otherwise, for a
couple of reasons: most people who are learning C use hosted
implementations, and most users of freestanding implementations are, I
would guess, more familiar both with the language and with the
vagaries of their particular implementation.
For *any* compiler, you should use only the forms of main that are
explicitly supported (i.e., documented) by the implementation. For a
hosted implementation, this *always* includes the standard forms
int main(void)
and
int main(int argc, char *argv[])
Using any other form may happen to work with some particular
implementation, but it breaks portability for no real benefit.
For a freestanding implementation, there are no standard forms for
main, and you're stuck using whatever the implementation documents.
I've never actually used a freestanding implementation; I'll take your
word for it that "void main(void)" is typical in that domain.