SAL: the Microsoft Source Code Annotation Language.

  SAL: the Microsoft Source Code Annotation Language.   

  微软代码注解语言。你可以用sal.h中的宏定义来注释函数的参数和返回值来描述他们的行为。

  曾经在Java中使用过注解,现在C++中也有注解了。

  sal.h - markers for documenting the semantics of APIs

   sal.h provides a set of annotations to describe how a function uses itsparameters

  C++中提供了一系列注解,来描述函数怎样来使用他的参数。


     The macros are defined in 3 layers, plus the structural set:

   _In_/_Out_/_Ret_ Layer:
----------------------
This layer provides the highest abstraction and its macros should be used
in most cases. These macros typically start with:
_In_ : input parameter to a function, unmodified by called function
_Out_ : output parameter, written to by called function, pointed-to
location not expected to be initialized prior to call
_Outptr_ : like _Out_ when returned variable is a pointer type
(so param is pointer-to-pointer type). Called function
provides/allocated space.
_Outref_ : like _Outptr_, except param is reference-to-pointer type.
_Inout_ : inout parameter, read from and potentially modified by
called function.
_Ret_ : for return values
_Field_ : class/struct field invariants
For common usage, this class of SAL provides the most concise annotations.
Note that _In_/_Out_/_Inout_/_Outptr_ annotations are designed to be used
with a parameter target. Using them with _At_ to specify non-parameter
targets may yield unexpected results. This layer also includes a number of other properties that can be specified
to extend the ability of code analysis, most notably:
-- Designating parameters as format strings for printf/scanf/scanf_s
-- Requesting stricter type checking for C enum parameters

   上面: 本层提供最高的抽象并且他的宏可应用于大多数场合。他们的宏都以_In_, _Out_ , _Inout开头

 _Pre_/_Post_ Layer:
------------------
The macros of this layer only should be used when there is no suitable macro
in the _In_/_Out_ layer. Its macros start with _Pre_ or _Post_.
This layer provides the most flexibility for annotations.

  上面:当_In_\_Out层没有适当的宏时才被使用,有很强的灵活性,他们的宏都以_Pre_, _Post_, _Ret_,_Deref_pre_ _Deref_post_ , _Deref_ret_开头

  _Pre_在函数调用前需要知道参数条件的时候

  _Post_在函数调用后需要知道的参数条件

  _Ret_ 函数调用后返回的参数条件

  _Deref_pre_  对于被间接引用的指针数组参数在函数调用前的条件
  _Deref_post_  对于被间接引用的指针数组参数在函数调用后的条件
  _Deref_ret

  _Pre_post在函数调用前或后的条件

  _Deref_prepost

  Implementation Abstraction Layer:
--------------------------------
Macros from this layer should never be used directly. The layer only exists
to hide the implementation of the annotation macros.

  上面:本层从不被直接使用,隐藏注释宏的实现

   Structural Layer:
----------------
These annotations, like _At_ and _When_, are used with annotations from
any of the other layers as modifiers, indicating exactly when and where
the annotations apply.

  上面:结构层,明确指定什么时候,在什么地方注解应用。

Common syntactic conventions:  常见的语法约定
   ----------------------------

Usage:
   -----
   _In_, _Out_, _Inout_, _Pre_, _Post_, are for formal parameters(常规参数).
   _Ret_, _Deref_ret_ must be used for return values.

Nullness:
   --------
   If the parameter can be NULL as a precondition to the function, the
   annotation contains _opt. If the macro does not contain '_opt' the
   parameter cannot be NULL.

If an out/inout parameter returns a null pointer as a postcondition, this is
   indicated by _Ret_maybenull_ or _result_maybenull_. If the macro is not
   of this form, then the result will not be NULL as a postcondition.
     _Outptr_ - output value is not NULL
     _Outptr_result_maybenull_ - output value might be NULL

String Type:
   -----------
   _z: NullTerminated string
   for _In_ parameters the buffer must have the specified stringtype before the call
   for _Out_ parameters the buffer must have the specified stringtype after the call
   for _Inout_ parameters both conditions apply

