larsjensen at rcn dot com wrote:
> then I get an error, it's straightforward for me to convert it to this:
>
> dim i as integer = myObject.myProperty
> MyMethod(i)
> myObject.myProperty = i
>
> What's stopping the compiler from doing that allocation of temporary
> storage, and doing the assignment on return?
It would introduce a side-effect. You must assume that neither MyMethod nor
any of the methods it could potentially call could ever care about the fact
that myObject.myProperty does not *actually* equal i until after MyMethod
returns. You can make this assumption, since you wrote the code and know
what it expects; the compiler does not know what you intended and must stick
to the face value of the expression.
Besides, it would make the ByRef rules more confusing. Right now it's
simple: "no expressions, simple variables only".
Mars Saxman
REAL Software
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>
|