digitalmars.D.learn - Why D doesn't have constant function arguments?
- Artyom Shalkhakov (6/6) Apr 03 2007 Hello everyone.
- Aarti_pl (9/19) Apr 03 2007 It is work in progress. There was lot of discussion recently on d.D NG
- Dan (10/14) Apr 03 2007 It's not really a reference. It's really just that instead of:
- Jarrett Billingsley (3/19) Apr 03 2007 But.. isn't that exactly what reference parameters in C++ do?
- Chris Nicholson-Sauls (4/29) Apr 03 2007 Except that (as I recall, its been a while) C++ referances are part of t...
- Artyom Shalkhakov (2/26) Apr 03 2007 Thanks for your answer. I'm off to read those articles.
Hello everyone. Could anyone answer my question? And there's another one: why there are no 'constant references' when passing arguments in D (like those in C++: const Type &), I suppose they would be quite useful for various applications (like, parameter passing for some maths functions). 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? Or maybe this is done the other way? The D Way? Thanks in advance.
Apr 03 2007
Artyom Shalkhakov napisał(a):Hello everyone. Could anyone answer my question? And there's another one: why there are no 'constant references' when passing arguments in D (like those in C++: const Type &), I suppose they would be quite useful for various applications (like, parameter passing for some maths functions).It is work in progress. There was lot of discussion recently on d.D NG about it recently (please read Extended Type Design - first article from 2007-03-14). D will have constants which hopefully will be much better than C++/Java.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.Best Regards Marcin Kuszczak (aarti_pl)
Apr 03 2007
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.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.Or maybe this is done the other way? The D Way? Thanks in advance.
Apr 03 2007
"Dan" <murpsoft hotmail.com> wrote in message news:euua0c$21vl$1 digitalmars.com...But.. isn't that exactly what reference parameters in C++ do?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.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.Or maybe this is done the other way? The D Way? Thanks in advance.
Apr 03 2007
Jarrett Billingsley wrote:"Dan" <murpsoft hotmail.com> wrote in message news:euua0c$21vl$1 digitalmars.com...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-SaulsBut.. isn't that exactly what reference parameters in C++ do?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.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.
Apr 03 2007
Aarti_pl Wrote:Artyom Shalkhakov napisał(a):Thanks for your answer. I'm off to read those articles.Hello everyone. Could anyone answer my question? And there's another one: why there are no 'constant references' when passing arguments in D (like those in C++: const Type &), I suppose they would be quite useful for various applications (like, parameter passing for some maths functions).It is work in progress. There was lot of discussion recently on d.D NG about it recently (please read Extended Type Design - first article from 2007-03-14). D will have constants which hopefully will be much better than C++/Java.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.Best Regards Marcin Kuszczak (aarti_pl)
Apr 03 2007