Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

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.

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);
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.