Path: utzoo!censor!becker!bdb From: bdb@becker.UUCP (Bruce Becker) Newsgroups: comp.lang.c Subject: Re: Style (was: C-DATABASE B-PLUS a quick look) Keywords: kluge Message-ID: <189@becker.UUCP> Date: 30 Dec 88 09:45:32 GMT References: <2537@xyzzy.UUCP> Reply-To: bdb@becker.UUCP (Bruce Becker) Organization: G. T. S., Toronto, Ontario Lines: 42 In article <2537@xyzzy.UUCP> throopw@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 !mcnc!rti!xyzzy!throopw Cheers, -- _ _/\ Bruce Becker Toronto, Ont. \`o O| Internet: bdb@becker.UUCP, bruce@gpu.utcs.toronto.edu \(")/ BitNet: BECKER@HUMBER.BITNET ---mm-U-mm--- "The OSF is suffering from Penix envy" - Rocky Raccoon