www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - new [] and length

reply Carlos Santander <csantander619 gmail.com> writes:
Are there any differences between these two fragments, besides the syntax?

char [] buf = new char [count];

char [] buf;
buf.length = count;

I ask because when I use the first method and then pass it to Mango's 
Atoi.parse, sometimes I get:

Error: ArrayBoundsError 
/Users/carlos/Development/d/mango-2.0/mango/convert/Atoi.d(175)

But when I use the second method, I never get that error. In both cases I'm 
using the same data, which unfortunately is too large and complex to make a 
reduced test case.

I'm using GDC 0.17 on Mac. Could this be Mac only or GDC only?

-- 
Carlos Santander Bernal
May 09 2006
parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
Is it always "count" or are you ever using "length" inside the brackets 
for new?

-[Unknown]


 Are there any differences between these two fragments, besides the syntax?
 
 char [] buf = new char [count];
 
 char [] buf;
 buf.length = count;
 
 I ask because when I use the first method and then pass it to Mango's 
 Atoi.parse, sometimes I get:
 
 Error: ArrayBoundsError 
 /Users/carlos/Development/d/mango-2.0/mango/convert/Atoi.d(175)
 
 But when I use the second method, I never get that error. In both cases 
 I'm using the same data, which unfortunately is too large and complex to 
 make a reduced test case.
 
 I'm using GDC 0.17 on Mac. Could this be Mac only or GDC only?
 
May 09 2006
parent Carlos Santander <csantander619 gmail.com> writes:
Unknown W. Brackets escribió:
 Is it always "count" or are you ever using "length" inside the brackets 
 for new?
 
 -[Unknown]
 
 
 Are there any differences between these two fragments, besides the 
 syntax?

 char [] buf = new char [count];

 char [] buf;
 buf.length = count;

 I ask because when I use the first method and then pass it to Mango's 
 Atoi.parse, sometimes I get:

 Error: ArrayBoundsError 
 /Users/carlos/Development/d/mango-2.0/mango/convert/Atoi.d(175)

 But when I use the second method, I never get that error. In both 
 cases I'm using the same data, which unfortunately is too large and 
 complex to make a reduced test case.

 I'm using GDC 0.17 on Mac. Could this be Mac only or GDC only?
Always "count". Say no to length :P -- Carlos Santander Bernal
May 09 2006