Thread overview
[bug]
Jan 23, 2004
Dr.Dizel
Jan 23, 2004
imr1984
Jan 23, 2004
Dr.Dizel
Jan 23, 2004
Andrew Edwards
Jan 23, 2004
Ilya Minkov
vec.length++ (was [bug])
Jan 24, 2004
J C Calvarese
January 23, 2004
Here if I change string "_vec.length = _vec.length + 1;" to "++_vec.length;" it reports me a bug. :-\ Am I have a bug or dmd. :)

class vebu
{
uint _last = 0;
ubyte[4096][] _vec;

this() { _vec.length = 1;}

public:
void add(ubyte _byte)
{
if (_last >= _vec[0].length) { _vec.length = _vec.length + 1;  _last = 0;}
_vec[_vec.length - 1][_last] = _byte; ++_last;
}

void add(ubyte[] _p1) { foreach(ubyte F; _p1) add(F);}
uint length() { return (_vec.length - 1) * 4096 + _last;}
//...

}


January 23, 2004
what you are trying to do isnt supported, although i wish it was

In article <buqr9u$2hpd$1@digitaldaemon.com>, Dr.Dizel says...
>
>Here if I change string "_vec.length = _vec.length + 1;" to "++_vec.length;" it reports me a bug. :-\ Am I have a bug or dmd. :)
>
>class vebu
>{
>uint _last = 0;
>ubyte[4096][] _vec;
>
>this() { _vec.length = 1;}
>
>public:
>void add(ubyte _byte)
>{
>if (_last >= _vec[0].length) { _vec.length = _vec.length + 1;  _last = 0;}
>_vec[_vec.length - 1][_last] = _byte; ++_last;
>}
>
>void add(ubyte[] _p1) { foreach(ubyte F; _p1) add(F);}
>uint length() { return (_vec.length - 1) * 4096 + _last;}
>//...
>
>}
>
>


January 23, 2004
In article <bur463$30a3$1@digitaldaemon.com>, imr1984 says...
>
>what you are trying to do isnt supported, although i wish it was
>
But... it works in this case :-\


January 23, 2004
Dr.Dizel wrote:
> In article <bur463$30a3$1@digitaldaemon.com>, imr1984 says...
> 
>>what you are trying to do isnt supported, although i wish it was
>>
> 
> But... it works in this case :-\
> 
> 
I assume you mean here:

	_vec.length = _vec.length + 1;

that is authorized in D. What is not authorized is the incrementation or decrementation of properties using ++ or --.

so you cannot type

	++_vec.length
	_vec.length++

in hopes of obtaining the same outcome as above (it is not supported)!

Andrew
January 23, 2004
Andrew Edwards wrote:
> so you cannot type
> 
>     ++_vec.length
>     _vec.length++

However, what is the purpose of this? If the purpose is to add a new element el, simply do:

vec ~= el;

-eye

January 24, 2004
Andrew Edwards wrote:
> Dr.Dizel wrote:
> 
>> In article <bur463$30a3$1@digitaldaemon.com>, imr1984 says...
>>
>>> what you are trying to do isnt supported, although i wish it was
>>>
>>
>> But... it works in this case :-\
>>
>>
> I assume you mean here:
> 
>     _vec.length = _vec.length + 1;
> 
> that is authorized in D. What is not authorized is the incrementation or decrementation of properties using ++ or --.
> 
> so you cannot type
> 
>     ++_vec.length
>     _vec.length++
> 
> in hopes of obtaining the same outcome as above (it is not supported)!
> 
> Andrew


I'd still like to be able to do vec.length++, but the compiler deliberately prohibits this:

"Note: Properties currently cannot be the lvalue of an op=, ++, or -- operator."
http://www.digitalmars.com/d/property.html (bottom of page)

I think the reason might be the one that Sean Palmer suggested, "Am I correct in saying that the problem is that we can't know if postfix++ happens before or after the assignment, which depends on the ++ executing before the assignment, or it'll store into invalid memory?"
http://www.digitalmars.com/drn-bin/wwwnews?D/12869

Other theories:
http://www.digitalmars.com/drn-bin/wwwnews?D/12707
http://www.digitalmars.com/drn-bin/wwwnews?D/12858

-- 
Justin
http://jcc_7.tripod.com/d/