home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!fuug!demos!kiae!glas!demos!ucc.su.oz.a!extro.ucc.su.OZ.AU!maxtal
- From: maxtal@extro.ucc.su.OZ.AU
- Newsgroups: comp.lang.c++
- Date: 18 Jul 92 10:29 MDT
- Subject: Re: boolean (was: Re: typedef vs enum)
- Sender: Notesfile to Usenet Gateway <notes@glas.apc.org>
- Message-ID: <1992Jul18.062922.124@ucc.su.oz.a>
- References: <1992Jul11.195547.18323@cmcl2.nyu>
- Nf-ID: #R:1992Jul11.195547.18323@cmcl2.nyu:1382747533:1992Jul18.062922.124@ucc.su.oz.a:1138516199:001:1439
- Nf-From: extro.ucc.su.OZ.AU!maxtal Jul 18 10:29:00 1992
- Lines: 46
-
-
- In article <23195@alice.att.com> ark@alice.UUCP () writes:
- >I do not use a special Boolean type in my programs because
- >the built-in operators == != < > <= >= && || ! all return int
- >and there's no way to change that.
- >
- >I would love to see a built-in Boolean type in C++, but
- >unfortunately it's too big a change from C.
- >--
- > --Andrew Koenig
- > ark@europa.att.com
-
- No it isnt. Just add a new standard type bool. It converts
- to int or anything else as 0 and 1. Anything non-zero
- assigned to a bool turns into a 1 (incuding a pointer
- if you want). End.
-
- Such a bool is quite transparent: its only effect is the
- converion on assignment (or initialisation) to 1.
-
- That is exactly the same as assigning a long to a char,
- except the conversion rules are slightly different.
-
- What wrong with this?
-
- Well, you can ALREADY do it trivially:
-
- class bool {
- int x; //any integral type can be used for 'int'
- bool(const int y) : x(y){}
- operator int(){return x;}
- };
-
- const bool true=1;
- const bool false=0;
-
- Something wrong with the way this works?
- [A standard type might allow bools to be stored bit-wise,
- otherwise it ought to be the same as the above class IMHO]
-
- --
- ;----------------------------------------------------------------------
- JOHN (MAX) SKALLER, maxtal@extro.ucc.su.oz.au
- Maxtal Pty Ltd, 6 MacKay St ASHFIELD, NSW 2131, AUSTRALIA
- ;--------------- SCIENTIFIC AND ENGINEERING SOFTWARE ------------------
-
-