__in __out __in_opt __allowed() 的目的是什么,它们是如何工作的?我应该在自己的代码中使用类似的构造吗?

发布于 2024-10-03 19:25:34 字数 368 浏览 0 评论 0原文

其中一些预处理器定义位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深海夜未眠 2024-10-10 19:25:34

它们是源代码注释语言中的 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.

凉薄对峙 2024-10-10 19:25:34

SAL 注释有两个用途:

  • 通过 PREfast 进行静态分析(使用 /analyze 进行编译)
  • 人类读者可以查看注释并找出应如何调用函数,并快速确定输入/输出参数。

当您的代码通过分析进行编译时,这些宏实际上会扩展为各种 declspec 表达式。我在代码中一直使用这些注释。

SAL annotations are useful for two things:

  • Static analysis through PREfast (compile with /analyze)
  • Human readers can look at the annotations and figure out how a function should be called, and quickly determine the input/output parameters.

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.

吃→可爱长大的 2024-10-10 19:25:34

它们在 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.

荒路情人 2024-10-10 19:25:34

这些 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.,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文