#define together with #pragma

Discussion in 'C++' started by przemyslaw.sliwa@gazeta.pl, Oct 27, 2006.

  1. Guest

    Hi,

    I just wanted to write a quick macro, which will wrap the following
    code

    #define EXCLUDE_WIN_WARNING(warning_id) \
    #ifdef _MSC_VER \
    #pragma warning(push) \
    #pragma warning(disable, warning_id) \
    #endif
    #define RESTORE_WIN_WARNING \
    #ifdef _MSC_VER \
    #pragma warning(pop) \
    #endif


    This does not compile at all. The problem in this case is the # sign.
    I would like to use it in the following way:

    EXCLUDE_WIN_WARNING(3456)
    #include <third_party_header.h>
    RESTORE_WIN_WARNING

    Can somone tell me how to tho this? It is probably something silly I
    forget but I am having problems with compilation.

    Thanks a lot for help,

    Pshemek
     
    , Oct 27, 2006
    #1
    1. Advertising

  2. Bart Guest

    wrote:
    > Hi,
    >
    > I just wanted to write a quick macro, which will wrap the following
    > code
    >
    > #define EXCLUDE_WIN_WARNING(warning_id) \
    > #ifdef _MSC_VER \
    > #pragma warning(push) \
    > #pragma warning(disable, warning_id) \
    > #endif
    > #define RESTORE_WIN_WARNING \
    > #ifdef _MSC_VER \
    > #pragma warning(pop) \
    > #endif
    >
    >
    > This does not compile at all. The problem in this case is the # sign.


    You can't have a preprocessor directive as the result of macro
    expansion.


    > I would like to use it in the following way:
    >
    > EXCLUDE_WIN_WARNING(3456)
    > #include <third_party_header.h>
    > RESTORE_WIN_WARNING
    >
    > Can somone tell me how to tho this? It is probably something silly I
    > forget but I am having problems with compilation.


    Place the directives in a separate file and #include the file.

    Regards,
    Bart.
     
    Bart, Oct 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theotyflos
    Replies:
    3
    Views:
    508
    Thomas Matthews
    Feb 19, 2004
  2. robin liu
    Replies:
    3
    Views:
    867
    Robin Liu
    Apr 21, 2006
  3. Replies:
    0
    Views:
    328
  4. Replies:
    1
    Views:
    346
  5. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    516
    Brian Takita
    Jan 23, 2006
Loading...

Share This Page