Click to See Complete Forum and Search --> : 'False' undeclared
lamars
July 2nd, 2002, 11:00 AM
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.
Graham
July 2nd, 2002, 11:09 AM
"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).
dude_1967
July 2nd, 2002, 11:12 AM
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.
:)
lamars
July 2nd, 2002, 12:43 PM
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.
proxima centaur
July 2nd, 2002, 12:48 PM
lowercase false and true are defined in the language. They are of type bool.
all in lowercase.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.