_Visual C ++中的_Pragma预处理程序运算符 [英] _Pragma preprocessor operator in Visual C++
问题描述
在Visual C ++中是否有类似ANSI C运算符_Pragma
的内容?
Is there something like the ANSI C operator _Pragma
in Visual C++?
例如,我正在尝试定义以下宏:
For example, I'm trying to define the following macro:
#ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x) _Pragma (#x)
#else // #ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x)
#endif // #ifdef _OPENMP
因此,我可以在较早的GCC编译器中规避针对未知#pragma omp ...
的编译器警告.
在VisualC ++中有类似的方法吗?
So I can circumvent compiler warnings for unknown #pragma omp ...
in older GCC compilers.
Is there a similar means available in VisualC++?
推荐答案
是的,但是有两个下划线:__pragma
Yes, but it's two underscores: __pragma
我不确定omp
编译指示的工作方式,但是,下面是使用VC ++的optimize
编译指示的示例:
I'm not sure about how the omp
pragma works, however, here's an example using VC++'s optimize
pragma:
#define PRAGMA_OPTIMIZE_OFF __pragma(optimize("", off))
// These two lines are equivalent
#pragma optimize("", off)
PRAGMA_OPTIMIZE_OFF
编辑:我刚刚确认omp
编译指示也可以这样使用:
I've just confirmed that the omp
pragmas can also be used like this:
#define OMP_PARALLEL_FOR __pragma(omp parallel for)
因此,是的,如果按如下所示进行定义,您的宏应该可以正常工作(请注意,您的原始代码错误地使用了字符串化运算符#x
:
So, yes, your macro should work if defined as follows (note that your original code incorrectly used the stringizing operator #x
:
#ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x) __pragma (x)
#else // #ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x)
#endif // #ifdef _OPENMP
这篇关于_Visual C ++中的_Pragma预处理程序运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!