range attribute

The [range] attribute lets you specify a range of allowable values for arguments or fields whose values are set at run time. When used with a pipe type, the attribute specifies the allowable range for the count of elements in the pipe chunks.

[range(low-val,high-val)] type-specifier declarator



The lowest allowable value that the parameter or field can hold.


The highest allowable value that the parameter or field can hold.


An integral type other than hyper or __int64, a type identifier to an integral type, an enum type, or a pipe type name.


A standard C declarator, such as an identifier.


Use the [range] attribute to modify the meaning of sensitive parameters or fields, such as those used for size or length, with conformant or varying arrays; or whenever you want to check a parameter or field value against a range of valid values. The attribute is applicable to top-level parameters as well as lower-level parameters and fields. Adding the [range] attribute to a type does not change its wire format, thus does not affect backward compatibility.

The [range] attribute can also be used on conformant data such as buffers or arrays with a conformance attribute. The effect is to limit all conformance sizes for the conformant data to the specified range. If the conformant data is a multi-dimensional array, each array dimension is limited to the specified range.

Use of [range] on conformant data requires that the compilation target be –target NT60 or higher.

Note that you must use the /robust compiler option when you compile your IDL file in order to generate the stub code that will perform these checks. Without the /robust switch, the MIDL compiler ignores this attribute.


HRESULT Method1(
    [in, range(0,100)] ULONG m,
    [in, range(0,100)] ULONG n,
    [size_is(m,n)] ULONG **pplong);

void InPipe(
    [in, range(0, MAX_CHUNK) LONG_PIPE pipe_date);

See also

Interface Definition (IDL) File