c++ - minwindef.h 中的 IN 和 OUT 宏

标签 c++ visual-c++

这些在 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/

相关文章:

c++ - Malloc 无法在 Windows 上分配 1 GiB 的内存

c++ - 在不声明成员变量的情况下更改按钮颜色

c++ - 从共享对象中的类继承

c++ - 基于 Chromium Edge 的 WebView2 不起作用

c++ - 用于二进制分发的 clang 编译器标志(通用 CPU)

c++ - TBB 编译器错误 - 'my_task' : references must be initialized

c++ - 如何反转文本文件中的输出

c++ - 如何在函数中释放内存

Java native 访问代码错误 : "Invalid memory access"

apache - 该程序无法启动,因为您的计算机缺少MSVCR110.dll