473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

bool to int cast

Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?

Jeroen
Jul 9 '07 #1
3 45472
MathWizard wrote:
Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?
No, int(true) is always 1. And int(false) is always 0.

--
rbh
Jul 9 '07 #2
"MathWizard" <no*****@please.comwrote in message
news:46***********************@dreader16.news.xs4a ll.nl...
Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?
From bool to int, false is always 0, true is always 1.
From int to bool, 0 is always false, anything other than 0 is true.
Jul 9 '07 #3
Jim Langston schreef:
"MathWizard" <no*****@please.comwrote in message
news:46***********************@dreader16.news.xs4a ll.nl...
>Hi all,

I was wondering how the cast from bool to an integer is defined. I guess
that 'false' always leads to '0', but I'm not sure that 'true' always
leads to '1'. Is it possible that 'true' casts tot something like
'non-zero' and thus can take any positive value?

From bool to int, false is always 0, true is always 1.
From int to bool, 0 is always false, anything other than 0 is true.

OK, thanks guys.
Jul 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Vinokur | last post by:
========================= Windows 2000 Professional Digital Mars C/C++ 8.36 STLport 4.5.3 ========================= I have got a problem with compilation of the following piece of code using...
3
by: Floela | last post by:
I keep geting the exception: System.InvalidCastException: Specified cast is not valid. I get this when I try to pass a DataRow into an object method. The line that causes this error is: ...
8
by: CA | last post by:
Hi, I have a function where I would like to test whether an object is of a certain type. Here is my code so far. public bool HasValidType(Type t, object val) { try { if (t==typeof(double))
0
by: cody | last post by:
Why isn't there an explicit conversation from bool to int and vice versa? I Understand they dropped the _implicit_ conversions between bool and int but why can't I use an explicit cast? I want to...
4
by: Justin Piper | last post by:
I was toying with using function pointers to implement a state machine, and ran into trouble when I tried to use a template to specify the type of one of the arguments. I was able to determine that...
2
by: DMG | last post by:
Why does this fail with a cast exception? The field is coming in from the data base as null due some bad design on my part but I thought this would allow me to test and set to false. ...
10
by: 2005 | last post by:
Hi, The expression below bool Full() {return ((mSize==MAXSIZE) ? true : false);} My question is if (mSize==MAXSIZE), would it return 1 or 0? Of course I ran the code but it conflicts with...
12
by: aaragon | last post by:
Hi All, I'm trying to print boolean values and after I searched the entire web, I couldn't find anything that does this =/ The code that I ended up using is as follows: string...
5
by: taumuon | last post by:
I've got an object, Person, that supports IEquatable<Person>. It implements bool Equals(Person obj) as well as overriding bool Equals(object obj) I've got a container type that holds a member...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.