Still getting used to the formatting when writing C code, come from a Lua background. How do I correctly format a if/conditional expressions as my example highlights below.
This will correctly run, but with warnings which is unideal:
return (boolean == true) and init() or 0;
Highlighted Warning:
expected a ';'C/C (between "(boolean == true)" "and")
CodePudding user response:
and
and or
are keywords are considered a bit archaic. They are technically valid C keywords in modern C (since C 98 it seems). You must be using a very old C compiler that was written before they were added to C . They, and their usage, never took off. Classical &&
and ||
operators continue to rule the roost and are not going anywhere.
Therefore: although it is true that this expression should be logically equivalent to boolean && init()
, you might want to consider assigning somewhat higher priority of updating your C compiler to something more modern, if that's indeed the reason for the compilation error.