[Coco] help with C problem

Bob Devries devries.bob at gmail.com
Mon Jan 2 08:59:19 EST 2006


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.
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 




More information about the Coco mailing list