Compilers and programming style (was Re: A question of style)

P E Smee exspes at gdr.bath.ac.uk
Mon Jan 1 02:32:41 AEST 1990


In article <4367 at rtech.rtech.com> mikes at rtech.UUCP (Mike Schilling) writes:
>From article <1989Dec22.100135.2903 at gdt.bath.ac.uk>, by exspes at 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 at bristol.ac.uk  :-)  (..!uunet!ukc!gdr.bath.ac.uk!exspes if you MUST)



More information about the Comp.lang.c mailing list