[Coco] Found strangeness in C compiler (bug)

Mark McDougall msmcdoug at iinet.net.au
Tue May 21 02:05:48 EDT 2019


On 21/05/2019 3:32 pm, Walter Zambotti wrote:

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

I think you'll find this behaviour is undefined by the standard, which 
is why you have inconsistent results depending on type.

It's not something I'd code that way in any case. I think your "work 
around" is better (more readable/maintainable) code.

Regards,

---8<------8<------8<------8<------8<------8<------8<------8<------8<------8<---

2) Between the previous and next sequence point, the prior value of a 
scalar object that is modified by the evaluation of the expression, must 
be accessed only to determine the value to be stored. If it is accessed 
in any other way, the behavior is undefined.

cout << i << i++; // undefined behavior (until C++17)
a[i] = i++; // undefined behavior (until C++17)



-- 
Mark McDougall
<http://retroports.blogspot.com.au>


More information about the Coco mailing list