Gooly
Gooly

Reputation: 79

Variadic Macro with 3 terms

I am trying to understand a C++ code that reads a dll explicitly. Does any one know how the line #define LFE_API(name) LFE_##name name below actually works? I understand #define LFE_API(name) LFE_##name but get confused about the last "name".

    struct Interface
{
    #   ifdef LFE_API
    #       error You can't define LFE_API before. 
    #   else
    #       define LFE_API(name) LFE_##name name
                LFE_API(Init);
                LFE_API(Close);
                LFE_API(GetProperty);
    #       undef LFE_API
    #   endif
};

Upvotes: 0

Views: 168

Answers (2)

xcramps
xcramps

Reputation: 1213

LFE_Init Init;

etc.

Run g++ -E on code to see what is produced. A structure element needs a type and a name.

Upvotes: 1

Dr. Snoopy
Dr. Snoopy

Reputation: 56357

Since the first part of the macro (LFE_##name) just concatenates both parts, a call to LFE_API is creating a variable named name with the type LFE##name, such as:

LFE_API(Init) expands to LFE_Init Init;

Upvotes: 1

Related Questions