Randy Kramer wrote:
> [EMAIL PROTECTED] wrote:
> > Can we have a sort of middle point here?
> >
> > x = x * y should be replaced by x *= y
>
> (A newbie C/C++ question:)
>
> Just out of curiosity, is that just a "cosmetic" change, or does that
> actually change the machine code emitted by the compiler?

Both. It does affect semantics of the expression. For the expression
  x = x * y

the non-optimizing compiler generates something like
  tmp = x.operator*(y);
  x = tmp;

while
  x *= y
becomes
  x.operator*=(y);

For POD (Plain Old Data) types any reasonable optimizer generates the same
code, but for an unoptimized build or when using non-trivial objects it can
make quite a difference.

/Mike



Reply via email to