Works on gdc/1.0

downs default_357-line at yahoo.de
Tue Mar 18 08:34:40 PDT 2008


Tobias Kieslich wrote:
> Hi,
> 
> dmd version was 2.012 for this.
> 
> 	I'm sorry if that should have gone to learn-d but it also might be a
> bug. Anyway, I'm here to to get some insight.
> Coming from scripting languages (Python, JavaScript as fnctional
> language, etc) I try to come to terms with the rules of a language like
> D.
> I tried some array concatenation the other day to figure out about when
> I can use a~=1 vs a~=[1]. Where the first strongly resambles constructs
> like a.append(1) and the latter a += [1] in python. Anyway, approaching
> multidimensional arrays I ran into an obvious issue, that I have to
> write:
> 
> 	int [][] a =[[0,1],[2,3]];
> 	a ~= [4,5];    //fail
> 	a ~= [[4,5]];  //success
> 
> because D inspects the first element of an array to determine it's type.
> Now, here it is where it gets weird. Dynamic arrays of static arrays:
> 
> 	int [2][] b =[[0,1],[2,3]];
> 	b ~= [[4,5]];  // fail, because concatenate [2u][] with [][1u]
> 	b ~= [4,5];    // success but wrong result as b holds now:
> 	// [[0 1] [2 3] [4 5] [0 0]]
> 

Strange.
Using GDC 0.24/1.028 on 4.1.2, I get this:

gentoo-pc ~ $ cat test6.d; gdc test6.d -o test6 && ./test6
import std.stdio;

void main() {
        int[2][] b = [[0,1], [2,3]];
        b ~= [[4, 5]];
        b ~= [6, 7];
        writefln(b);
}
[[0,1],[2,3],[4,5],[6,7]]

So it's probably something that broke on the change to 2.0.

Could somebody please try to reproduce on DMD/1.0?

 --downs



More information about the Digitalmars-d mailing list