PRB: Undesired Side Effects from toascii, tolower, toupperLast reviewed: August 26, 1997Article ID: Q98588 |
The information in this article applies to:
SYMPTOMSIn an application compiled with Microsoft C/C++, using the toascii, tolower, or toupper macros with a pointer value produces incorrect results, such as corrupted strings or a GP fault, depending on which compiler you use.
CAUSEBecause the tolower and toupper macros evaluate the input argument twice, the compiler performs any pointer arithmetic specified in a macro argument twice. This problem occurs most often with macros that affect an individual character because character pointers are common arguments for these macros.
RESOLUTIONThe text below presents two methods to address the behavior the side effects cause.
MORE INFORMATION
Sample Code
/* * Compile options needed: none */ #include <stdio.h> #include <ctype.h> char string[20]="this is a string"; void main(void) { char *x; x = string; while (*x != '\0') *x = (char)toupper((int) *(x++)); printf("%s\n", string); }The sample code above may produce the following output:
thHssiI ttiIgg Keywords : CRTIss Version : 6.0 6.0a 6.0ax 7.0 1.0 1.5 1.51 2.0 2.1 4.0 4.1 4.2 5.0 Platform : MS-DOS NT WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |