BUG: sizeof Used in Comparison Does Not Generate C4018

Last reviewed: July 24, 1997
Article ID: Q117201
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft C for MS-DOS, versions 6.0, 6.0a, 6.0ax - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 4.1, 4.2,

         5.0
    

SYMPTOMS

According to ANSI specifications, the sizeof macro returns the unsigned integer size of a particular data type or variable.

When the sizeof macro is used in a comparison with an integer variable, the compiler should, but does not, generate the following warning:

   warning C4018: 'op' : signed/unsigned mismatch

STATUS

Microsoft has confirmed this to be a bug in the products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The following sample code can be used to demonstrate the problem. The C4018 warning is produced for the statement in function3, but not for the statements in function1 and function2.

Sample Code

   /* Compile options needed: /W4
   */

   int i;
   unsigned u;

   int function1(void)
   {
      return(i > sizeof(i));
   }

   int function2(void)
   {
      return(i > (unsigned) sizeof(i));
   }

   int function3(void)
   {
      u = sizeof(i);
      return(i > u);
   }


Additional query words: 6.00 6.00a 6.00ax 7.00 8.00 8.00c 9.00
Keywords : CLIss vcbuglist400 vcbuglist500
Version : 6.0 6.0a 6.0ax 7.0 1.0 1.5 2.0 4
Platform : MS-DOS NT WINDOWS
Issue type : kbbug


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: July 24, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.