Edward Diener wrote:
It is implementation-defined whether or not the contents of a #pragma directive are macro expanded--I think that VC allows it. C99 explicitly allows it, but says that any #pragma that begins with STDC is explicitly _not_ macro expanded. C99, of course, has the _Pragma operator which can be generated by a macro expansion (not that that is relevent here).
The opposite way was what I was wondering about. Can a #define create a #pragma which then is picked up as a preprocessor line ? As an example will this work:
#define CREATE_PRAGMA #pragma somepragma
// Code CREATE_PRAGMA // Code
Will a compiler correctly pick up the #pragma as a preprocessor line or is the preprocessor stage finished once the macro is fully expanded ? I believe the latter is true, although I could be wrong.
It is not technically legal, but it might work anyway, as #pragmas usually aren't picked up by the preprocessor.
If I am right, then creating a Boost macro for these data layout #pragmas for BCB and VC++, and any other compiler which lets one fix data layout details such as packing from within each header file, will not work. In that case the alternative of a easily remembered header file name, which contains the appropriate #pragma, is a good alternative for adding such #pragmas in the correct place of header files which need such data layout reliability.
Well, #pragmas that the compiler doesn't understand are supposed to be ignored. However, using a header for it is also a good option. You can even use a macro to introduce the header if you like: #include CREATE_PRAGMA() Paul Mensonides