As a side note, there is another, even more obscure old "trick" like this still used by some people today. Actually, I worked for a project in the last months where a very few somewhat unexperienced people tried to create a coding guideline which was very thin, lacking all important things, but mentioned this "trick" as good practice (and they didn't even explain why they thought so):
#define FOO(x) do { foo(x); bar(x); } while (0)
Similar to the "value == variable" idea, this is just a silly idea which makes the code much less readable while gaining an advantage in one singular case that would never occur if using a more sensible coding guideline. Like either forbidding function like defines like this (and use inline functions instead) and/or to forbidding if/else statements without parentheses.
There's nothing similar to the "value == variable" idea here. The key difference is that "value == variable" is supposed to be plastered all over the code at all levels, i.e. every time one needs a comparison of this kind. It is a
client-code level trick.
Meanwhile, the `do/while(0)` is a
library-code level trick - something you use hide internally, as an implementation detail in a macro. To the client code that macro is a black box (with usual caveats). The client code does not need to know what tricks were employed internally in implementing that macro. Nobody expects (or encourages) the client code to use similar tricks or even know about them.
Because of that, the `do/while(0)` qualifies as an extremely useful idiom, as opposed to the pesky "value == variable" idea.
---
If you open the source code of some C standard library implementation, you'll see a lot of horrendously looking trickery being used there. The code is virtually unreadable and can only be understood by a specialist specializing in standard library implementations. But the users of the library don't need to expose themselves any of that. And, of course, they are not expected to use similar techniques in their code (at least on a regular basis). The `do/while(0)` idiom is just a milder version of that.