I did not understand the following line:
which value does cxCaps get? And what are the "?" and ":" symbols used for?Code:cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
:rolleyes:
Printable View
I did not understand the following line:
which value does cxCaps get? And what are the "?" and ":" symbols used for?Code:cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
:rolleyes:
The ? and : are the C++ only ternary operator. It means that if the expression tm.tmPitchandFamily & 1 is true then 3 is multiplied by cxChar else 2.
but 1 is not a boolean expression. How can it be true of false?
x & 1 checks bit patterns, and if it's found, returns true. Plus most integers can be converted to bool (0 = false, everything else = true).
0 is false in C++ and everyother value is true. That is why
while(1) is an infinite loop. But in this case it is not just 1 it is
tm.tmPitchAndFamily & 1
Whoops!! parksie is faster :(
Hope im not sounding stupid hear, but...
Doesnt "x & 1" perform a binary AND on x with 0x0001?
Z.
Yes, like Parksie said about the bit patterns, & is a bitwise operator.
& - bitwise AND
&& - boolean AND