开发者

useless class storage specifier in empty declaration

开发者_JS百科

gcc 4.4.1 c89

I have the following code:

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

And I get a warning:

useless class storage specifier in empty declaration

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,


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.


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.


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).


Try:

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