What does ref means
Johannes Totz
johannes at jo-t.de
Wed Sep 7 11:50:04 PDT 2011
On 06/09/2011 12:00, bearophile wrote:
> malio:
>
>> Okay, thanks bearophile. But I currently doesn't exactly understand
>> what's the difference between "ref" and "const ref"/"immutable
>> ref". If "ref" is syntactic sugar for pointers only (like your
>> first example), does it also create a copy of the parameters which
>> are marked as "ref"? I thought that pointers (and in this context
>> also "ref") avoid the creation of costly copies?!?
>
> "ref" just passes a reference to something, so it doesn't perform
> copies.
>
> "const ref" or "immutable ref" just means that you can't change the
> value (with the usual semantic differences between const and
> immutable, that are both transitive).
So if a parameter is immutable (without ref) the compiler could infer a
ref to avoid copy because it can't be modified?
> For the programmer that reads your code, "ref" means the function you
> have written will usually modify the given argument, while "const
> ref" means it will not modify it.
More information about the Digitalmars-d-learn
mailing list