I believe this has something to do with the use of if-statements and macro's. As you know, you can leave out the braces if there is only one expression:
Code: Select all
if(something)
foo();
if(something)
{
foo();
}
If you have more than one statement, you are forced to use braces. Macro's usually look like one function call, but they may instead expand to multiple statements and still need braces. Let's try that with macro's:
Code: Select all
#define Foo(x) { a = x; b = x; c = x; }
if(something)
Foo(arg); // Wrong!
The above code will fail because there is a trailing semicolon ';' at the end after the braces. But if we do it this way:
Code: Select all
#define Foo(x) do { a = x; b = x; c = x; } while(0)
if(something)
Foo(arg); // Works
The compiler is happy and it's not a syntax error to add the trailing semicolon.
This article also explains it.
EDIT: gerryg400 beat me to it
.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.