const?? When and why? This is ugly!
Walter Bright
newshound1 at digitalmars.com
Sat Mar 7 19:31:49 PST 2009
Andrei Alexandrescu wrote:
> Walter Bright wrote:
>> If I may restate your case, it is that given function that does
>> something with character arrays:
>>
>> int foo(string s);
>>
>> and you wish to pass a mutable character array to it. If foo was
>> declared as:
>>
>> int foo(const(char)[] s);
>>
>> then it would just work. So why is it declared immutable(char)[] when
>> that isn't actually necessary?
>>
>> The answer is to encourage the use of immutable strings. I believe the
>> future of programming will tend towards ever more use of immutable
>> data, as immutable data:
>>
>> 1. is implicitly sharable between threads
>
> In fact const data is also implicitly sharable between threads.
No. You have to declare it "shared const" to make it sharable between
threads.
More information about the Digitalmars-d
mailing list