BUG: Intrinsic Version of strcmp May Return Incorrect ResultLast reviewed: July 31, 1997Article ID: Q167326 |
The information in this article applies to:
SYMPTOMSExplicitly referencing the Null character in the second argument of strcmp causes the intrinsic version of strcmp to incorrectly report the two arguments are not equal. Please see the sample code below.
RESOLUTIONThere are two workarounds:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONYou can enable intrinsic functions either by using of the /Oi compiler switch or #pragma intrinsic. To disable intrinsic functions, remove the /Oi compiler switch, add /Oi-, or use #pragma function to force a function call on a function by function basis. Please see the sample code below for use of the #pragma function.
Sample Code
/* Build Options: /Oi */ #include <stdio.h> #include <string.h> // uncomment the following line for workaround #2 //#pragma function(strcmp) int main(void) { char somestr [15] = "Some String"; somestr[1] = 0; // change the following to strcmp(somestr,"S") for workaround #1 if (strcmp(somestr,"S\0") == 0) printf("match: correct\n"); else printf("no match: incorrect\n"); return 0; }Note that a more common use of an embedded Null character may be to compare a string to "\0" to see if it is an empty string. For workaround #1, compare it to "" instead. Keywords : CRTIss vcbuglist500 kbcode kbprg kbbuglist Version : 5.0 Platform : NT WINDOWS Issue type : kbbug |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |