From what I understand, #define x y
and const int x = y;
should work identically under the Visual Studio compiler, but const int x = y;
is the preferred method.
The C code I have looks something like this:
static const int x = 100000;
void SomeFunction(...)
{
volatile static int y = x;
...
}
The problem here is with the declaration of y. If I use a #define
for x, then there are no problems, but using the above code results in the compiler returning with "error c2099: initializer is not a constant."
I'm trying to compile from the command line, and I'm not using any compiler flags, so I'm not sure if I need to set a flag in order for the compiler to optimize out the const - or if I stumbled onto some kind of special case.
Compiling the program as a C++ program also works, but I would rather avoid that, if possible.