digitalmars.D.learn - Does using "const" keyword for scalar parameters mean anything?
[code] void test( const int a ){} [/code] Does that "const" make any difference at all? At the end, it is a scalar, and passed as value.
Jun 04 2015
On Thursday, 4 June 2015 at 11:28:51 UTC, tcak wrote:[code] void test( const int a ){} [/code] Does that "const" make any difference at all? At the end, it is a scalar, and passed as value.All it does is it makes the variable "a" const: ---- void test( const int a ) { a = 42; /* Error: cannot modify const expression a */ } ---- But the value is copied, yes. You can pass a mutable int in an immutable parameter and vice-versa.
Jun 04 2015