Say I have something like this in a C Code. I know you can use a #define instead, to make the compiler not compile it, but just out of curiosity I\'m asking if
Below is specific to C language. I don't know how Java handles it.
Since int is defined as a const, if (i) becomes a no-op instruction here. A smart compiler should be able to optimize away that empty if statement.
Example: VC 2008
A non-empty {} with if statement:
const int i = 1;
// mov dword ptr [i], 1
if (i)
// mov eax, 1
// test eax, eax
// je wmain+35h
{
int j = 2;
// move dword ptr [j], 2
}
// ..
Empty {} with if statement:
const int i = 1;
// mov dword ptr [i], 1
if (i)
{
}
// ..