“重新定义'foo'作为不同种类的符号”
我正在尝试重构并引入一些旧代码,并且遇到了这样的事情:
struct foo;
typedef struct foo * foo;
当尝试编译它时,我收到以下错误:
Source/Types/Types.h:27:18:错误:将“foo”重新定义为不同类型的符号 typedef 结构 foo * foo; ^
有人知道是什么原因造成的吗?我已经很长时间没有接触过代码了,但是我当然不记得任何与此相关的错误。它是代码库中最核心的一些代码,一切都取决于它;如果确实是一个错误,我不明白我怎么可能会错过如此明显的错误。由于原始的 foo
是一个“struct 标记”(只是 struct
关键字之后的正常引用),它怎么会与我的新 foo
冲突呢? typedef 类型?
编辑1:这是整个实际文件,也许我遗漏了一些东西,但它看起来非常简单。它转储大量与上述相同的错误,每种类型一个:(
# if !defined(TYPE_DECLARATIONS)
# define TYPE_DECLARATIONS
# include "Core.h"
# warning "in Core.h"
static int class = 0; // to prove I’m not compiling as C++
struct e(fork);
typedef struct e(fork)* e(fork);
struct e(execution);
typedef struct e(execution)* e(execution);
struct e(thing);
typedef struct e(thing) e(thing);
struct e(typeRepresentation);
typedef struct e(typeRepresentation)* e(typeRepresentation);
struct e(typeRepresentation) {
void * family;
char name[64]; };
struct e(thing) {
void * const pointer;
e(typeRepresentation) const isa; };
# endif //!defined(TYPE_DECLARATIONS)
此外,忽略 e()
宏;在本例中它是一个 nooop。)
I’m trying to refactor and bring-over some old code, and I ran across something like this:
struct foo;
typedef struct foo * foo;
When attempting to compile it, I get the following sort of error:
Source/Types/Types.h:27:18: error: redefinition of 'foo' as different kind of symbol typedef struct foo * foo; ^
Anybody know what’s causing this? I haven’t touched the code in a long time, but I certainly don’t remember any errors relating to that. It’s some of the most core code in the codebase, everything depends on it; I don’t see how I could possibly have missed such a glaring error, if it is indeed an error. Since the original foo
is a “struct tag” (only a sane reference after the struct
keyword), how can it conflict with my new foo
typedef’d type?
Edit 1: Here’s the entire actual file, maybe I’m missing something, but it seems pretty straight-forward. It dumps a slew of the same errors described above, one for each type:
# if !defined(TYPE_DECLARATIONS)
# define TYPE_DECLARATIONS
# include "Core.h"
# warning "in Core.h"
static int class = 0; // to prove I’m not compiling as C++
struct e(fork);
typedef struct e(fork)* e(fork);
struct e(execution);
typedef struct e(execution)* e(execution);
struct e(thing);
typedef struct e(thing) e(thing);
struct e(typeRepresentation);
typedef struct e(typeRepresentation)* e(typeRepresentation);
struct e(typeRepresentation) {
void * family;
char name[64]; };
struct e(thing) {
void * const pointer;
e(typeRepresentation) const isa; };
# endif //!defined(TYPE_DECLARATIONS)
(Also, ignore the e()
macro; it’s a noop in this case.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
啊,我解决了我自己的问题。我设法搞砸了我的
e()
宏,使它实际上执行了一个 noop,删除了有问题的代码。 :哦,我是个白痴。抱歉浪费了大家的时间。
Ah, I solved my own problem. I managed to screw up my
e()
macro such that it was literally preforming a noop, removing the code in question. :OI’m an idiot. Sorry for wasting everyone’s time.
您现在是否将其编译为 C++,而它过去是编译为 C 的?
在 C++ 中,结构和枚举标记与其他类型名称位于同一命名空间中。
Are you now compiling this as C++, whereas it used to be compiled as C?
In C++, struct and enum tags live in the same namespace as other type names.
您将名称 foo 与两种不同的类型相关联。 struct foo 和指向 struct foo 的指针是不同的类型。
you associate the name foo with two different types. struct foo and a pointer to struct foo are different types.