barbaros
barbaros

Reputation: 49

Why is "static" ignored?

 static enum RetType
        {
        SET_SUCCESS=0,
        SET_ET_ERROR = -1,
        SET_CBL_ERROR = -2,
        SET_SEN_ERROR = -3,
        SET_TAR_ERROR = -4,
        SET_ENG_ERROR = -5,
        SET_IO_ERROR = -6
        };

enum RetType ret = SET_SUCCESS;

I declare a static enum in global. But Visual Studio gives warning:

warning C4091: 'static ': ignored on left of 'RetType' when no variable is declared.

Why does it ignore "static"?

Upvotes: 2

Views: 2864

Answers (2)

R4444
R4444

Reputation: 2114

As other's mentioned, static can only be used with variables (or functions). Basically "static" keyword is used to declare variables in data section of the process memory (and not on the stack). In your case, you are defining RetType globally as a type (and not the variable or function). Hence in you case you must:

enum RetType
        {
        SET_SUCCESS=0,
        SET_ET_ERROR = -1,
        SET_CBL_ERROR = -2,
        SET_SEN_ERROR = -3,
        SET_TAR_ERROR = -4,
        SET_ENG_ERROR = -5,
        SET_IO_ERROR = -6
        };
static enum RetType ret = SET_SUCCESS;

If you would like to declare ret statically. Here, ret is of type RetType, which is present in the .data section.

Upvotes: 3

Lundin
Lundin

Reputation: 213832

Because its an enum definition, it doesn't make sense to make it static. You probably meant to do this instead:

typedef enum 
{
  SET_SUCCESS   =  0,
  SET_ET_ERROR  = -1,
  SET_CBL_ERROR = -2,
  SET_SEN_ERROR = -3,
  SET_TAR_ERROR = -4,
  SET_ENG_ERROR = -5,
  SET_IO_ERROR  = -6,
} RetType;

...

static RetType ret = SET_SUCCESS;

Upvotes: 0

Related Questions