[Coco] Found strangeness in C compiler (bug)
Walter Zambotti
zambotti at iinet.net.au
Mon May 27 21:43:11 EDT 2019
Joel
Your code assumes integer not double. But aside from that...
My understanding from K&R is the right hand expression of the "=" is evaluated before the left hand side and visa-versa the left hand side is evaluated last.
So everything on the right hand side is evaluated before the assignment on the left as there is no value in assigning the result before it is calculated.
So if the right hand side contained a div by 0 for instance the left hand side would never be done.
So
*a++ = b / c; //where c = 0
Should never increment 'a' ever because an exception occurs before there is a chance to perform the assignment.
Walter
-----Original Message-----
From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of Joel Rees
Sent: Monday, 27 May 2019 8:08 PM
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Subject: Re: [Coco] Found strangeness in C compiler (bug)
hmm. Let's see what this looks like in (idealized) assembly language.
On Sat, May 25, 2019 at 8:05 AM Joel Rees <joel.rees at gmail.com> wrote:
>
> 2019年5月21日(火) 14:32 Walter Zambotti <zambotti at iinet.net.au>:
>>
>> I have a situation where the auto post-increment was occurring first.
>
>> The increment only occurs at the wrong time when the pointer types
>> are double (maybe float). So the following code works for int but not double.
>>
>> int *da, *dN ; or double *da, *dN;
* Guessing these were global, so we can keep some things simple.
da rmb 2 ; for example, this might be allocated from 0x100 dN rmb 2 ; then this would be allocated at 0x102 ...
v rmb 2 ; and this would be allocated at someplace similar.
>> *da++ = *dN++ * v - *da; // this is correct as the increment should
>> happen
ldx da ; *da++
tfr x,y ; old value of da
leax 2,x
stx da ; update da
ldx dN ; *dN
ldd ,x++
stx dN ; update dN
pshu d
ldd v ; Not pointer.
jsr multiply ; top item on U stack by d, result in d
* Now the problem -- Which da? old one in Y or new one in da?
* If old one in y
* subd ,y
* If the new one in da,
* subd [da] ; gots ta loves them indirect modes!
std ,y ; post-inc is for the store on the left side of the equals.
****
Now, that's seriously idealized code. Actual code will not be nearly as optimal.
K&R's wording left room to choose either of the above, at least, according to many compiler writers.
Does that help?
--
Joel Rees
http://reiisi.blogspot.jp/p/novels-i-am-writing.html
--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco
More information about the Coco
mailing list