www.digitalmars.com         C & C++   DMDScript  

D - [bug]

reply Dr.Dizel <Dr.Dizel_member pathlink.com> writes:
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;}
//...	

}
Jan 23 2004
parent reply imr1984 <imr1984_member pathlink.com> writes:
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;}
//...	

}
Jan 23 2004
parent reply Dr.Dizel <Dr.Dizel_member pathlink.com> writes:
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 :-\
Jan 23 2004
parent reply Andrew Edwards <edwardsac spamfreeusa.com> writes:
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
Jan 23 2004
next sibling parent Ilya Minkov <minkov cs.tum.edu> writes:
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
Jan 23 2004
prev sibling parent J C Calvarese <jcc7 cox.net> writes:
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/
Jan 23 2004