char ***argc problems.

Simen Kjaeraas simen.kjaras at gmail.com
Sun Aug 12 13:51:36 PDT 2012


On Sun, 12 Aug 2012 22:30:57 +0200, Andrew <andrew.spott at gmail.com> wrote:

> I'm attempting to create a wrapper for MPI, however, MPI_Init
> wants to read the arguments for main():
>
> MPI_Init(int *argv, char ***argc);
>
> How do I get this last level of pointer reference?
>
> So far, I have:
>
> void main (string[] args)
> {
>       auto argarr = new char*[args.length];
>       foreach(i, a; args)
>           argarr[i] = (a.dup ~ '\0').ptr;
>
>       int argc = to!(int)(argarr.length);
>       MPI_Init(&argc, argarr.ptr);
> }
>
> Any ideas?


     // Array of pointers to command line parameters.
     char*[] argv = args.map!((a)=>(a.dup~'\0').ptr).array;
     // Address of first element of that array.
     char** argvp = &argv[0];
     // And finally, address of the pointer to that first element.
     char*** argvpp = &argvp;

Now, the interesting part is reconstructing the string[] from
the potentially modified argvpp...

-- 
Simen


More information about the Digitalmars-d-learn mailing list