简体   繁体   English

__in,__ out,__ in_opt的含义

[英]Meaning of __in , __out, __in_opt

在函数参数中的变量之前使用这些关键字的含义是什么?

  • __in
  • __out
  • __in_opt

Those are some of the older decoration macro's from Microsoft's SAL Annotations ( the newer ones now follow different casing, starting with a capital). 这些是来自微软SAL Annotations的一些较旧的装饰宏(现在较新的装饰宏是按照不同的外壳,从首都开始)。 These have no real affect on compilation (under VS 2010 they aren't even expanded), they are there for inline API documentation. 这些对编译没有实际影响(在VS 2010下它们甚至没有扩展),它们用于内联API文档。

  1. __in : this parameter is an input to the function (read-only, caller initialized). __in :此参数是函数的输入(只读,调用者已初始化)。
  2. __out : this parameter contains output from the function when it returns (write-only, caller initialized). __out :此参数包含函数返回时的输出(只写,调用者初始化)。
  3. __in_opt : a compound annotation formed from _in and _opt , _opt indications that the parameter is optional and can be set to a default value (generally NULL ). __in_opt :由_in_opt形成的复合注释, _opt表示该参数是可选的,可以设置为默认值(通常为NULL )。

You can get the full explanation here of the older decorations here . 你可以在这里得到了充分的解释旧的装饰品在这里

As answered by Nercolis, these are SAL annotation attributes. 正如Nercolis所回答的,这些是SAL注释属性。 However, these aren't just internal or just for API documentation . 但是,这些不仅仅是内部的,也不仅仅是API文档 The real purpose is for Code Analysis . 真正的目的是进行代码分析 When you build the project with /analyze compiler option (Project Properties, Code Analysis -> General), these play important role in finding the coding issues. 使用/ analyze编译器选项(项目属性,代码分析 - >常规)构建项目时,这些选项在查找编码问题中起着重要作用。

For example, if a particular pointer argument says __in then it must not be passed a null pointer. 例如,如果特定指针参数显示__in则不得传递空指针。 The function will not check for null and may cause SEH. 该函数不会检查null并可能导致SEH。 __in_opt argument may be null. __in_opt参数可以为null。 When compiler finds some issue, it reports it as a warning. 当编译器发现某些问题时,它会将其报告为警告。 See this article . 看到这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM