June 04, 2015 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. |
June 04, 2015 Re: Does using "const" keyword for scalar parameters mean anything? | ||||
---|---|---|---|---|
| ||||
Posted in reply to tcak | 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.
|
Copyright © 1999-2021 by the D Language Foundation