A use case for fromStringz
Andrej Mitrovic
andrej.mitrovich at gmail.com
Thu Mar 31 14:23:55 PDT 2011
On 3/31/11, Jesse Phillips <jessekphillips+D at gmail.com> wrote:
> Why not:
>
> string getNameOld()
> {
> static char[256] name;
> cDispatch(name.ptr, kGetProductName);
> return to!string(name.ptr);
> }
>
Nice catch! But see my second reply. If a null terminator is missing
and we know we're operating on a D array (which has a length), then it
could be best to check for a null terminator. If there isn't one it is
highly likely that the array contains garbage.
More information about the Digitalmars-d-learn
mailing list