The const keyword modifies the type of a type declaration or the type of a function parameter, preventing the value from varying.
const const-type identifier = const-expression ; [ typedef [ , type-attribute-list ] ] const const-type declarator-list; [ typedef [ , type-attribute-list ] ] pointer-type const declarator-list; [ [ function-attr-list ] ] type-specifier [ ptr-decl ] function-name( [ [ parameter-attribute-list ] ] ) const; const-type [declarator], [ [ parameter-attribute-list ] ] pointer-type const [declarator], ...);
Specifies a valid MIDL integer, character, string, or Boolean type. Valid MIDL types include small, short, long, char, charÂ *, wchar_t, wchar_tÂ *, byte, byteÂ *, and voidÂ *. The integer and character types can be signed or unsigned.
Specifies a valid MIDL identifier. Valid MIDL identifiers consist of up to 31 alphanumeric and/or underscore characters and must start with an alphabetic or underscore character.
Specifies an expression, identifier, or numeric or character constant appropriate for the specified type: constant integer literals or constant integer expressions for integer constants; Boolean expressions that can be computed at compilation for Boolean types; single-character constants for char types; and string constants for [string] types. The voidÂ * type can be initialized only to NULL.
Specifies one or more attributes that apply to the type.
Specifies a valid MIDL pointer type.
- declarator and declarator-list
Specifies standard C declarators, such as identifiers, pointer declarators, and array declarators. For more information, see Array and Sized-Pointer Attributes, arrays, and Arrays and Pointers. The declarator-list consists of one or more declarators, separated by commas. The parameter-name identifier in the function declarator is optional.
Specifies zero or more attributes that apply to the function. Valid function attributes are [callback], [local]; the pointer attribute [ref], [unique], or [ptr]; and the usage attributes [string], [ignore], and [context_handle].
Specifies zero or more pointer declarators. A pointer declarator is the same as the pointer declarator used in C. It is constructed from the * designator, modifiers such as far, and the qualifier const.
Specifies the name of the remote procedure.
Specifies zero or more directional attributes, field attributes, usage attributes, and pointer attributes appropriate for the specified parameter type. Separate multiple attributes with commas.
MIDL allows you to declare constant integer, character, string, and Boolean types in the interface body of the IDL file. Const type declarations are reproduced in the generated header file as #define directives.
DCE IDL compilers do not support constant expressions. Therefore, this feature is not available when you use the MIDL compiler /osf switch.
A previously defined constant can be used as the assigned value of a subsequent constant. The value of a constant integral expression is automatically converted to the respective integer type in accordance with C conversion rules.
The value of a character constant must be a single-quoted ASCII character. When the character constant is the single-quote character itself ('), the backslash character (\) must precede the single-quote character, as in \'.
The value of a character-string constant must be a double-quoted string. Within a string, the backslash (\) character must precede a literal double-quote character ( " ), as in \". Within a string, the backslash character (\) represents an escape character. String constants can consist of up to 255 characters.
The value NULL is the only valid value for constants of type voidÂ *. Any attributes associated with the const declaration are ignored.
The MIDL compiler does not check for range errors in const initialization. For example, when you specify "const short x = 0xFFFFFFFF;" the MIDL compiler does not report an error and the initializer is reproduced in the generated header file.
const void * p1 = NULL; const char my_char1 = 'a'; const char my_char2 = my_char1; const wchar_t my_wchar3 = L'a'; const wchar_t * pszNote = L"Note"; const unsigned short int x = 123; typedef [string] const char *LPCSTR; HRESULT GetName([out] wchar_t * const pszName );
- MIDL Base Types
- Interface Definition (IDL) File