string types: const(char)[] and cstring

Walter Bright newshound1 at digitalmars.com
Fri May 25 22:08:16 PDT 2007


Myron Alexander wrote:
> Walter Bright wrote:
>> Daniel Keep wrote:
>>
>> const(char)[] => array of const characters
>> const char[] => const array of const characters
>> const(char[]) => const array of const characters
>>
>> Think of const as if it were a template:
>>
>>     Const!(T)
>>
>> which returns a const version of its argument.
>>
>> const without any parens means it applies to the whole type.
> 
> Looking mighty fine.

I like it a lot better than the C++ "here a const, there a const, 
everywhere a const const" like:

	const char * const * const p;

etc. instead of:

	const(char**) p;

Const in D is transitive, so const(char**) is equivalent to:

	const(const(const(char)*)*)

And no, it is not possible to have a pointer to const pointer to 
mutable. It is both not possible syntactically to declare it, nor is it 
  semantically allowed. You can force the issue with casts (which allow 
you to do whatever you *need* to do), but the result will be undefined 
behavior.



More information about the Digitalmars-d-announce mailing list