views:

80

answers:

2

Hi everyone,

I'm just to figure out what does this method do, I know there must be a way to put this line by line, can you help me please?

Thanks

int
conditional ( int n, EXPRESSION * * o )
{
  return (evaluateExpression( *o++ )? evaluateExpression( *o ) : evaluateExpression( *++o ) );
}

UPDATE: This is the evaluateExpression Code

int
evaluateExpresion ( EXPRESSION * e)
{
__asm
{
mov eax,dword ptr [e] 
movsx ecx,byte ptr [eax] 
test ecx,ecx 
jne salto1
mov eax,dword ptr [e] 
mov eax,dword ptr [eax+4] 
jmp final
salto1:
mov esi,esp 
mov eax,dword ptr [e] 
mov ecx,dword ptr [eax+8] 
push ecx  
mov edx,dword ptr [e] 
movsx eax,byte ptr [edx] 
push eax  
mov ecx,dword ptr [e] 
mov edx,dword ptr [ecx+4] 
call edx  
add esp,8
final:
} 
}
+6  A: 

The "ternary expression" used in that long return statement has a net effect just like an if/else statement, such as the following:

if (evaluateExpression(*o++)) {
  return evaluateExpression(*o);
} else {
  return evaluateExpression(*++o);
}
Alex Martelli
Thank you very much!
Sheldon
if ... (?) then ... else (:) ...
stefanB
But, evaluateExpression is not a boolean function, is an integer function. How does this work in this scenario?
Sheldon
If it `evaluateExpression()` returns 0, it would take the 'false' path. If it returns anything else it would be 'true'.
Carl Norum
ohhh :S jajaja thanks!
Sheldon
Artelius
+2  A: 

It takes an array of three EXPRESSIONs and evaluates the first one. If the first one evaluates to a true value, it evaluates the second expression and returns its value. Otherwise it evaluates the third expression and returns its value.

yjerem