When did the bool type make it into the language?

C

Christopher Pisz

Trivial argument at work. My cooworker claims that Windows invented the
BOOL type before C++ had a bool type. We're bored.

When did bool make it's way into C or into C++ if not from the beginning?
 
S

Stefan Ram

Christopher Pisz said:
Trivial argument at work. My cooworker claims that Windows invented the
BOOL type before C++ had a bool type. We're bored.

Windows is an operating system. An operating system
cannot invent something.

The type »bool« was added to C++ in the early 90s.

Of course,

typedef int BOOL;

or even

#define BOOL int

predates Windows.

Of course, BOOL is not bool.

However, one needs to take care with code such as, e.g.,

#include <ctype>
....
if( ::std::isprint( c )== true )...
 
C

Christopher Pisz

Windows is an operating system. An operating system
cannot invent something.

The type »bool« was added to C++ in the early 90s.

Of course,

typedef int BOOL;

or even

#define BOOL int

predates Windows.

Of course, BOOL is not bool.

However, one needs to take care with code such as, e.g.,

#include <ctype>
...
if( ::std::isprint( c )== true )...

.

Ah. I did look up C89 and didn't see a boolean type in there. I think I
am going to lose and have to buy beers. I might be able to prove we are
both wrong if I can produce an example of typedef int BOOL; in code
before the first Windows OS. Do you know of such an example?
 
Ö

Öö Tiib

Ah. I did look up C89 and didn't see a boolean type in there. I think I
am going to lose and have to buy beers. I might be able to prove we are
both wrong if I can produce an example of typedef int BOOL; in code
before the first Windows OS. Do you know of such an example?

I trust the ALGOL (1960) language had Boolean data type with values true
and false and logical operations. Bill Gates was 5 years old back then ...
no windows or anything.
 
I

Ike Naar

However, one needs to take care with code such as, e.g.,

#include <ctype>
...
if( ::std::isprint( c )== true )...

That's easy to fix :)

if (((true != !::std::isprint(c)) == true) == ((true != !true) == true)) ...
 
J

James Kanze

Trivial argument at work. My cooworker claims that Windows invented the
BOOL type before C++ had a bool type. We're bored.
When did bool make it's way into C or into C++ if not from the beginning?

It depends on what you mean by "made it's way into". The first
language specification to include it was C++98. The actual
proposal to adopt it was somewhat earlier, however, and was
straightforward enough that it could have safely implemented
before the final standard, without excessive risk of changes.
C adopted their version of bool somewhat later.

The BOOL in Windows is part of their C interface, which is
definitely prior to bool in C, and quite probably prior to the
bool in C++. The lack of a boolean type was felt as a defect
long before the committee got around to addressing it.
 
S

Stefan Ram

BOOL type before C++ had a bool type

What /is/ a type?

A type is a flag/marker that tells how to interpret
a certain recording (for example a bit sequence).

For example, »unsigned int i; signed int j;« create
two objects of the same size, but with different types.

These are compile-time types. When choosing how to
translate an overloaded operator like »+«, the
compiler can use the type information to choose the
appropriate compilation/implementation. The type
information then is discarded and not available at
run time.

There also are run-time types, which actually is
what OOP (polymorphism) is all about. One also can
implement run-time types oneself in C or C++:

struct my_object
{ int tag; /* 0 = int, 1 = bool */
union record
{ int int_value;
int bool_value; /* 0 = false, otherwise true */ }}

or, the OOP way:

struct MyObject
{ struct vtable * vtable_;
... }

The above structs show how to actually implement
a run-time boolean type in C.

As others have said, one /cannot/ implement a
/compile-time/ boolean type in C using #define
or typedef. After

#define BOOL int

or

typdef int BOOL

, the declaration

BOOL b;

does /not/ give the compiler any information other
than b has the type /int/. However,

struct/union bool { int value; };

should do the trick (to create a compile-time type
»bool«.)

Also see:

http://www.gotw.ca/gotw/026.htm
 
C

Christopher Pisz

BOOL is not a separate type in Windows, it is a typedef creating an alias
for an existing type. It does not change function signatures, one cannot
overload templates on it, etc. So you can claim BOOL *type* has never been
invented :)

Cheers
Paavo


Ah, the technical loophole!
 
G

Geoff

With respect to BOOL, they have exactly two values. Zero and not-zero.

Except, as in the case of the previously cited GetMessage, it has the
values of zero and not-zero and not-zero-meaning-error.
 
J

Jorgen Grahn

Windows is an operating system. An operating system
cannot invent something.

Surely that's obviously short for the claim "BOOL first appeared in
Microsoft's header files for Windows C programming"?
The type »bool« was added to C++ in the early 90s.

I would have thought it happened earlier, but ... "Design and
Evolution" writes about it, but unfortunately not about when it
happened. Just that Dan Bruck and A. Koenig pushed for it, and that
the committee accepted it. That places it in the 1990s and before
1998, I guess.

/Jorgen
 
S

Stefan Ram

Jorgen Grahn said:
Surely that's obviously short for the claim "BOOL first appeared in
Microsoft's header files for Windows C programming"?

When I wrote in school »The car drove ...« my teacher marked
this as an error (in the sense of an error that can lower my
grade) and explained to me that a car cannot drive, instead
the driver drives the car.

So it seems that I was educated to read things in this
more restricted literal way.
I would have thought it happened earlier, but ... "Design and
Evolution" writes about it, but unfortunately not about when it
happened. Just that Dan Bruck and A. Koenig pushed for it, and that
the committee accepted it. That places it in the 1990s and before
1998, I guess.

After my previous post, IIRC I learned that there was
publication in 1991 (the ARM?) that did not yet have »bool«.
And I have very vague memories of reading that bool was
there in 1995 or shortly after 1991 (it just did not make it
into the 1991 publication anymore). So it might have been
introduced between 1991 and 1995. I did not take notes when
I read this, because, after all, I did not care that much.
 
J

Jorgen Grahn

(cd /work/reference/usl; find . -type f | xargs grep -iw bool)|more

./unix/v7/usr/src/cmd/sh/mac.h:#define TYPE typedef
./unix/v7/usr/src/cmd/sh/mode.h:TYPE char BOOL;
./unix/v7/usr/src/cmd/adb/mode.h:TYPE char BOOL;

That would be 1979.

On the other hand ... all examples of older stuff so far have been
applications or non-vital libraries.

Core Unix APIs (the extended libc) tend to use int for booleans (or
the "0 is true and -1 is false" idiom which I personally detest).

1980s home computer systems like Windows and AmigaDOS tended to use
very specific typedefs like CHAR, WORD, LONG and BOOL[1]. You used
these everywhere in your own code too, and as I remember it, if I saw
a literal "int" in some code, I assumed it was a straight port of Unix
code.

So, there's a distinction between (a) someone, in some subsystem
simulating a boolean type and (b) everyone programming for that
platform using the same one.

I'm sure (a) happened as soon as someone who was used to a boolean
type from some other language sat down and used C.

/Jorgen

[1] Not 100% sure anymore that AmigaDOS did have BOOL specifically.
I have my SDK somewhere, but it's on unreadable floppies ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top