Turtle
Turtle

Reputation: 25

Effect of #include inside C++ enums

enum CMD 

    {
        CMD_none,
        #define A(x)    CMD_##x,
        #include "cmd.h"
    };

I encountered the above while going through a github repository. Can someone tell me what the above code does? I do not understand the effect of #include inside enum. The official documentation also does not tell anything about such cases.

Upvotes: 2

Views: 110

Answers (1)

eerorika
eerorika

Reputation: 238361

Can someone tell me what the above code does?

enum CMD 

    {

This is a declaration of an enum by the name CMD.

CMD_none,

This is the first enumerator. Its name is CMD_none and the value is 0.

#define A(x)    CMD_##x,

This is a pre-processor macro definition.

#include "stdio.h"

I do not understand the effect of #include inside enum.

The effect of #include is to include the content of the file into the source file that contains the #include directive.

It can be reasonable - although likely obfuscatory - if the included file contains valid list of enumerators. "stdio.h", if it resolves to the standard header, does not contain a valid list of enumerators, and thus it makes no sense to write this. I suspect that it has been written by mistake.

Upvotes: 3

Related Questions