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.
A pragma is a compiler directive that allows you to provide additional information to the compiler. This information can change compilation details that are not otherwise under your control. For example, the pack pragma affects the layout of data within a structure. Compiler pragmas are also called directives.
The pragma command is specific to SQLite and is not compatible with any other SQL database engine. Specific pragma statements may be removed and others added in future releases of SQLite. There is no guarantee of backwards compatibility. No error messages are generated if an unknown pragma is issued.
The #pragma in C is a directive that is provided by the C standard in order to provide extra required details to the C compiler. These extra details can be anything that was somehow not passed within the program or the code logic. These directives, known as pragma are prefixed by the STDC in the standard.
A typical use of the message pragma is to display informational messages at compile time. The message-string parameter can be a macro that expands to a string literal, and you can concatenate such macros with string literals in any combination.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With