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. Linux内核的总结认识

    转载博文: http://www.linuxdiyf.com/linux/11234.html 1.内核是怎样实现其管理的职能? 以前在学校时一直不能理解内核是怎么做管理?比如内核如何知道在什么时候对 ...

  2. LINUX 更新

    sudo apt-get dist-upgrade,更新所有的软件

  3. ROS 新手教程 命令汇总

    ## 工作环境搭建 查看环境变量的配置: wangsan@wangsan-Y50:~$ export | grep ROS declare -x ROSLISP_PACKAGE_DIRECTORIES ...

  4. 用js将从后台得到的时间戳(毫秒数)转换为想要的日期格式

    得到后台从数据库中拿到的数据我们希望格式是 2016年10月25日 17时37分30秒 或者 2016/10/25 17:37:30 然而我们前台得到的却是一段数字(时间戳,毫秒数) 14773860 ...

  5. 动态生成DropDownList 并取值

    Default.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Def ...

  6. 模糊测试(Fuzz testing)

    模糊测试(fuzz testing)是一种安全测试方法,他介于完全的手工测试和完全的自动化测试之间.为什么是介于那两者之间?首先完全的手工测试即是渗透测试,测试人员可以模拟黑客恶意进入系统.查找漏洞, ...

  7. lvs + keepalived 介绍及安装

    LVS介绍 lvs 核心ipvs      Ipvs(IP Virtual Server)是整个负载均衡的基础,如果没有这个基础,故障隔离与失败切换就毫无意义了.Ipvs 具体实现是由ipvsadm ...

  8. IT人 转型

    IT人 转型 转自: http://blog.sina.com.cn/s/blog_88534dff0101232b.html      “35岁,技术生涯即告终结.”这种说法在it界得到众多人认可, ...

  9. textField和textView限制输入条件

    以下两法方法都是实现textfield和textView的代理方法  需要先遵循代理 一:textField限制只能输入数字和小数点 且小数点后只能保留两位 小数点前最多5位 - (BOOL)text ...

  10. some things

    ////html[1]/body[1]/div[9]/div[1]/div[1]/div[1]/ul/li  截取规则 Articles/Article[1]:选取属于Articles子元素的第一个A ...