Given the following expression, where A and B stand for arbitrary operands (e.g. local or global variables, values returned by functions, etc.)
A -= B;
Can we always replace this with the following without changing meaning?
(type of A)* temp = &(A);
(*temp) = (*temp) - B;
return (*temp); // implicit
It seems to work, as long as the type of A is not volatile/atomic.
Simple test case:
extern int f (void);
return *f() -= 5;
// is equivalent to
(int)* temp = &(*f()); // single call to function
(*temp) = (*temp) - B;
return (*temp);
Another:
extern int * p;
return p -= 5;
// is equivalent to
(int*)* temp = &(p);
(*temp) = (*temp) - 5; // pointer arithmetic works fine
return (*temp);