这些在 minwindef.h 中定义(通常位于 Program Files (x86)\Windows Kits\8.1\Include\shared\minwindef.h)
#ifndef IN
#define IN
#endif
#ifndef OUT
#define OUT
#endif
而且我经常看到这样用这些宏装饰的参数:
void SomeFunction(IN const MyClass& obj)
这些宏的意义是什么?为什么要用它修饰参数?
最佳答案
为了与标准 C 和标准兼容,这些宏可以定义为空 C++ 或者它们可以定义为特定于 MS 的 SAL (Microsoft source code annotation language) annotations 对于Annotating Function Parameters and Return Values ,例如
#define IN _In_
#define OUT _Out_
具有文档含义:
_In_
Annotates input parameters that are scalars, structures, pointers to structures and the like. Explicitly may be used on simple scalars. The parameter must be valid in pre-state and will not be modified.
_Out_
Annotates output parameters that are scalars, structures, pointers to structures and the like. Do not apply this to an object that cannot return a value—for example, a scalar that's passed by value. The parameter does not have to be valid in pre-state but must be valid in post-state.
当然,SAL 注释由 MS 编译器解析。 MSDN Windows API 文档 使用 SAL 注释,for example
关于c++ - minwindef.h 中的 IN 和 OUT 宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35907493/