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

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...

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...

You know.. it'd be much simpler if argc & argv were stored somewhere.
druntime/src/rt/dmain2.d is where the action begins:
extern (C) int main(int argc, char** argv) { ... }
And then this is stored as a string[] to _d_args which can be picked
up via Runtime.args() in core.runtime.
I'm thinking that having to retrieve the original argc/argv is common
when interfacing with C/C++, so maybe we should have a druntime
function which can return the original unprocessed args?

You know.. it'd be much simpler if argc & argv were stored somewhere.
druntime/src/rt/dmain2.d is where the action begins:
extern (C) int main(int argc, char** argv) { ... }
And then this is stored as a string[] to _d_args which can be picked
up via Runtime.args() in core.runtime.
I'm thinking that having to retrieve the original argc/argv is common
when interfacing with C/C++, so maybe we should have a druntime
function which can return the original unprocessed args?