home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!keinstr!chaplin
- From: chaplin@keinstr.uucp (Roger Chaplin)
- Subject: Re: The Correct Way To Write C if-Statements
- Message-ID: <1992Nov19.170421.7903@keinstr.uucp>
- Organization: Keithley Instruments, Cleveland, Ohio
- X-Newsreader: TIN [version 1.1 PL6]
- References: <605@ulogic.UUCP>
- Date: Thu, 19 Nov 1992 17:04:21 GMT
- Lines: 33
-
- Richard M. Hartman (hartman@ulogic.UUCP) wrote:
-
- : if (!condition)
- : do_something;
- :
- : should obviously be written as:
- :
- : if ( condition )
- : {
- : }
- : else
- : {
- : do_something;
- : }
- :
- : so as to avoid the "!" operator.
-
- Why avoid the `!' operator? Obviously the intention of this code is
- "If not condition then do something." Writing it as "If condition then
- don't do anything, otherwise do something" obfuscates it. I quickly
- grep'ed through the 1992 winning Obfuscated C contest files, and didn't
- find `Hartman' anywhere B-)
-
- In my experience (disclaimer B-) the compiled code will execute equally
- fast (or slowly) whether it is branching on zero or branching on
- not-zero. Maybe I've just been lucky in never having had to work with
- bizarre processors.
-
- --
- Roger Chaplin / Instruments Division Engineering / "This land is your land,
- chaplin@keinstr.uucp / CI$: 76307,3506 / This land is my land,
- #include <disclaimer.h> / One of us has a bogus deed
- #include "disclaimer.h" /* cover all bases */ / to this land." - George Carlin
-