Macro inside macro: Q_DECLARE_METATYPE



  • Hi,

    I noticed that the Q_DECLARE_METATYPE macro contains another macro in this line:

    @static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); @

    How is Q_BASIC_ATOMIC_INITIALIZER expanded inside this macro? I thought you couldn't use a macro inside another macro.

    I'm asking because I register types in my program using my own macro, and it'd be helpful if I could register the type to Qt at the same time. Right now, I call both MY_TYPE_REGISTER_MACRO(MyClass) and Q_DECLARE_METATYPE(MyClass) in my program.


  • Moderators

    macros can be nested. Of course there are some "pitfalls":http://gcc.gnu.org/onlinedocs/cpp/Macro-Pitfalls.html#Macro-Pitfalls.
    Do you receive an error?



  • Hmm... You're right, I must have done something wrong when I tried to include Q_DECLARE_METATYPE in my macro.

    It's funny (well, not really :)) how you can program for years and still miss basic stuff like this. It even says in one of the docs you linked to (thanks for that!) " Recall that all macro definitions are rescanned for more macros to replace". For some reason I took for granted that the preprocessor only runs a single scan.

    Thanks again, if I cant get my modified macro to work I may drop another message. :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.