I am trying to implement a progress bar for a console application in windows using Win32 Console API. My problem is that the compiler gives the error, error C2059: syntax error : 'constant'. The relevant code is as follows.
void updateBar(PBAR * pbr, float ratio){
COORD pos;
pos.X = 0;
pos.Y = 25;
SetConsoleCursorPosition(hConOut, pos);
}
COORD is the Win32 structure for denoting a co-ordinate pair. hConOut is a global variable and PBAR is a structure. Above error is given twice for two assignments (pos.X = 0 an pox.Y = 25). If I use the following, it compiles perfectly.
void updateBar(PBAR * pbr, float ratio){
COORD pos = {0, 25};
SetConsoleCursorPosition(hConOut, pos);
}
I really can’t understand the reason for this. I mean it’s just an assignment to structure members, right ?? If I do something like POINT pt; pt.x = 0; pt.y = 25, it compiles perfectly. POINT is just another structure.
I use visual studio 2010 on windows 7 and compiler is:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80×86
Any thoughts ?? Thanks in advance.
I compiled this and it works fine.
However, if I define X or Y as macros, e.g.
then I get exactly the same error as you. Do you have these macros?