const a storage class or a type modifier?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Nov 28 05:28:45 PST 2010


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.

On 11/28/10, Jens Mueller <jens.k.mueller at gmx.de> wrote:
> Don wrote:
>> Jens Mueller wrote:
>> >Walter Bright wrote:
>> >>const in D1 is a storage class, in D2 it's a type modifier. The web
>> >>page needs updating.
>> >
>> >I'm attaching an svn diff. Can you apply it? Since one doesn't need to
>> >care about const then maybe one should drop the complete section. What
>> >do you think?
>> >I find this converting tutorial quite useful. Is there anything else
>> >missing or wrong? I'd like to adjust it because it helps people to add C
>> >libraries to D.
>> >
>> >Jens
>>
>> I removed the section entirely for D2. It remains unaltered for D1.
>> http://www.dsource.org/projects/phobos/changeset/2201
>
> Removing it leaves some questions open. At least the current thread
> revealed some problems. What about the attached update?
>
> Jens
>


More information about the Digitalmars-d mailing list