BUG: sizeof Used in Comparison Does Not Generate C4018Last reviewed: July 24, 1997Article ID: Q117201 |
The information in this article applies to:
SYMPTOMSAccording 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 STATUSMicrosoft 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 INFORMATIONThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |