Path: utzoo!utgpu!water!watmath!clyde!rutgers!ucsd!sdcsvax!sdcc6!ix426 From: ix426@sdcc6.ucsd.EDU (Tom Stockfisch) Newsgroups: comp.lang.c Subject: Re: == vs = Message-ID: <3610@sdcc6.ucsd.EDU> Date: 4 Feb 88 05:27:17 GMT References: <11523@brl-adm.ARPA> <1202@eneevax.UUCP> <8836@ism780c.UUCP> <2006@rti.UUCP> Reply-To: ix426@sdcc6.ucsd.edu.UUCP (Tom Stockfisch) Organization: University of California, San Diego Lines: 79 In article <2006@rti.UUCP> trt@rti.UUCP (Thomas Truscott) writes: >>[ discussion of =, == confusion] > >The cost of developing a C program would be even less >if the compiler (and of course lint) simply pointed out >such possible mistakes. Lint should do this only with the -h flag. Many people like to get their programs to pass lint without any comment and still use their own idea of style. > Compilers should warn of possible mistakes such as: > if (x = y) foo(); /* :: would be just as dubious */ > > Compilers should warn of dubious indentations, such as: > while (foo() > 0); > bar(); > > Compilers should warn of hazardous operator usage, such as: > i = 1< I don't mind as long as the warnings are produced ONLY if you specify an extra flag to cc. I don't want any warnings from the compiler if my code is correct, and I don't want to have to conform to some compiler writer's idea of what good style is. C is a free-form input language. If the compiler warns whenever ";" is not followed by newline, then we might as well dump the superfluous ";" and have newline terminate statements. There are times that I don't follow the usual indentation in order to make code clearer. For instance, suppose protect() causes an interrupt handler to be postponed and unprotect() calls the handler if an interrupt occured. Code that shouldn't be interrupted I then write as follows: ... protect(); update_linked_list(); /* note indentation */ get_more_mem_and_save_it(); ... unprotect(); ... Written like this, it is easy to see what code is sensitive and what isn't. I don't want cc complaining here about dubious indentation. >I do not want special purpose programs to check for these or to rewrite >the code. And I strongly prefer these checks to be in the compiler >as well as in lint, if only to cut down on the flood of simple >programming mistakes that are posted to this newsgroup. The only thing that I really would like to be checked by the compiler instead of lint is function argument/return value type mis-matches. But with proposed ANSI function prototypes, compilers will have to do this anyway. >(I also think that the cc/lint business needs to be reconsidered.) In the spirit of unix, each program should do one thing, and do that well. Compilers should compile, and linters should pick lint. >C compilers already have dozens of warning messages, >and they have saved programmers much grief. To reiterate, compilers should not complain about style, only about marginally legal statements. >I see no big issues here, just the details of for what to issue warnings, >how to phrase them, and (if it is warranted) how to suppress them. I don't want messages like warning: your programming style is different from mine warning: code doesn't look exactly like everyone else's unless I explicitly ask for them. -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu