Thread: using bool

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    167

    using bool

    Code:
    #include<stdio.h>
    int main()
    {
            bool a=false;
            a=true;
            if(a) printf("a e adevarat\n");
            else printf("a e fals\n");
            return 0;
    }
    why can't i do this using gcc version 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu9) ?
    it tells me that:
    Code:
    gcc -o bool bool.c -Wall
    bool.c: In function ‘main’:
    bool.c:4: error: ‘bool’ undeclared (first use in this function)
    bool.c:4: error: (Each undeclared identifier is reported only once
    bool.c:4: error: for each function it appears in.)
    bool.c:4: error: syntax error before ‘a’
    bool.c:5: error: ‘a’ undeclared (first use in this function)
    bool.c:5: error: ‘true’ undeclared (first use in this function)
    make: *** [all] Error 1
    thank you!

  2. #2
    Registered User
    Join Date
    Jun 2005
    Location
    Stockholm, Sweden
    Posts
    64
    From the FAQ:

    A list of features that C++ supports which C does not includes:
    /snip/
    bool keyword

  3. #3
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    That FAQ is a little inaccurate, and is better stated as "a list of features that C++ supports which C89 does not include"

    Add #include <stdbool.h> to your code and it will compile as C99 on a compiler that attempts to implement C99 (such as gcc).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing params between managed c++ and unmanaged c++
    By cechen in forum C++ Programming
    Replies: 11
    Last Post: 02-03-2009, 08:46 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. Need Help With an RPG Style Game
    By JayDog in forum Game Programming
    Replies: 6
    Last Post: 03-30-2003, 08:43 PM