When did the bool type make it into the language?

Discussion in 'C++' started by Christopher Pisz, Apr 29, 2013.

  1. 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?
    Christopher Pisz, Apr 29, 2013
    #1
    1. Advertising

  2. Christopher Pisz

    Stefan Ram Guest

    Christopher Pisz <> writes:
    >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 )...
    Stefan Ram, Apr 30, 2013
    #2
    1. Advertising

  3. Christopher Pisz

    Stefan Ram Guest

    -berlin.de (Stefan Ram) writes:
    >#include <ctype>


    I intended to write »cctype« there. Might have been a
    keyboard effect.
    Stefan Ram, Apr 30, 2013
    #3
  4. On 4/29/2013 6:31 PM, Stefan Ram wrote:
    > Christopher Pisz <> writes:
    >> 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 )...
    >
    > .
    >


    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?
    Christopher Pisz, Apr 30, 2013
    #4
  5. Christopher Pisz

    Öö Tiib Guest

    On Tuesday, 30 April 2013 03:00:26 UTC+3, Christopher Pisz wrote:
    > 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.
    Öö Tiib, Apr 30, 2013
    #5
  6. Christopher Pisz

    Stefan Ram Guest

    William Ahern <william@wilbur.25thandClement.com> writes:
    >as_maxy=1993


    »The history of Windows dates back to September 1981,
    when the project named "Interface Manager" was started.
    It was first presented to the public on November 10,
    1983, renamed to "Microsoft Windows";«

    http://en.wikipedia.org/wiki/Windows_1.0
    Stefan Ram, Apr 30, 2013
    #6
  7. Christopher Pisz

    Ike Naar Guest

    On 2013-04-29, Stefan Ram <-berlin.de> wrote:
    > 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)) ...
    Ike Naar, Apr 30, 2013
    #7
  8. Christopher Pisz

    James Kanze Guest

    On Monday, April 29, 2013 10:31:54 PM UTC+1, Christopher Pisz wrote:
    > 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.

    --
    James
    James Kanze, Apr 30, 2013
    #8
  9. Christopher Pisz

    Stefan Ram Guest

    <> writes:
    >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
    Stefan Ram, Apr 30, 2013
    #9
  10. On 4/29/2013 11:49 PM, Paavo Helde wrote:
    > Christopher Pisz <> wrote in news:klmom5$t6v$1@dont-
    > email.me:
    >
    >> Trivial argument at work. My cooworker claims that Windows invented the
    >> BOOL type before C++ had a bool type. We're bored.

    >
    > 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!
    Christopher Pisz, Apr 30, 2013
    #10
  11. Christopher Pisz

    Geoff Guest

    On Wed, 01 May 2013 18:17:35 GMT, (Scott Lurndal)
    wrote:

    >"christian.bau" <> writes:
    >>On Apr 30, 5:48=A0pm, Christopher Pisz <> wrote:
    >>
    >>> Ah, the technical loophole!

    >>
    >>A "proper" boolean type would be one with only two different values,
    >>so that for any boolean x either (x =3D=3D true) or (x =3D=3D false) is tru=
    >>e.
    >>That is not the case for all these "fake" boolean types that are just
    >>typedefs; they all have at least 255 possible different values.

    >
    >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.
    Geoff, May 1, 2013
    #11
  12. Christopher Pisz

    Jorgen Grahn Guest

    On Mon, 2013-04-29, Stefan Ram wrote:
    > Christopher Pisz <> writes:
    >>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.


    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

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, May 5, 2013
    #12
  13. Christopher Pisz

    Stefan Ram Guest

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

    >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.
    Stefan Ram, May 5, 2013
    #13
  14. Christopher Pisz

    Jorgen Grahn Guest

    On Tue, 2013-04-30, Scott Lurndal wrote:
    > Christopher Pisz <> writes:
    >>On 4/29/2013 6:31 PM, Stefan Ram wrote:
    >>> Christopher Pisz <> writes:
    >>>> Trivial argument at work. My cooworker claims that Windows invented the
    >>>> BOOL type before C++ had a bool type. We're bored.

    ....
    >>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?

    >
    > (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 ...

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, May 5, 2013
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick Olurotimi Ige

    Cannot implicitly convert type 'object' to 'bool' Error

    Patrick Olurotimi Ige, Jan 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    12,201
    Patrick Olurotimi Ige
    Jan 25, 2005
  2. Replies:
    1
    Views:
    307
  3. Replies:
    3
    Views:
    351
  4. FE
    Replies:
    6
    Views:
    513
    Balog Pal
    Aug 4, 2009
  5. Daniel Waite
    Replies:
    2
    Views:
    225
    Daniel Waite
    May 2, 2008
Loading...

Share This Page