Thread overview
Interfacing to C arrays of unknown size
Jun 16, 2005
Benjamin Herr
Jun 18, 2005
Walter
Jun 19, 2005
Manfred Nowak
Jun 19, 2005
Denis R
Jun 19, 2005
Manfred Nowak
June 16, 2005
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
June 18, 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


June 18, 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."


June 19, 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 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
June 19, 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 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
June 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