#define together with #pragma

P

przemyslaw.sliwa

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
 
B

Bart

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top