From Ubuntu to Windows: Syntax Error C2059 / C2143
-
I just copy my working Qt project from my Ubuntu 20.04 machine to my Windows 10 x64 machine.
I got two weird compile time errors in my custom header file:
#ifndef MESSAGE_TYPES_H #define MESSAGE_TYPES_H typedef enum { ERROR = -2, // C2059: syntax error: 'constant' WARNING = -1, STATUS = 0 } MSG_TYPE; // C2143: syntex error: ';' missing before '}' #endif // MESSAGE_TYPES_H
Why it's happening?
How can I fix it?My systems are:
A)- Ubuntu 20.04 x64
- Qt Creator 4.12.4
- Qt 5.15
- GCC 9.3 Compiler x64
B)
- Windows 10 x64
- Qt Creator 4.12.4
- Qt 5.15
- MSVC 2019 x64
-
Hi
Its a name clash with MSVC 2019
ERROR is defined already. -
@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? -
@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
-
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. -
@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