8

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?

3
  • Looks like you need pre-processor output stackoverflow.com/questions/4900870/… Commented Aug 4, 2016 at 5:48
  • Your project directory structure is flat? If it isn't it's unlikely grep will find anything. You should run grep from within a find command Commented Aug 4, 2016 at 6:01
  • @SameerNaik Exactly what I needed, thanks. :) Commented Aug 4, 2016 at 6:30

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

3

Converting my comment to answer.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.