0

I am writing a serial library using boost and I have an enum:

enum parity_t { PARITY_NONE, PARITY_ODD, PARITY_EVEN };

I get errors like:

Error 1 error C2059: syntax error : '('

I couldn't figure out what the issue was. Then my friend and I tried:

void PARITY_NONE();

And we got these errors:

Error 1 error C2143: syntax error : missing ')' before 'constant'

Error 2 error C2143: syntax error : missing ';' before 'constant'

Error 3 error C2182: 'WORD' : illegal use of type 'void'

Error 4 error C2059: syntax error : ')'

I am including boost asio, which I figure is including the Windows serial api somewhere. This only occurs in Windows. As a work around I have changed my enumeration names. I cannot, however, find anything related to this issue on the internet. Can someone help us figure this out?

Community
  • 1
  • 1
wjwwood
  • 326
  • 5
  • 14

4 Answers4

5

It's defined in winbase.h:

//
// Settable Stop and Parity bits.
//

#define STOPBITS_10       ((WORD)0x0001)
#define STOPBITS_15       ((WORD)0x0002)
#define STOPBITS_20       ((WORD)0x0004)
#define PARITY_NONE       ((WORD)0x0100)
#define PARITY_ODD        ((WORD)0x0200)
#define PARITY_EVEN       ((WORD)0x0400)
#define PARITY_MARK       ((WORD)0x0800)
#define PARITY_SPACE      ((WORD)0x1000)

#undef them before creating your enum.

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
  • Damn and a +1 for being faster! ;) Or rather, damn IntelliSense for choking on 433 to-be-parsed include files after one little `#include ` for the first time.. – Xeo Mar 22 '11 at 17:33
  • 3
    That's why macros are evil : [C++ - enum vs. const vs. #define](http://stackoverflow.com/questions/4767667/c-enum-vs-const-vs-define) – Nawaz Mar 22 '11 at 17:33
2

It's defined in WinBase.h:

//
// Settable Stop and Parity bits.
//

#define STOPBITS_10       ((WORD)0x0001)
#define STOPBITS_15       ((WORD)0x0002)
#define STOPBITS_20       ((WORD)0x0004)
#define PARITY_NONE       ((WORD)0x0100)
#define PARITY_ODD        ((WORD)0x0200)
#define PARITY_EVEN       ((WORD)0x0400)
#define PARITY_MARK       ((WORD)0x0800)
#define PARITY_SPACE      ((WORD)0x1000)

Might aswell use their values, as they would work the same as your enum if you don't use that enum for indexing an array or the likes.

Xeo
  • 129,499
  • 52
  • 291
  • 397
1

What's most likely happening here is one of the values in your enum is already #define to a different value. The expansion of that value is causing the enum to issue a compiler error. You can verify this by changing the code to the following

#ifdef PARITY_NONE
#error Duplicate definition
#endif

Repeat for every value in the enum

Discovering where the definition is coming from is a bit trickier. If you're lucky the following will work

  • Comment out your enum definition
  • Type PARITY_NONE in a method
  • Right click and select "Go To Definition"
JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • `grep -d PARITY_NONE *.h` is a bit cleaner. – TonyK Mar 22 '11 at 17:48
  • @TonyK i disagree. This will tell if you if it's defined anywhere in a particular directory tree. Not if that define is actually included in your application. Nor is it easier if your header files are from multiple unrelated directories (as is often the case with windows projects). – JaredPar Mar 22 '11 at 17:50
0

If you CTRL + Left Click on your attribute in Visual Studio, you will see it.

If you CTRL + Left Click on your attribute in Visual Studio, you will see this

NeWi-SL
  • 127
  • 1
  • 6