Andrej Mitrovic: > I wish "newVoid" was a language feature. If we have: > int x = void; > > It'd also be nice to have a similar form for the new operator: > int[] x = void new int[](size); > x[] = 1; > > "int x = void" might not save too much cycles, but initializing a > large array twice.. that's another thing. > > newVoid seems to only work for 1-dimensional arrays. I could use > something of this form: > double[][] arr = newVoid!(double[][])(16, 100); > > Not a big deal, I could write something like this for my own projects. > I'm just commenting. > > I used GC.malloc before but I never once thought about setting the > NO_SCAN flag. Heh. :)
This is kind of off-topic. There is a very simple syntax, nice and clean: // doesn't initialize foo1 auto foo1 = new uint[5] = void; // initializes the dynamic array to 5, avoiding a double initialization auto foo2 = new uint[5] = 10; // works for nD arrays too auto mat1 = new double[][][](n1,n2,n3) = 0.0; That syntax is inspired by fixed-sized array syntax, so I don't think it will take lot of time to people to learn it, quite the opposite: uint[5] a1 = void; uint[5] a2 = 10; double[n1][n2][n3] mat2 = 0.0; The increase of language complexity for the programmer is minimal. But its usage as expression is not the most nice, so it's probably better to disallow this usage: void foo(int[] a) {} main() { foo(new[5] = 5); } Bye, bearophile