什么是 __pragma 以及 __pragma 和 #pragma 之间有什么区别

2022-01-11 00:00:00 macros c++

以下宏让我感到困惑.我想知道 __pragma 是什么,__pragma 和 #pragma 有什么区别.

The following macros confused me. I wondering what is __pragma and wwhat are the differences between __pragma and #pragma.

#define OPENVDB_START_THREADSAFE_STATIC_WRITE       __pragma(warning(disable:1711))
#define OPENVDB_FINISH_THREADSAFE_STATIC_WRITE      __pragma(warning(default:1711))

推荐答案

#pragma 本身就是一个预处理器指令;它不能在 #define 指令中使用.

#pragma is a preprocessor directive in its own right; it can't be used within a #define directive.

所以,这就是 __pragma 存在的原因:它提供了一种从使用它的宏展开的任何地方发出 pragma 的方法.

So, this is why __pragma exists: it provides a way for a pragma to be issued from wherever the macro that uses it is expanded.

这是一个非标准的编译器扩展(MSVC、Intel 和一些 C 编译器在不同程度上支持它).另请参阅在较新版本的 C/C++ 标准(以及用途相同,但语法略有不同).

This is a non-standard compiler extension (MSVC, Intel, and some C compilers support it to varying degrees). See also the _Pragma operator that is defined in newer versions of the C/C++ standards (and serves the same purpose, but with a slightly different syntax).

相关文章