“redefinition of 'foo' as different kind of symbol”

ELLIOTTCABLE picture ELLIOTTCABLE · Mar 4, 2011 · Viewed 7.8k times · Source

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.)

Answer

sbi picture sbi · Mar 4, 2011

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.