【发布时间】:2011-03-04 08:48:56
【问题描述】:
我正在尝试重构和引入一些旧代码,我遇到了这样的事情:
struct foo;
typedef struct foo * foo;
在尝试编译时,我收到以下错误:
Source/Types/Types.h:27:18: error: redefinition of 'foo' as different kind of symbol typedef struct foo * foo; ^
有人知道这是什么原因吗?我已经很久没有接触过代码了,但我当然不记得任何与此相关的错误。它是代码库中一些最核心的代码,一切都取决于它;我不明白我怎么可能错过这样一个明显的错误,如果它确实是一个错误的话。由于原来的foo 是一个“结构标记”(在struct 关键字之后只是一个合理的引用),它怎么会与我的新foo typedef 类型冲突?
编辑 1: 这是整个实际文件,也许我遗漏了一些东西,但看起来很简单。它会转储 slew 的上述相同错误,每种类型都有一个:
# 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() 宏;在这种情况下它是一个 noop。)
【问题讨论】:
-
该代码编译对我来说没有问题。你用的是什么编译器?我在 gcc 4.3.3
-
看来您确实在尝试编译为
C++。尝试在合适的地方添加int class;并检查编译器是否抱怨:) -
static int class = 0;在全局范围内就在其他代码导致没有新错误之前
标签: c types typedef identifier redefinition