home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16813 < prev    next >
Encoding:
Text File  |  1992-11-19  |  1.4 KB  |  45 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!keinstr!chaplin
  3. From: chaplin@keinstr.uucp (Roger Chaplin)
  4. Subject: Re: The Correct Way To Write C if-Statements
  5. Message-ID: <1992Nov19.170421.7903@keinstr.uucp>
  6. Organization: Keithley Instruments, Cleveland, Ohio
  7. X-Newsreader: TIN [version 1.1 PL6]
  8. References: <605@ulogic.UUCP>
  9. Date: Thu, 19 Nov 1992 17:04:21 GMT
  10. Lines: 33
  11.  
  12. Richard M. Hartman (hartman@ulogic.UUCP) wrote:
  13.  
  14. :     if (!condition)
  15. :         do_something;
  16. : should obviously be written as:
  17. :     if ( condition )
  18. :         {
  19. :         }
  20. :     else
  21. :         {
  22. :         do_something;
  23. :         }
  24. : so as to avoid the "!" operator.  
  25.  
  26. Why avoid the `!' operator?  Obviously the intention of this code is
  27. "If not condition then do something."  Writing it as "If condition then
  28. don't do anything, otherwise do something" obfuscates it.  I quickly
  29. grep'ed through the 1992 winning Obfuscated C contest files, and didn't
  30. find `Hartman' anywhere B-)
  31.  
  32. In my experience (disclaimer B-) the compiled code will execute equally
  33. fast (or slowly) whether it is branching on zero or branching on
  34. not-zero.  Maybe I've just been lucky in never having had to work with
  35. bizarre processors.
  36.  
  37. -- 
  38. Roger Chaplin / Instruments Division Engineering / "This land is your land,
  39. chaplin@keinstr.uucp / CI$: 76307,3506          / This land is my land,
  40. #include <disclaimer.h>                        / One of us has a bogus deed
  41. #include "disclaimer.h" /* cover all bases */ / to this land."  - George Carlin
  42.