What is the purpose of __in __out __in_opt __allowed(), how do they work? Should I use similar constructs in my own code?(__in __out __in_opt __allowed() 的目的是什么,它们是如何工作的?我应该在自己的代码中使用类似的结构吗?)
问题描述
其中一些预处理器定义在 WinMain 函数和其他 windows 库函数中.他们的目的是什么?它们是如何工作的?将它们写入您的实现或函数调用是一种好习惯吗?
Some of these Preprocessor definitions are in the WinMain function and other windows library functions. What is their purpose? How do they work? and is it good practice to write them into your implementations or function calls?
我最初的研究表明,它们只是简单地设置为:
My initial research suggests they're simply set up equlivalent to:
#define __in
#define __out
#define __in_opt
意味着它们在预处理器过程中被 nothing 替换.它们只是一种文档方法,没有任何功能吗?
Meaning they get replaced with nothing on the Preprocessor pass. Are they just a documentation method, without any functionality?
如果是这样,我可以看到像这样记录代码的好处.使用 doxygen 之类的东西,您需要写出两次参数名称.所以这在理论上可以帮助减少重复并保持一致性......
If so, I can see the advantage to documenting the code in line like this. With something like doxygen you need to write out the parameter names twice. So this could in theory help reduce duplication, and maintain consistency...
我不知道 __allowed() 应该如何工作.
I have no theory for how __allowed() is supposed to work.
推荐答案
它们是 Source-code Annotation Language 中的 SAL 注释.微软工具依赖于它.MSDN 库文章在这里.代码分析就是一个很好的例子.另一个完全不相关但受这些注释支持的工具是 Pinvoke Interop Assistant.
They are SAL annotations in the Source-code Annotation Language. Microsoft tooling depends on it. The MSDN Library article is here. A good example is Code Analysis. Another quite unrelated tool, but empowered by these annotations is the Pinvoke Interop Assistant.
这篇关于__in __out __in_opt __allowed() 的目的是什么,它们是如何工作的?我应该在自己的代码中使用类似的结构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:__in __out __in_opt __allowed() 的目的是什么,它们是如何工作的?我应该在自己的代码中使用类似的结构吗?
基础教程推荐
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
