digitalmars.D.learn - char ***argc problems.
- Andrew (15/15) Aug 12 2012 I'm attempting to create a wrapper for MPI, however, MPI_Init
- Timon Gehr (11/26) Aug 12 2012 Maybe like this?
- Andrew (8/41) Aug 12 2012 I don't know why I didn't think of this:
- Timon Gehr (3/50) Aug 12 2012 oops.
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? -Andrew
Aug 12 2012
On 08/12/2012 10:33 PM, Andrew 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? -AndrewMaybe like this? import std.algorithm, std.array, std.conv; void main(string[] args){ auto argarr = args.map!(a=>(a ~ '\0').ptr).array; int argc = to!(int)(argarr.length); auto argv = argarr.ptr; MPI_Init(&argc, &argv); args = argv[0..argc].map!(to!string).array; // ... }
Aug 12 2012
On Sunday, 12 August 2012 at 20:57:34 UTC, Timon Gehr wrote:On 08/12/2012 10:33 PM, Andrew wrote:I don't know why I didn't think of this: auto argv = argarr.ptr; Which fixed it. Unfortunately, using args.map! doesn't work, because it returns an immutable, which MPI_Init can't take. Thanks for the help -AndrewI'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? -AndrewMaybe like this? import std.algorithm, std.array, std.conv; void main(string[] args){ auto argarr = args.map!(a=>(a ~ '\0').ptr).array; int argc = to!(int)(argarr.length); auto argv = argarr.ptr; MPI_Init(&argc, &argv); args = argv[0..argc].map!(to!string).array; // ... }
Aug 12 2012
On 08/12/2012 11:38 PM, Andrew wrote:On Sunday, 12 August 2012 at 20:57:34 UTC, Timon Gehr wrote:oops. auto argarr = args.map!(a=>(a.dup ~ '\0').ptr).array;On 08/12/2012 10:33 PM, Andrew wrote:I don't know why I didn't think of this: auto argv = argarr.ptr; Which fixed it. Unfortunately, using args.map! doesn't work, because it returns an immutable, which MPI_Init can't take.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? -AndrewMaybe like this? import std.algorithm, std.array, std.conv; void main(string[] args){ auto argarr = args.map!(a=>(a ~ '\0').ptr).array; int argc = to!(int)(argarr.length); auto argv = argarr.ptr; MPI_Init(&argc, &argv); args = argv[0..argc].map!(to!string).array; // ... }Thanks for the help -Andrew
Aug 12 2012