Immutability and other attributes, please review

Roman D. Boiko rb at d-coding.com
Thu Jun 14 08:32:03 PDT 2012


On Thursday, 14 June 2012 at 15:21:53 UTC, dennis luehring wrote:
> Am 14.06.2012 15:26, schrieb Roman D. Boiko:
>> But now, with everything immutable, I had to comment out 
>> several
>> test cases. I cannot pass an immutable struct allocated on 
>> stack,
>> into a method by reference, and then store a pointer to it,
>
> thats sounds very evil - with or without immutable
> how should that work anyway?
>
>> because compiler says it is not an l-value. Should I allocate 
>> it
>> on heap? Or get rid of functions taking parameter by ref, and 
>> use
>> only those which take a pointer?
>
> i would use the heap and ref - else you need to copy, the 
> pointer would also not work if your struct is still in the 
> stack - or does the stack live long enough?

I agree, just looking how to accomplish my goals. I decided to 
get rid of casting, and will store everything on heap. I don't 
know how to put a variable of type float to the heap, and thought 
that it would be nice to allow the user to pass anything inside, 
but copy when that is not an l-value.

I posted another question: 
http://forum.dlang.org/thread/nsishethfwgxygsmzjwi@forum.dlang.org


More information about the Digitalmars-d-learn mailing list