www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - inout verses ref

reply Spacen Jasset <spacenjasset yahoo.co.uk> writes:
These two attributes seem to do similar things. Infact, do they do the 
same thing? Or is it that in the case of ref a reference is passed, and 
in the case of inout a value is copies in via the stack and then passed 
back out?

Why would one use inout instead of ref since inout must be slower for 
larger objects.
Mar 10 2008
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Spacen Jasset" <spacenjasset yahoo.co.uk> wrote in message 
news:fr3m65$bse$1 digitalmars.com...
 These two attributes seem to do similar things. Infact, do they do the 
 same thing? Or is it that in the case of ref a reference is passed, and in 
 the case of inout a value is copies in via the stack and then passed back 
 out?

 Why would one use inout instead of ref since inout must be slower for 
 larger objects.
They are exactly the same. There is no semantic difference, only what word is used. 'ref' was introduced in anticipation of reference return values or possibly even general reference types. Having an 'inout' return value or an 'inout' integer doesn't make much sense other than with parameters, but 'ref' does.
Mar 10 2008