[Coco] Microware C question/problem
James Jones
jamesjones01 at mchsi.com
Sun Apr 9 23:54:32 EDT 2006
Bob Devries wrote:
> besides that, the code output for "/"||"\\" is:
> ldd #1
> very odd indeed.
You can thank what optimization the compiler does. Remember what || is
defined to do: x || y has the same result as
x ? 1 : (y ? 1 : 0)
"/", being a string constant, evaluates to a pointer to the first
character of the string. It's guaranteed that NULL (0) is not equal to
the address of anything, so "/" || "\\" can be evaluated at compile time
to the constant 1.
It looks like the original author was looking for the last character in
the string that is either a slash or a backslash, and did the moral
equivalent of someone who writes
n == 2 || 3
and expects it to evaluate to 1 if n is either equal to 2 or equal to 3.
James
> --
> 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: Saturday, December 31, 2005 11:33 AM
> Subject: [Coco] Microware C question/problem
>
>
>> I am trying to test a library function in Microware C. A very strange
>> bug was found for which I can't find a source. Here is the library
>> call that causes the problem. Ignore whether the C syntax is correct
>> but just look at the resulting asm code.
>>
>> n = strrchr(*file, "/" || "\\");
>>
>> Partial output from c.pass2
>>
>> lead _3,pcr
>> lbne _6
>> _7
>> lead _4,pcr
>>
>> Clearly this is not legal code because of the lead. If the || "\\" is
>> removed from the source, the lead goes away.
>>
>> What is causing this bad asm code? It seems to be a c.pass2 problem
>> but I've compiled some very large C programs and never seen anything
>> like this before.
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> http://five.pairlist.net/mailman/listinfo/coco
>>
>>
>> --
>> No virus found in this incoming message.
>> Checked by AVG Free Edition.
>> Version: 7.1.371 / Virus Database: 267.14.9/217 - Release Date:
>> 30/12/2005
>>
>>
>
>
More information about the Coco
mailing list