Thursday, 5 September 2013

which code is more efficient? calling twice a macro or just assigning macro to a variable and use it twice?

which code is more efficient? calling twice a macro or just assigning
macro to a variable and use it twice?

From the below code snippets which one is more efficient (1 or 2) and Why?
Please shed some light on this. Thanks in advance!
//I am doing some operation with this macro.
#define ERRMAP( sts ) ((A_ABS( sts ) < FIRST_ERR) ? \
sts : \
((A_ABS( sts ) > A_ABS( LAST_ERR )) ? \
sts : \
sts_to_errno_ma[A_ABS( sts ) - FIRST_ERR]))
//Code snippet 1
int some_fun (int sts) {
int i = ERRMAP( sts );
printf(" sts = %d", i);
return i;
}
//Code snippet 1
int some_fun (int sts) {
printf(" sts = %d", ERRMAP( sts ));
return (ERRMAP( sts ));
}

No comments:

Post a Comment