|
-
July 2nd, 2002, 11:00 AM
#1
'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.
-
July 2nd, 2002, 11:09 AM
#2
"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
-
July 2nd, 2002, 11:12 AM
#3
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.
-
July 2nd, 2002, 12:43 PM
#4
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.
-
July 2nd, 2002, 12:48 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|