Why D doesn't have constant function arguments?

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Apr 3 15:07:42 PDT 2007


"Dan" <murpsoft at hotmail.com> wrote in message 
news:euua0c$21vl$1 at digitalmars.com...
>
>> > I think that 'inout' could be used in place of C++'s const references, 
>> > but how does it work? Is this a masked pointer or something?
>
>> AFAIK 'inout' is similar to C++ passing by reference.
>
>> > Or maybe this is done the other way? The D Way?
>> > Thanks in advance.
>
> It's not really a reference.  It's really just that instead of:
>
> int f1(int x){  <-- makes a copy of x, puts it on the stack
>  x += 3;  <-- affects the copy on the stack, not the original
>  return x;
> }
>
> int f2(inout int x){ <-- does not copy the data, uses the original 
> register or memory location.
>  x += 3;  <-- affects the original
>  return x;
> }
>
> That's the difference.

But.. isn't that exactly what reference parameters in C++ do? 




More information about the Digitalmars-d-learn mailing list