1

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

} 
9
  • 1
    It is just here to skip something which became useless. Commented Apr 16, 2015 at 18:05
  • Can #define be used with "..." like this? Seems like there there is something missing. Commented Apr 16, 2015 at 18:05
  • @AlainD: Yes, variadic macros. gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html But this one expands to nothing at all. Commented Apr 16, 2015 at 18:09
  • @MooingDuck so does this mean it nullfies the type or something. I know that inorder to get rid of SAL based annotation in gcc they are defined with nothing. Commented Apr 16, 2015 at 18:11
  • @JamesFranco: Most likely if a compiler flag is set it's defined to do something else, such as declaring legacy types. With the current compiler flags, it doesn't need to do anything, so it doesn't do anything., Commented Apr 16, 2015 at 18:12

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.