PRB: C/QuickC May Incorrectly Generate C4135 or C4136 Warning

ID Number: Q71888

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SYMPTOMS

The C versions 6.0, 6.0a, and 6.0ax and QuickC versions 2.5 and

2.51 compilers may incorrectly generate the following warning

messages:

warning C4135: conversion between different integral types

warning C4136: conversion between different floating types

The sample program below can be used to illustrate this problem.

When compiled at warning level 3 or 4 (/W3 or /W4), the compiler

incorrectly generates a C4135 warning for the first comparison. No

warning is generated for the second comparison, which is the

correct behavior.

RESOLUTION

To eliminate the incorrect warnings, you can explicitly typecast

the smaller operand to the type of the larger operand.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax and QuickC versions 2.5 and 2.51 (buglist2.50 and

buglist2.51). This problem was corrected in C version 7.0.

More Information:

A similar problem occurs when comparing floats and doubles. If the

types of a and b in the code below are changed to float and double,

respectively, a C4136 warning will be incorrectly generated (for the

first comparison only).

Although there are some implicit type promotions carried out when

types of different sizes are compared, the warning should not be

generated in these cases because there is no possible loss of

precision here.

Sample Code

-----------

/* Compile options needed: /W3

*/

void main(void)

{

int a = 0;

long b = 0;

if (a < b) /* C4135 warning generated (incorrect) */

;

if (b > a) /* no warning generated (correct) */

;

}

Additional reference words: 6.00 6.00a 6.00ax