two-dimensional C array and its analog in D

Ali Çehreli acehreli at yahoo.com
Tue Aug 7 22:13:50 PDT 2012


On 08/07/2012 11:07 PM, Alexandr Druzhinin wrote:
 > 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)

This seems to work:

import std.stdio;

void main()
{
     enum M = 3;
     enum N = 4;

     int[M][N] data;
     data[0][0] = 42;
     writeln(data);
}

The output:

[[42, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]

Ali



More information about the Digitalmars-d-learn mailing list