GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Feb-2006, 23:53
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

bool and Boolean


1.Is there any difference between bool and Boolean in Managed C++ except Boolean being in System namespace.

2.
Quote:
A Boolean value is one can have only one of two values. Either it is true or it is false. It is also sometimes considered being either 0 or non-0 but Managed C++, unlike C++, makes a formal distinction between a Boolean value and a number.
I came across this statement and tried testing it in VC++2005 Expresss Edition. It doesn't complain of me using non-zero value for true and 0 for false both in case for bool and Boolean.
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
  #2  
Old 03-Feb-2006, 08:29
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,700
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: bool and Boolean


Quote:
Originally Posted by alcoholic
1.Is there any difference between bool and Boolean in Managed C++ except Boolean being in System namespace.

2.

I came across this statement and tried testing it in VC++2005 Expresss Edition. It doesn't complain of me using non-zero value for true and 0 for false both in case for bool and Boolean.

I can't (won't) speak of managed code of any kind or any of the classes of Managed C++.

Here are a few things worth knowing about "bool" in Standard C++.

1. "bool" is an integer data type. "bool" is a C++ keyword and can not be used for any other purpose. Note that, unlike other integer data types (int, char, short, long, etc.), there are no separate "signed" and "unsigned" types for "bool". There is only "bool". Note that while sizeof(char) is required by the Standard to be 1, sizeof(bool) is implementation-defined.

2. A variable of type "bool" can have a value of true or false. Operators for operations between "bool" variables (and/or literals) obey the rules that you are probably familiar with. Note that an unitialized "bool" variable may actually have a value that appears to be neither "true" or "false". Note also that results of certain operations on "bool" variables (the "--" operator, for example) are not guaranteed. (In other words, if you expect "--true" to give a value of "false", it may just happen for a particular compiler, but is absolutely and explicitly "not guaranteed" by the Standard. I have actually seen this silliness in code by someone who called himself/herself a Software Engineer. Oh, man! Where is my airsick bag?)

3. If an assignment statement has a "bool" variable on the left hand side, the assigned value is "false" if the right-hand side has a value of zero (or NULL in the case of a pointer), otherwise the assigned value is "true".

4. If a "bool" is used in an arithmetic expression with numerical data types (including an assignment to another data type), a "bool" variable with a value of "false" is converted to zero, and a value of "true" is converted to one.

There may be more things to say, but I think these will get you started.

If any Managed Code wonks are present, they may be able to answer the question as to what the differences are. I personally don't see the relevance. The question might as well be "What is the difference between C# and Java?"
They are different, and someone using one might or might not benefit (or suffer) from knowing the other. I prefer to concentrate on learning one at a time. (But that's just me --- I'm funny that way.)

Regards,

Dave
  #3  
Old 03-Feb-2006, 08:52
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

Re: bool and Boolean


Thanks....Most of the points were familier to me. Let's see if anybody else has to say anything about it.
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
  #4  
Old 03-Feb-2006, 10:04
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Re: bool and Boolean


Quote:
Originally Posted by davekw7x
wonks

"one who studies or works too much; one who is full of oneself (Slang)"

Now, that we cleared that up ...

alcoholic, In Managed (Extensions for) C++, "Bool" is the keyword for "System.Boolean".
"bool" is not translated by Managed (Extensions for) C++ into "portable" CIL (MSIL, IL ... choose your favorite name). Notice that C# does recognize the keyword "bool" as "System.Boolean".

So, there are differences, but the answer to your question is basically this:
When writing code in Managed (Extensions for ...) C++ or any .NET language, when using non CTS types, portability is not assured (I have some reservations about portability at all with .NET, but thats for another day).

Shabat Shalom,
Kobi.
__________________
It's actually a one time thing (it just happens alot).
  #5  
Old 03-Feb-2006, 19:13
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

Re: bool and Boolean


Quote:
Originally Posted by kobi_hikri
In Managed (Extensions for) C++, "Bool" is the keyword for "System.Boolean".
I have been using Boolean. I don't think there's any keyword named Bool.
Quote:
Originally Posted by kobi_hikri
"bool" is not translated by Managed (Extensions for) C++ into "portable" CIL (MSIL, IL ... choose your favorite name).
So this also applies to int, short, float ?? as there is an equivalent of them in System namespace-int32,int16,single.
Am i right to think that way??
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
  #6  
Old 04-Feb-2006, 03:37
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Re: bool and Boolean


Quote:
Originally Posted by alcoholic
I have been using Boolean. I don't think there's any keyword named Bool.

Try ...

Quote:
Originally Posted by alcoholic
So this also applies to int, short, float ?? as there is an equivalent of them in System namespace-int32,int16,single.
Am i right to think that way??

Actually, "System.Int16" is referred by the keyword "short"
"System.Int32" by "int" or "long"
"System.Single" by "Float"

I wish I could refer you to the table I'm working with, but it's a book
I think you can find this table in msdn.

Notice that some keywords start with lower-case letter and others with upper-case letter. If you are not sure, use the System. ... to verify that you are using CTS.

Kobi.
__________________
It's actually a one time thing (it just happens alot).
  #7  
Old 04-Feb-2006, 03:47
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

Re: bool and Boolean


Quote:
Originally Posted by kobi_hikri
Try ...
I did tried...its not working in VC++2003 and I didn't found any reference to it.
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
  #8  
Old 04-Feb-2006, 04:48
kobi_hikri's Avatar
kobi_hikri kobi_hikri is offline
Regular Member
 
Join Date: Apr 2005
Location: Israel
Posts: 431
kobi_hikri has a spectacular aura aboutkobi_hikri has a spectacular aura about

Re: bool and Boolean


Quote:
Originally Posted by alcoholic
I did tried...its not working in VC++2003 and I didn't found any reference to it.

Yeahh, it doesn't work with VC++2005 either.
I was referring to the table displayed in the book "Pro C# 2005 and the .NET 2.0 Platform", page 18.
The correct keyword for "System.Boolean" ("System::Boolean") is "bool" in managed c++.
The other part of my previous answer remains (if your compiler allows for usage of non-CTS types, CIL portability is not assured).

Sorry to mislead you.
Kobi.
__________________
It's actually a one time thing (it just happens alot).
  #9  
Old 04-Feb-2006, 05:07
alcoholic's Avatar
alcoholic alcoholic is offline
Member
 
Join Date: Nov 2005
Posts: 170
alcoholic is on a distinguished road

Re: bool and Boolean


Thank You
__________________
Gravitation is not responsible for people falling in love.
-Albert Einstein
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert char to integer blah C++ Forum 40 18-Aug-2005 14:08
Detect Removable USB Device Automatik C Programming Language 8 26-Jul-2005 04:36
I need help implementing kjc_13 C++ Forum 0 14-Feb-2005 16:00
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 21:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:58.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.