Extent Syntax:
   -------------
   Buffer sizes are expressed as element counts, unless the macro explicitly
   contains _byte_ or _bytes_. Some annotations specify two buffer sizes, in
   which case the second is used to indicate how much of the buffer is valid
   as a postcondition. This table outlines the precondition buffer allocation
   size, precondition number of valid elements, postcondition allocation size,
   and postcondition number of valid elements for representative buffer size
 aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggAAADOCAIAAADUsG20AAAP6UlEQVR4nO3dUZKjOAyA4T1JDrQXmBvOOfdhq1Ix2EK2ZUsW/1dbW900yBIQBExI/vkAAPDjH+8EAACx0BgAAAUaAwCgcF5j+PP3X+8UACCz3Y1Bf1inAQCACxoDAKAgNYY/f//9/7/fX39/aE0UFr9M7Jqzuqwyz3vky0RhPQDAqzQbw+XQ+f3h92d5ohzq8a+tg/X9WK/Ps7UUjQEAvh5uJd1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6rCG/N+VFLwxpL+VpEmpK078nT6IfCsq342XfBUphXiOQXnrpjpP75zC0NXp+jm/f2qV0yq/N6XqQIYVyblpBlJGi4krhiCjD+yf5vJVpHTSk8/x1+YbyFuBbaSXb11RURrnfR9DnJQmkdLL5Vu9VJTGSVcMAIANaAwAgAKNAQBQoDEAPvLdv6aiNGgM2MrqlZbgFZughAsqSiPEcwzJzLylZ2BB5VMLEZi/K9ww2jfmtvVmPor7Ro+2v83LV5GS/5PPjzMbzrnTPStlnl3lVFdp13ruHcg9yKJon8Y6XGfd2vB6RcR8Jc7IV5GS/2clKec3mXOnzY1hOMLMQJsjrI5JYzDMIYd8FSnxfQz1OeX7M0Ly1Xq7nhprlTm8lloVKddSV0y5rsdKNTnIMa0c1xj2RN48rn4PWSRfRUr+VwytMx35jPvx/KjrgCUf03snavKX89EP1KpdE/PTuZaUMZUR9It3rWQTe160Rye/YejeHWyFfBUpZW4MY4l9FBcimjSiNYZWRZqUWjG74rSyGliwa9xe216xRye/Z3T3M+t1jSE4GkP3EVyZRrTG8DiWPitlGlY50Bh8Y7qPnvIaKDj/dyUFbwxyzic2Bq8rBk0a1TPE+eRjOj3/u3WHUa91la8ipRDPMShv3VTn6Z1TGLo6XT/n90+tclrl96ZUHciwIjkxOeZjBHn0VrRWRcpxu2x7xa4YyPdwY34Y7d3BzJkP7V6R0klPPsdfm3ik6YsmceJLUMIFFaXB9zG4yZeSyeJdixwtX7FUlMZJVwwAgA1oDACAAo0BAFCgMQAACjQGAECBxgAAKNAYAAAFGgMAoEBjAAAUaAwAgAKNAQBQoDEAAAo0BgBAgcYAACjQGAAAhf8AVRtatYmPHm8AAAAASUVORK5CYII=" alt="" />

For the _Outptr_ annotations, the buffer in question is at one level of
   dereference. The called function is responsible for supplying the buffer.

Success and failure:
   -------------------
   The SAL concept of success allows functions to define expressions that can
   be tested by the caller, which if it evaluates to non-zero, indicates the
   function succeeded, which means that its postconditions are guaranteed to
   hold.  Otherwise, if the expression evaluates to zero, the function is
   considered to have failed, and the postconditions are not guaranteed.

The success criteria can be specified with the _Success_(expr) annotation:
     _Success_(return != FALSE) BOOL
     PathCanonicalizeA(_Out_writes_(MAX_PATH) LPSTR pszBuf, LPCSTR pszPath) :
        pszBuf is only guaranteed to be NULL-terminated when TRUE is returned,
        and FALSE indiates failure. In common practice, callers check for zero
        vs. non-zero returns, so it is preferable to express the success
        criteria in terms of zero/non-zero, not checked for exactly TRUE.

Functions can specify that some postconditions will still hold, even when
   the function fails, using _On_failure_(anno-list), or postconditions that
   hold regardless of success or failure using _Always_(anno-list).

The annotation _Return_type_success_(expr) may be used with a typedef to
   give a default _Success_ criteria to all functions returning that type.
   This is the case for common Windows API status types, including
   HRESULT and NTSTATUS.  This may be overridden on a per-function basis by
   specifying a _Success_ annotation locally.

