FIX: No C4051 Warnings Compiling .CPP or .CXX Files

Last reviewed: September 16, 1997
Article ID: Q100539
7.00 | 1.00 1.50 | 1.00
MS-DOS | WINDOWS   | WINDOWS NT
kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE), included with:

        - Microsoft C/C++ for MS-DOS, versions 7.0
        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
        - Microsoft Visual C++ 32-bit Edition, version 1.0
    

SYMPTOMS

When Microsoft C/C++ compiles a source code file that has the .CPP or .CXX filename extension, the compiler does not generate any C4051 warning messages. However, when Microsoft C/C++ compiles a source code file that contains similar code but that has the .C filename extension, the compiler correctly generates C4051 warning messages as follows:

   C4051: type conversion; possible loss of data

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ 32-bit Edition version 2.0.

MORE INFORMATION

According to the online help, the C4051 warning indicates that two data items in an expression have different base types. In the process of converting one of the items, it was truncated. To avoid this warning, cast the data item to an appropriate data type.

The following code example demonstrates this problem.

Sample Code

/*
 * Compile options needed: /W4
 */

void main()
{
   int i;

   i = 66.66 * 55.55;
}


Additional reference words: 1.00 1.50 7.00 8.00 8.00c
KBCategory: kbtool kbfixlist kbbuglist
KBSubcategory: CPPIss
Keywords : CPPIss kbbuglist kbfixlist kbtool
Version : 7.00 | 1.00 1.50 | 1.00
Platform : MS-DOS NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.