I got an error while compiling a program in GCC in windows. When i put an initialization expression inside an if condition without braces, I get an error : expected expression before short/int. When I put braces, for the body of the if, the source is compiled without any errors. This problem persists in any program. I wrote a program containing only an if condition, and still I get the error. This is the code :
int main(void)
{
if (1 < 2) // Doesn't work with any condition I've tested so far.
int a = 0; // Expected expression before int here.
}
But the problem is resolved when I put the "int a = 0" part within braces. I just want to know why this is happening. Is it a bug in the compiler?