Re: Whats the point of bool?
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Wed, 03 Jun 2009 15:46:26 -0700
kid joe <spamtrap@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.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: Whats the point of bool?
- From: chad
- Re: Whats the point of bool?
- References:
- Whats the point of bool?
- From: kid joe
- Whats the point of bool?
- Prev by Date: Re: 2D logical array, find closest element with value false
- Next by Date: Re: Passing an array to a function
- Previous by thread: Whats the point of bool?
- Next by thread: Re: Whats the point of bool?
- Index(es):
Relevant Pages
|
Loading