views:

37

answers:

2

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" bellow 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
};

Thanks in advance

Gooly

+1  A: 

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;

Matias Valdenegro
Thanks, good answer :)
Gooly
A: 
LFE_Init Init;

etc.

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

xcramps
Thanks, I didn't realize that it is a type and a name before.
Gooly