Re: enum variables and extern



On Apr 30, 10:59 am, Harald van Dijk <true...@xxxxxxxxx> wrote:
Charlie wrote:
I have a file, data.c, where I define all of my global variables.

I then have a header file, data.h, which I include in every file in
which I reference all of the variables defined in data.c.

For the most part, I am having no problem with this.  However, I
defined an variable of type myenum in data.c:

enum myenum
{
    Mon,
    Tues,
    Wed
} enum_var;

Now when I try to reference enum_var in data.h, the compiler gives me
issues.  I have tried multiple ways of referencing it and defining it,
but nothing is working.  I guess I just don't understand something
about enum types and/or extern.

You need to define 'enum myenum' everywhere you reference it. You
can't use an enum by merely declaring it, as you can for variables. So
it has to be in the data.h file.

data.c:
#include "data.h"
enum myenum enum_var;

data.h:
extern enum myenum
{ ... } enum_var;

or

data.h:
enum myenum
{ ... };
extern enum myenum enum_var;

Thank you for the speedy response.

However, when I define myenum in data.h, for every file I include
data.h, I get the compiler error:

Error: identifier myenum redeclared in data.h

Note: I am removing the myenum declaration in data.c.

On top of that, I also get:

Error: illegal name overloading

For the first two identifier within myenum { ... } (there are three)
everytime I get the redeclaration error.

I am really confused.

.



Relevant Pages

  • Re: enum variables and extern
    ... defined an variable of type myenum in data.c: ... You need to define 'enum myenum' everywhere you reference it. ...
    (comp.lang.c)
  • Re: enum variables and extern
    ... in which I reference all of the variables defined in data.c. ... defined an variable of type myenum in data.c: ... understand something about enum types and/or extern. ... along with an extrn reference for an object: ...
    (comp.lang.c)
  • Problem extracting an enum from an Any
    ... The enum MyEnum is passed through an interface "send" as a ... Extraction on the client side is as follows: ... My problem is that my customer will have to recompile his client with ...
    (comp.object.corba)
  • Re: enum variables and extern
    ... in which I reference all of the variables defined in data.c. ... defined an variable of type myenum in data.c: ... understand something about enum types and/or extern. ... along with an extrn reference for an object: ...
    (comp.lang.c)
  • Bug discovered in .NET compiler - mixed-language solutions
    ... Define an enumerator MyEnum in a VB project. ... Create a C# project C_Proj_2, with a reference to VB_Proj_1 ... Define an interface MyInterface in C_Proj_2, ... Create a class in VB_Proj_3 that implements MyInterface. ...
    (microsoft.public.dotnet.framework)