Jens Gustedt <> writes:
> Am 27.08.2012 21:48, schrieb Vincenzo Mercuri:
>> That's the point. If you say that "int main(void)" is equivalent to
>> "int main()" then you are saying that it is also equivalent to
>> "int main(int argc, char **argv, char **env)" or "int main(int argc)",
>> but I'm not convinced that compilers are obliged to support all these
>> definitions.
>
> No "int main()" is equivalent to "int main(void)" for
> definitions. There is this extra rule for definitions (versus just
> declarations) such that these two are equivalent.
Definitions also provide declarations.
This program contains a constraint violation:
int main(void) {
if (0) main(42);
return 0;
}
This one, I argue, is strictly conforming (its behavior would be
undefined if the call were executed).
int main() {
if (0) main(42);
return 0;
}
Thus the two definitions are not equivalent, unless you use a rather
loose definition of the word "equivalent".
On the other hand, I believe it was *intended* for `int main()` to be
valid; requiring the `void` keyword would have broken existing pre-ANSI
code.
But `int main(void)` (if you don't need argc and argv) is better for
newly written C programs.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"