[Coco] Found strangeness in C compiler (bug)

Walter Zambotti zambotti at iinet.net.au
Tue May 21 01:39:49 EDT 2019


Actually I did manage to make an isolated example.

Walter

-----Original Message-----
From: Coco [mailto:coco-bounces at maltedmedia.com] On Behalf Of Walter Zambotti
Sent: Tuesday, 21 May 2019 1:32 PM
To: 'CoCoList for Color Computer Enthusiasts' <coco at maltedmedia.com>
Subject: [Coco] Found strangeness in C compiler (bug)

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;

 

*da++ = *dN++ * v - *da; // this is correct as the increment should happen after the assignment.

*da++ = *dN++ * v - *da;

*da = *dN * v - da*;

 

The auto post increment on the left hand side of the "=" should occur after the assignment but it was occurring first.

 

So I fixed the problem by converting the code to: (this code works for all)

 

*da = *dN++ * v - *da; da++;  // this is correct by intention

*da = *dN++ * v - *da; da++;

*da = *dN * v - da*;

 

Or (this code incorrectly works for doubles and correctly fails for ints)

 

*da = *dN++ * v - *da++;  // this is wrong as the expression on the right increments da before it is assigns the value to where da points.

*da = *dN++ * v - *da++;

*da = *dN * v - da*;

 

Ensuring the increment occurred last in order to get it working.

 

However when I can't duplicate the problem in an isolated example.  

 

Do we have the C source anywhere?

 

Walter


--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco



More information about the Coco mailing list