enum variables and extern CW v 5.6.1.1658 for DSP56F801

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

enum variables and extern CW v 5.6.1.1658 for DSP56F801

2,607 Views
Charlie
Contributor III
Hello,

Target: DSP56F801FA60
Code Warrior Version: 5.6.1.1658

For my project I use a file to declare all of my global variables, data.c. I then reference all of these variables from data.h, which I include in every file.

This works fine for all my int, chars, etc. . .

However. I create an enum variable in data.c:

enum myenum
{
identifier1,
identifier2,
identifier3
} enumvar;

I have tried multiple ways to reference this in data.h to make enumvar a global variable. However, I always get a compiler error.

At someone's suggesting, I declared the myenum type in data.h, but that give me a redeclaration compilation error.

I can't get this to work and I would really like that to be a global variable. Any help would be great.

Thanks,
Charlie
Labels (1)
Tags (1)
0 Kudos
Reply
2 Replies

406 Views
CompilerGuru
NXP Employee
NXP Employee
I don't know DSP56F801, but answer this question as general C one.
I would define this type in the header and use this definition to declare the variable in the header and in the C file.
E.g.

/* file.h */
#ifndef FILE_H_
#define FILE_H_

enum myenum
{
  identifier1,
  identifier2,
  identifier3
};

extern enum myenum enumvar;

#endif /* FILE_H_ */


/* file.c: */
#include "file.h"

enum myenum enumvar= identifier1;

(or you can use:
typedef enum
{
  identifier1,
  identifier2,
  identifier3
}
myenum;
 and then you must not use "enum" before
myenum afterwards.

(or even
typedef enum  myenum;
{
  identifier1,
  identifier2,
  identifier3
}
myenum;
and then you can use enum before
myenum, but you don't have to)


Daniel



0 Kudos
Reply

406 Views
Charlie
Contributor III
Thanks a lot!

That #ifndef was exactly what I needed.
0 Kudos
Reply