Thread overview
array.length++ not allowed?
Jan 18, 2003
Kimberley Burchett
Jan 18, 2003
Carlos
Jan 18, 2003
Burton Radons
Jan 21, 2003
Russell Lewis
January 18, 2003
The expression array.length++ yields the compiler error "'array.length' is not an lvalue"

Is this a bug or is it intentional?


Kimberley Burchett


January 18, 2003
"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


January 18, 2003
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.

January 21, 2003
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.