Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!samsung!think!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Warning messages Keywords: large projects Message-ID: <15673@haddock.ima.isc.com> Date: 17 Jan 90 02:32:07 GMT References: <1471@mdbs.UUCP> <2NNQZ%@rpi.edu> <25AFE8A6.14024@paris.ics.uci.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 36 In article <25AFE8A6.14024@paris.ics.uci.edu> rfg@ics.uci.edu (Ron Guilmette) writes: >In article <2NNQZ%@rpi.edu> adamsf@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@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|.