Link to home
Start Free TrialLog in
Avatar of LuckyLucks
LuckyLucks

asked on

bool defined where?

Hi

what's the most standard lib that defines this for C++? and for c+11?

thanks
Avatar of LuckyLucks
LuckyLucks

ASKER

I thought is was a builtin type. But a simple snippet of code in C++ using visual studio 2008 is complaining that it is an unreferenced local variable when i do
bool myBoolVar;
Avatar of phoffric
By any chance did your file have a .c extension. ANSI C-language does not have bool intrinsically defined.
If you want, you can post the small snippet and we'll see if it runs it builds in different environments.
The bool is a keyword in C++. You cannot redefine it. If you read that in your old source, it is probably a C source -- as phoffric said. If you want to have syntactically the same bool type and true and false constants, you can add elsewhere code like this:

#ifndef __cplusplus
typedef unsigned char bool;
static const bool false = 0;
static const bool true = 1;
#endif

Open in new window


The __cplusplus symbol (two underscores) is defined by the any C++ compiler for solving the situations like this. The code says: If the symbol is not defined (that is we use a C compiler [setting]), then define the bool type using the standard C way. Define also the constants. If the symbol is defined, then the lines are skipped and the built-in type and values (keywords) are used.

I did not check, whether bool became also keyword in later C standards. In such case, the above construct would colide even with C.
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
good observation pepr.
Would also have helped if the author had used the word, "warning". I took complaining too strongly as in error.
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: pepr (https:#a41801075)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer