Code:
if ((SysFlags & 0x02) != 0x00) // Reset Flag Activated
Your code is correct, but I think this is a better way to write it:
Code C - [expand] |
1
| if (SysFlags & 0x02) // Reset Flag Activated |
The opposite test is written like this:
Code C - [expand] |
1
| if (!(SysFlags & 0x02)) // Reset Flag not Activated |
By using that style, you eliminate the possibility to write broken code like this:
Code C - [expand] |
1
| if ((SysFlags & 0x02) == 1) // Reset Flag Activated |
A related thing is the handling of "false" and "true".
Some programmers use declarations like this:
#define FALSE 0
#define TRUE 1
You don't see that in the original C book by Kernighan & Ritchie, and for a good reason.
An expression is "true" in C if it is non-zero. It is impossible to define a macro TRUE to have the same meaning for assignments and tests..
FALSE is a little better, but not much.
The following lines are broken:
Code C - [expand] |
1
2
3
| if ((SysFlags & 0x02) == TRUE) // Reset Flag Activated
...
if ((SysFlags & 0x02) == !FALSE) // Reset Flag Activated |
This will work, but I don't recommend it:
Code C - [expand] |
1
2
3
| if ((SysFlags & 0x02) == !TRUE) // Reset Flag not Activated
...
if ((SysFlags & 0x02) != FALSE) // Reset Flag Activated |
So my recommendation is to avoid FALSE, TRUE and comparisons with boolean variables.
Just do if(variable) or if(!variable).