home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11425 < prev    next >
Encoding:
Internet Message Format  |  1992-07-23  |  1.7 KB

  1. Path: sparky!uunet!olivea!apple!apple!netcomsv!ulogic!hartman
  2. From: hartman@ulogic.UUCP (Richard M. Hartman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: boolean (was: Re: typedef vs enum)
  5. Message-ID: <147@ulogic.UUCP>
  6. Date: 23 Jul 92 17:50:27 GMT
  7. References: <DOUGM.92Jul17133255@titan.cs.rice.edu> <1992Jul18.193943.3804@taumet.com> <1992Jul19.142813.9295@ucc.su.OZ.AU>
  8. Organization: negligable
  9. Lines: 37
  10.  
  11. In article <1992Jul19.142813.9295@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  12. >In article <1992Jul18.193943.3804@taumet.com> steve@taumet.com (Steve Clamage) writes:
  13. >>If you come up with a proposal, please remember that existing code
  14. >>which assumes 0/1 int results for || && ! operators should still work.
  15. >>Such code should also work in if/while/for/switch control expressions.
  16. >>So should expressions of type boolean.
  17. >
  18. >    It follows that pointers and numbers MUST convert to
  19. >type boolean automatically.
  20.  
  21. Why?  Couldn't we overload || && and ! to return bool?
  22.  
  23. >    Now there is only ONE decision left:
  24. >
  25. >    should boolean convert to int without an explicit cast?
  26.  
  27. This we DO need, since we cannot overload "if", and if we want
  28.  
  29. to write 
  30.     bool cond;
  31.  
  32.     if (cond) 
  33.         something;
  34.  
  35. I *think* we need to provide auto-conversion from bool to int.
  36.  
  37.  
  38. >     I say yes, although such a boolean type is hardly
  39. >    isolated from integral types!
  40.  
  41. Since I have suggested NO auto conversion from int-->bool we
  42. still have some isolation.  You can use a bool where an int
  43. may be expected (such as in "if"), but NOT (without casting)
  44. use an int where a bool is expected!
  45.  
  46. Of course, if the compiler accepts a bool in an "if" condition
  47. w/o providing a bool-->int auto-conversion even better.
  48.