3

我正在尝试重构和引入一些旧代码,我遇到了这样的事情:

          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关键字后只有一个理智的引用),它怎么会与我的新footypedef'd 类型冲突?

编辑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()宏;在这种情况下它是一个 noop。)

4

3 回答 3

2

您现在是否将其编译为 C++,而它曾经被编译为 C?

在 C++ 中,struct 和 enum 标记与其他类型名称位于相同的命名空间中。

于 2011-03-04T08:52:28.620 回答
2

啊,我解决了我自己的问题。我设法搞砸了我的e()宏,以至于它实际上是在执行一个 noop,删除有问题的代码。:O

我是个白痴。很抱歉浪费了大家的时间。

于 2011-03-04T09:29:42.897 回答
0

您将名称 foo 与两种不同的类型相关联。struct foo 和指向 struct foo 的指针是不同的类型。

于 2011-03-04T08:56:08.323 回答