www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - cannot resize a dynamic array of int[int]

reply Ran <saotome.ran googlemail.com> writes:
It should be a stupid question. But I still hope for any response. Could anyone
tell me pls why the following code doesn't work ?

uint numberOfSubsets(uint n) {
	return (1 << n) - 1;
}

void main(char[][] args) {
	int[int] a[];
	a.length = numberOfSubsets(3);
}
The generated program runs endlessly. I'm using D2.
Ran
Oct 21 2008
next sibling parent "Denis Koroskin" <2korden gmail.com> writes:
On Tue, 21 Oct 2008 21:24:28 +0400, Ran <saotome.ran googlemail.com> wrote:

 It should be a stupid question. But I still hope for any response. Could  
 anyone tell me pls why the following code doesn't work ?

 uint numberOfSubsets(uint n) {
 	return (1 << n) - 1;
 }

 void main(char[][] args) {
 	int[int] a[];
 	a.length = numberOfSubsets(3);
 }
 The generated program runs endlessly. I'm using D2.
 Ran

This is a bug, try wrapping the assoc. array in a struct so that you make array of structs instead of array of maps. It should help.
Oct 21 2008
prev sibling next sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Tue, Oct 21, 2008 at 1:31 PM, Denis Koroskin <2korden gmail.com> wrote:
 On Tue, 21 Oct 2008 21:24:28 +0400, Ran <saotome.ran googlemail.com> wrote:

 It should be a stupid question. But I still hope for any response. Could
 anyone tell me pls why the following code doesn't work ?

 uint numberOfSubsets(uint n) {
        return (1 << n) - 1;
 }

 void main(char[][] args) {
        int[int] a[];
        a.length = numberOfSubsets(3);
 }
 The generated program runs endlessly. I'm using D2.
 Ran

This is a bug, try wrapping the assoc. array in a struct so that you make array of structs instead of array of maps. It should help.

It's a bug that's been around for way too fucking long, excuse the language. It's apparently a one-character change in the typeinfo for AAs.
Oct 21 2008
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Jarrett Billingsley" wrote
 On Tue, Oct 21, 2008 at 1:31 PM, Denis Koroskin <2korden gmail.com> wrote:
 On Tue, 21 Oct 2008 21:24:28 +0400, Ran <saotome.ran googlemail.com> 
 wrote:

 It should be a stupid question. But I still hope for any response. Could
 anyone tell me pls why the following code doesn't work ?

 uint numberOfSubsets(uint n) {
        return (1 << n) - 1;
 }

 void main(char[][] args) {
        int[int] a[];
        a.length = numberOfSubsets(3);
 }
 The generated program runs endlessly. I'm using D2.
 Ran

This is a bug, try wrapping the assoc. array in a struct so that you make array of structs instead of array of maps. It should help.

It's a bug that's been around for way too fucking long, excuse the language. It's apparently a one-character change in the typeinfo for AAs.

FYI, this was just posted to the bug report:
 http://d.puremagic.com/issues/show_bug.cgi?id=929





 ------- Comment #15 from kamm-removethis incasoftware.de  2008-10-21 
 12:40 -------
 Just to make the patch more explicit: Adding

 int TypeAArray::isZeroInit()
 {
    return 1;
 }

 to mtype.c and the matching prototype to mtype.h fixes it. Tested in LDC.

-Steve
Oct 21 2008
prev sibling parent reply "Jarrett Billingsley" <jarrett.billingsley gmail.com> writes:
On Tue, Oct 21, 2008 at 3:41 PM, Steven Schveighoffer
<schveiguy yahoo.com> wrote:
 "Jarrett Billingsley" wrote
 On Tue, Oct 21, 2008 at 1:31 PM, Denis Koroskin <2korden gmail.com> wrote:
 On Tue, 21 Oct 2008 21:24:28 +0400, Ran <saotome.ran googlemail.com>
 wrote:

 It should be a stupid question. But I still hope for any response. Could
 anyone tell me pls why the following code doesn't work ?

 uint numberOfSubsets(uint n) {
        return (1 << n) - 1;
 }

 void main(char[][] args) {
        int[int] a[];
        a.length = numberOfSubsets(3);
 }
 The generated program runs endlessly. I'm using D2.
 Ran

This is a bug, try wrapping the assoc. array in a struct so that you make array of structs instead of array of maps. It should help.

It's a bug that's been around for way too fucking long, excuse the language. It's apparently a one-character change in the typeinfo for AAs.

FYI, this was just posted to the bug report:
 http://d.puremagic.com/issues/show_bug.cgi?id=929





 ------- Comment #15 from kamm-removethis incasoftware.de  2008-10-21
 12:40 -------
 Just to make the patch more explicit: Adding

 int TypeAArray::isZeroInit()
 {
    return 1;
 }

 to mtype.c and the matching prototype to mtype.h fixes it. Tested in LDC.

-Steve

Downs posted an equivalent solution over a year ago to the same bug.
Oct 21 2008
parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"Jarrett Billingsley" wrote
 On Tue, Oct 21, 2008 at 3:41 PM, Steven Schveighoffer
 <schveiguy yahoo.com> wrote:
 "Jarrett Billingsley" wrote
 On Tue, Oct 21, 2008 at 1:31 PM, Denis Koroskin <2korden gmail.com> 
 wrote:
 On Tue, 21 Oct 2008 21:24:28 +0400, Ran <saotome.ran googlemail.com>
 wrote:

 It should be a stupid question. But I still hope for any response. 
 Could
 anyone tell me pls why the following code doesn't work ?

 uint numberOfSubsets(uint n) {
        return (1 << n) - 1;
 }

 void main(char[][] args) {
        int[int] a[];
        a.length = numberOfSubsets(3);
 }
 The generated program runs endlessly. I'm using D2.
 Ran

This is a bug, try wrapping the assoc. array in a struct so that you make array of structs instead of array of maps. It should help.

It's a bug that's been around for way too fucking long, excuse the language. It's apparently a one-character change in the typeinfo for AAs.

FYI, this was just posted to the bug report:
 http://d.puremagic.com/issues/show_bug.cgi?id=929





 ------- Comment #15 from kamm-removethis incasoftware.de  2008-10-21
 12:40 -------
 Just to make the patch more explicit: Adding

 int TypeAArray::isZeroInit()
 {
    return 1;
 }

 to mtype.c and the matching prototype to mtype.h fixes it. Tested in 
 LDC.

-Steve

Downs posted an equivalent solution over a year ago to the same bug.

I meant FWI. (For Walter's Info) ;) -Steve
Oct 21 2008