Re: MS VisualStudio C++ specific fixes

From: Robert Collins <robertc@dont-contact.us>
Date: 25 Nov 2002 20:37:16 +1100

On Mon, 2002-11-25 at 21:27, Henrik Nordstrom wrote:
> Does not surprise me.. type converted items are generally r-value only.
> (l = left, r = right, as to where they may be used in the = operator)
>
> In the code as shown the compiler is wise to at least warn about the use
> of ++ and should preferably not allow such code as it is quite likely
> not what the programmer intended in more complex cases. The assignment
> side effect of ++ is discarded there as it is done on a temporary
> r-value int object who is not saved anywhere (not even in a local).

Oops. Ahm. Errm. Well. BLUSH.

> A more sane implementation of the snippet below is
>
> aLogType = (log_type) ((int)aLogType) + 1;
>
> or expanded similar to your proposal to avoid deep nesting of type
> conversions:
>
> int i = (int)aLogType;
> aLogType = (aLogType)(i + 1);
>
> Alternatively the operator can be implemented as a friend who is allowed
> to operate directly on the internal representation of aLogType to
> implement ++.

aLogType is an enum. The only reason for the operator ++ is to prevent
rewriting loop code in the short term.

Rob

Received on Mon Nov 25 2002 - 03:35:59 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:18:49 MST