Raised This Month: $ Target: $400
 0% 

String manipulation fun!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flynn
Senior Member
Join Date: Sep 2009
Old 09-22-2009 , 18:23   Re: String manipulation fun!
Reply With Quote #1

Quote:
Originally Posted by PM View Post
true + true still gives 2 on C++:
PHP Code:
int c b
outputs 2. That's because the + operator expects two int parameters - and bools get automatically promoted to int.
Thats because the storing variable is an int. If you had c as a bool, it's actually still only '1'.

Besides, 8bits are required for address referencing; that is not to say the -storage- that the address references is 8 bits (hence 32 bit and 64 bit machines). Regardless, a bool refers to a single bit; the first one. All other bits are thrown out (regardless of usage).

Notice B1 and B2 in the for loop of the code are booleans? I am only adding to a boolean - no ints are involved anywhere.

Also, original test in image format for others to see...
http://img6.**************/img6/1663/demotp.jpg
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-22-2009 , 18:35   Re: String manipulation fun!
Reply With Quote #2

Quote:
Originally Posted by Flynn View Post
Thats because the storing variable is an int. If you had c as a bool, it's actually still only '1'.
The result of true + true is always 2. But when you assign the result, 2, back to a bool variable, the integer result 2 automatically gets converted to bool which is != 0 so it becomes "true". This conversion is why MSVC outputs a warning on bool c = true + true;

Quote:
Originally Posted by Flynn View Post
Besides, 8bits are required for address referencing; that is not to say the -storage- that the address references is 8 bits (hence 32 bit and 64 bit machines). Regardless, a bool refers to a single bit; the first one. All other bits are thrown out (regardless of usage).
Yes. Just wanted to point out that when you type bool a; it will reserver one whole byte of memory and not one single bit

EDIT: Basically the only thing that is important here to me: I don't see a reason to use + in an all-bool context except to maybe confuse the reader. | is designed for that case and makes more sense to almost everyone.
__________________
hello, i am pm

Last edited by PM; 09-22-2009 at 18:46.
PM is offline
Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode