Ref parameter: intended behavior or bug?

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed Aug 22 17:45:46 PDT 2007


"Mike Parker" <aldacron71 at yahoo.com> wrote in message 
news:faiicj$2hms$1 at digitalmars.com...
> Yeah, I get it, but it still /feels/ inconsistent to me. If the size of a 
> class reference is 4 bytes, then it seems to me that the size of a ref 
> parameter should be the same and not the size of the object to which it 
> refers. But I suppose we aren't supposed to think of a ref parameter as a 
> true reference, but rather as a mutable view of the original data.

Right, which is more of how I've understood Walter's intentions for 'ref': 
the semantics imply a mutable view of a piece of data, but the actual 
implementation should not be revealed.  The compiler could, for example, 
pass the parameter by value into the function, and then when the function 
returns, copy that parameter back into where it came from, in which case no 
actual pointers are being used.  Of course this is a roundabout and 
ineffecient way of implementing 'ref', but according to the semantics, a 
valid one. 




More information about the Digitalmars-d-learn mailing list