IonicWind Software

Aurora Compiler => Coding Help - Aurora 101 => Topic started by: pistol350 on July 09, 2007, 04:27:25 AM

Title: Weird C synthax Topic :)
Post by: pistol350 on July 09, 2007, 04:27:25 AM
Hi all!
Is there anyone out there who understands the meaning of this synthax ?
??? ??? ???

xincr = x2 > x1 ? 1 : -1;

thanks!
Title: Re: Weird C synthax Topic :)
Post by: Ionic Wind Support Team on July 09, 2007, 04:43:38 AM
That's C's infamous ternary operator.   It is just a shorthand IF statement.

if(x2 > x1)
    xincr = 1
else
    xincr = -1;


The ternary operator can lead to the most unreadable code that C programmers can write.  Especially when they nest it.

Paul.
Title: Re: Weird C synthax Topic :)
Post by: pistol350 on July 09, 2007, 06:34:47 AM
Thanks Paul!
QuoteThe ternary operator can lead to the most unreadable code that C programmers can write.  Especially when they nest it.

Unlucky me! i often stumble on this king of code  ;D