[comp.lang.c] Why is tolower behave different???

shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) (07/20/90)

I just finished porting a software package that ran on a VAX 11/780
to a Sun SPARCserver. One of the programs would not run. (Could not find
the filename specified.). The program was looking for a certain extension,
but could not find it.

Finally, it dawned on me that the function call tolower was to blame.
On the VAX, the call did nothing if the char was already lowercase, while
the Sun converted it anyway.

I know, I know... RTFM. The FM does say this also.

What a pain in the ...

I wonder what other little gotchas there are...


-- 
Steve Hodsdon                          | Stay sane inside insanity.
shodsdon@elrond.CalComp.COM            | Don't dream it, be it.
{decvax|harvard}!elrond!shodsdon       |
(603) 885-8324                         |

diamond@tkou02.enet.dec.com (diamond@tkovoa) (07/23/90)

In article <2841@elrond.CalComp.COM> shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) writes:

>I just finished porting a software package that ran on a VAX 11/780
>to a Sun SPARCserver. One of the programs would not run.
>Finally, it dawned on me that the function call tolower was to blame.
>On the VAX, the call did nothing if the char was already lowercase, while
>the Sun converted it anyway.
>I know, I know... RTFM. The FM does say this also.

Huh?  File a bug report.  Tell Sun to RTFS.

It's nice to see that the VAX compiler conforms more closely to the
standard than Sun does.

-- 
Norman Diamond, Nihon DEC     diamond@tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.

bruce@seismo.gps.caltech.edu (Bruce Worden) (07/23/90)

In article <1863@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com (diamond@tkovoa) writes:
>In article <2841@elrond.CalComp.COM> shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) writes:
>
>>I just finished porting a software package that ran on a VAX 11/780
>>to a Sun SPARCserver. One of the programs would not run.
>>Finally, it dawned on me that the function call tolower was to blame.
>>On the VAX, the call did nothing if the char was already lowercase, while
>>the Sun converted it anyway.
>>I know, I know... RTFM. The FM does say this also.

>Huh?  File a bug report.  Tell Sun to RTFS.

No don't file a bug report.  The tolower() function (it is a function 
now) works as per the ANSI standard under SunOS 4.1.  It did have
the described behavior up to and including SunOS 4.0.3.  I do believe
however that, in the pre-ANSI standard version of K&R, it is not
quite clear what behavior tolower() should have when the argument
is already lower case.  I can't find an explicit statement.  Do note,
however, that the example program given checks the case of the 
argument before calling tolower().  In the absence of an explicit
statement Sun may have opted for the simplest implementation, if not
the most benign.

--------------------------------------------------------------------------
Bruce Worden				bruce@seismo.gps.caltech.edu
Seismological Laboratory
Caltech
--------------------------------------------------------------------------

boylanr@silver.ucs.indiana.edu (ross boylan) (07/24/90)

diamond@tkou02.enet.dec.com (diamond@tkovoa) writes:

>In article <2841@elrond.CalComp.COM> shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) writes:

>>I just finished porting a software package that ran on a VAX 11/780
>>to a Sun SPARCserver. One of the programs would not run.
>>Finally, it dawned on me that the function call tolower was to blame.
>>On the VAX, the call did nothing if the char was already lowercase, while
>>the Sun converted it anyway.
>>I know, I know... RTFM. The FM does say this also.

>Huh?  File a bug report.  Tell Sun to RTFS.

I recall having a similar problem with tolower, but I think it's a
"feature" not a bug.  On some systems tolower is only defined for
upper case laters--that is, it will do strange things to non-upper
case letters.  May be a Unix Sys V v. BSD difference.  The world would

wht@n4hgf.Mt-Park.GA.US (Warren Tucker) (07/24/90)

>>>Finally, it dawned on me that the function call tolower was to blame.
>>>On the VAX, the call did nothing if the char was already lowercase, while
>>>the Sun converted it anyway.

System 5-derived tolower() absolutely coverts, while BSD 
does the equivalent
   if isupper(ch) convert

ANSI aside, I'll always code
   if(isupper(ch))
		ch = tolower(ch);
to be safe.
 
----------------------------------------------------------------------
Warren Tucker, TuckerWare   emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
"It was electrons that brought down the Berlin Wall." -- Timothy Leary

johnb@srchtec.UUCP (John Baldwin) (07/24/90)

In article <1863@tkou02.enet.dec.com> diamond@tkou02.enet.dec.com
(diamond@tkovoa) writes:
>
>...  Tell Sun to RTFS.
                  ^^^^
I LOVE IT!  Great new acronym!
-- 
John T. Baldwin            | Disclaimer:
search technology, inc.    |    Some people claim I never existed.
Norcross, Georgia          | (real .sig under construction
johnb@srchtec.uucp         |  at Starfleet Orbital Navy Yards ;-)

merriman@ccavax.camb.com (07/24/90)

In article <2841@elrond.CalComp.COM>, 
	shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) writes:
> I just finished porting a software package that ran on a VAX 11/780
> to a Sun SPARCserver. One of the programs would not run. (Could not find
> the filename specified.). The program was looking for a certain extension,
> but could not find it.
> 
> Finally, it dawned on me that the function call tolower was to blame.
> On the VAX, the call did nothing if the char was already lowercase, while
> the Sun converted it anyway.

Converted it to what?

henry@zoo.toronto.edu (Henry Spencer) (07/24/90)

In article <1990Jul23.040004.12292@laguna.ccsf.caltech.edu> bruce@seismo.gps.caltech.edu (Bruce Worden) writes:
>... in the pre-ANSI standard version of K&R, it is not
>quite clear what behavior tolower() should have when the argument
>is already lower case...

The only explicit statement you will find about tolower()'s behavior in
the early days was that given an uppercase letter, it produced the
corresponding lowercase letter.  Its behavior on any other input was
in fact undefined.
-- 
NFS:  all the nice semantics of MSDOS, | Henry Spencer at U of Toronto Zoology
and its performance and security too.  |  henry@zoo.toronto.edu   utzoo!henry

shodsdon@elrond.CalComp.COM (Steve V. Hodsdon) (07/25/90)

In article <174@n4hgf.Mt-Park.GA.US> wht@n4hgf.UUCP (Warren Tucker) writes:
>
>System 5-derived tolower() absolutely coverts, while BSD 
                            ^^^^^^^^^^^^^^^^^^
Just aother little gotcha: Motorola's sysV68 R3.5 checks first before
converting to lower (or upper). There is the macro's _tolower and _toupper
which assume the 'proper case'.
 
>----------------------------------------------------------------------
>Warren Tucker, TuckerWare   emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
>"It was electrons that brought down the Berlin Wall." -- Timothy Leary


-- 
Steve Hodsdon                          | Stay sane inside insanity.
shodsdon@elrond.CalComp.COM            | Don't dream it -  Be it.
{decvax|harvard}!elrond!shodsdon       |
(603) 885-8324                         |