ValidElements

更新:2007 年 11 月

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

示例

下面的代码演示如何使用 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);

请参见

概念

批注概述

其他资源

批注属性