"redefining" foo "as another kind of character"

I am trying to refactor and use the old code, and I came across something like this:

          struct foo;
typedef   struct foo *    foo;

When I try to compile it, I get the following error:

Source/Types/Types.h:27:18: error: redefinition of 'foo' as different kind of symbol
typedef   struct foo *    foo;
                 ^

Does anyone know what causes this? I didn’t touch the code for a long time, but of course I don’t remember the errors associated with this. Its part of the most basic code in the code base, it all depends on it; I don’t see how I could miss such a blatant mistake, if it really is a mistake. Since the source foois a "struct tag" (only the correct link after the keyword struct), how can it conflict with my new typedefd type foo?

Change 1: . Has the whole actual file, maybe I missed something, but it looks pretty straight forward. It discards many of the 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 macro e(); its noop in this case.)

+3
source share
4 answers

Ah, I solved my problem. I managed to ruin my macro e()so that it literally transforms noop by deleting this code .: O

I am an idiot. Sorry for your time.

+2
source

You are now compiling it as C ++, whereas it was compiling as C?

In C ++, the struct and enum tags live in the same namespace as other type names.

+2
source

foo . struct foo struct foo - .

0

This is legal C, but not legal C ++. Are you accidentally trying to compile a C ++ compiler? My gcc can compile your code perfectly, as it should be.

-1
source

Source: https://habr.com/ru/post/1796242/


All Articles