RRam_k
June 25th, 2002, 12:15 AM
Hi NG,
I am using conditional operators extensively in my program for just to avoid simple if and else conditions.Please see the code below
#include "stdafx.h"
#include <conio.h>
void check(BOOL flag,int x)
{
printf("Result is %d,%d",flag,x);
}
int main(int argc, char* argv[])
{
int a=10,b=20;
BOOL x=TRUE,y=FALSE;
if(x==TRUE)
{
if(b>a)
check(FALSE,b);
else
check(FALSE,a);
}
else
{
if(b>a)
check(TRUE,b);
else
check(TRUE,a);
}
//check((x==TRUE) ?FALSE:TRUE,(b>a)?b:a); //uncomment this code and comment the if and else
getch();
return 0;
}
I want to know the pros and cons of using the conditional operator inside a function call. Is the code is efficient or inefficient? Is it conforms to the standard code writing practice? I have just looked into the assembly code generated for the both. The code generated for the function call with conditional operator is around 15 and the other one is around 29.
Thanks in Advance
with kind regards
Raghuram
I am using conditional operators extensively in my program for just to avoid simple if and else conditions.Please see the code below
#include "stdafx.h"
#include <conio.h>
void check(BOOL flag,int x)
{
printf("Result is %d,%d",flag,x);
}
int main(int argc, char* argv[])
{
int a=10,b=20;
BOOL x=TRUE,y=FALSE;
if(x==TRUE)
{
if(b>a)
check(FALSE,b);
else
check(FALSE,a);
}
else
{
if(b>a)
check(TRUE,b);
else
check(TRUE,a);
}
//check((x==TRUE) ?FALSE:TRUE,(b>a)?b:a); //uncomment this code and comment the if and else
getch();
return 0;
}
I want to know the pros and cons of using the conditional operator inside a function call. Is the code is efficient or inefficient? Is it conforms to the standard code writing practice? I have just looked into the assembly code generated for the both. The code generated for the function call with conditional operator is around 15 and the other one is around 29.
Thanks in Advance
with kind regards
Raghuram