Keith Thompson said:
Tim Rentsch said:
Keith Thompson said:
[...]
In short, I'm not opposed to the idea of having a warning
for main(), just opposed to the idea that such a warning be
required at all times for all C compilers.
So that you can have the benefits of defining main in some
non-standard way without having the compiler complain about it.
Um, what were those benefits again?
I think you're assuming that it's always possible, with
relatively little effort, for an implementation to know
whether a particular form of main() is supported by the
target execution environment. For one thing, knowing that
may not always be easy. Moreover, a single compilation may
produce an object file that can be used in several target
execution environments, and the rules for main() in those
environments may differ from one to another. I don't think
people should be forced to compile a program multiple times,
with different sets of compiler options, just because, eg,
the result is going to be run on several different *nix
variants with different rules about which forms of main()
will work.
All conforming (hosted) C implementations support "int main(void)"
and "int main(int argc, char *argv[])".
My question was, what are the benefits of defining main in some way
other than those two?
I didn't get that sense reading the previous posting, and reading
it over again, I still don't. But I will ignore that and address
the question as you restated it.
I don't see an answer to that.
That seems obvious - a fair number of implementations choose to do so,
both historically and (I assume) currently, because the implementors
believe there is value in doing so. Before C was standardized I was
used to a three argument form of main(), and I'm sure many other
people were as well. I'm not going to try to give examples; I think
the existence of implementations that avail themselves of the allowed
flexibility is evidence enough.
Yes, I'm assuming that a given compiler knows what forms of main are
supported by that compiler. That's not *necessarily* true; the same
compiler could be used both for a target that supports "double
main(char*)" and for one that doesn't. In effect, the same compiler
would be part of two distinct implementations.
I simply disagree with the assumption. I think it's much harder
than you seem to think it is.
But in such a case, it shouldn't be at all difficult to parameterize the
compiler so that it *does* know what forms of main are supported.
First, I disagree with your assessment. Second, my point is
that the cost of requiring it of ALL implementations outweighs
the benefit. The cost is non-trivial; the benefit is trivial.
There's no reason a single compiler can't produce different diagnostics
when invoked for different targets.
And I don't know of any such implementations anyway. Do you?
You're assuming that a compiler always knows exactly for which
target it is being invoked, and that it is always invoked
separately for different targets. I believe both of these
assumptions are wrong.
The scenario you seem to be advocating is this:
I write a non-standard definition for "main", perhaps out of
ignorance. The implementation I am using does not support that
particular definition; my program's behavior is therefore undefined.
The compiler does not warn me about this.
I'm not advocating any particular compiler use case. I
believe allowing such use cases has value, but more to
the point disallowing them has relatively little value
but non-trivial costs. The ROI is negative.
You really see some benefit in that behavior?
There are cases where such use cases have value, yes. But
that belief is incidental to my main point.
I also want diagnostics for syntax errors, missing headers,
undeclared identifiers, and so forth. These diagnostics are required
by the language, and I presume you don't object to that.
I fail to see how using a definition of main *that is not supported
by the compiler I'm using* should be any different.
Here is an important difference. The other cases you mention all
depend on things that are completely under the implementation's
control. Because the implementation has total knowledge, it's
easy for it to give diagnostics in precisely those circumstances
that cause problems. The possible forms of main() depend on
things that are outside the implementation's control, and may
change over time, and indeed may be unknown (or potentially even
unknowable) to the implementation. Therefore it is more
difficult, and in some cases conceivably impossible, for the
implementation to know precisely which circumstances are going
to cause problems.
But if you don't want such a warning, you could always filter it
out or invoke the compiler in some non-conforming mode.
Since you're the person who's proposing a change, it's up
to you to convince other people it's a good idea. Telling
me I'm going to have to do more work so we get something
that I think doesn't have much value in the first place
does not convince me, and in fact very much the opposite.