Re: enum variables and extern



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.



/* a.h */
enum myenum { Mon, Tues, Wed };
enum myenum fun(enum myenum x);


/* a.c */
#include <stdio.h>
#include "a.h"

int main(void)
{
enum myenum y = Mon;
printf("Calling fun with y = %d\n", y);
y = fun(y);
printf("Now y = %d\n", y);
return 0;
}


/* b.c */
#include "a.h"

enum myenum fun(enum myenum x)
{
return x + 1;
}


.



Relevant Pages

  • Re: enum variables and extern
    ... 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. ... along with an extrn reference for an object: ... extrn enum myenum enum_var; ...
    (comp.lang.c)
  • enum variables and extern
    ... I then have a header file, data.h, which I include in every file in ... defined an variable of type myenum in data.c: ... Now when I try to reference enum_var in data.h, ...
    (comp.lang.c)
  • Re: enum variables and extern
    ... defined an variable of type myenum in data.c: ... Now when I try to reference enum_var in data.h, ... You need to define 'enum myenum' everywhere you reference it. ... extern enum myenum enum_var; ...
    (comp.lang.c)
  • 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
    ... I then have a header file, data.h, which I include in every file in ... defined an variable of type myenum in data.c: ... Now when I try to reference enum_var in data.h, ... about enum types and/or extern. ...
    (comp.lang.c)