[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | DEC C Problem Reporting Forum |
Notice: | Report DEC C++ problems in TURRIS::C_PLUS_PLUS |
Moderator: | CXXC::REPETE TCHEON |
|
Created: | Fri Nov 13 1992 |
Last Modified: | Fri Jun 06 1997 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 1299 |
Total number of notes: | 6249 |
1282.0. "toupper and tolower behavior on VAX vs Alpha" by CSC32::E_VAETH (Suffering from temporary brain cramp, stay tuned) Mon Mar 24 1997 12:02
Hi,
DEC C V5.5-002, OpenVMS Alpha V7.0, OpenVMS VAX 6.1, 6.2, 7.0.
A customer finds that toupper (tolower) do not give the same results on OpenVMS
Alpha and VAX. There appears to be a descrepancy in when the pointer is updated
in the following test case.
Is this a bug?
Thanks,
elin
Results on VAX:
6360_elin>run a
*xview*
*XVIEW*
*VIEW* >>>> the first byte not there
6360_elin>
Results on Alpha:
SUPAI_elin>link a
SUPAI_elin>run a
*xview*
*XVIEW*
*XVIEW*
$ cc tst
#include <string.h>
#include <stdio.h>
#include <ctype.h>
main()
{
char whole_file_string[10],*ptr;
strcpy(whole_file_string,"xview");
printf("*%s*\n",whole_file_string);
ptr = whole_file_string;
while(*ptr = toupper(*ptr))ptr++;
printf("*%s*\n",whole_file_string);
ptr = whole_file_string;
while(*ptr++ = toupper(*ptr));
printf("*%s*\n",whole_file_string);
}
T.R | Title | User | Personal Name | Date | Lines |
---|
1282.1 | | SPECXN::DERAMO | Dan D'Eramo | Mon Mar 24 1997 12:19 | 8 |
| Hi Elin. The program is illegal...
while(*ptr++ = toupper(*ptr));
The above violates the paragraph at line 5 in section 3.3 on
page 39.
Dan
|
1282.2 | DEC C V5.6 will tell you... | DECC::SULLIVAN | Jeff Sullivan | Mon Mar 24 1997 12:59 | 38 |
| I think Dan's correct in .1. Note that DEC C V5.6 and later will produce the
following warning:
% cc t2.c
cc: Warning: t2.c, line 15: In this statement, the expression
"*ptr++=((int)(((*(__lc_ctype->core.towupper))==0)?__lc_ctype->_upper[*ptr]:(*(_
_lc_ctype->core.towupper))(...)))" modifies "ptr", and fetches its value in a
computation that is not used to produce the modified value without an
intervening sequence point. This behavior is undefined.
while(*ptr++ = toupper(*ptr));
--------^
% a.out
*xview*
*XVIEW*
*VIEW*
After the following change:
% diff t2.c t3.c
< while(*ptr++ = toupper(*ptr));
---
> while(*ptr = toupper(*ptr)) ptr++;
I see the "expected" results:
% cc t3.c; a.out
*xview*
*XVIEW*
*XVIEW*
This type of latent bug was also reported recently as C_PLUS_PLUS 3510, so it is
not an uncommon problem. Better diagnostics (as above) can help resolve these
types of problems.
-Jeff
|
1282.3 | Thanks | CSC32::E_VAETH | Suffering from temporary brain cramp, stay tuned | Mon Mar 24 1997 14:28 | 0
|