Why isn't bool a built-in type?

This is a discussion on Why isn't bool a built-in type? within the C++ Programming forums, part of the General Programming Boards category; I was just wondering, why wasn't the bool type built-in to C++? That seems like it would've been a good ...

  1. #1
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146

    Question Why isn't bool a built-in type?

    I was just wondering, why wasn't the bool type built-in to C++? That seems like it would've been a good idea.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    It is AFAIK.

  3. #3
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    It is. It wasn't in C, however.

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    It is AFAIK.
    Huh? What does that mean?

    It is. It wasn't in C, however.
    Really? Then why does my compiler give me an error whenever I use bool without including "bool.h"?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Because you are probably using a C compiler.

    EDIT: Or perhaps a REALLY old C++ compiler?
    Last edited by Polymorphic OOP; 01-06-2003 at 10:56 PM.

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    As Far As I Know...

    What compiler are you using? I think bool is somewhat new.

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    The copyrights on the compiler I use at home, MPW, are from 1985-1999. Is that the problem, then?
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Yeah, most likely. You're best off getting a new compiler.

  9. #9
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by Polymorphic OOP
    Yeah, most likely. You're best off getting a new compiler.
    I'd like to, but MPW is the only free compiler available for Macs. Oh well. I'm hopefully *crosses fingers* getting a new computer soon. In that case, I'll run Linux on it, and I believe that Linux comes with gcc.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  10. #10
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You can always define your own bool type Some people will tell you to define true as 1 and false as 0. I don't know about that, this is how I do it.

    Code:
    #define true ( 5 == 5 )
    #define false ( !true )
    
    typedef int bool;

  11. #11
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Thanks, but I already have a header file for bool:
    Code:
    #ifndef BOOL_H
    #define BOOL_H
    #undef true
    #undef false
    const int true = 1;
    const int false = 0;
    typedef int bool;
    #endif
    I was just complaining cuz I hafta include that in every program I write that uses boolean variables
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by MrWizard
    You can always define your own bool type Some people will tell you to define true as 1 and false as 0. I don't know about that, this is how I do it.

    Code:
    #define true ( 5 == 5 )
    #define false ( !true )
    
    typedef int bool;
    yeah, i learned true as 1 and false as 0, binary...
    you could do it that way, or another way, (I think this is right)
    Code:
    enum bool {
          false, true
    };
    I'm not sure if that is how you implement an enumerated type, not sure on syntax, I haven't worked with enum that much.

  13. #13
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    You might also try checking for updates to MPW.

    Here's a link I found to apple.com that allows for downloading it. And the file is dated 2001.

    ftp://ftp.apple.com/developer/Tool_C...MPW-GM_Images/

    As for compilers... I even found a C compiler for the old Commodore computers. http://www.cc65.org/

  14. #14
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Just return 1 for true and 0 for false, I think that is what a bool type would do anyway it would just be masked with words, or you could define them.

    Code:
    #define FALSE 0
              #define TRUE !FALSE
    Thats has always worked for me and I am using a very old compiler.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  15. #15
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Just return 1 for true and 0 for false, I think that is what a bool type would do anyway it would just be masked with words, or you could define them.

    Code:
    #define FALSE 0
    #define TRUE !FALSE
    Thats has always worked for me and I am using a very old compiler.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  2. Replies: 6
    Last Post: 04-21-2006, 09:49 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  4. help with type bool functions
    By quizteamer in forum C++ Programming
    Replies: 3
    Last Post: 10-17-2004, 08:12 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21