FIX: Warning C4135 Issued for Valid Assignment
PSS ID Number: Q116242
Article last modified on 06-20-1994

7.00

MS-DOS


----------------------------------------------------------------------
The information in this article applies to:

 - Microsoft C/C++ for MS-DOS, version 7.0
----------------------------------------------------------------------

SYMPTOMS
========

The sample code in the "MORE INFORMATION" section, below, causes the
compiler to incorrectly return warning C4135, "conversion between
different integral types," for the line that has a binary expression
containing a "short" or "char" data type as an operand assigned to a
variable of the short data type.

CAUSE
=====

If an expression contains short or char data types as operands to a binary
expression, the expressions are first converted to "int" (Integral
Promotion) data type by ANSI standard rules. When the resulting int is then
assigned to a short, the warning occurs.

RESOLUTION
==========

While using the C/C++ compiler, version 7.0 or 7.0a, this warning can be
avoided using "#pragma warning(disable:4135)" or by explicitly casting the
expression to a short.

STATUS
======

Microsoft has confirmed this to be a problem in Microsoft C/C++ compiler
for MS-DOS, versions 7.0 and 7.0a, This problem was corrected in the C/C++
compiler for MS-DOS, version 8.0, and the C/C++ compiler for Windows NT,
version 8.0.

MORE INFORMATION
================

The following sample code can be used to demonstrate this problem:

Sample Code
-----------

/* Compile options needed: none
*/

   void main()
   {
      short result;
      short x=5, y=6;

   /* This pragma shuts off the warning. */
   /* #pragma warning(disable:4135) */

   /* This line generates the warning. */
      result = (x*y);

   /* result = (short)(x*y); explicit cast works also */
   }

Additional reference words: 7.00
KBCategory: Tls
KBSubCategory: CLIss

=============================================================================

Copyright Microsoft Corporation 1994.
