www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does using "const" keyword for scalar parameters mean anything?

reply "tcak" <tcak gmail.com> writes:
[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
parent "anonymous" <anonymous example.com> writes:
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