const a storage class or a type modifier?
Andrej Mitrovic
andrej.mitrovich at gmail.com
Sun Nov 28 05:48:50 PST 2010
I think scope needs to be documented better in the docs. I didn't even
know it could be used in the parameter list, or what it does for that
matter.
On 11/28/10, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Sunday 28 November 2010 05:28:45 Andrej Mitrovic wrote:
>> AFAIK "in" will guarantee you can't change a variable, even when using
>> arrays, e.g.:
>>
>> void foo(in int[] a) {
>> int[] b;
>> a[0] = 1; // won't compile
>> a = b; // won't compile (I think?)
>> }
>>
>> void foo(int[] a) {
>> int[] b;
>> a[0] = 1; // compiles, and changes are reflected in the caller
>> a = b; // compiles, but it doesn't change "a" in the calling code
>> }
>>
>> I don't have DMD on this PC so I haven't tested it.
>
> Well, in is essentially an alias for const scope, so no, you can't change
> any
> variables marked in. And since const is transitive, that includes anything
> that
> the variable references. So, arrays marked with in are fully const and
> cannot be
> altered in any way.
>
> - Jonathan M Davis
>
More information about the Digitalmars-d
mailing list