www.digitalmars.com         C & C++   DMDScript  

D - [BUG?] cannot subscript an array by uint

reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
   value_type[] e = new value_type[length];

"list.d(519): cannot implicitly convert uint() to int"

   value_type[] e = new value_type[cast(int)(length)];

compiles ok

Surely this is wrong?
Apr 21 2004
next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Matthew wrote:

    value_type[] e = new value_type[length];
 
 "list.d(519): cannot implicitly convert uint() to int"

That suggests to me the bug (?) whereby addressing a property without () doesn't work in all situations. Does value_type[] e = new value_type[length()]; work in your case? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.
Apr 21 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
You were right. It's the failure to convert the property.

"Stewart Gordon" <smjg_1998 yahoo.com> wrote in message
news:c65jc2$8b4$1 digitaldaemon.com...
 Matthew wrote:

    value_type[] e = new value_type[length];

 "list.d(519): cannot implicitly convert uint() to int"

That suggests to me the bug (?) whereby addressing a property without () doesn't work in all situations. Does value_type[] e = new value_type[length()]; work in your case? Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit.

Apr 21 2004
prev sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Matthew wrote:

   value_type[] e = new value_type[length];

"list.d(519): cannot implicitly convert uint() to int"

   value_type[] e = new value_type[cast(int)(length)];

compiles ok

Surely this is wrong?


  

use negative numbers for arrays anyway? -- -Anderson: http://badmama.com.au/~anderson/
Apr 21 2004
parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
Sorry dude, I don't follow your response. As shown, the code doesn't have
anything to do with opApply(), it's just talking about an array.

As for -ves with arrays, that is useful, because one might pass a pointer to
somewhere in the middle of an array, in which case a -ve index is eminently
meaningful.

"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:c65k0v$92k$3 digitaldaemon.com...
 Matthew wrote:

   value_type[] e = new value_type[length];

"list.d(519): cannot implicitly convert uint() to int"

   value_type[] e = new value_type[cast(int)(length)];

compiles ok

Surely this is wrong?

use negative numbers for arrays anyway? -- -Anderson: http://badmama.com.au/~anderson/

Apr 21 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Matthew wrote:

Sorry dude, I don't follow your response. As shown, the code doesn't have
anything to do with opApply(), it's just talking about an array.
  

Sorry, your right. Didn't read the code properly <g>
As for -ves with arrays, that is useful, because one might pass a pointer to
somewhere in the middle of an array, in which case a -ve index is eminently
meaningful.
  

want negatives. Negatives with arrays... the coder should be explicit. -- -Anderson: http://badmama.com.au/~anderson/
Apr 21 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:c6614u$vr7$1 digitaldaemon.com...
 Matthew wrote:

Sorry dude, I don't follow your response. As shown, the code doesn't have
anything to do with opApply(), it's just talking about an array.

Sorry, your right. Didn't read the code properly <g>
As for -ves with arrays, that is useful, because one might pass a pointer to
somewhere in the middle of an array, in which case a -ve index is eminently
meaningful.

want negatives. Negatives with arrays... the coder should be explicit.

Sorry mate, I'm lost. I was illustrating how subscripting should support (but not require; hence my post) signed types. I didn't mention opApply at all. For the record, I have objected several times to Walter about opApply() using an int. I believe it should use an enum which contains only one publicly known value - "ok" (or "complete" or some such). All the author of an opApply() should be able to do is test whether the delegate return is == / != "ok". As it currently stands, the author of opApply() is able to write all kinds of unknown bad code by returning one of the magic numbers that the freach mechanism uses to indicate break, complete, whatever.
Apr 21 2004