ValidElements

ValidElements 属性指定指针指向的数组或缓冲区的可以合法读取的元素数目。 Pre 和 Post 特性上允许此属性,此属性可以在指针或数组数据类型上使用。 此属性的值是一个表达式,其中涉及到另一个参数,该值指定有效元素的实际数目。

示例

下面的代码演示如何使用 ValidElements 属性:

// C
#include <CodeAnalysis\SourceAnnotations.h>
void f([SA_Pre(ValidElements="count") ] char *pc, size_t count);

// The keyword 'return' is used to indicate the return value,
// which in this case is the number of valid elements.
[returnvalue:SA_Post(MustCheck=SA_Yes)]int f([SA_Post(ValidElements="return")] char *pc);

// C++
#include <CodeAnalysis\SourceAnnotations.h>
using namespace vc_attributes; 
void f([Pre(ValidElements="count") ] char *pc, size_t count);

// The keyword 'return' is used to indicate the return value,
// which in this case is the number of valid elements.
[returnvalue:Post(MustCheck=Yes)]int f([Post(ValidElements="return")] char *pc);

请参见

概念

批注概述

其他资源

批注属性