Why would one write a literal directly followed by a semicolon in c/c++?

Viewed 242

I'm looking at some code and I've come across the following line in a macro:

int foo = 0; (foo);

It compiles just fine. In fact, it seems that

0;

is a valid line of code in C/C++.

I've taken a look at the produced assembly in debug and release builds (on msvc), and it does not make a difference to the assembly. My test was a simple one though (with and without (foo);):

int main()
{
    int foo = 0;
    (foo);
    return 0;
}

My question is why would anyone want to do this? I'm sure (foo); is in the macro for a reason, but I'm not sure why.

For context, the macro it is found in looks like this (I've renamed the variables):

#define MY_MACRO int _foo = 0; (_foo); UINT _bar = CP_THREAD_ACP; (_bar); LPCWSTR _baz = NULL; (_baz); LPCSTR _thing = NULL; (_thing)

In the code, it is simply called like

MY_MACRO;
//other code...
2 Answers
Related