Results 1 to 7 of 7

Thread: why MACROS are used between class name and class keyword

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default why MACROS are used between class name and class keyword

    Hi
    What is the use of using MACRO in between the class name and class keyword such as the following declaration.

    Qt Code:
    1. class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
    2. {
    3. ...
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: why MACROS are used between class name and class keyword

    it's used for correct compilation of dll on windows.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    babu198649 (4th February 2009)

  4. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: why MACROS are used between class name and class keyword

    Thanks,
    Is it legal to define macro between the class keyword and class name or it is compiler specific.
    Does defining macro between class name and class keyword makes any difference on the linux.
    Does anyone knows a good link which explains about this(googling had not helped).

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: why MACROS are used between class name and class keyword

    actually import/export specifiers are used only on windows on Linux they have no effect.
    take a look at QTDIR/src/corelib/global/qglobal.h where you can find Q_DECL_EXPORT/Q_DECL_IMPORT macros
    Qt Code:
    1. #ifndef Q_DECL_EXPORT
    2. # ifdef Q_OS_WIN
    3. # define Q_DECL_EXPORT __declspec(dllexport)
    4. # elif defined(QT_VISIBILITY_AVAILABLE)
    5. # define Q_DECL_EXPORT __attribute__((visibility("default")))
    6. # endif
    7. # ifndef Q_DECL_EXPORT
    8. # define Q_DECL_EXPORT
    9. # endif
    10. #endif
    11. #ifndef Q_DECL_IMPORT
    12. # if defined(Q_OS_WIN)
    13. # define Q_DECL_IMPORT __declspec(dllimport)
    14. # else
    15. # define Q_DECL_IMPORT
    16. # endif
    17. #endif
    To copy to clipboard, switch view to plain text mode 
    so, if you need to create your own dll you need to specify these macros, see detailes here dll & Qt
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: why MACROS are used between class name and class keyword

    Thanks again,
    As per the c++ language standard can a macro be present between class-name and class keyword or it is an extension of the compiler.

  7. #6
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    518
    Thanks
    13
    Thanked 77 Times in 75 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: why MACROS are used between class name and class keyword

    Hi, you should be able to place a macro nearly everywhere as it will just be replaced by the preprocessor.

    Some of the replacements are compiler specific (e.g. __declspec), some define calling conventions like the order of parameters on the stack for a function call.

    Ginsengelf
    Last edited by Ginsengelf; 4th February 2009 at 13:15. Reason: updated contents

  8. The following user says thank you to Ginsengelf for this useful post:

    babu198649 (4th February 2009)

  9. #7
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: why MACROS are used between class name and class keyword

    you should be able to place a macro nearly everywhere as it will just be replaced by the preprocessor
    Right,Unless the macro doesnot contains any value

    Some of the replacements are compiler specific (e.g. __declspec)
    Thanks ,That cleared my doubt.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.