PeterH:
Just out of curiosity, what is the purpose of the do/while here?
It is a way to define a multi statement macro that works regardless of whether used
along side or inside other constructs such an if statement regardless of whether
braces are used.
Suppose the macro were defined as:
#define delayMicroseconds(us) if(us) delayMicroseconds(us)
and then the code that used it were:
if(xxx)
delayMicroseconds(delay);
else
foo(); // do other work
If you expand that out it becomes:
if(xxx)
if (delay) delayMicroseconds(delay);
else
foo(); // do other work
This silently/unexpectedly changes what the author wanted
in that now foo(); is called if delay is zero
vs if xxx is zero, and when xxx is zero nothing happens.
For readibility here is the resulting code re-formatted
if(xxx)
if (delay)
delayMicroseconds(delay);
else
foo(); // do other work
This change would not have happened if the original code used brackets
if(xxx)
{
delayMicroseconds(delay);
}
else
{
foo(); // do other work
}
But since using brackets is not mandatory for simple statements, the
macro should still work as expected when brackets are not used since it appears to be a simple function.
The do/while essentially turns the multi-statement macro back into a simple/single statement that can work
correctly when braces are not used.
Further reading:
--- bill