Warning messages
Karl Heuer
karl at haddock.ima.isc.com
Wed Jan 17 13:32:07 AEST 1990
In article <25AFE8A6.14024 at paris.ics.uci.edu> rfg at ics.uci.edu (Ron Guilmette) writes:
>In article <2NNQZ%@rpi.edu> adamsf at turing.cs.rpi.edu (Frank Adams) writes:
>>For conscientious software engineers, the solution is to treat warnings as
>>errors, so that the final program generates no warning messages...
>
>Agreed. I always do.
I try to, and in fact I normally compile with all warnings enabled. There's
one that still gives me grief, which I haven't yet decided how to resolve.
Assume that, for reasons beyond the scope of this discussion$, |main()|%
terminates with |exit()| rather than |return|. What is the correct way to
declare it? I was using |void main()|, but X3J11 didn't bless that variant,
so I've stopped using it. If I leave it blank, just writing |main()|, then I
get a warning about it being implicitly |int|. (And quite rightly so; I've
never liked that anyway.) Defining it as |int main()| is conforming and
silences gcc (since I've configured it to know that |exit()| is nonreturning),
but (a) it's misleading and (b) at any time, gcc or some other compiler could
decide that declaring a nonreturning function with a type other than |void|
deserves a warning.
If the Committee had chosen to not even legalize the common |int main(void)|&,
then a similar problem would occur when the compiler complains about args
declared but not used.
Karl W. Z. Heuer (karl at haddock.isc.com or ima!haddock!karl), The Walking Lint
________
$ If you say that the solution is to use |return| instead of |exit()|, I can't
accept that. Both are correct, the arguments for one are about as good as
for the other, and it's not the sort of thing that the compiler should try
to enforce.
% I say |main()| only for brevity. In actual code I would write either
|main(void)| or |main(int argc, char **argv)|.
& I think I agree with Doug that this would probably have been the better
solution. Zero-arg |main| would then be reduced to a Common Extension, like
three-arg |main|.
More information about the Comp.lang.c
mailing list