Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bool defined where?

Posted on 2016-08-30
6
Medium Priority
?
38 Views
Last Modified: 2016-11-28
Hi

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

thanks
0
Comment
Question by:LuckyLucks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:LuckyLucks
ID: 41777360
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;
0
 
LVL 32

Expert Comment

by:phoffric
ID: 41777549
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.
1
 
LVL 29

Expert Comment

by:pepr
ID: 41780540
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.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 29

Accepted Solution

by:
pepr earned 2000 total points
ID: 41801075
Reading the second comment...
complaining that it is an unreferenced local variable when i do
bool myBoolVar;

It actually has nothing to do with "where the bool is defined" or whether it is a keyword or not. It says that the myBoolVar was declared here, and it is not used in the code. In other words, you can remove the definition. You can also try to search for all the myBoolVar string in the sources to check whether it is true.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 41801149
good observation pepr.
Would also have helped if the author had used the word, "warning". I took complaining too strongly as in error.
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41903861
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
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question