“重新定义'foo'作为不同种类的符号”

发布于 2024-10-20 00:50:46 字数 1444 浏览 8 评论 0原文

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

          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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

旧城空念 2024-10-27 00:50:46

啊,我解决了我自己的问题。我设法搞砸了我的 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. :O

I’m an idiot. Sorry for wasting everyone’s time.

安稳善良 2024-10-27 00:50:46

您现在是否将其编译为 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.

旧伤还要旧人安 2024-10-27 00:50:46

您将名称 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文