www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Interfacing to C arrays of unknown size

reply Benjamin Herr <ben 0x539.de> writes:
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
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
"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
parent reply Manfred Nowak <svv1999 hotmail.com> writes:
"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 are
Nice 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
parent reply Denis R <denis_r telkomsa.net> writes:
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 are
Nice 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
parent Manfred Nowak <svv1999 hotmail.com> writes:
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
prev sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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