[ create a new paste ] login | about

Link: http://codepad.org/OGjXADdu    [ raw code | output | fork ]

D, pasted on Dec 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import std.stdio, std.string;

struct Foo {
  int something;
  char[] toString() { return format("%s", something); }
}

Foo[] test = cast(Foo[])([1, 2, 3, 4]);

static x = [1, 2, 3, 4];

static x2 = [1.34, 6.45, 12.3];

void main() {
   writefln("%s", test);
   writefln("%s", cast(Foo[])(x));
   //and this made many people believe that casting arrays does the right thing:
   writefln("%s", cast(int[])([1.34, 6.45, 12.3]));
   //but it doesn't work
   writefln("%s", cast(int[])x2);
}


Output:
1
2
3
4
[0,0,0,0]
[1,2,3,4]
[1,6,12]
[-687194767,1073049763,-858993459,1075432652,-1717986918,1076402585]


Create a new paste based on this one


Comments: