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
};
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;
LFE_Init Init;
etc.
Run g++ -E on code to see what is produced. A structure element needs a type and a name.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论