home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11365 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1.9 KB  |  59 lines

  1. Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!ucc.su.oz.a!extro.ucc.su.OZ.AU!maxtal
  2. From: maxtal@extro.ucc.su.OZ.AU
  3. Newsgroups: comp.lang.c++
  4. Date: 18 Jul 92 10:29 MDT
  5. Subject: Re: boolean (was: Re: typedef vs enum)
  6. Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
  7. Message-ID: <1992Jul18.062922.124@ucc.su.oz.a>
  8. References: <1992Jul11.195547.18323@cmcl2.nyu>
  9. Nf-ID: #R:1992Jul11.195547.18323@cmcl2.nyu:1382747533:1992Jul18.062922.124@ucc.su.oz.a:1138516199:001:1439
  10. Nf-From: extro.ucc.su.OZ.AU!maxtal    Jul 18 10:29:00 1992
  11. Lines: 46
  12.  
  13.  
  14. In article <23195@alice.att.com> ark@alice.UUCP () writes:
  15. >I do not use a special Boolean type in my programs because
  16. >the built-in operators == != < > <= >= && || ! all return int
  17. >and there's no way to change that.
  18. >
  19. >I would love to see a built-in Boolean type in C++, but
  20. >unfortunately it's too big a change from C.
  21. >-- 
  22. >                --Andrew Koenig
  23. >                  ark@europa.att.com
  24.  
  25. No it isnt. Just add a new standard type bool. It converts
  26. to int or anything else as 0 and 1. Anything non-zero
  27. assigned to a bool turns into a 1 (incuding a pointer
  28. if you want). End.
  29.  
  30. Such a bool is quite transparent: its only effect is the
  31. converion on assignment (or initialisation) to 1.
  32.  
  33. That is exactly the same as assigning a long to a char,
  34. except the conversion rules are slightly different.
  35.  
  36. What wrong with this?
  37.  
  38. Well, you can ALREADY do it trivially:
  39.  
  40.     class bool {
  41.         int x; //any integral type can be used for 'int'
  42.         bool(const int y) : x(y){}
  43.         operator int(){return x;}
  44.     };
  45.  
  46.     const bool true=1;
  47.     const bool false=0;
  48.  
  49. Something wrong with the way this works?
  50. [A standard type might allow bools to be stored bit-wise,
  51. otherwise it ought to be the same as the above class IMHO]
  52.  
  53. -- 
  54. ;----------------------------------------------------------------------
  55.         JOHN (MAX) SKALLER,         maxtal@extro.ucc.su.oz.au
  56.     Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
  57. ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
  58.  
  59.