www.digitalmars.com         C & C++   DMDScript  

D - array.length++ not allowed?

reply Kimberley Burchett <kimbly at kimbly.com> <Kimberley_member pathlink.com> writes:
The expression array.length++ yields the compiler error 
"'array.length' is not an lvalue"

Is this a bug or is it intentional?


Kimberley Burchett
Jan 17 2003
next sibling parent "Carlos" <carlos8294 msn.com> writes:
"Kimberley Burchett" <kimbly at kimbly.comKimberley_member pathlink.com>
escribiσ en el mensaje news:b0a8hn$j0a$1 digitaldaemon.com...
| The expression array.length++ yields the compiler error
| "'array.length' is not an lvalue"
|
| Is this a bug or is it intentional?
|
|
| Kimberley Burchett
|
|

As far as I remember, yes, it's intentional, but I don't remember the
reason. I think it was something with not allowing novices to do things like
this:

for (int i=0;i<1000;i++) {
    array.length++;
    ...
}

But someone also said that people still could do this:

for (int i=0;i<1000;i++) {
    array.length+=1; //or array.length=array.length+1, if += not supported
either
    ...
}

That's what I can remember.

—————————————————————————
Carlos Santander
http://carlos3.netfirms.com/


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.443 / Virus Database: 248 - Release Date: 2003-01-10
Jan 17 2003
prev sibling next sibling parent Burton Radons <loth users.sourceforge.net> writes:
Kimberley Burchett  wrote:
 The expression array.length++ yields the compiler error 
 "'array.length' is not an lvalue"
 
 Is this a bug or is it intentional?
It was to prevent: array [array.length ++] = 45; Which is dependent on undefined behaviour.
Jan 17 2003
prev sibling parent Russell Lewis <spamhole-2001-07-16 deming-os.org> writes:
Kimberley Burchett  wrote:
 The expression array.length++ yields the compiler error 
 "'array.length' is not an lvalue"
 
 Is this a bug or is it intentional?
 
 
 Kimberley Burchett
Walter thought that array.length++; hid too much complexity. That statement can cause: * realloc * malloc/memcpy (if realloc has to move the array) * GC run (if malloc doesn't have space) Personally, I wish the syntax was legal...but I don't write the compiler.
Jan 21 2003