"immutable string" vs "const string*"

rikki cattermole rikki at cattermole.co.nz
Sun Sep 9 08:49:56 UTC 2018


On 09/09/2018 8:41 PM, Christian Mayer wrote:
> On Sunday, 9 September 2018 at 08:14:41 UTC, rikki cattermole wrote:
> 
>> Are you aware that a string is just an alias of immutable(char)[]?
> 
> Yes, I'm aware of that. But it's the same, for example, with just one 
> char. "immutable char" vs "const char*".
> 
> Or int, or any other data type. As of my current understanding "char" 
> will create a new variable and copy the content of the original to the 
> new variable. "char*" will just use the pointer. And "const char*" is 
> good for when not modifying. But I also can achieve the same using 
> "immutable char". But I'm not sure when better using "immutable char".
> 
> In C I would rather use a const pointer. But since I just started 
> learing D I'm not so sure because there are so many ways.

Don't over think it. The only thing you're doing by micro-optimization 
is causing potential problems that wouldn't otherwise exist.


More information about the Digitalmars-d-learn mailing list