Thread: Simple boolean problem

  1. #1
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96

    Simple boolean problem

    I always use Visual C++, but now I'm in school and they have only DOS version of Borland C++ with really @#^&* help. I've never seen worse help than this. Even QBasic has better. My problem is funny. This line:
    Code:
      bool test() {
        return true;
      }
    doesn't compile!
    I think it doesn't take the bool type - it's not highlighted as a keyword. Maybe I have to link a library to use bool type. If so, what library is it? I can't find something in this stupid DOS help. And if not, how can I solve my problem?
    Please excuse my poor english...

  2. #2
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    I defined bool by myself for now:
    Code:
    enum bool {true = 1, false = 0};
    But if anyone knows which library is it, please reply.
    Please excuse my poor english...

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    hm... I think the bool datatype is C++ standard, but anyway,

    >"doesn't compile!"

    Can you give any more info ? Your compiler must have given you
    some sort of explanation WHY it doesn't compile.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    I'm home now, but as far as I remember, there was some sort of "declaration error" or something. I'm almost sure it didn't recognize the bool type, because if I changed type of this return value from bool to e.g. int and used "true" or "false" identifiers later in code, I received an error telling me those symbols are undefined.
    There was no syntactic mistake, I checked the code about 100 times. And after all, what mistake can one make in 3 lines of code? Maybe I'm so stupid that I made one (it seems strange to me too why bool shouldn't be standard type), but which one??
    Last edited by larry; 10-12-2001 at 03:35 PM.
    Please excuse my poor english...

  5. #5
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    yes, there's a library, use <windows.h>, I mean Visual C's, I've tried that function and it works.


    Oskilian

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    No, BOOL, TRUE, and FALSE are defined in windows.h

    bool, true, and false are keywords under ANSI C++. It is possible that either:

    1) You are compiling it as C code, not C++ code.
    2) The compiler is too old to support those keywords.

  7. #7
    Ethereal Raccoon Procyon's Avatar
    Join Date
    Aug 2001
    Posts
    189
    My old compiler, Borland C/C++ v3.1, does not support "bool"; so I just typedef it as a char (or use enum in C++).

  8. #8
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    > My old compiler, Borland C/C++ v3.1, does not support "bool"; so I just typedef it as a char (or use enum in C++).

    That's what they has in our school. There are NC computers which boot from network and have no VC or BCW installed.
    Please excuse my poor english...

  9. #9
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    make a file boolean.h and include it whenevr you need to use bool if your compiler doesn't support it natively....

    boolean.h
    Code:
    typedef char bool;
    const bool false=0;
    const bool true=1;
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  10. #10
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    I know. I was just wondering why it's not implemented. Thanx anyway.
    Please excuse my poor english...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  3. Simple File I/O problem
    By Ignited in forum C++ Programming
    Replies: 3
    Last Post: 01-07-2006, 10:49 AM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM