two-dimensional C array and its analog in D

Alexandr Druzhinin drug2004 at bk.ru
Tue Aug 7 23:07:54 PDT 2012


Hello,
there is the following C function:

void foo(const void** data);

in C I can do:

int data[N][M];

data[0][0] = ..;
data[0][1] = ..;
data[1][0] = ..;
data[1][1] = ..;

foo(data); // for C code it works and in D code it doesn't (compile, but 
do nothing)

I've "solved" the problem like this:

int real_data[N*M];

real_data[0] = ..;
real_data[1] = ..;
real_data[2] = ..;
real_data[3] = ..;

int* data[N];
foreach(i; 0..N)
	data[i] = &real_data[i*M];

T.i. I form an array of pointers by myself without compiler so it 
doesn't seem to be good enough for some overcode and it looks dirty a 
little bit. Is there more suitable variant?

P.S. in few words I'd like to construct some D data structure that is 
binary compatible with two-dimensional C array (and do it in simple way, 
of course).



More information about the Digitalmars-d-learn mailing list