C return and comparation inline
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开发者_如何学JAVA?
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:
}
}
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);
}
It takes an array of three EXPRESSION
s 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.
精彩评论