Pragma in define macro
Is there some way to embed pragma statement in macro with other statements?
I am trying to achieve something like:
#define DEFINE_DELETE_OBJECT(type) \
void delete_ ## type_(int handle); \
void delete_ ## type(int handle); \
#pragma weak delete_ ## type_ = delete_ ## type
I am okay with boost solutions (save for wave) if one exists.
If you're using c99 or c++0x there is the pragma operator, used as
_Pragma("argument")
which is equivalent to
#pragma argument
except it can be used in macros (see section 6.10.9 of the c99 standard, or 16.9 of the c++0x final committee draft)
For example,
#define STRINGIFY(a) #a
#define DEFINE_DELETE_OBJECT(type) \
void delete_ ## type ## _(int handle); \
void delete_ ## type(int handle); \
_Pragma( STRINGIFY( weak delete_ ## type ## _ = delete_ ## type) )
DEFINE_DELETE_OBJECT(foo);
when put into gcc -E
gives
void delete_foo_(int handle); void delete_foo(int handle);
#pragma weak delete_foo_ = delete_foo
;
One nice thing you can do with _Pragma("argument") is use it to deal with some compiler issues such as
#ifdef _MSC_VER
#define DUMMY_PRAGMA _Pragma("argument")
#else
#define DUMMY_PRAGMA _Pragma("alt argument")
#endif