2

I am encountering the following problem in C: I declare a typedef for a struct in a headerfile ("mep.h")

#ifndef MEP_H
#define MEP_H

typedef struct Mep_tag Mep;
<other stuff declared here>

#endif

I use another headerfile ("mep_types.h") that includes "mep.h", defines the struct "Mep_tag" and uses the "Mep" type name:

#ifndef MEP_TYPES_H
#define MEP_TYPES_H

#include "mep.h"
#include "file1.h"

struct Mep_MsgElement_tag
{
    const Mep * MsgCh;                   
};

struct Mep_tag
{
    <stuff in here>
};

#endif

For some reason when this compiles, I get the following error: "mep_types.h: error: unknown type name "'Mep'".

However, if in the "mep.h" I place the typedef outside the ifndef guard like this...

typedef struct Mep_tag Mep;

#ifndef MEP_H
#define MEP_H

<other stuff declared here>

#endif

... the "Mep" type name is visible in "mem_types.h".

Might someone know how this could happen?

Constantine
  • 43
  • 1
  • 6
  • 4
    Looks like "MEP_H" is already defined in another header file. Try to temporarily change it to "TEMP_MEP_H" and see if that changes anything. – R Sahu Jan 30 '15 at 16:48
  • So, is it possible that some other file could be including "mep.h", defining "MEP_H" along the way, so that when "mep_types.h" is compiled the "mep.h" file's contents are not included? – Constantine Jan 30 '15 at 16:56
  • More precisely, some file defines `MEP_H` explicitly, _without_ including "mep.h". – mafso Jan 30 '15 at 16:59
  • Yes, I have verified that this is the case, one file has a define "MEP_H". Removing this statement does the trick. Thank you all very much for your time and for helping me. – Constantine Jan 30 '15 at 17:03

0 Answers0