August said:
Exactly. As I have already mentioned in this thread I wouldn't write
this kind of code myself. Would you also reject the string copy idiom
while (*t++ = *s++);
with the same motivation?
/August
No, I think that's reasonable (essentially it's describing an LDCPIR,
which one would hope the compiler would be clever enough to optimise it
into), except that if using the result of an assignment as a condition
you should enclose in an extra set of brackets. Typically your compiler
should warn you otherwise (as you might have meant == instead). Of
course, unless you want to compare to something other than zero,
string.h's strcpy() would be more appropriate.
The interesting one, though, is if you want to copy within an array,
perhaps even copying between regions which overlap - since then you need
to be able to choose whether it LDIRs or LDDRs. In that case you might
have something like
while(i++,a[i-1]=a
);
to shift down, but
while(a=a[i-1],i--);
to shift up (of course you'd have to initialise i appropriately).
You have to be careful, though, not to invoke UB with something like
that (hence why I've used separate comma expressions to inc/dec i).
-Edward