I have noticed a programming style in Embedded C, used for firmware programming:
#define WRITE_REGISTER(reg, value) \
do { \
write_to_register(reg, value); \
} while (0)
How does this do...while (0) help over:
#define WRITE_REGISTER(reg, value) write_to_register(reg, value)
As you can see here the
do {} while(0)permits to avoid compilation errors or bad working when there are multiple lines in the macro and you try to call the macro in the same way as a c function (which is the way everyone does).As an example (I report the one in the link here so you don't need to navigate the page)
will generate a compilation error because it will result in:
Using the do while everything will work fine, infact it will be:
Note that in this case putting braces will not save you because:
still generates an error.
In your case I think it's only a coding style because there's one line only.