C
Chris Torek
BRG said:In the statement: k = x[ k ]++; [ ... snippage ]
Moreover, there appears to be nothing in the C standard to prevent
either of the interpretations:
t = k; k = x[t]; x[t]++;
[equivalently: old_val = x[k]++; k = old_val;]
or
k = x[k]; x[k]++;
[The first] is the correct implementation.
This may be the one you prefer (and the one I prefer, too!), but
unless the Standard actually *says* that, the Standard does not
*say* that.
I believe the wording in the C standards (both C89 and C99) can
reasonably be interpreted *not* to say that. In other words, the
Standard does not say what I want it to say. Too bad for me (and
you, too). So just write:
old_val = x[k]++;
k = old_val;
when you mean that -- and/or lobby for a future DR or TC and/or a
future C standard to actually *say* that the expression has to mean
what you and I want it to mean.
"If the Standard says that the result depends on the phase of the
moon, the programmer should be prepared to look out the window as
necessary." --me