Why D doesn't have constant function arguments?
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Tue Apr 3 16:20:49 PDT 2007
Jarrett Billingsley wrote:
> "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?
>
>
Except that (as I recall, its been a while) C++ referances are part of the type, whereas
D's 'inout' is just a storage class.
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list