string types: const(char)[] and cstring

Daniel Keep daniel.keep.lists at gmail.com
Sat May 26 00:24:38 PDT 2007



Reiner Pope wrote:
> Walter Bright wrote:
>> Under the new const/invariant/final regime, what are strings going to
>> be ? Experience with other languages suggest that strings should be
>> immutable. To express an array of const chars, one would write:
>>
>>     const(char)[]
>>
> ....
>> String literals, on the other hand, will be invariant (which means
>> they can be stuffed into read-only memory). So,
>>     typeof("abc")
>> will be:
>>     invariant(char)[3]
> 
> The thing I don't get about this syntax is what happens when you take
> off the [].
> 
> 1.   invariant(char) c = 'b'; // c is 'b' now, and will never change.
> 2.   final(char) d = 'b';     // but calling it final means the same...
> 3.   const(char) e = 'b';     // ummm... what?
> 
> It seems like const(char) is a constant char -- one that can't change.
> Does that make final obsolete?
> 
> Also, I can't see any difference between const(char) and
> invariant(char), since neither can ever be rebound. In that case, if I
> assume that they are identical types, how can an array of const(char) be
> different from an array of invariant(char)?
> 
> -- Reiner

This is what I'm wondering; I thought const and invariant only applied
to reference types (which is why we have final as storage const), in
which case, const(char)[] doesn't make any sense...

	-- Daniel

-- 
int getRandomNumber()
{
    return 4; // chosen by fair dice roll.
              // guaranteed to be random.
}

http://xkcd.com/

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d-announce mailing list