Style (was: C-DATABASE B-PLUS a quick look)
Bruce Becker
bdb at becker.UUCP
Fri Dec 30 19:45:32 AEST 1988
In article <2537 at xyzzy.UUCP> throopw at xyzzy.UUCP (Wayne A. Throop) writes:
>[...]
> for( p = s; *p ++p )
> if( *p >= 0 )
> *p = toupper( *p );
>
>because all functions defined in ctype.h take arguments that
>are integers, but give defined results only if those integers have
>values representable as unsigned integer (or are the constant EOF).
>
>Thus, the test for negative values is (I *think*) necessary. Unless,
>of course, you are willing to otherwise ensure that s only points at
>strings of vanilla characters... then the loop is OK as it was.
I'd like to point out a (possibly icky) variant -
for( p = s; *p ++p )
*p = toupper( *p&0xff );
This gets at possible 256-character sets in the
environments where the compiler &/| hardware has
sign-extended the negative byte value.
Not all _ctype arrays have the same range - some
are only 128 bytes. In those cases the '0xff' above
becomes '0x7f'.
It might be useful to add that testing for EOF is
possible - this raises the question of its value.
Ought it to be -1, or 0xFF, or what? I'm confused
about what the value of "toupper(EOF)" should be...
>Wayne Throop <the-known-world>!mcnc!rti!xyzzy!throopw
Cheers,
--
_ _/\ Bruce Becker Toronto, Ont.
\`o O| Internet: bdb at becker.UUCP, bruce at gpu.utcs.toronto.edu
\(")/ BitNet: BECKER at HUMBER.BITNET
---mm-U-mm--- "The OSF is suffering from Penix envy" - Rocky Raccoon
More information about the Comp.lang.c
mailing list