I'm assuming that ADC1Flag has a
volatile qualified type so that the act of reading its value it is a side-effect. That being the case, I think you have only two options: either nest the tests (as you did in your proposed solution), or perform the
volatile access first, e.g.
Code: Select all
flag = ADC1Flag <= 0u;
if ((DualDAC == 0) && flag)
{
// Code Here
}
The functional difference between the two methods is that the first one only accesses ADC1Flag if the (DualDAC == 0) condition is satisfied, whereas the second accesses it regardless. Since accessing a
volatile has potential side-effects, such as unlatching data, clearing status flags and so on, which of the options is the right one depends on you application and the hardware you are running on. That's why the rule is there: to remind you that the RHS of a logical operator isn't always evaluated and to force you to make explicit in your code whether you want that behaviour or not.
In passing, I'd note that it's unusual, though not incorrect, to test an unsigned quantity against 0 using a <= operator. An unsigned quantity can never be less than zero so it's more usual to use == in this situation.