Incrementing [].length

Andrei Khropov andkhropov at nospam_mtu-net.ru
Wed Jun 21 07:35:04 PDT 2006


Luis Marques wrote:

> Hello
> 
> Consider this code:
> 
> int list[];
> list.length += 1;
> 
> dmd issues the error "(list).length is not an lvalue".
> 
> Why doesn't "+=" work for the length property?
> "list.length = list.length + 1" works.
It's because D compiler treats a = b as a(b) 
in order to simplify properties implementation.

So, actually 
"list.length = list.length + 1;"
 equals to 
"list.length( list.length() + 1 );"

As you can see "list.length += 1" doesn't fit in these semantics.

But I agree that it is some kind of inconsistency and it fools our expectations.
I'd like this syntax to be allowed by some mechanism.

It has been already discussed here:
http://www.digitalmars.com/drn-bin/wwwnews?digitalmars.D.learn/3516.









-- 
AKhropov



More information about the Digitalmars-d mailing list