/char switch
The /char switch helps to ensure that the MIDL compiler and C compiler operate together correctly for all char and small types.
midl /char { signed | unsigned | ascii7 }
-
signed
-
Specifies that the default C-compiler type for char is signed. All occurrences of char not accompanied by a sign specification are generated as unsigned char.
-
unsigned
-
Specifies that the default C-compiler type for char is unsigned. All uses of small not accompanied by a sign specification are generated as signed small.
-
ascii7
-
Specifies that all char values are to be passed into the generated files without a specific sign keyword. All uses of small not accompanied by a sign specification are generated as small.
By definition, MIDL char is unsigned. "Small" is defined in terms of char (#define small char), and MIDL small is signed.
The /char switch directs the MIDL compiler to specify explicit signed or unsigned declarations in the generated files when the C-compiler sign declaration conflicts with the MIDL default for that type.
Remember that the MIDL compiler generates the stubs as C source code, which you must compile as part of your client and server programs. Some compilers use a signed char everywhere char data is specified in the source code. The stub source code that the MIDL compiler generates treats all char data as unsigned char. If the MIDL compiler simply generated all char data in the IDL file as char data in the stubs, compilers that use a signed char for char data would cause a conflict in the stub source code.
The purpose of the /char command line switch is to resolve these potential conflicts. It preserves all data specified as char in the IDL file as unsigned char in the stub source code. It also maintains small data as signed.
The following table summarizes the generated types.
midl /char option | Generated char type | Generated small type |
---|---|---|
midl /char signed | unsigned char | small |
midl /char unsigned | char | signed small |
midl /char ascii7 | char | small |
The /char signed option indicates that the C-compiler char and small types are signed. To match the MIDL default for char, the MIDL compiler must convert all uses of char not accompanied by a sign specification to unsigned char. The small type is not modified because this C-compiler default matches the MIDL default for small.
The /char unsigned option indicates that the C-compiler char type is unsigned. The MIDL compiler converts all uses of small not accompanied by a sign specification to signed small.
The ascii7 option indicates that no explicit sign specification is added to char types. The type small is generated as small.
To avoid confusion, you should use explicit sign specifications for char and small types whenever possible in the IDL file. Note that the use of explicitly signed char types in your IDL file is not supported by DCE IDL. Therefore, this feature is not available when you compile with the MIDL /osf switch.
For more information related to /char, see small.
midl /char signed filename.idl
midl /char unsigned filename.idl
midl /char ascii7 filename.idl