C++中的注解理解的更多相关文章

  1. 理解Android中的注解与反射

    反射 Java反射(Reflection)定义 Java反射机制是指在运行状态中 对于任意一个类,都能知道这个类的所有属性和方法:对于任何一个对象,都能够调用它的任何一个方法和属性: 这样动态获取新的 ...

  2. 模拟实现Spring中的注解装配

    本文原创,地址为http://www.cnblogs.com/fengzheng/p/5037359.html 在Spring中,XML文件中的bean配置是实现Spring IOC的核心配置文件,在 ...

  3. 为何在新线程中使用注解获取不到Spring管理的Bean

    新建的线程类NewThread,在这个类中国使用Spring的注解获取Service,为null 网上已有这种问题的解决方案,但是为何在新线程中使用注解获取不到Spring管理的Bean? 问了老大, ...

  4. 0000 - Spring 中常用注解原理剖析

    1.概述 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来 ...

  5. 【java】详解java中的注解(Annotation)

    目录结构: contents structure [+] 什么是注解 为什么要使用注解 基本语法 4种基本元注解 重复注解 使用注解 运行时处理的注解 编译时处理的注解 1.什么是注解 用一个词就可以 ...

  6. Spring 中常用注解原理剖析

    前言 Spring 框架核心组件之一是 IOC,IOC 则管理 Bean 的创建和 Bean 之间的依赖注入,对于 Bean 的创建可以通过在 XML 里面使用 <bean/> 标签来配置 ...

  7. Python中使用@的理解

    Python函数中使用@ 稍提一下的基础 fun 和fun()的区别 以一段代码为例: def fun(): print('fun') return None a = fun() #fun函数并将返回 ...

  8. @RequestBody, @ResponseBody 注解理解

    @RequestBody, @ResponseBody 注解理解 自己以前没怎么留意过,来实习后公司采用前后端分离的开发方式,前后端拿到的注释都是 json 格式的,这时候 @RequestBody, ...

  9. 【转载:java】详解java中的注解(Annotation)

    目录结构: contents structure [+] 什么是注解 为什么要使用注解 基本语法 4种基本元注解 重复注解 使用注解 运行时处理的注解 编译时处理的注解 1.什么是注解 用一个词就可以 ...

随机推荐

  1. [C#][.net 4]Task 代码示例

    using System; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; name ...

  2. @RequestBody接收ajax的json字符串

    在使用ajax进行请求,并传递参数时,偶尔需要把数组作为传递参数,这是就要使用@RequestBody来解决这个问题 在页面端的处理: (1)利用JSON.stringify(arr)需要把json对 ...

  3. 脚本录制(JMeter)

    使用JMeter录制脚本: 1.打开JMeter工具,创建一个线程组,接着创建一个http代理服务器,代理服务器设置如下:

  4. Window 命令

    tracert XXX.XXX.XXX.XXX 路由追踪命令,可以显示到目的IP所经过的路由    

  5. jeasyui datagrid控件的一个小问题

    页面上用了datagrid,但今天把easyui更新到1.4.2以后出了个错,Cannot read property 'width' of null,以前用1.3.6的时候没有这个问题. 由于表格中 ...

  6. 【转】Win7 64bit Oracle 11g 使用PL/SQL Developer 连接时提示“SQL*Net not properly installed”

    转载:http://www.cnblogs.com/xihuaodc/p/3189257.html  因为之前的Oracle不能用了,所以重新安装了64位的Oracle,安装一路正常 完了之后安装了P ...

  7. .Net判断一个对象是否为数值类型探讨总结(高营养含量,含最终代码及跑分)

    前一篇发出来后引发了积极的探讨,起到了抛砖引玉效果,感谢大家参与. 吐槽一下:这个问题比其看起来要难得多得多啊. 大家的讨论最终还是没有一个完全正确的答案,不过我根据讨论结果总结了一个差不多算是最终版 ...

  8. CMakeLists for tesseract

    在网上找了很多,直接用都不行,试了半天的到以下的结果. cmake_minimum_required(VERSION 2.8) project( test ) include_directories ...

  9. 2-2. Initializing Objects with Initializer Lists

    Using Uniform Initialization to Construct a vector #include <iostream> #include <vector> ...

  10. AngularJs自定义指令详解(7) - multiElement

    multiElement不太常用,从下面这个例子可以大致看出它的作用: <!DOCTYPE html> <html> <head lang="en"& ...