Array initialization (again)
Stefano Corsi <[email protected]> Mon, 27 Jan 2003 17:30:25 +0000
| Newsgroups | gmane.comp.lang.moto.devel |
|---|---|
| Organization | Moto Project |
| Message-ID | <[email protected]> |
This also works:
String[][][] paperino = <String[][][]>[
[
["Nel","mezzo"],
["del","cammin","di"]
],
[
["nostra","vita"],
["mi","ritrovai"]
],
[
["per","una"],
["selva","oscura"]
]
];
int i,j,k;
for (i = 0; i < length(paperino); i++) {
for (j = 0; j < length(paperino[i]); j++) {
for (k = 0; k < length(paperino[j]); k++) {
print paperino[i][j][k] + "\n";
}
}
}
produces:
Nel
mezzo
del
cammin
nostra
vita
mi
ritrovai
per
una
selva
oscura
So there are no limitations in the number of elements, neither all the
elements shall be of the same size. But I get a segfault if I do:
String[][][] paperino = <String[][][]>[
["Nel"],
["del","cammin","di"],
[
["nostra","vita"],
["mi","ritrovai"]
],
[
["per","una"],
["selva","oscura"]
]
];
And this is probably right, because I'm mixing arrays and simple strings. I'm
mixing different dimensions.
(Yeah, of course, in perl you can do it, but ...)
Stefano