Tim Rentsch <> writes:
> Keith Thompson <kst-> writes:
[...]
>> I've argued that a program using "int main()", as opposed to "int
>> main(void)", has undefined behavior, since "int main()" is not one of
>> the forms permitted by C99 5.1.2.2.1 (nor is it quite equivalent to
>> either of them). [snip]
>
> It is equivalent in the sense that the Standard uses the
> term. Obviously so, since otherwise every single K&R-era
> program that had 'int main(){ ... }' would have undefined
> behavior under ANSI/ISO C; surely that point was considered
> by the standard committee.
I'm uncomfortable with conclusions reached by first assuming that the
standard doesn't break pre-ANSI code, and interpreting the wording based
on that assumption.
I can accept, based on your argument, that "int main()" is *intended* to
be valid. I don't agree that the current wording in the standard
actually *says* that it's valid. The only basis for assuming that
"equivalent" has the meaning you say it does is that Bad Things Happen
if it doesn't.
Someone reading the current ISO C standard with no knowledge of pre-ANSI
C would have no basis to assume that "int main()" is valid.
These two programs differ only in how they define main, and they clearly
are not equivalent; the first violates a constraint, while the second
does not.
int main(void) {
if (0) return main(42);
}
int main() {
if (0) return main(42);
}
I believe this was an oversight by the authors of the standard (one that
isn't corrected in C11, unless they did something after N1570).
--
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"