From Ubuntu to Windows: Syntax Error C2059 / C2143
-
@fem_dev said in From Ubuntu to Windows: Syntax Error C2059 / C2143:
Why this happen?
Because it's already defined as @mrjj already told you. It's a #define .
-
@mrjj Thank you....now its working good!
Second doubt: I was thinking that 'ERROR' inside the custom
enum
will not clash with MSVC 2019.
Why this happen? -
wrote on 15 Jul 2020, 20:03 last edited by
You have the option of using mingw in windows (basically gcc for windows). This will help avoid these kinds of problems. YMMV.
-
@fcarney said in From Ubuntu to Windows: Syntax Error C2059 / C2143:
This will help avoid these kinds of problems. YMMV.
No, not in this case. ERROR is a define in a windows header.
btw: using uppercase in enums is ... strange -
@mrjj Thank you....now its working good!
Second doubt: I was thinking that 'ERROR' inside the custom
enum
will not clash with MSVC 2019.
Why this happen?@fem_dev You can use "enum class" to avoid name clashes:
typedef enum class { ERROR = -2, // C2059: syntax error: 'constant' WARNING = -1, STATUS = 0 } MSG_TYPE;
But then you will need to qualify using enum name:
MSG_TYPE::ERROR;
-
@fcarney said in From Ubuntu to Windows: Syntax Error C2059 / C2143:
This will help avoid these kinds of problems. YMMV.
No, not in this case. ERROR is a define in a windows header.
btw: using uppercase in enums is ... strange@Christian-Ehrlicher said in From Ubuntu to Windows: Syntax Error C2059 / C2143:
btw: using uppercase in enums is ... strange
Sadly its mandatory - at least the first letter - if you want to expose your enum to the QML-Engine
-
@Christian-Ehrlicher said in From Ubuntu to Windows: Syntax Error C2059 / C2143:
btw: using uppercase in enums is ... strange
Sadly its mandatory - at least the first letter - if you want to expose your enum to the QML-Engine
wrote on 16 Jul 2020, 12:49 last edited by JonB@J-Hilk
In fairness, the usual way now for anenum
is initial capital followed by smalls, which should avoid the calls withERROR
. -
Hi
Just a note.
I seen many C(not ++) coding standards that say to use all caps for enum values
over the years to follow all caps for constants. -
Hi
Just a note.
I seen many C(not ++) coding standards that say to use all caps for enum values
over the years to follow all caps for constants.wrote on 16 Jul 2020, 15:34 last edited by@mrjj
Indeed, that's why I wrote " the usual way now". I think it has changed so thatenum
constants are like class names. Certainly if you look at https://doc.qt.io/qt-5/qt.html you see all Qt enum values are done that way for their values. -
@fem_dev You can use "enum class" to avoid name clashes:
typedef enum class { ERROR = -2, // C2059: syntax error: 'constant' WARNING = -1, STATUS = 0 } MSG_TYPE;
But then you will need to qualify using enum name:
MSG_TYPE::ERROR;
@jsulm said in From Ubuntu to Windows: Syntax Error C2059 / C2143:
But then you will need to qualify using enum name:
MSG_TYPE::ERROR;Again: this will not help. It's a define in wingdi.h:
/* Region Flags */ #define ERROR 0 #define NULLREGION 1 #define SIMPLEREGION 2 #define COMPLEXREGION 3 #define RGN_ERROR ERROR
-
wrote on 16 Jul 2020, 16:16 last edited by
About wingdi.h clobbering the global #define-space, Microsoft usually provides an escape hatch, put this
#define NOGDI
somewhere before #include windows.h
13/14