On Friday, 14 March 2014 at 19:24:21 UTC, Chris Williams wrote:
In D, an array is a struct (struct Array), with an address and
a length value. A multi-dimensional array is an Array with an
address pointing to an array of Arrays. So with an int[2][2]
array, you have a layout like:
@1000 Array(
On Friday, 14 March 2014 at 19:24:21 UTC, Chris Williams wrote:
It looks like you might be right after all about the code being
invalid D. It could be a bug when it compiles without the cast.
I filed a bug report about it, see where it leads :D
Thanks,
ed
On Friday, 14 March 2014 at 19:24:21 UTC, Chris Williams wrote:
[snip]
address pointing to an array of Arrays. So with an int[2][2]
array, you have a layout like:
@1000 Array(address=1016, length=2)
@1016 [Array(address=1048, length=2),Array(address=1056,
length=2)]
@1048 [1,2]
@1056 [3,4]
On Friday, 14 March 2014 at 04:36:27 UTC, ed wrote:
As to whether or not this should work:
int[4] a=[1,2,3,4];
int[2][2] b;
b=a;
is up to the D language gurus. I think it should... but I'm no
language developer, there may be other side-effects I haven't
thought about.
Cheers,
ed
In C, any
On Friday, 14 March 2014 at 04:18:18 UTC, ed wrote:
On Thursday, 13 March 2014 at 18:17:03 UTC, Chris Williams
wrote:
On Thursday, 13 March 2014 at 03:31:09 UTC, ed wrote:
On Thursday, 13 March 2014 at 00:15:19 UTC, Chris Williams
wrote:
[snip]
It shouldn't and probably isn't working.
It is
On Thursday, 13 March 2014 at 18:17:03 UTC, Chris Williams wrote:
On Thursday, 13 March 2014 at 03:31:09 UTC, ed wrote:
On Thursday, 13 March 2014 at 00:15:19 UTC, Chris Williams
wrote:
[snip]
It shouldn't and probably isn't working.
It is working and in fact it is in a "const pure @safe"
f
On Wednesday, 12 March 2014 at 06:53:19 UTC, monarch_dodra wrote:
I *believe* it's really just that you are allowed to
*initialize* a static array (of any depth) from a dynamic array.
However, for assignment, it doesn't work that way:
int[] a = [0, 1, 2, 3];
int[2][1][2][1] b = a; //OK
On Thursday, 13 March 2014 at 03:31:09 UTC, ed wrote:
On Thursday, 13 March 2014 at 00:15:19 UTC, Chris Williams
wrote:
[snip]
It shouldn't and probably isn't working.
It is working and in fact it is in a "const pure @safe"
function. So I will trust it :-)
Well it's like a broken watch be
On Wednesday, 12 March 2014 at 07:43:46 UTC, bearophile wrote:
monarch_dodra:
int[] a = [0, 1, 2, 3];
int[2][1][2][1] b;
*cast(int[4]*)&b = a;
assert(b == 0, 1]], [[2, 3);
Those pointers are not needed:
cast(int[4])b = a;
Bye,
bearoophile
Thanks for this, the casts wor
On Thursday, 13 March 2014 at 00:15:19 UTC, Chris Williams wrote:
[snip]
It shouldn't and probably isn't working.
It is working and in fact it is in a "const pure @safe" function.
So I will trust it :-)
If nothing else, when you use to!(x)(y), "x" should be the type
that you're trying to c
On Wednesday, 12 March 2014 at 03:37:49 UTC, ed wrote:
My understanding of your explanation is that it shouldn't work.
It shouldn't and probably isn't working. If nothing else, when
you use to!(x)(y), "x" should be the type that you're trying to
convert into. So I would expect your code to be
monarch_dodra:
int[] a = [0, 1, 2, 3];
int[2][1][2][1] b;
*cast(int[4]*)&b = a;
assert(b == 0, 1]], [[2, 3);
Those pointers are not needed:
cast(int[4])b = a;
Bye,
bearoophile
On Wednesday, 12 March 2014 at 07:43:46 UTC, bearophile wrote:
monarch_dodra:
int[] a = [0, 1, 2, 3];
int[2][1][2][1] b;
*cast(int[4]*)&b = a;
assert(b == 0, 1]], [[2, 3);
Those pointers are not needed:
cast(int[4])b = a;
Bye,
bearoophile
I'm *never* actually sure if t
On Wednesday, 12 March 2014 at 03:37:49 UTC, ed wrote:
Thanks for explaining this, it makes sense what you said. But
I'm still not sure why my original Example 1 worked.
~~~
// This works OK and converts long[4] to int[] then implicitly
to int[2][2]
long[4] a=[1,2,3,4];
int[2][2] b = to!(int[
On Wednesday, 12 March 2014 at 02:14:45 UTC, bearophile wrote:
ed:
I am trying to convert a 1D array to a 2D array
If you have a dynamic array (1D), you can convert it to a
dynamic array of dynamic arrays (2D) using chunks:
void main() {
import std.stdio, std.range, std.algorithm;
ed:
I am trying to convert a 1D array to a 2D array
If you have a dynamic array (1D), you can convert it to a dynamic
array of dynamic arrays (2D) using chunks:
void main() {
import std.stdio, std.range, std.algorithm;
int[] a = [1, 2, 3, 4, 5, 6];
int[][] b = a.chunks(2).arra
16 matches
Mail list logo