[Coco] help with C problem
Gene Heskett
gene.heskett at verizon.net
Mon Jan 2 11:19:17 EST 2006
On Monday 02 January 2006 08:59, Bob Devries wrote:
>Thanks, Robert. I, too realised that it was that sex that caught me,
> but there was another error I overlo0oked as well.
>
>I replaced this line:
> while ((int)*s2 < 128) { /* line 8*/
>with:
> while (((int)*s2 & 0xFF) < 128) {
>but I also needed to save a copy of the pointer to the start of the
> s1 char array, since I modified it in the routine.
>
>The resulting code is now:
>char *
>strhcpy(s1, s2)
>char *s1;
>char *s2;
>{
> char *temp;
> temp = s1;
> while (((int)*s2 & 0xFF) < 128) {
> *s1++ = *s2++;
> }
> *s1++ = *s2++ & 0x7F;
> *s1 = '\0';
>
> return (temp);
>}
>
>which works as intended.
This while statement then is going to be forever true if its a '< 128'
test if what its being compared to has been anded with 0xFF(127
decimal). In my mind anyway, it still needs a stopper of '<=127'.
Or am I not understanding what it is that you want to do, Bob?
>Thanks for the help.
>--
>Regards, Bob Devries, Dalby, Queensland, Australia
>
>Isaiah 50:4 The sovereign Lord has given me
>the capacity to be his spokesman,
>so that I know how to help the weary.
>
>website: http://www.home.gil.com.au/~bdevasl
>my blog: http://bdevries.invigorated.org/
>
>----- Original Message -----
>From: "Robert Gault" <robert.gault at worldnet.att.net>
>To: "CoCoList for Color Computer Enthusiasts" <coco at maltedmedia.com>
>Sent: Monday, January 02, 2006 11:38 PM
>Subject: Re: [Coco] help with C problem
>
>> Assuming there is not a BUG, looks like the error is dependent on
>> the software in use. This works with Microware C in OS-9. The
>> crucial lines might be found if you can get the program saved as an
>> .a file.
>>
>> _3 (int)*s2 < 128
>> ldb [6,s]
>> sex
>> cmpd #128
>> lblt _4
>>
>> If there is no equivalent to sex on your system or there is some
>> other size mismatch, then maybe (int)*s2 will always be less than
>> 128. Turns out that in OS-9 you get the exact same conversion with
>> *s2<128, (char)*s2 < 128, or (short)*s2 <128.
>>
>> If the OS-9 package is not "outside the pale" for C usage, then
>> most likely char *s2 or (int)*s2 does not result in what you are
>> expecting.
>>
>> Bob Devries wrote:
>>> To all you C gurus: I have a problem with compiling the following
>>> code:
>>>
>>> char *
>>> strhcpy(s1, s2)
>>> char *s1;
>>> char *s2;
>>> {
>>> while ((int)*s2 < 128) { /* line 8*/
>>> *s1++ = *s2++;
>>> }
>>> *s1++ = *s2++ & 0x7F;
>>> *s1 = '\0';
>>> return (s1);
>>> }
>>>
>>> The compiler always gives a warning in line 8: [Warning]
>>> comparison is always true due to limited range of data type
>>>
>>> Can someone PLEASE tell me what I'm doing wrong?
>>> Yes, you're right, I'm trying to write a PC version of the OS9
>>> library function strhcpy().
>>>
>>> --
>>> Regards, Bob Devries, Dalby, Queensland, Australia
>>>
>>> Isaiah 50:4 The sovereign Lord has given me
>>> the capacity to be his spokesman,
>>> so that I know how to help the weary.
>>>
>>> website: http://www.home.gil.com.au/~bdevasl
>>> my blog: http://bdevries.invigorated.org/
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> http://five.pairlist.net/mailman/listinfo/coco
--
Cheers, Gene
People having trouble with vz bouncing email to me should add the word
'online' between the 'verizon', and the dot which bypasses vz's
stupid bounce rules. I do use spamassassin too. :-)
Yahoo.com and AOL/TW attorneys please note, additions to the above
message by Gene Heskett are:
Copyright 2005 by Maurice Eugene Heskett, all rights reserved.
More information about the Coco
mailing list