On Thursday, 22 January 2015 at 00:16:23 UTC, bearophile wrote:
anon:
I have the following C code, how can I do the same in D.
Info **info;
info = new Info*[hl + 2];
int r;
for(r = 0; r < hl; r++)
{
info[r] = new Info[vl + 2];
}
info[r] = NULL;
I suggest you to ignore ketmar, he's not helping :-)
Is your code initializing info[r+1]?
This is roughly a D translation (untested):
void main() @safe {
import std.stdio;
enum uint hl = 5;
enum uint vl = 7;
static struct Info {}
auto info = new Info[][](hl + 2);
foreach (ref r; info[0 .. hl])
r = new Info[vl + 2];
writefln("[\n%(%s,\n%)\n]", info);
}
Output:
[
[Info(), Info(), Info(), Info(), Info(), Info(), Info(),
Info(), Info()],
[Info(), Info(), Info(), Info(), Info(), Info(), Info(),
Info(), Info()],
[Info(), Info(), Info(), Info(), Info(), Info(), Info(),
Info(), Info()],
[Info(), Info(), Info(), Info(), Info(), Info(), Info(),
Info(), Info()],
[Info(), Info(), Info(), Info(), Info(), Info(), Info(),
Info(), Info()],
[],
[]
]
Is this what you look for?
Bye,
bearophile
Hi Bearophile,
It looks like what I need.
Thanks,
anon