digitalmars.D.learn - Interfacing to C arrays of unknown size
- Benjamin Herr (6/6) Jun 16 2005 Hello, D,
- Walter (4/9) Jun 18 2005 In D you'll need to specify the number of members of it:
- Manfred Nowak (16/21) Jun 18 2005 Nice to see, that it should work this way, but it does not.
- Denis R (10/38) Jun 19 2005 Hi,
- Manfred Nowak (8/10) Jun 19 2005 [...]
- Jarrett Billingsley (4/9) Jun 18 2005 You would use a pointer, just like how arrays are pointers in C. So you...
Hello, D, as I understand it, the C declaration `` extern T a[]; '' declares an elsewhere-defined array of Ts, without specifying the amount of members, which needs to be given at the point of definition. What is the analogous in D? -- ben
Jun 16 2005
"Benjamin Herr" <ben 0x539.de> wrote in message news:d8t27v$7c$1 digitaldaemon.com...Hello, D, as I understand it, the C declaration `` extern T a[]; '' declares an elsewhere-defined array of Ts, without specifying the amount of members, which needs to be given at the point of definition. What is the analogous in D?In D you'll need to specify the number of members of it: extern T[6] a; // or however many members there are
Jun 18 2005
"Walter" <newshound digitalmars.com> wrote: [...]In D you'll need to specify the number of members of it: extern T[6] a; // or however many members there areNice to see, that it should work this way, but it does not. ---- lib.c ---- int arr[100]={100,1}; ---- user.d ------ import std.stdio; extern int[100] arr; void main(){ writefln( arr[0]); } ------------------dmc -c lib.c dmd user.d lib.obj| Error 42: Symbol Undefined _D4user3arrG100i Even if you introduce the forgotten "extern (C)": | Error 1: Previous Definition Different : _arr -manfred
Jun 18 2005
Hi, Its actually working here. I have in separate d file, which you make sure is not being compiled (thanks Ben #d irc.freenode.net :) extern (C) { uint[128] acs_map; } then in other module just using it normally. On Sun, 19 Jun 2005 02:15:11 +0000 (UTC) Manfred Nowak <svv1999 hotmail.com> wrote:"Walter" <newshound digitalmars.com> wrote: [...]In D you'll need to specify the number of members of it: extern T[6] a; // or however many members there areNice to see, that it should work this way, but it does not. ---- lib.c ---- int arr[100]={100,1}; ---- user.d ------ import std.stdio; extern int[100] arr; void main(){ writefln( arr[0]); } ------------------dmc -c lib.c dmd user.d lib.obj| Error 42: Symbol Undefined _D4user3arrG100i Even if you introduce the forgotten "extern (C)": | Error 1: Previous Definition Different : _arr -manfred
Jun 19 2005
Denis R <denis_r telkomsa.net> wrote: [...]I have in separate d file, which you make sure is not being compiled (thanks Ben #d irc.freenode.net :)[...] Thx. I should have looked into the htomodule-specs first. The need to give a number somehow looks like a defect to me, because it suffices to give a number large enough to inactivate the bounds check. -manfred
Jun 19 2005
"Benjamin Herr" <ben 0x539.de> wrote in message news:d8t27v$7c$1 digitaldaemon.com...Hello, D, as I understand it, the C declaration `` extern T a[]; '' declares an elsewhere-defined array of Ts, without specifying the amount of members, which needs to be given at the point of definition. What is the analogous in D?You would use a pointer, just like how arrays are pointers in C. So you'd write "extern T* a."
Jun 18 2005