G
Gustavo L. Fabro
Greetings.
Is there a way to run the preprocessor twice? Rephrasing that, is there a
way to:
#define SOMETHING #pragma OTHERTHING
and have the preprocessor in somecode.cpp evaluate:
SOMETHING
as
#pragma OTHERTHING
and then evaluate this #pragma directive as it should?
I know the C++ standard under 16.3.4 says:
"The resulting completely macro replaced preprocessing token sequence is not
processed as a preprocessing directive even if it resembles one."
but the C standard (1999) under 6.10.3.4 appears to change this to allow
#pragma directives in macros:
"The resulting completely macro-replaced preprocessing token sequence is not
processed as a preprocessing directive even if it resembles one, but all
pragma unary operator expressions within it are then processed as specified
in 6.10.9 below."
I know C is not C++ and so MSVC shouldn't actually allow this over my C++
code (if I'm interpreting the standard right). But is there a way to do it?
;-)
In case you want to know why I want this: I'm performance tuning my
application and I have a couple of functions and classes I'd like to compile
as native code.
Some of these classes have methods that call .NET Framework functions. I
have to explicity set these particular methods with a #pragma managed so
they will compile, Interop will do its job and it will run.
My code is being compiled under 2 different compilers. I'm using #define and
#ifdef directives to accomplish this. And my other compiler keeps shooting
me warnings over unknows #pragmas (such as #pragma unmanaged, for instance).
Having said that, I'd like to define things like:
#ifdef VISUAL_C //I #define this when using my MSVC compiler
#define SET_CLR_MODE #pragma managed
#define SET_NATIVE_MODE #pragma unmanaged
#else
#define SET_CLR_MODE
#define SET_NATIVE_MODE
#endif
and just SET_CLR_MODE whenever I needed IL and SET_NATIVE_MODE when I wanted
to go back to native.
Is it possible?
Thanx,
Fabro
Is there a way to run the preprocessor twice? Rephrasing that, is there a
way to:
#define SOMETHING #pragma OTHERTHING
and have the preprocessor in somecode.cpp evaluate:
SOMETHING
as
#pragma OTHERTHING
and then evaluate this #pragma directive as it should?
I know the C++ standard under 16.3.4 says:
"The resulting completely macro replaced preprocessing token sequence is not
processed as a preprocessing directive even if it resembles one."
but the C standard (1999) under 6.10.3.4 appears to change this to allow
#pragma directives in macros:
"The resulting completely macro-replaced preprocessing token sequence is not
processed as a preprocessing directive even if it resembles one, but all
pragma unary operator expressions within it are then processed as specified
in 6.10.9 below."
I know C is not C++ and so MSVC shouldn't actually allow this over my C++
code (if I'm interpreting the standard right). But is there a way to do it?
;-)
In case you want to know why I want this: I'm performance tuning my
application and I have a couple of functions and classes I'd like to compile
as native code.
Some of these classes have methods that call .NET Framework functions. I
have to explicity set these particular methods with a #pragma managed so
they will compile, Interop will do its job and it will run.
My code is being compiled under 2 different compilers. I'm using #define and
#ifdef directives to accomplish this. And my other compiler keeps shooting
me warnings over unknows #pragmas (such as #pragma unmanaged, for instance).
Having said that, I'd like to define things like:
#ifdef VISUAL_C //I #define this when using my MSVC compiler
#define SET_CLR_MODE #pragma managed
#define SET_NATIVE_MODE #pragma unmanaged
#else
#define SET_CLR_MODE
#define SET_NATIVE_MODE
#endif
and just SET_CLR_MODE whenever I needed IL and SET_NATIVE_MODE when I wanted
to go back to native.
Is it possible?
Thanx,
Fabro