Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Sat Apr 30, 2016 7:35 am |
|
|
This is standard C. Every C textbook will have it. It's called a 'conditional expression'
You shouldn't have to change it to work with CCS, it'll work as it is.
The statement (test)?expr1:expr2
Evaluates 'test'. If test is true, it returns expr1, if not, it returns expr2.
In some cases, it can be done slightly smaller/faster than an 'if, since there only has to be one set of code to 'write' to the target variable.
So in your example, if x is > 200, the code returns 199, otherwise it returns Y.
This return is then put into X.
The actual syntax used seems slightly 'odd'. I'd have expected (for example), as a way of limiting a return value to 199:
X will then get set to Y, if Y is less than 200, or 199 otherwise.
Key difference to your #2 code, is it does not change what is in the variable being tested. This may matter, depending on what the code is doing.... |
|