CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    7

    'False' undeclared

    Hello All,

    I am trying to compile some code (an example from a book) using 'make' on a Linux system.

    when I compile, I get:

    'False' undeclared here (not in a function)

    The line this error speaks to is:

    static int srvr_comm=FALSE;


    I sense this is more C than C++, however, I know the experts are here.

    Can anyone help me with this?

    I appreciate it.

  2. #2
    Join Date
    Apr 1999
    Location
    Altrincham, England
    Posts
    4,470
    "FALSE" and "TRUE" are macros defined by Micro$oft for use with their "type" BOOL in the Windows headers. They are not part of C or C++. C++ has a "bool" type which can take the values "false" and "true" (lower case).
    Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
    --
    Sutter and Alexandrescu, C++ Coding Standards

    Programs must be written for people to read, and only incidentally for machines to execute.

    --
    Harold Abelson and Gerald Jay Sussman

    The cheapest, fastest and most reliable components of a computer system are those that aren't there.
    -- Gordon Bell


  3. #3
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557
    Remember, the silly compiler needs to have everything explicitly defined. Many programmers define TRUE and FALSE to improve code quality.

    In pure C, I assume that FALSE and TRUE are never defined separately, meaning that both of them are defined or neither of them is defined.

    #ifndef FALSE
    #define FALSE 0
    #define TRUE 1
    #endif

    Make sure that this code is included in some header which is included in the relevant file or that this definition is somewhere near the top of the C/C++ file.

    Some authors prefer

    typedef enum { FALSE = 0, TRUE = 1};

    As before in header file or near the top of the source file.

    With either one of these definition mechanisms you can use the symbolic words TRUE and FALSE in your program.

    Have fun! Chris.

    You're gonna go blind staring into that box all day.

  4. #4
    Join Date
    May 2002
    Posts
    7
    Thanks for the response, Graham and Chris.

    Graham, thank you for the explanation

    Chris, thank you for the insight.

    I defined FALSE and TRUE as you stated and it worked.

    I didn't think I had to define these in general and especially with some code (examples from a book). :-)

    Aren't False and True already defined in C++?

    appreciate your help.

  5. #5
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    lowercase false and true are defined in the language. They are of type bool.

    all in lowercase.
    Martin Breton
    3D vision software developer and system integrator.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured