Thread overview
correct way to set a dynamic 2d array?
May 31, 2005
clayasaurus
May 31, 2005
Derek Parnell
May 31, 2005
Hasan Aljudy
May 31, 2005
Derek Parnell
Jun 02, 2005
Stewart Gordon
May 31, 2005
is this the correct way to set a dynamic 2D array?

int[][] dynamic;

dynamic.length = width;

for (int i = 0; i < dynamic.length; i++)
   dynamic[i].length = height;

Just seems a bit weird.
May 31, 2005
On Tue, 31 May 2005 03:56:00 +0000, clayasaurus wrote:

> is this the correct way to set a dynamic 2D array?
> 
> int[][] dynamic;
> 
> dynamic.length = width;
> 
> for (int i = 0; i < dynamic.length; i++)
>     dynamic[i].length = height;
> 
> Just seems a bit weird.

Currently, yes. Though it could also be written as ...

 int[][] dynamic;

 dynamic.length = width;

 foreach (inout int[] x; dynamic)
     x.length = height;


-- 
Derek
Melbourne, Australia
31/05/2005 2:33:02 PM
May 31, 2005
Derek Parnell wrote:
> On Tue, 31 May 2005 03:56:00 +0000, clayasaurus wrote:
> 
> 
>>is this the correct way to set a dynamic 2D array?
>>
>>int[][] dynamic;
>>
>>dynamic.length = width;
>>
>>for (int i = 0; i < dynamic.length; i++)
>>    dynamic[i].length = height;
>>
>>Just seems a bit weird.
> 
> 
> Currently, yes. Though it could also be written as ...
> 
>  int[][] dynamic;
>   dynamic.length = width;
>   foreach (inout int[] x; dynamic)
>      x.length = height;
> 
> 

can't you just say this?
dynamic[].length = height;

May 31, 2005
On Tue, 31 May 2005 00:31:47 -0600, Hasan Aljudy wrote:

> Derek Parnell wrote:
>> On Tue, 31 May 2005 03:56:00 +0000, clayasaurus wrote:
>> 
>>>is this the correct way to set a dynamic 2D array?
>>>
>>>int[][] dynamic;
>>>
>>>dynamic.length = width;
>>>
>>>for (int i = 0; i < dynamic.length; i++)
>>>    dynamic[i].length = height;
>>>
>>>Just seems a bit weird.
>> 
>> Currently, yes. Though it could also be written as ...
>> 
>>  int[][] dynamic;
>> 
>>  dynamic.length = width;
>> 
>>  foreach (inout int[] x; dynamic)
>>      x.length = height;
>> 
> 
> can't you just say this?
> dynamic[].length = height;

No. You get this message ...

 slice expression dynamic[] is not a modifiable lvalue

-- 
Derek
Melbourne, Australia
31/05/2005 4:46:02 PM
May 31, 2005
"Derek Parnell" <derek@psych.ward> wrote in message news:k3gx4tkutm62$.wl0ydvkulqru.dlg@40tude.net...
>> can't you just say this?
>> dynamic[].length = height;
>
> No. You get this message ...
>
> slice expression dynamic[] is not a modifiable lvalue

Isn't this something that would be possible with array vectorization?

I'd really love this syntax..


June 02, 2005
Jarrett Billingsley wrote:
> "Derek Parnell" <derek@psych.ward> wrote in message news:k3gx4tkutm62$.wl0ydvkulqru.dlg@40tude.net...
> 
>>>can't you just say this?
>>>dynamic[].length = height;
<snip>
> I'd really love this syntax.. 

But it would create confusion..

http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.bugs/1942

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.