James Franco
James Franco

Reputation: 4706

Variadic Macros

I came across this code that involved variadic Macros and I wanted to know what that meant

#define DECLARE_LEGACY_TYPES(...)  //This all of the macro - I am not holding out on anything

Now There is this class as this

Header file: .h
    namespace LG_Wrapper
    {
        template <LG_Thread Thread>
        class EffectApplication : public ktApplication
        {
        public:
        static EffectApplication<Thread>& GetInstance();
        protected:
            .....
            .....
            static boost::recursive_mutex mResource;
          }
    }

    DECLARE_LEGACY_TYPES(EffectApplication);  <---- What does this do ?

I wanted to know what effect the macro has ?

Update: I have received numerous downvotes on this as this question gives of the impression that something is missing that I did not post the entire content of the macro. There is nothing more to the macro. I wish there was. This question is related to this which was closed. The macro literally just ends after (...)

 #define DECLARE_LEGACY_TYPES(...)

but there isnt. That is one of the reason why I am here as I am not sure how to deal with this situation. Does this macro have not effect then ?

More Info:

This is what I have in another file I am using the following defined in my project setting

LG_WRAPPER_EXPORTS
LG_THREAD_NAME=GAME

Following is the code

namespace LG_Wrapper
{

enum LG_Thread
{
    GAME,
    OTHER
};


/*
If the library itself is including this file
*/
#ifdef LG_WRAPPER_EXPORTS

    #ifndef LG_THREAD_NAME
        #error You must define LG_THREAD_NAME!
    #endif

    //Legacy types should not be used internally
    #define DECLARE_LEGACY_TYPES(...)

#else // LG_WRAPPER_EXPORTS

    //Legacy typenames are provided for convenience to the client
    #define DECLARE_LEGACY_TYPES(ClassType) \
        typedef LG_Wrapper::##ClassType##<LG_Wrapper::GAME>             ClassType; \

#endif // LG_WRAPPER_EXPORTS

} 

Upvotes: 1

Views: 232

Answers (1)

Mooing Duck
Mooing Duck

Reputation: 66912

This is actually pretty common, but it depends on other code that wasn't mentioned in the other code you looked at:

#if USING_OLD_COMPILER //when using an older compiler, use this to declare legacy types
#define DECLARE_LEGACY_TYPES(...) STUFF(__VA_ARGS__)    
#else //new compiler doesn't have to do anything special
#define DECLARE_LEGACY_TYPES(...)
#endif


//in older compilers we had to declare legacy types for this
//newer compilers don't need this step, so this does nothing at all in them.
DECLARE_LEGACY_TYPES(EffectApplication);

I don't actually know this macro, so I don't know it's actual purpose. But it's common to see macros without definitions for similar tricks as this.

Upvotes: 5

Related Questions