[Coco] Found strangeness in C compiler (bug)
joel.rees at gmail.com
Mon May 27 08:07:50 EDT 2019
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
stx da ; update da
ldx dN ; *dN
stx dN ; update dN
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?
More information about the Coco