Re: Access to structures defined in C

2018-09-19 Thread Atila Neves via Digitalmars-d-learn
On Wednesday, 19 September 2018 at 00:46:54 UTC, Joe wrote: On Tuesday, 18 September 2018 at 13:47:50 UTC, Atila Neves wrote: Sorry, Atila, I got confused looking at my two cases. I should have said "an array of ints", e.g., int yp[] = {2, 4, 0}; int yq[] = {10, 12, 0}; That makes more

Re: Access to structures defined in C

2018-09-18 Thread Joe via Digitalmars-d-learn
On Tuesday, 18 September 2018 at 13:47:50 UTC, Atila Neves wrote: On Tuesday, 18 September 2018 at 02:39:39 UTC, Joe wrote: The second type is like that shown above. The first is a simpler array of pointers to int, e.g., int *yp = {2, 4, 0}; int *yq = {10, 12, 0}; This is valid C in the

Re: Access to structures defined in C

2018-09-18 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 18 September 2018 at 02:39:39 UTC, Joe wrote: On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote: That worked but now I have a more convoluted case: a C array of pointers to int pointers, e.g., int **xs[] = {x1, x2, 0}; int *x1[] = {x1a, 0}; int *x2[] = {x2a, x2b, 0}; ... int

Re: Access to structures defined in C

2018-09-17 Thread Joe via Digitalmars-d-learn
On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote: That worked but now I have a more convoluted case: a C array of pointers to int pointers, e.g., int **xs[] = {x1, x2, 0}; int *x1[] = {x1a, 0}; int *x2[] = {x2a, x2b, 0}; ... int x2a[] = { 1, 3, 5, 0}; Only the first line is exposed (and

Re: Access to structures defined in C

2018-06-10 Thread Joe via Digitalmars-d-learn
On Sunday, 10 June 2018 at 17:59:12 UTC, Joe wrote: That worked but now I have a more convoluted case: a C array of pointers to int pointers, e.g., int **xs[] = {x1, x2, 0}; int *x1[] = {x1a, 0}; int *x2[] = {x2a, x2b, 0}; ... int x2a[] = { 1, 3, 5, 0}; Only the first line is exposed (and

Re: Access to structures defined in C

2018-06-10 Thread Joe via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 02:17:57 UTC, Adam D. Ruppe wrote: The type system would *like* to know, certainly for correct range errors, but if you declare it as the wrong length and use the .ptr, it still works like it does in C: extern(C) __gshared extern char*[1] files; // still works

Re: Access to structures defined in C

2018-03-13 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 14 March 2018 at 01:58:24 UTC, Joe wrote: The C header of course declares this as: extern char *files[]; The way to declare it in a D module appears to be: extern (C) { __gshared extern char *[] files; } A D array[] should *almost never* be used in extern(C). (tbh I'm

Access to structures defined in C

2018-03-13 Thread Joe via Digitalmars-d-learn
What is the correct way to declare and access storage managed by C? For example, say a C module defines an array of filenames, e.g., char *files[] = { "one", "two", "three", 0}; The C header of course declares this as: extern char *files[]; The way to declare it in a D module appears to be: