Uhmm
Are you (Michalson and a person) sure on the thing about compilers turning "if (a == TRUE)" into "if (a != FALSE)" (and vice-versa)?
Cause thats a bit nonsense, as TRUE (FALSE) is defined to 1 (0), so thats basically turning :
if (a == 1)
into
if (a != 0)
Which in most cases isnt what you want, as, lets say you do something like this :
int x, y, a;
x = rand()%100;
y = rand()%100;
a = x + y;
if (a == 1)
printf ("Woot, 1!");
else
printf ("Wah, not 1!");
If your compiler turn "a == 1" into "a != 0", you will get the "Woot, 1!" phrase almost all the time, while you whould be getting it only very rarely (only when the sum is exactly 1, and not non-zero).
That doesnt make any sense.
One explanation would be that the compiler actually treats differently the "TRUE"/"FALSE" things, and not simply turn them into "1"/"0" before compiling, which I dont know, but I dont think it does...
Cya,
-RoTTer
Which one is faster?
quote:
Original post by RoTTer
One explanation would be that the compiler actually treats differently the "TRUE"/"FALSE" things, and not simply turn them into "1"/"0" before compiling, which I dont know, but I dont think it does...
windef.h :typedef int BOOL;#define TRUE 1#define FALSE 0
TRUE, FALSE and BOOL are not the same things as true, false and bool.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Hey
Uhmm, I didnt really get what you mean heh. "TRUE" and "FALSE" is what we all talked about here, and I dont know what "true" and "false" are as I never used them.
If thats only what the compiler does (changed "TRUE" to "1", "FALSE" to "0") as I stated that I thought that it did, then my question still remains, and I didnt understand a bit of what you mean... =/.
Cya,
-RoTTer
quote:
Original post by Frunywindef.h :typedef int BOOL;#define TRUE 1#define FALSE 0
TRUE, FALSE and BOOL are not the same things as true, false and bool.
Uhmm, I didnt really get what you mean heh. "TRUE" and "FALSE" is what we all talked about here, and I dont know what "true" and "false" are as I never used them.
If thats only what the compiler does (changed "TRUE" to "1", "FALSE" to "0") as I stated that I thought that it did, then my question still remains, and I didnt understand a bit of what you mean... =/.
Cya,
-RoTTer
the cap versions are the macro/typedef compiler specific version while the lower case versions represent the standard c/c++ versions.
Oh, I see...
But what can the compiler do to change the defs to make the "a != FALSE" actually work? And what compilers does that?
Cya,
-RoTTer
But what can the compiler do to change the defs to make the "a != FALSE" actually work? And what compilers does that?
Cya,
-RoTTer
I just wanted to say that the answer to this question is simple THEY ARE THE SAME THING! Once you''ve calculated for one you know the other!
For instance x = 1 y = 0
In order to figured if they are != you run through the bits until you find one that is not the same as the other.
To find out if they are =, what do you do? You run through the bits until you find one that is not the same as the other.
What makes a difference is if they ARE equal it may take longer than if they are not, because it will have to check all the bits.
~Vendayan
For instance x = 1 y = 0
In order to figured if they are != you run through the bits until you find one that is not the same as the other.
To find out if they are =, what do you do? You run through the bits until you find one that is not the same as the other.
What makes a difference is if they ARE equal it may take longer than if they are not, because it will have to check all the bits.
~Vendayan
"Never have a battle of wits with an unarmed man. He will surely attempt to disarm you as well"~Vendayan
quote:
Original post by RoTTer
Oh, I see...
But what can the compiler do to change the defs to make the "a != FALSE" actually work? And what compilers does that?
Well,
bool
is a built-in type in C++, so the compiler can be sure that the only possible values are true
or false
, whereas BOOL
is just a synonym for int
, so can take many values. Thus the compiler can''t make such assumptions about BOOL
.As for the original question, I doubt any CPU worth it''s salt would compare the bits one by one - you''d do it all in parallel.
codeka.com - Just click it.
do programs that run both for 24 hours straight.
.sen

"I want to make a simple MMORPG first" - Fenryl
I personally don''t know whats going on here. But I got an idea from the begginer ppl (that were talking my language, Assembly). I mean for integers I agree with the earlier stated you can do a "CMP" insturction and use the Conditional Jump intructions and do whatever. Most processors will do each equal. As for the FPU (in your case working with float var types in C). You would have to do the comparisn on the FPU then move the status word/byte from the FPU into the CPU and use the conditional jumps. So basically I would say their the same! It''s just a matter of preference and which one is easier for you to read/decipher
-Assembly (x86/x87/MMX/3DNow!)
-C/C++
-Visual Basic
-Turing
(And only 15 years old!!)
-Assembly (x86/x87/MMX/3DNow!)
-C/C++
-Visual Basic
-Turing
(And only 15 years old!!)
"I'm a rockstar, baby, baby , baby" -Bizarre
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement