tags:

views:

103

answers:

4

Hello,

gcc 4.4.1 c89

I have the following code and I get a warning:

useless class storage specifier in empty declaration

static enum states
{
    ACTIVE,
    RUNNING,
    STOPPED,
    IDLE
};

However, if i remove the static keyword I don't get that warning.

I am compiling with the following flags:

-Wall -Wextra

Many thanks for any suggestions,

+2  A: 

What do you want the static to do? It serves there to give variables defined in the declaration internal linkage:

static enum states { ... } a;

As a shortcut for

enum states { ... };
static enum states a;

Giving "a" internal linkage. But since you don't define a variable there in your code, it is useless in fact (if not illegal).

Johannes Schaub - litb
+1  A: 

Try:

static enum states
{
    ACTIVE,
    RUNNING,
    STOPPED,
    IDLE
} avar;

which actually creates a static variable called avar. Only variables can be static, not types.

anon
+4  A: 

Your enum declaration is defining a type, but it is not also declaring an object of that type.

static only applies to variables and functions so, as the compiler says, it is useless in the context in which you have it.

Charles Bailey
+1  A: 

You get the message because you're not actually declaring, you're only defining something, namely an enumeration named "states". You can later use this definition to declare a variable of that type. That variable may be a static or instance variable, but the definition doesn't need (and shouldn't have) the storage specifier attached to it.

tvanfosson