D2 toStringz Return Type
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Nov 7 11:38:24 PST 2008
Steven Schveighoffer wrote:
> "Andrei Alexandrescu" wrote
>> Mike Parker wrote:
>>> I'm curious as to why toStringz in D2 returns const(char)* instead of
>>> just a plain char*. Considering that the primary use case foe the
>>> function is interfacing with C code, it seems rather pointless to return
>>> a const(char)*.
>> We want to leave the opportunity open to not duplicate the actual memory
>> underneath the string object. (Right now that opportunity is not
>> effected.)
>
> My recommendation -- have 2 functions. One which always copies (and returns
> char *), and one which does not.
>
> This at least leaves a safe alternative for people who have headers that
> aren't properly constified, and don't want to go through the hassle of
> looking it up themselves. Also good for those C functions which actually
> require a mutable char *, since D2 strings are mostly invariant.
You can't quite do that because dynamic conditions establish whether
it's safe to avoid copying or not.
Andrei
More information about the Digitalmars-d
mailing list