I know this is simple but I have no idea how to translate this one:

boolActiveState = wParam != FALSE;

The thing that stumped me is the != , isn't this one used for if statements in C? Or is this a NOT instruction? NOT in C is !Variable.

Any Ideas? :confused:
Posted on 2002-02-21 12:41:07 by stryker
The (wParam != FALSE) part is an expression which is the same as in masm: test: wParam is not false?
this expression returns true or false, so this:

boolActiveState = wParam != FALSE;

will become:

boolActiveState = true; // if wParam!=false
boolActiveState = false; // if wParam==false

The fastest translation would probably be:

mov eax, wParam
mov boolActiveState, eax

Basically the C code just copies the boolean value in wParam to boolActiveState.

Posted on 2002-02-21 12:48:51 by Thomas
Thanks, Thomas, the != is confusing me? Thanks for clearing it up :)
Posted on 2002-02-21 12:57:20 by stryker
Isn't boolean assignment possible - wonder why the extra code?

boolActiveState = wParam; // doesn't this work?

Or, cast it to a boolean?

It is confusing. :)
Posted on 2002-02-21 13:03:14 by bitRAKE
Check this site http://www.directxfaq.com/kbase/dinput/getkeystate.htm this is where I got the C statement. This is for the game I'm creating http://www.asmcommunity.net/board/index.php?topic=3700
Posted on 2002-02-21 13:16:07 by stryker
Using it dependce on how boolActiveState is used.
!wParam means 0
but wParam may be any not zero value.
if code uses only statment if !(boolActive) then it's OK to do
but if code uses something like if boolActiveState==TRUE
it may result on compiling such code as
cmp boolActiveState,1
jne @FalseCase
Wich will work incorrectly 'cause in the hence of logic programmer
cmp boolActiveState,0
je @FalseCase.
It is also unacceptibal when boolActiveState values (wich often is a case) used for triggers like
mov eax,boolActiveState
xor eax,1
invoke ShowWindow,hWnd,eax
Posted on 2002-02-21 13:32:02 by The Svin

boolActiveState = wParam; // doesn't this work?

Or, cast it to a boolean?

The problem is that a bool is a BYTE in C, and wParam is a dword. Visual C++ outputs this with the original code:

mov esi,dword ptr [esp+0C4h] ; wParam
test esi,esi
setne dl ; dl = boolActiveState

Using it directly like you said generates the following warning, both directly and when casted to a bool:

warning C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)

But it generates exactly the same code.
In masm, you could also just use wParam as a bool, no need to copy it first.

Posted on 2002-02-21 14:01:00 by Thomas
or just extend the bool to dword
	mov	eax, wParam

test eax, eax
setne al
and eax, 0FFh
so you get a real TRUE (= 1) for wParam not equal zero
Posted on 2002-02-22 06:20:26 by beaster