Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!ukc!dcl-cs!gdt!gdr!exspes From: exspes@gdr.bath.ac.uk (P E Smee) Newsgroups: comp.lang.c Subject: Re: Compilers and programming style (was Re: A question of style) Message-ID: <1989Dec31.153241.16479@gdt.bath.ac.uk> Date: 31 Dec 89 15:32:41 GMT References: <1989Dec22.100135.2903@gdt.bath.ac.uk> <4367@rtech.rtech.com> Reply-To: exspes@gdr.bath.ac.uk (P E Smee) Organization: University of Bristol c/o University of Bath Lines: 35 In article <4367@rtech.rtech.com> mikes@rtech.UUCP (Mike Schilling) writes: >From article <1989Dec22.100135.2903@gdt.bath.ac.uk>, by exspes@gdr.bath.ac.uk (P E Smee): >> A compiler should *never* of its own choice put out gratuitous warnings >> about valid constructs, as many places will not allow release of code >> unless it compiles with NO messages at all; and because a compiler which >> forces you to ignore chatty messages will someday lead you to miss an >> important one. >How about this: > >sub() >{ > extern void (*ptr)(); > > *ptr; /* Should be (*ptr)(), of course */ >} > >This is legal c, but almost certainly *not* what was intended. Most compilers >I've used don't flag this as an error, or even a warning. In fact, there was >a posting in comp.lang.c yesterday by someone who did this, and couldn't figure >out why his function wasn't being called. Isn't a chatty message in order? Well, we're getting into theology, but *I* would say that the COMPILER should silently accept this, UNLESS you've used some '-chatty_messages' command line switch. Lint, or my hypothetical 'cstyle' should warn you. However, I wouldn't object terribly to a message in this case as the statement, while valid as written, clearly has no effects and no side effects. I'm willing to bend my principles a bit (or at least not offended by having them bent) to allow a compiler to complain about obviously unused blocks of code, unreachable statements, and statements with no effects or side effects. -- Paul Smee, Univ of Bristol Comp Centre, Bristol BS8 1TW, Tel +44 272 303132 Smee@bristol.ac.uk :-) (..!uunet!ukc!gdr.bath.ac.uk!exspes if you MUST)