unusual syntax - what does it mean?

well it's unusual to me anyway... from the Starlino IMU 6DOF code, here: A Guide To using IMU (Accelerometer and Gyroscope Devices) in Embedded Applications. – Starlino Electronics

signRzGyro = (cos(Awz[0]*PI/180) >= 0 ) ? 1 : -1;

hoping someone can explain what this code does?

tks

It is like a short form if statement.

If condition ? True value : false value

It is often used to eliminate the longer form of if when all you are doing is assigning a value to a variable, as in this case.

That statement can be expanded to:

if(cos(Awz[0]*PI/180) >= 0 )
{
  signRzGyro = 1;
} else {
  signRzGyro = -1;
}

It's called a "trinary" or "ternary" operator depending on who you ask.


Rob

excellent, thanks all

marco_c:
It is like a short form if statement.

If condition ? True value : false value

It is often used to eliminate the longer form of if when all you are doing is assigning a value to a variable, as in this case.

Its not a statement, its a conditional expression. Can use anywhere in an expression, very convenient and intuitive but woefully underused because its not taught enough. Many functions return expression can be concisely written with them:

int hexvalue (char c)
{
  return (c >= '0' && c <= '9') ? c - '0' :
         (c >= 'A' && c <= 'f') ? c - 'A' + 10 :
         (c >= 'a' && c <= 'f') ? c - 'a' + 10 :
         -1 ;
}