Kaz said:
The program's behavior is undefined, because implementations are not
required to support that form of main.
Implementation-defined behavior is not undefined behavior. So without
knowing anything about the implementation, it is not possible to
conclude whether this program's behavior is undefined or not. It is
possible to determine whether the program's behavior is defined for a
given compiler, because all implementation-defined behavior must be
documented. So in this case, it is necessary only to consult the
"implementation-defined behavior" section of the compiler's
documentation to find out what it says about arguments to main.
A program that uses a feature for which the support is
implementation-defined in fact invokes undefined behavior.
No, it invokes the behavior that the implementation, and not the
Standard, has defined for it.
I would say that the definition
int main(int a, int b, int c, int d, int e) { /* ... */ }
is /worse/ than one returning void! The reason is that no diagnostic is
required! A diagnostic is required if the return type is other than
int. (In that case, the C++ implementation can still translate and
execute the program anyway, but its behavior is undefined).
Anything other than int main() or int main(int, char **) runs by dumb
luck, or by means of being supported as an extension, which has nothing
to do with the standard other than being allowed with or without a
diagnostic, depending on whether the return type is int.
The C++ standard specifically leaves some questions - such as the size
of a byte or additional declarations of main - up to each
implementation to decide on its own. It does so because it recognizes
that a "one-size-fits-all" approach is not always practicable for all
types of processors and OS'es. Instead it is better to have each
implementation be responsible for deciding these types of issues and
for documenting the decision. So any C++ program whose behavior is
defined by either the Standard or by the implementation is a valid and
perfectly acceptable C++ program.
Greg