Christian Christmann said:
Hi,
the ANSI-C 99 standard specifies that the main function
has "int" as return type. However, there are still lots
of people declaring "void" as main return type.
Did previous ANSI-C standards defined "void" as return type
No, never, but see below.
or is this issue just a lack of C knowledge?
Mostly, yes.
The void type has never been a correct return type for main except in the
following circumstances, which also cover all other possible return types
(double main, struct tm main, union myunion main, etc):
1) in C90 and C99, if the implementation is freestanding and documents the
type in question as the appropriate return type for the entry point (which
might not even be called main);
2) in C99 *only*, if the implementation explicitly documents the return type
in question as being supported.
In each case, returning a value of a type other than int from main means
that your program is not portable to implementations that do not document
and support such a return type.
So, as with so much in life, the simple answer doesn't quite tell the full
story.
For maximal portability, use int as the type of your return value from main.
The only case where this doesn't work is where your (necessarily
freestanding) implementation specifically /requires/ you to do otherwise,
in which case your program - or at least the entry point part of it - isn't
going to be portable anyway.
A classic example of a freestanding implementation is Visual C when used in
the normal way to compile Windows programs - the entry point is not main,
but WinMain, and therefore the implementation *must* be freestanding!
Ironically for a company that has done so much to spread the void main myth,
Microsoft's WinMain is required to return int!