home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16296 < prev    next >
Encoding:
Text File  |  1992-11-10  |  2.1 KB  |  61 lines

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!rphroy!einstein!wenner
  2. From: wenner@einstein.eds.com (Rich Wenner)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Hows this for odd
  5. Message-ID: <1266@pascal.einstein.eds.com>
  6. Date: 10 Nov 92 22:38:38 GMT
  7. References: <1992Nov9.102217.23060@monu6.cc.monash.edu.au> <1992Nov9.231340.10201@ptcburp.ptcbu.oz.au> <1992Nov10.161008.27590@mksol.dseg.ti.com>
  8. Organization: Electronic Data Systems
  9. Lines: 50
  10.  
  11. In article <1992Nov10.161008.27590@mksol.dseg.ti.com> mccall@mksol.dseg.ti.com (fred j mccall 575-3539) writes:
  12. >In <1992Nov9.231340.10201@ptcburp.ptcbu.oz.au> michi@ptcburp.ptcbu.oz.au (Michael Henning) writes:
  13.  
  14. >>bena@yoyo.cc.monash.edu.au (Ben Aveling) writes:
  15.  
  16. >>>Just recently I saw the following fragment of code, and I thought I'd share
  17. >>>it with you all.  (This is real code, part of a real program people will
  18. >>>pay money for.)
  19.  
  20. >>>    ... ,(i==0)?TRUE:FALSE,...
  21.  
  22. >>From the source code for a popular UNIX debugger:
  23.  
  24. >>    if (strncmp(p, "", 1) != 0) {
  25. >>        ...
  26. >>    }
  27.  
  28. >>There are lots of gems like that around :-(
  29.  
  30. >Well, I generally do the explicit comparison on string comparisons,
  31. >too, because ...
  32.  
  33. I think you missed the point.  The above code compares "p" and the null string
  34. for a span of either 1 character or 1 more than the length of the shorter
  35. string, whichever is less.  This is something a sane programmer would code
  36.  
  37.     if (*p)
  38.  
  39. or, for the more verbose (but still sane -- no flames, please),
  40.  
  41.     if (*p != '\0')
  42.  
  43. >I'm afraid I find this other idiom ("(i==0)?TRUE:FALSE") to be just a
  44. >bit peculiar, though.
  45.  
  46. Just a bit peculiar?  My, but you are a kind-hearted soul.  :)
  47.  
  48. Why is it that nobody in this thread has yet mentioned that the above
  49. expression reverses the logic?  Is this equivalent to
  50.  
  51.     !i
  52.  
  53. or have I been reading too much of my students' code?
  54.  
  55.     
  56. -- 
  57. Rich Wenner              | Subject and verb always has to agree.
  58. wenner@csid.gmeds.com    | Consult a dictionary frequently to avoid mispelling.
  59.                          | Hopefully, you will use words correctly,
  60. #include <stddisclaim.h> |            irregardless of how others use them.
  61.