BOOL not getting inherited in fresh install of Xcode

Discussion in 'Mac Programming' started by mspman, Jan 7, 2012.

  1. macrumors regular

    Joined:
    Jun 7, 2007
    Location:
    Minneapolis, MN
    #1
    Okay, what am I doing wrong. I just installed Xcode on a friends MBA, and I'm having issues getting the "BOOL" datatype to be recognized. In the simplest of programs, "Hello World!", I'm importing stdio.h, and when I try to declare a BOOL, I get "Use of undeclared identifier BOOL."

    What am I missing??
     
  2. macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Sounds like you are writing a C program. BOOL is the Objective-C keyword. If you want to use a boolean in C code you need to either use the keyword bool (if you are happy using the C99 standard) or #define one yourself.
     
  3. Guiyon, Jan 7, 2012
    Last edited: Jan 7, 2012

    macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #3
    BOOL is not a C type, it is an Objective-C type. If you want to use it, you'll need to import and link the Foundation framework. If you are targeting the C99 standard, then there is a bool datatype (note the capitalization!) and, IIRC, you'll need to include the stdbool.h header to use it (this also defines true and false). You can also just typedef your own.
     
  4. thread starter macrumors regular

    Joined:
    Jun 7, 2007
    Location:
    Minneapolis, MN
    #4
    ARRRRGH!! That's it!

    Thanks guys and sorry for the stupid question!
     

Share This Page