Visual c++ _Visual C+中的Pragma预处理器运算符+; > VisualC++ ++?/p>中有类似ANSI C操作符
例如,我试图定义以下宏:Visual c++ _Visual C+中的Pragma预处理器运算符+; > VisualC++ ++?/p>中有类似ANSI C操作符,visual-c++,portability,pragma,c-preprocessor,Visual C++,Portability,Pragma,C Preprocessor,例如,我试图定义以下宏: #ifdef _OPENMP #define PRAGMA_IF_OPENMP(x) _Pragma (#x) #else // #ifdef _OPENMP #define PRAGMA_IF_OPENMP(x) #endif // #ifdef _OPENMP 因此,我可以绕过旧GCC编译器中未知的#pragma omp…的编译器警告。 VisualC++中有类似的方法吗?是的,但有两个下划线:\uu pragma 我不确定omppragma是如何工作的,但是
#ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x) _Pragma (#x)
#else // #ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x)
#endif // #ifdef _OPENMP
因此,我可以绕过旧GCC编译器中未知的#pragma omp…
的编译器警告。
VisualC++中有类似的方法吗?是的,但有两个下划线:
\uu pragma
我不确定omp
pragma是如何工作的,但是,下面是一个使用VC++的optimize
pragma的示例:
#define PRAGMA_OPTIMIZE_OFF __pragma(optimize("", off))
// These two lines are equivalent
#pragma optimize("", off)
PRAGMA_OPTIMIZE_OFF
编辑:我刚刚确认,omp
pragmas也可以这样使用:
#define OMP_PARALLEL_FOR __pragma(omp parallel for)
因此,是的,如果宏的定义如下(请注意,您的原始代码错误地使用了字符串化运算符#x
:
实际上,GCC文档给出了一个关于
#x
@Manuel的例子-我认为你把Pragma
与Pragma
混淆了;不幸的是,它们是具有不同语法的不同实体(后者是MSVC特有的)。请参阅:我建议禁用该警告。OpenMP杂注在不支持它们的编译器中设计为无害。
#ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x) __pragma (x)
#else // #ifdef _OPENMP
#define PRAGMA_IF_OPENMP(x)
#endif // #ifdef _OPENMP