Re: Whats the point of bool?
- From: luserXtrog <mijoryx@xxxxxxxxx>
- Date: Wed, 3 Jun 2009 18:30:22 -0700 (PDT)
On Jun 3, 6:04 pm, chad <cdal...@xxxxxxxxx> wrote:
On Jun 3, 3:46 pm, Keith Thompson <ks...@xxxxxxx> wrote:
kid joe <spamt...@xxxxxxxxxxxxxxxx> writes:
I know that from a C point of view, the bool or __Bool type was introduced
into C to standardize common practise in existing compilers, but from a
historical perspective does anyone understand what was the motivation for
languages like C++ and Java (and eventually C) to have a seperate type for
boolean variables instead of just using ints?
It seems pretty illogical to me, since I dont believe theres any common
hardware where individual bits can easily be addressed, so whats the gain
from having a type thats essentially an alias for int at the hardware
level, versus the added complexity for compiler writers and programmers?
It's the same reason languages distinguish between integers and
floating-point numbers, for example. On the hardware level they're
both machine words; we just apply different operations to them. And
in fact one of C's ancestors (either B or BCPL, I don't remember
which) actually didn't make that distinction; it merely used different
operators for integer vs. floating-point addition and so forth.
It's for the benefit of the human reader. Declaring an object as
bool, or int, or double, lets the reader know what it's to be used
for, and lets the compiler generate the right code for it (or reject
operations that don't make sense).
In some languages that are more strongly-typed than C, you can't even
perform an "and" or "or" operation on integers, or "+" or "-" on
booleans. C is a lot looser, but it's still useful to be able to make
the distinction.
Okay, at the risk of going off topic, what strongly-typed languages
can't peform "and" or "or" operations on integers, or "+" or "-" on
booleans? And more to the point. Why is this?
You can't do it in Postscript, either.
--
lxt
.
- References:
- Whats the point of bool?
- From: kid joe
- Re: Whats the point of bool?
- From: Keith Thompson
- Re: Whats the point of bool?
- From: chad
- Whats the point of bool?
- Prev by Date: Re: Whats the point of bool?
- Next by Date: Re: Typedef and const
- Previous by thread: Re: Whats the point of bool?
- Next by thread: Re: Whats the point of bool?
- Index(es):
Relevant Pages
|
Loading