Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


The ElementSize property is used to specify an element size, in bytes, that depends on the value of another parameter to the function. This property is allowed on Pre and Post attributes and can only be applied to pointer or array data types.

The ElementSize property must be used in conjunction with any one of the following properties:

  • ValidElements

  • ValidElementsLength

  • ValidElementsConst

  • WritableElements

  • WritableElementsConst

  • WritableElementsLength

The value of ElementSize property is a parameter to the function of type size_t. To specify an element size that is constant, use the ElementSizeConst property.


If size_t*count is passed as the size parameter, then ElementSize="*count" is used to specify the property value.

The following code shows the use of another parameter (size_t count) for specifying the size of each element in pc using the ElementSize property:

// C
#include <CodeAnalysis\SourceAnnotations.h>
void f ([SA_Pre(Deref=0, Null=SA_No, ElementSize="count", WritableElementsConst=3)] void *pc, size_t count);

// C++
#include <CodeAnalysis\SourceAnnotations.h>
using namespace vc_attributes;
void f ([Pre(Deref=0, Null=No, ElementSize="count", WritableElementsConst=3)] void *pc, size_t count);
© 2016 Microsoft