Re: <ctype.h> toLower()
From: Greg Comeau (comeau_at_panix.com)
Date: 12/05/03
- Next message: Jon Cosby: "Re: Hashmaps"
- Previous message: Greg Comeau: "Re: look for C++ "Keith Gorlen smalltalk like classes" or NIHCL"
- In reply to: Jumbo: "Re: <ctype.h> toLower()"
- Next in thread: Jumbo: "Re: <ctype.h> toLower()"
- Reply: Jumbo: "Re: <ctype.h> toLower()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 5 Dec 2003 10:27:56 -0500
In article <1070617947.62507@news.minx.net.uk>,
Jumbo <pcrcutitout1000011@uko2.co.uk> wrote:
>"Karl Heinz Buchegger" <kbuchegg@gascad.at> wrote in message
>news:3FD04B38.E3284974@gascad.at...
>> Jumbo wrote:
>> > I can't argue with that I better fix it straight away.
>> >
>> > int lowerize(char* dest, char* src){
>> > try{ dest[0] = src[0]; }
>> > catch(...){ return -1; }
>> > int _length = strlen(src);
>> > for(int i=0; i<=_length;i++)
>> > {
>> > dest[i] = tolower(src[i]);
>> > }
>> > return 1;
>> > }
>> >
>> > Returns -1 if error occurs.
>> > Returns 1 if no error occurs.
>> >
>>
>> Not true.
>> Assigning anything to a constant string literal brings up undefined
>> behaviour. Anything can happen and that includes: works as expected.
>>
>> Eg. the following can happen:
>>
>> ....
>>
>> int main()
>> {
>> lowerize( "HI ALL", "HELLO" );
>> printf( "HI ALL" );
>> printf( "\n" );
>> }
>>
>> And the program does not crash or throw an exception
>> but instead prints
>> hello
>
>No it doesn't .. It prints....
>HI ALL
He didn't say does, he said "can happen". And it can.
Granted, it may pring "HI ALL" for your machine.
But that was exactly Karl's point, since it's undefined behavior
it may do different things on different platforms, different
compilers, etc.
>It doesn't throw an exception, but it catches and handles one. The function
>returns -1 if it encounters an exception, otherwise it returns 1.
On which machine/platform/compiler do you know that it does that?
-- Greg Comeau/4.3.3:Full C++03 core language + more Windows backends Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90. Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
- Next message: Jon Cosby: "Re: Hashmaps"
- Previous message: Greg Comeau: "Re: look for C++ "Keith Gorlen smalltalk like classes" or NIHCL"
- In reply to: Jumbo: "Re: <ctype.h> toLower()"
- Next in thread: Jumbo: "Re: <ctype.h> toLower()"
- Reply: Jumbo: "Re: <ctype.h> toLower()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|