digitalmars.D - Simple array init question
- Graham (17/17) Apr 07 2007 Why will array setting work for a 1D array, but not a 2D? If I enter:
- Paul Findlay (5/8) Apr 07 2007 Have you tried:
- Graham (3/15) Apr 07 2007 Thanks for your reply. No, I didn't try that, since the array I'm
- Chris Nicholson-Sauls (12/29) Apr 07 2007 In which case you've got two immediate options, and a third option requi...
- Graham (6/28) Apr 07 2007 The 1st is what I went for. Not being able to initialise a
- Manfred Nowak (4/5) Apr 07 2007 In what domains do one need to represent dense multidimensional
- Graham (3/11) Apr 07 2007 A floating point texture buffer - 3 floats per pixel, and (say) 640x480
- Daniel Keep (30/42) Apr 07 2007 Perhaps you shouldn't be using jagged arrays, then. int[][] is *NOT* a
- Chris Nicholson-Sauls (6/47) Apr 07 2007 Actually, /IF/ he's using static/fixed-length arrays, then as I understa...
- Daniel Keep (12/62) Apr 07 2007 Ah yes, of course. Sorry; bit dense today :P
- Graham (7/61) Apr 08 2007 A bit of confusion here:-) Yes, it's a simple, static fixed size,
- Daniel Keep (15/79) Apr 08 2007 You *don't* have more than one dimension; you're really nesting arrays.
- Graham (10/17) Apr 08 2007 As I said before, I could use a normal 1D array. My basic point is that...
- Dan (11/15) Apr 09 2007 Actually, you're wrong sir. An int[5][5] produces an array containing 5...
- Frits van Bommel (36/55) Apr 09 2007 No, he was right. That struct is only used for dynamic arrays, not with
- Dan (10/63) Apr 09 2007 Fascinating. I thought static arrays were implemented in the same way (...
- Jarrett Billingsley (17/31) Apr 09 2007 Dynamic arrays. Nothing in the brackets -- always dynamic.
- Derek Parnell (20/28) Apr 09 2007 I don't read the spec that way at all.
- Bill Baxter (11/40) Apr 09 2007 Dan is not the first one to misread that particular passage in that
- Derek Parnell (8/12) Apr 09 2007 Yep.
- Manfred Nowak (5/7) Apr 08 2007 To me your remark does not explain the necessity of O(1) access to an
- Graham (8/18) Apr 08 2007 I'm not sure why you're concentrating on O(1) random access. I need a
- Manfred Nowak (13/15) Apr 08 2007 Yes. Thx. I am just searching for the more general pattern.
- Craig Black (5/22) Apr 09 2007 Graham, I was wondering if you were someone that I know. Are you the Gr...
- Saaa (2/5) Apr 09 2007
- Graham MacDonald (2/34) Apr 11 2007
Why will array setting work for a 1D array, but not a 2D? If I enter: int[5] buffer; buffer[] = 5; It compiles, but if I enter: int[5][5] buffer; buffer[][] = 5; (I tried the variation buffer[] = 5, but that didn't work either.) It fails to compile (in gdc), with the warning: MainLoop.d:56: Error: cannot implicitly convert expression (5) of type int to int[5] Error: cannot cast int to int[5] make: *** [build/MainLoop.o] Error 1 To my untrained eye, it looks like it would like me to pass it an int[5] to initialize the array, but that's a bit odd - I'd much rather treat it similarly to a 1D array in this case! Thanks, graham
Apr 07 2007
It compiles, but if I enter: int[5][5] buffer; buffer[][] = 5;Have you tried: int[5][5] buffer; buffer[] = [5,5,5,5,5]; // or something (Or try in the digitalmars.D.learn newgroup) - Paul
Apr 07 2007
Thanks for your reply. No, I didn't try that, since the array I'm actually using is several thousand elements large. Paul Findlay wrote:It compiles, but if I enter: int[5][5] buffer; buffer[][] = 5;Have you tried: int[5][5] buffer; buffer[] = [5,5,5,5,5]; // or something (Or try in the digitalmars.D.learn newgroup) - Paul
Apr 07 2007
Graham wrote:Thanks for your reply. No, I didn't try that, since the array I'm actually using is several thousand elements large. Paul Findlay wrote:In which case you've got two immediate options, and a third option requiring a library. :) value -- unfortunately this is rarely realistic as typedef types are strong in D. Library option - Use Cashew (cashew.utils.Array) thusly: int[1024][1024] buf = repeat(repeat(5, 1024_U), 1024_U); (Admittedly untested, but it should work fine. Cashew is available from DSource.) http://www.dsource.org/projects/cashew When it comes right down to it, I actually have to admit to wishing the '[][] = 5' approach worked. Hm. -- Chris Nicholson-SaulsIt compiles, but if I enter: int[5][5] buffer; buffer[][] = 5;Have you tried: int[5][5] buffer; buffer[] = [5,5,5,5,5]; // or something (Or try in the digitalmars.D.learn newgroup) - Paul
Apr 07 2007
The 1st is what I went for. Not being able to initialise a multidimensional array using the same syntax as a one dimensional array seems a bit inconsistent - either a bug or an omission - so I figured I'd mention it here. Thanks. Chris Nicholson-Sauls wrote:In which case you've got two immediate options, and a third option requiring a library. :) array. init value -- unfortunately this is rarely realistic as typedef types are strong in D. Library option - Use Cashew (cashew.utils.Array) thusly: int[1024][1024] buf = repeat(repeat(5, 1024_U), 1024_U); (Admittedly untested, but it should work fine. Cashew is available from DSource.) http://www.dsource.org/projects/cashew When it comes right down to it, I actually have to admit to wishing the '[][] = 5' approach worked. Hm. -- Chris Nicholson-Sauls
Apr 07 2007
Graham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 07 2007
A floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels. Manfred Nowak wrote:Graham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 07 2007
Graham wrote:A floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels. Manfred Nowak wrote:Perhaps you shouldn't be using jagged arrays, then. int[][] is *NOT* a multidimensional array. It's basically equivalent to this: struct int_array { int* ptr; size_t length; } struct int_array_array { int_array* ptr; size_t length; } int_array_array buffer; Notice those nested pointers; that means that your texture is not necessarily contiguous in memory, which would make, for example, loading the texture into GL a pain in the behind. Not sure if the cache would have problems... I think there's a few multidimensional array templates floating around... or if not, you can always write your own :) -- Daniel -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/Graham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 07 2007
Daniel Keep wrote:Graham wrote:Actually, /IF/ he's using static/fixed-length arrays, then as I understand it this ceases to be true. That is, static arrays are solid blocks of memory -- and I assume this stays the same for multi-dimensional arrays. Of course, /IF/ he's using dynamic-length arrays, then you're absolutely correct about it being likely opposite. -- Chris Nicholson-SaulsA floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels. Manfred Nowak wrote:Perhaps you shouldn't be using jagged arrays, then. int[][] is *NOT* a multidimensional array. It's basically equivalent to this: struct int_array { int* ptr; size_t length; } struct int_array_array { int_array* ptr; size_t length; } int_array_array buffer; Notice those nested pointers; that means that your texture is not necessarily contiguous in memory, which would make, for example, loading the texture into GL a pain in the behind. Not sure if the cache would have problems... I think there's a few multidimensional array templates floating around... or if not, you can always write your own :) -- DanielGraham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 07 2007
Chris Nicholson-Sauls wrote:Daniel Keep wrote:Ah yes, of course. Sorry; bit dense today :P -- Daniel -- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/Graham wrote:Actually, /IF/ he's using static/fixed-length arrays, then as I understand it this ceases to be true. That is, static arrays are solid blocks of memory -- and I assume this stays the same for multi-dimensional arrays. Of course, /IF/ he's using dynamic-length arrays, then you're absolutely correct about it being likely opposite. -- Chris Nicholson-SaulsA floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels. Manfred Nowak wrote:Perhaps you shouldn't be using jagged arrays, then. int[][] is *NOT* a multidimensional array. It's basically equivalent to this: struct int_array { int* ptr; size_t length; } struct int_array_array { int_array* ptr; size_t length; } int_array_array buffer; Notice those nested pointers; that means that your texture is not necessarily contiguous in memory, which would make, for example, loading the texture into GL a pain in the behind. Not sure if the cache would have problems... I think there's a few multidimensional array templates floating around... or if not, you can always write your own :) -- DanielGraham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 07 2007
A bit of confusion here:-) Yes, it's a simple, static fixed size, multi-dimensional array. I could use a 1D array, but I wanted to try out the 2D approach and was puzzled why I couldn't use the initialiser for the entire array if I had more than one dimension. There's nothing more to this! Thanks. Daniel Keep wrote:Chris Nicholson-Sauls wrote:Daniel Keep wrote:Ah yes, of course. Sorry; bit dense today :P -- DanielGraham wrote:Actually, /IF/ he's using static/fixed-length arrays, then as I understand it this ceases to be true. That is, static arrays are solid blocks of memory -- and I assume this stays the same for multi-dimensional arrays. Of course, /IF/ he's using dynamic-length arrays, then you're absolutely correct about it being likely opposite. -- Chris Nicholson-SaulsA floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels. Manfred Nowak wrote:Perhaps you shouldn't be using jagged arrays, then. int[][] is *NOT* a multidimensional array. It's basically equivalent to this: struct int_array { int* ptr; size_t length; } struct int_array_array { int_array* ptr; size_t length; } int_array_array buffer; Notice those nested pointers; that means that your texture is not necessarily contiguous in memory, which would make, for example, loading the texture into GL a pain in the behind. Not sure if the cache would have problems... I think there's a few multidimensional array templates floating around... or if not, you can always write your own :) -- DanielGraham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 08 2007
Graham wrote:A bit of confusion here:-) Yes, it's a simple, static fixed size, multi-dimensional array. I could use a 1D array, but I wanted to try out the 2D approach and was puzzled why I couldn't use the initialiser for the entire array if I had more than one dimension. There's nothing more to this! Thanks.You *don't* have more than one dimension; you're really nesting arrays. Strictly speaking, int[5][5] is an (albeit static) jagged array. I realise that for your purposes, it's six of one, half a dozen of the other -- I'm just being pedantic :) -- DanielDaniel Keep wrote:-- int getRandomNumber() { return 4; // chosen by fair dice roll. // guaranteed to be random. } http://xkcd.com/ v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/Chris Nicholson-Sauls wrote:Daniel Keep wrote:Ah yes, of course. Sorry; bit dense today :P -- DanielGraham wrote:Actually, /IF/ he's using static/fixed-length arrays, then as I understand it this ceases to be true. That is, static arrays are solid blocks of memory -- and I assume this stays the same for multi-dimensional arrays. Of course, /IF/ he's using dynamic-length arrays, then you're absolutely correct about it being likely opposite. -- Chris Nicholson-SaulsA floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels. Manfred Nowak wrote:Perhaps you shouldn't be using jagged arrays, then. int[][] is *NOT* a multidimensional array. It's basically equivalent to this: struct int_array { int* ptr; size_t length; } struct int_array_array { int_array* ptr; size_t length; } int_array_array buffer; Notice those nested pointers; that means that your texture is not necessarily contiguous in memory, which would make, for example, loading the texture into GL a pain in the behind. Not sure if the cache would have problems... I think there's a few multidimensional array templates floating around... or if not, you can always write your own :) -- DanielGraham wroteseveral thousand elements large.In what domains do one need to represent dense multidimensional structures with O(1) time for accesses of elements? -manfred
Apr 08 2007
As I said before, I could use a normal 1D array. My basic point is that as I was trying to initialise a static, rectangular array, there's no reason (that I can see) why the initialiser can't work for more than 1D. (And to be pedantic, int[5][5] is a 2D rectangular array, which in memory is exactly the same as int[25] - a 1D array, of course - so six of one and half a dozen of the other perhaps, but int[5][5] does have > 1 dimension :-)) (Thanks for the previous recommendations though!) g Daniel Keep wrote:You *don't* have more than one dimension; you're really nesting arrays. Strictly speaking, int[5][5] is an (albeit static) jagged array. I realise that for your purposes, it's six of one, half a dozen of the other -- I'm just being pedantic :) -- Daniel
Apr 08 2007
Graham Wrote:(And to be pedantic, int[5][5] is a 2D rectangular array, which in memory is exactly the same as int[25] - a 1D array, of course - so six of one and half a dozen of the other perhaps, but int[5][5] does have > 1 dimension :-))Actually, you're wrong sir. An int[5][5] produces an array containing 5 structs, each of: struct Array { size_t(or was it int? uint?) length; void* ptr; } Each of those arrays then points to another array of 5 elements. What I believe you want is a rectangular array: int[5,5], which will produce a single Array struct that you can access via taking a multiple of the first index added to the second index (or is it vice versa?) This notation tends to typically be inferior to int[25] for that very reason, each access requires math on two indices. I might also note that it is typically more efficient to use a power of two for array sizes for indexing purposes - so long as the array size doesn't cause the OS you're working on to have difficulty allocating the space. Some OS's allocate in 4kb units and then take 16 bytes for metadata, some allocate anything > 2kb in a "giant data" page-set which may be more inefficient than the smaller page-sets as it may allocate your data accross pages.
Apr 09 2007
Dan wrote:Graham Wrote:No, he was right. That struct is only used for dynamic arrays, not with static arrays. Static arrays are just a linear row of members stored in-place (but passed by reference). You don't need to take my word for it, look at what the compilers do: ===== $ cat test.d import std.stdio; int[5][5] matrix; void main() { // Initialize foreach (r, inout row; matrix) { foreach (c, inout elt; row) { elt = r * 5 + c; } } // Access as a linear array: uint* p = cast(uint*) matrix.ptr; // (Note: ".ptr" is not actually stored but inserted as // a constant) for (size_t i = 0; i < 25; i++) { writef(p[i],' '); } writefln(); } $ dmd -run test.d 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 $ gdc -o test test.d && ./test 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 =====(And to be pedantic, int[5][5] is a 2D rectangular array, which in memory is exactly the same as int[25] - a 1D array, of course - so six of one and half a dozen of the other perhaps, but int[5][5] does have > 1 dimension :-))Actually, you're wrong sir. An int[5][5] produces an array containing 5 structs, each of: struct Array { size_t(or was it int? uint?) length; void* ptr; } Each of those arrays then points to another array of 5 elements.What I believe you want is a rectangular array: int[5,5], which will produce a single Array struct that you can access via taking a multiple of the first index added to the second index (or is it vice versa?)Sorry, "int[5,5]" only compiles because of the obscure comma operator. The first 5 is evaluated and thrown away, what's left is a regular old int[5]. (Still stored in-place by the way)This notation tends to typically be inferior to int[25] for that very reason, each access requires math on two indices. I might also note that it is typically more efficient to use a power of two for array sizes for indexing purposes - so long as the array size doesn't cause the OS you're working on to have difficulty allocating the space.Providing two indices to a variable declared as "int[5,5]" will evaluate the first index and throw it away, only using the second. The comma operator strikes again.Some OS's allocate in 4kb units and then take 16 bytes for metadata, some allocate anything > 2kb in a "giant data" page-set which may be more inefficient than the smaller page-sets as it may allocate your data accross pages.
Apr 09 2007
Frits van Bommel Wrote:Dan wrote:Fascinating. I thought static arrays were implemented in the same way (in terms of structure) as dynamic arrays. I'm curious then if I declare a: struct z { int[] y; } static z[] x = [ { y:[1,2,3] } ]; Does this implement a static array, or a dynamic array? I *hope* a dynamic one, as otherwise I will have to rewrite my entire Global_init routine for Walnut 2.x. : oGraham Wrote:No, he was right. That struct is only used for dynamic arrays, not with static arrays. Static arrays are just a linear row of members stored in-place (but passed by reference). You don't need to take my word for it, look at what the compilers do: ===== $ cat test.d import std.stdio; int[5][5] matrix; void main() { // Initialize foreach (r, inout row; matrix) { foreach (c, inout elt; row) { elt = r * 5 + c; } } // Access as a linear array: uint* p = cast(uint*) matrix.ptr; // (Note: ".ptr" is not actually stored but inserted as // a constant) for (size_t i = 0; i < 25; i++) { writef(p[i],' '); } writefln(); } $ dmd -run test.d 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 $ gdc -o test test.d && ./test 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 =====(And to be pedantic, int[5][5] is a 2D rectangular array, which in memory is exactly the same as int[25] - a 1D array, of course - so six of one and half a dozen of the other perhaps, but int[5][5] does have > 1 dimension :-))Actually, you're wrong sir. An int[5][5] produces an array containing 5 structs, each of: struct Array { size_t(or was it int? uint?) length; void* ptr; } Each of those arrays then points to another array of 5 elements.According to the D spec, that should compile as a rectangular array. I haven't tried it. I have read the spec. See: http://digitalmars.com/d/arrays.html and visit "Rectangular Arrays". PS: Walter, any chance we can get <a name=""> so we can link directly to specific parts of the spec?What I believe you want is a rectangular array: int[5,5], which will produce a single Array struct that you can access via taking a multiple of the first index added to the second index (or is it vice versa?)Sorry, "int[5,5]" only compiles because of the obscure comma operator.
Apr 09 2007
"Dan" <murpsoft hotmail.com> wrote in message news:evem9b$a9p$1 digitalmars.com...Fascinating. I thought static arrays were implemented in the same way (in terms of structure) as dynamic arrays. I'm curious then if I declare a: struct z { int[] y; } static z[] x = [ { y:[1,2,3] } ]; Does this implement a static array, or a dynamic array? I *hope* a dynamic one, as otherwise I will have to rewrite my entire Global_init routine for Walnut 2.x. : oDynamic arrays. Nothing in the brackets -- always dynamic.According to the D spec, that should compile as a rectangular array. I haven't tried it. I have read the spec. See: http://digitalmars.com/d/arrays.html and visit "Rectangular Arrays".quote: ================ Fortunately, D static arrays, while using the same syntax, are implemented as a fixed rectangular layout: double[3][3] matrix; declares a rectangular matrix with 3 rows and 3 columns, all contiguously in memory. ***In other languages***, this would be called a multidimensional array and be declared as: double matrix[3,3]; ================ Notice the "in other languages" bit ;) (though I have no idea _what_ other languages Walter's referring to in this sentence..)PS: Walter, any chance we can get <a name=""> so we can link directly to specific parts of the spec?I think there are some anchors, they're just not visible outside the page source. That would be very convenient, of course.
Apr 09 2007
On Mon, 09 Apr 2007 20:38:03 -0400, Dan wrote:I don't read the spec that way at all. "Fortunately, D static arrays, while using the same syntax, are implemented as a fixed rectangular layout: double[3][3] matrix; declares a rectangular matrix with 3 rows and 3 columns, all contiguously in memory. In other languages, this would be called a multidimensional array and be declared as: double matrix[3,3]; " To me, this is say that D uses the [3][3] syntax but *other* languages use the [3,3] syntax. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Justice for David Hicks!" 10/04/2007 11:03:42 AMSorry, "int[5,5]" only compiles because of the obscure comma operator.According to the D spec, that should compile as a rectangular array. I haven't tried it. I have read the spec. See: http://digitalmars.com/d/arrays.html and visit "Rectangular Arrays".
Apr 09 2007
Derek Parnell wrote:On Mon, 09 Apr 2007 20:38:03 -0400, Dan wrote:Dan is not the first one to misread that particular passage in that particular way. It needs to be rewritten. The fact that the [3,3] appears in a code box just like other D code is hugely misleading. It should at least be followed by an ALL CAPS comment: double matrix[3,3]; // NOT D CODE! But anyway, there's really no reason for that last sentence. Just cut it, I say. The docs are supposed to describe what you can do in *D* and how to do it. How other (vague and unspecified) languages do it is irrelevant. --bbI don't read the spec that way at all. "Fortunately, D static arrays, while using the same syntax, are implemented as a fixed rectangular layout: double[3][3] matrix; declares a rectangular matrix with 3 rows and 3 columns, all contiguously in memory. In other languages, this would be called a multidimensional array and be declared as: double matrix[3,3]; " To me, this is say that D uses the [3][3] syntax but *other* languages use the [3,3] syntax.Sorry, "int[5,5]" only compiles because of the obscure comma operator.According to the D spec, that should compile as a rectangular array. I haven't tried it. I have read the spec. See: http://digitalmars.com/d/arrays.html and visit "Rectangular Arrays".
Apr 09 2007
On Tue, 10 Apr 2007 12:36:53 +0900, Bill Baxter wrote:But anyway, there's really no reason for that last sentence. Just cut it, I say. The docs are supposed to describe what you can do in *D* and how to do it. How other (vague and unspecified) languages do it is irrelevant.Yep. -- Derek (skype: derek.j.parnell) Melbourne, Australia "Justice for David Hicks!" 10/04/2007 2:38:43 PM
Apr 09 2007
Graham wroteA floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels.To me your remark does not explain the necessity of O(1) access to an element randomly choosen---sorry for letting that out in my previous question. -manfred
Apr 08 2007
I'm not sure why you're concentrating on O(1) random access. I need a static buffer of fixed width & height. As I mentioned in a previous post, I could use a 1D array, but wanted to try a multi dimensional array and was puzzled why the initialiser didn't work. I'm passing this array to OpenGL, so I need a contiguous buffer. Does that explain what I'm after? Thanks. Manfred Nowak wrote:Graham wroteA floating point texture buffer - 3 floats per pixel, and (say) 640x480 pixels.To me your remark does not explain the necessity of O(1) access to an element randomly choosen---sorry for letting that out in my previous question. -manfred
Apr 08 2007
Graham wroteDoes that explain what I'm after?Yes. Thx. I am just searching for the more general pattern. Now I can give up to find a foundation for your wish:I'd much rather treat it similarly to a 1D array in this case!As you state it yourself it is just a single case, where you want to treat something differently from the general pattern, that arrays of type T[] are assigned to by mentioning a value of the type T. You want to extend this general pattern by being able for all natural numbers n to initialize an array of type T[]^n by mentioning a value of type T. But how to write a class that is able to mimic this behaviour? -manfred
Apr 08 2007
Graham, I was wondering if you were someone that I know. Are you the Graham I am thinking of? -Craig "Graham" <grahamamacdonald gmail.com> wrote in message news:ev7kdm$1p8e$1 digitalmars.com...Why will array setting work for a 1D array, but not a 2D? If I enter: int[5] buffer; buffer[] = 5; It compiles, but if I enter: int[5][5] buffer; buffer[][] = 5; (I tried the variation buffer[] = 5, but that didn't work either.) It fails to compile (in gdc), with the warning: MainLoop.d:56: Error: cannot implicitly convert expression (5) of type int to int[5] Error: cannot cast int to int[5] make: *** [build/MainLoop.o] Error 1 To my untrained eye, it looks like it would like me to pass it an int[5] to initialize the array, but that's a bit odd - I'd much rather treat it similarly to a 1D array in this case! Thanks, graham
Apr 09 2007
I think you have yourself confused. http://stumail.curry.edu/~dthibeau/Graham_Craig.jpgGraham, I was wondering if you were someone that I know. Are you the Graham I am thinking of? -Craig
Apr 09 2007
I don't think so... Sorry! Craig Black wrote:Graham, I was wondering if you were someone that I know. Are you the Graham I am thinking of? -Craig "Graham" <grahamamacdonald gmail.com> wrote in message news:ev7kdm$1p8e$1 digitalmars.com...Why will array setting work for a 1D array, but not a 2D? If I enter: int[5] buffer; buffer[] = 5; It compiles, but if I enter: int[5][5] buffer; buffer[][] = 5; (I tried the variation buffer[] = 5, but that didn't work either.) It fails to compile (in gdc), with the warning: MainLoop.d:56: Error: cannot implicitly convert expression (5) of type int to int[5] Error: cannot cast int to int[5] make: *** [build/MainLoop.o] Error 1 To my untrained eye, it looks like it would like me to pass it an int[5] to initialize the array, but that's a bit odd - I'd much rather treat it similarly to a 1D array in this case! Thanks, graham
Apr 11 2007