Convert string[] to char**

David d at dav1d.de
Tue Jun 4 05:07:32 PDT 2013


Am 04.06.2013 13:49, schrieb Bruce Smith:
> Thank you Jacob and bearophile ... just had to add a cast to get rid of
> immutable from your suggestion. For completeness, this compiles under
> 2.063:
> 
>     void foo(char** k)
>     {
>         // body
>     }
> 
>     string[] mykeys;
>     auto ckeys = cast(char**)mykeys.map!toStringz.array;
> 
>     foo(ckeys);
> 
> Bruce
> 
> On 04/06/13 20:59, Jacob Carlborg wrote:
>> On 2013-06-04 12:41, bearophile wrote:
>>
>>> An alternative is something like (untested):
>>>
>>> auto ckeys = mykeys.map!toStringz.array;
>>
>> Right, that should work.
>>
> 

Casting it isn't the best way here, you shouldn't cast immutability
away, make sure your function does not mutate it (it must not!) then you
could change the function signature to const(void*)*, otherwise use
char[] instead of string, this should do it:

mykeys.map!(x => x.dup.toStringz).array


More information about the Digitalmars-d mailing list