string types: const(char)[] and cstring
Reiner Pope
some at address.com
Fri May 25 23:33:30 PDT 2007
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
More information about the Digitalmars-d-announce
mailing list