Udostępnij za pośrednictwem


ValidElements

The ValidElements property specifies either the number of elements of an array or a buffer pointed to by a pointer that can be legally read. This property is allowed on Pre and Post attributes and can be used on pointer or array data types. The value of this property is an expression that involves another parameter, which specifies the actual number of valid elements.

Example

The following code shows how to use the ValidElements property:

// 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);

See Also

Concepts

Annotation Overview

Other Resources

Annotation Properties