mpatnode@polyslo.UUCP (Mike Patnode) (05/26/87)
In article <2065@husc6.UUCP> ddl@husc6.UUCP (Dan Lanciani) writes: >In article <345@polyslo.UUCP>, mpatnode@polyslo.UUCP (Mike Patnode) writes: >> toupper(p++) >> This is a BIG NO-NO since toupper is actually a macro which >> evaluates it's arguments 3 times!!!!! > > Not quite. This is a no-no, but for a different reason. The macros >toupper and tolower do not evaluate their arguments more than once. (At >least on BSD and MSC 4.0 and other "compatible" systems.) In order to >avoid multiple eveluation, these macros do NOT check that their arguments >are suitable. Well Dan this is straight out of my ctype.h: #define toupper ((isupper(c)) ? _tolower(c) : (c)) Upon closer evaluation I now see the argument is only evaluated 2 times. But this was with MSC 3.00 so 4.0 may have change. ------------------------------------------------------------------ Mike "Dodger" Patnode | ..csustan!polyslo!mpatnode Western Mobile Communications | or (but really just a student) | mpatnode@polyslo.UUCP 3020 Skyway Dr. | Santa Maria, Ca |
ark@alice.UUCP (05/29/87)
In article <348@polyslo.UUCP>, mpatnode@polyslo.UUCP writes:
-> Well Dan this is straight out of my ctype.h:
->
-> #define toupper ((isupper(c)) ? _tolower(c) : (c))
->
-> Upon closer evaluation I now see the argument is only evaluated 2
-> times. But this was with MSC 3.00 so 4.0 may have change.
Gee, I guess MSC 3.00 is broken, then. Maybe they'll fix it in 4.0
rap@oliveb.UUCP (05/29/87)
In article <6933@alice.UUCP> ark@alice.UUCP writes: >In article <348@polyslo.UUCP>, mpatnode@polyslo.UUCP writes: >-> Well Dan this is straight out of my ctype.h: >-> >-> #define toupper ((isupper(c)) ? _tolower(c) : (c)) >-> >-> Upon closer evaluation I now see the argument is only evaluated 2 >-> times. But this was with MSC 3.00 so 4.0 may have change. > >Gee, I guess MSC 3.00 is broken, then. Maybe they'll fix it in 4.0 It pains me sometimes to see people who are smart enough to know everything. Sorry for the dig, but if you read the manual you would see that there are both macros and functions for toupper and tolower. Microsoft suggests that if the macros are not desired, delete them from the include file and link with some other library file. Its all spelled out. -- Robert A. Pease {hplabs|fortune|idi|ihnp4|tolerant|allegra|glacier|olhqma}!oliveb!olivej!rap
gwyn@brl-smoke.ARPA (Doug Gwyn ) (05/30/87)
In article <1163@oliveb.UUCP> rap@olivej.UUCP (Robert A. Pease) writes: >In article <6933@alice.UUCP> ark@alice.UUCP writes: >>In article <348@polyslo.UUCP>, mpatnode@polyslo.UUCP writes: >>-> #define toupper ((isupper(c)) ? _tolower(c) : (c)) >>Gee, I guess MSC 3.00 is broken, then. Maybe they'll fix it in 4.0 >Its all spelled out. It sure is, and if MicroSoft wants to be standard-conforming, they're going to have to fix this bug. Just because they document it doesn't make it right.
jae@ncoast.UUCP (Jeff Evans) (05/31/87)
In article <348@polyslo.UUCP>, mpatnode@polyslo.UUCP (Mike Patnode) writes: > In article <2065@husc6.UUCP> ddl@husc6.UUCP (Dan Lanciani) writes: > >In article <345@polyslo.UUCP>, mpatnode@polyslo.UUCP (Mike Patnode) writes: > >> toupper(p++) > >> This is a BIG NO-NO since toupper is actually a macro which > >> evaluates it's arguments 3 times!!!!! > > > > Not quite. This is a no-no, but for a different reason. The macros > >toupper and tolower do not evaluate their arguments more than once. (At > >least on BSD and MSC 4.0 and other "compatible" systems.) In order to > >avoid multiple eveluation, these macros do NOT check that their arguments > >are suitable. > Well Dan this is straight out of my ctype.h: > > #define toupper ((isupper(c)) ? _tolower(c) : (c)) > > Upon closer evaluation I now see the argument is only evaluated 2 > times. But this was with MSC 3.00 so 4.0 may have change. Here it is, straight from the horses mouth ... (Microsoft C 4.0 Runtime Lib. Manual p. 406 [for toascii - toupper]) These functions are implemented as macros. However, tolower and toupper are also implemented as functions, because the macro versions do not correctly handle arguments with side effects. The function versions can be used by removing the macro definitions through #undef directives or by not including ctype.h. Function declarations of tolower and toupper are given in stdlib.h. I had the same problem using the macro version of toupper, but the problem disappeared with the function version. -- |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-| | Jeff Evans Bailey Controls Co. - Systems Engineering | | Path: ...cbosgd!cwruecmp!ncoast!jae Domain: jae@ncoast.UUCP | |=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=| Disclaimer : My views are of my own creation ... I had no help.
jmsellens@watdragon.UUCP (06/01/87)
In article <5915@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes: >In article <1163@oliveb.UUCP> rap@olivej.UUCP (Robert A. Pease) writes: >>In article <6933@alice.UUCP> ark@alice.UUCP writes: >>>In article <348@polyslo.UUCP>, mpatnode@polyslo.UUCP writes: >>>-> #define toupper ((isupper(c)) ? _tolower(c) : (c)) >>>Gee, I guess MSC 3.00 is broken, then. Maybe they'll fix it in 4.0 >>Its all spelled out. > >It sure is, and if MicroSoft wants to be standard-conforming, >they're going to have to fix this bug. Just because they >document it doesn't make it right. They already have it fixed, as WAS POINTED OUT IN THE ORIGINAL ARTICLE!!! ark@alice wasn't paying attention, and chopped out the part of the article that said that it was fixed in MSC 4.0. And I quote: <Message-ID: <348@polyslo.UUCP> < <In article <2065@husc6.UUCP> ddl@husc6.UUCP (Dan Lanciani) writes: <... <> Not quite. This is a no-no, but for a different reason. The macros <>toupper and tolower do not evaluate their arguments more than once. (At <>least on BSD and MSC 4.0 and other "compatible" systems.) In order to <>avoid multiple eveluation, these macros do NOT check that their arguments <>are suitable. < Well Dan this is straight out of my ctype.h: < <#define toupper ((isupper(c)) ? _tolower(c) : (c)) < < Upon closer evaluation I now see the argument is only evaluated 2 < times. But this was with MSC 3.00 so 4.0 may have change. <... PLEASE PLEASE PLEASE READ the article you are following up to!!
john@viper.UUCP (06/03/87)
In article <348@polyslo.UUCP>, mpatnode@polyslo.UUCP (Mike Patnode) writes: > > #define toupper ((isupper(c)) ? _tolower(c) : (c)) > While I'm sure this is just an oversight, I'm a bit surprised nobody else noticed and/or commented-on this... The define given is actualy the one for tolower(), not toupper() (and it's missing the dummy parameter "c").... The defines should be: #define toupper(c) (islower(c) ? _toupper(c) : (c)) #define tolower(c) (isupper(c) ? _tolower(c) : (c)) --- John Stanley (john@viper.UUCP) Software Consultant - DynaSoft Systems UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john
lombrozo@ucsbcsl.UUCP (06/05/87)
I don't suppose anyone noticed the correct #define for toupper() is: #define toupper(c) ( (islower(c)) ? _toupper(c) : (c) ) ??? lombrozo@cslvax
gwyn@brl-smoke.UUCP (06/16/87)
In article <494@ucsbcsl.UUCP> lombrozo@ucsbcsl.UUCP (Peter Lombrozo) writes: >I don't suppose anyone noticed the correct #define for toupper() is: >#define toupper(c) ( (islower(c)) ? _toupper(c) : (c) ) Nobody noticed that, because it's not true. Consider what happens if `c' has side-effects.