_Pragma preprocessor operator in Visual C++

北战南征 提交于 2019-11-29 10:47:28

Yes, but it's two underscores: __pragma

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

EDIT: I've just confirmed that the omp pragmas can also be used like this:

#define OMP_PARALLEL_FOR __pragma(omp parallel for)

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!