__in __out __in_opt __allowed() 的目的是什么,它们是如何工作的?我应该在自己的代码中使用类似的构造吗?
其中一些预处理器定义位于 WinMain 函数和其他 Windows 库函数中。他们的目的是什么?它们如何工作?将它们写入您的实现或函数调用中是一个好习惯吗?
我的初步研究表明,它们的设置相当于:
#define __in
#define __out
#define __in_opt
意味着它们在预处理器过程中被替换为无。它们只是一种文档方法,没有任何功能吗?
如果是这样,我可以看到像这样在线记录代码的优点。对于像 doxygen 这样的东西,你需要写出参数名称两次。因此,这在理论上可以帮助减少重复并保持一致性......
我没有关于 __allowed() 应该如何工作的理论。
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
Meaning they get replaced with nothing on the Preprocessor pass. Are they just a documentation method, without any functionality?
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...
I have no theory for how __allowed()
is supposed to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它们是源代码注释语言中的 SAL 注释。 Microsoft 工具依赖于它。 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.
SAL 注释有两个用途:
当您的代码通过分析进行编译时,这些宏实际上会扩展为各种 declspec 表达式。我在代码中一直使用这些注释。
SAL annotations are useful for two things:
The macros do in fact expand to various declspec expressions when your code is compiled with analysis on. I use these annotations all the time in my code.
它们在 Microsoft 语义分析工具中用作代码标记。除非您打算自己使用这个工具,否则使用它们没有什么意义。
They're used in a Microsoft semantic analysis tool as code markups. Unless you plan on using this tool yourself, there's little purpose in using them.
这些 Microsoft 宏通常不会展开任何内容,旨在为读者提供提示。
然而,上次我检查例如
MessageBox
参数的提示是完全错误的,暗示第一个、第二个和第三个参数具有有用的默认值(当您指定 0 时),而实际上它是第一个和第四个参数有有用的默认值。也许还有默认为“Error”的标题参数,但我从未发现它有用。所以,这只是微软的事情,暗示你不能也不应该依赖,只是误导性的视觉混乱。干杯&呵呵,
These Microsoft macros generally expand to nothing, and are meant as hints to the reader.
However, last time I checked e.g. the hinting on the
MessageBox
arguments was completely wrong, hinting that first, second and third argument had useful defaults (when you specify 0), while in reality it's first and fourth argument that have useful defaults. Maybe also the title argument which defaults to "Error", but I've never found that useful. So, it's just a Microsoft thing, hints that you cannot and should not rely on, just misleading visual clutter.Cheers & hth.,