Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum error: expected identifier before numeric constant

I added a file in source control which had an enum definition as:

enum { OK = 0, ERROR };

But on compilation it was throwing errors like "expected identifier before numeric constant." Did my research on that and the culprit was supposed to be 'OK' which was defined somewhere else in the code. So, i changed OK with say, OK_1, and the issue was, indeed, resolved.

However, I have not been able to find where in my code base was this 'OK' defined before. I ran a grep from top level and couldn't find it. I am pretty sure I have covered all the application related code, but OK wasn't there.

I think it's unlikely that it was a part of some shared library as compilation process didn't even reach linking phase. It could have come from one of the header files maybe.

Is there a way/linux tool that somehow can be tricked to find where this OK is coming from?

like image 590
Sahil Avatar asked Jun 26 '26 09:06

Sahil


2 Answers

If you are using C++ 11 take a look at enum class: http://www.cprogramming.com/c++11/c++11-nullptr-strongly-typed-enum-class.html

One big draw back of enum is that you cant have 2 enums with the same name. With enum class this draw back is gone, you can write thing like this:

enum class Color {RED, GREEN, BLUE}; 
enum class Feelings {EXCITED, MOODY, BLUE};

And later on in the code:

Color color = Color::GREEN;
if ( Color::RED == color )
{
    // the color is red
}

Code example is pasted from linked www page

like image 169
Wielki_i_niezlomny Avatar answered Jun 28 '26 21:06

Wielki_i_niezlomny


Converting my comment to answer.

Looks like you need pre-processor output Can gcc output C code after preprocessing?

like image 26
Sameer Naik Avatar answered Jun 28 '26 21:06

Sameer Naik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!