This type of syntax is called a ternary operator. They are generally used to perform simple expressions, or assign things to ONE variable based on a condition, rather than handle assignment logic with two variables.
This is why you can’t have both a = TRUE
and b = TRUE
in the ternary operator. You should only have values or things that return values in there.
e.g.
BOOL result = (num == 21 ? TRUE : FALSE);
BOOL a = result;
BOOL b = !result;
Read more on ternary operators on Mozilla’s documentation
Also, slightly unrelated to your actual question, but still an issue you should fix; Lee Daniel Crocker made a good point. FALSE
shouldn’t really be defined as 1
, as it is usually defined as 0
in most programming contexts. TRUE
is defined as any number other than 0
, i.e. !FALSE
. Hence, try doing this to define your TRUE and FALSE:
#define FALSE 0
#define TRUE !FALSE
2
solved Strange things happen with bool? [closed]