Tentative patch to catch a[n]=b[n++]...

Kaz Kylheku kaz@cafe.net
Mon Apr 27 11:10:00 GMT 1998


On Saturday, April 25, 1998 2:10 PM, Michael Meeks 
[SMTP:michael@imaginator.com] wrote:
>
> Hi,
>
> 	I have written a patch for gcc-2.8.1 / egcs-1.0.2 that flags
> warnings on the more simple cases of modifying a variable between sequence
> points.

However, the example given in your Subject: line isn't a case of modifying
a variable more than once between sequence points.

It is a violation of the second law: the value of a modified object shall be 
accessed
only for the purpose of computing the new value.

Suppose that a[] and b[] do not overlap. What is wrong with a[n] = b[n++]?
Clearly, no object is modified more than once. But the prior value of 'n' is
used in a subexpression which is not subordinate to the computation
of the new value, namely the subexpression which supplies the offset
into a[]. This use of n does not demonstrably precede its modification,
so it is ambiguous whether the prior value or the new value is used---or
even whether indeed some half-baked value is used. The behavior is
undefined.

I hate to ask this, but are you sure you know what you are doing? :) :)




More information about the Gcc mailing list