1 matches bool, 2 matches long

Jonathan M Davis jmdavisProg at gmx.com
Sat Apr 27 17:28:46 PDT 2013


On Saturday, April 27, 2013 14:52:31 Walter Bright wrote:
> On 4/27/2013 2:29 PM, Rob T wrote:
> > If bools are 1 bit ints, then why do we have 'true' and 'false' as
> > keywords?
> Because writing cast(bool)0 and cast(bool)1 is unappealing.

You'd only be forced to do that outside of conditions, as the cast is already 
inserted for you in conditions. And if you really need bool, one could argue 
that it doesn't make sense to be using integer literals anyway. We already 
have true and false if you really want a bool when deal with literals. I like 
being able to do while(1) because it's shorter, but it's not ultimately all 
that onerous to have to do while(true), and the casting in conditions takes 
care of that case anyway. In most cases, simply using a bool when you mean 
bool, and an int when you want an integral type solves the problem quite 
cleanly.

The main place that I can see that it makes sense to end up with casts to and 
from bool which might get annoying is if you're trying to use bools in 
arithmetic, and I honestly don't think that allowing implicit casts there is 
worth all of the other weirdness it causes in the language in general.

- Jonathan M Davis


More information about the Digitalmars-d mailing list