Microsoft KB Archive/117201

= The sizeof operator used in a comparison does not generate C4018 =

Article ID: 117201

Article Last Modified on 7/5/2005

-

APPLIES TO


 * Microsoft C Professional Development System 6.0a
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 1.5 Professional Edition
 * Microsoft Visual C++ 1.0 Professional Edition
 * Microsoft Visual C++ 2.0 Professional Edition
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Standard Edition
 * Microsoft Visual C++ 6.0 Service Pack 5
 * Microsoft Visual C++ .NET 2002 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition

-



This article was previously published under Q117201



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

When the sizeof operator 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 that this is a bug in the Microsoft products that are listed in the "Applies to" section.



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: kbVC400bug 6.00 6.00a 6.00ax 7.00 8.00 8.00c 9.00

Keywords: kbbug kbcompiler KB117201

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.