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.
但在编译时,它会抛出诸如“数字常量之前的预期标识符”之类的错误。我对那个问题的研究和那个罪犯应该是“OK”的,这是在代码中其他地方定义的。所以,我改变了OK,比如说,OK_1,问题确实解决了。
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.
然而,我以前一直没能找到在我的代码库中定义了“OK”的地方。我从顶层跑了一个grep,找不到。我很确定我已经涵盖了所有与应用程序相关的代码,但OK不在其中。
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?
有没有一种方法/linux工具可以被骗去找到OK的来源?
3 个解决方案
#1
4
Converting my comment to answer.
把我的评论转换成答案。
Looks like you need pre-processor output Can gcc output C code after preprocessing?
看起来您需要预处理器输出,gcc能在预处理后输出C代码吗?
#2
-1
my English is not good,but you can try enum var{xxx,xxx},you can customize var.
我的英语不好,但是你可以试试enum var{xxx,xxx},你可以自定义var。
#3
-1
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
如果您使用的是c++11,请查看enum类:http://www.cprogramming.com/c++11/c++11- nullptr-strongtype -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的一个重要的收缩是不能有两个名称相同的enum。随着enum类的退出,你可以这样写:
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
代码示例粘贴自链接的www页面
#1
4
Converting my comment to answer.
把我的评论转换成答案。
Looks like you need pre-processor output Can gcc output C code after preprocessing?
看起来您需要预处理器输出,gcc能在预处理后输出C代码吗?
#2
-1
my English is not good,but you can try enum var{xxx,xxx},you can customize var.
我的英语不好,但是你可以试试enum var{xxx,xxx},你可以自定义var。
#3
-1
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
如果您使用的是c++11,请查看enum类:http://www.cprogramming.com/c++11/c++11- nullptr-strongtype -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的一个重要的收缩是不能有两个名称相同的enum。随着enum类的退出,你可以这样写:
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
代码示例粘贴自链接的www页面