int, float, long, DWORD, all the same size?

Started by
21 comments, last by billybob 21 years, 4 months ago
quote:Original post by ga
the compiler can''t do that for you because it would have problems when you do operations with pointers to those bools...
That is sure a problem. I said the compiiler *might* do it, not that it would. I know that there were compilers that could do that under some circumstances. Personally, I hate compilers that change the "structure" of my code.

Advertisement
I personaly use bool instead of BOOL just 'cause it colors to
blue and I like to see the types of variables in a diferent
color, it's easier to read the code, however I use DWORD instead
of unsigned long, just 'cause it's shorter to type.

Sometimes I get a problem with bool and BOOL, sometimes when I
try to make a simple thing like "bool aaa = bbb"(bbb is BOOL),
the compiler says "warning - forcing bool to int, performance
might be affected" or something like that, why does this occurs ???
And if I change the variable "bbb" to BOOL it does not complain
any more... It just happens sometimes, usually I don't get problems
using bool's instead if BOOL's, it just happens sometimes...

Kamikaze

[edited by - Kamikaze15 on December 11, 2002 2:40:59 PM]
BOOL b; bool a = b;

Remember that BOOL is a typedef for unsigned long, so it is simply a 32-bit integer. The compiler doesn''t know it''s supposed to be a boolean, it just sees a 32-bit integer. Since a is only either true or false, in order to convert b to a, the compiler puts a conditional jump in the code, which is basically an if statement. So it executes "if b != 0 then a=1; else a=0;". That is slower than a regular variable assignment.

You can avoid the warning by typing the conditional statement yourself:

BOOL b; bool a = b ? true : false;


~CGameProgrammer( );
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement