Strict definition of value types and reference types
Ali Çehreli
acehreli at yahoo.com
Sat Apr 13 21:01:34 PDT 2013
On 04/13/2013 08:46 PM, Nicholas Smith wrote:
> On Sunday, 14 April 2013 at 02:51:35 UTC, bearophile wrote:
>> slices are kind of hybrids between values and references. You can also
>> think of them as fat references. When you program in D you must
>> remember this nature of sliced, otherwise your code will not work...
>>
>> Bye,
>> bearophile
>
> Ali Çehreli uses slices as the first example for what a reference type
> is in his "Programming in D". Perhaps that is not a good example then.
That must be fixed then. :/ Slices are value types but they have
reference semantics: they are references to elements but a slice
variable itself is data on its own.
Your definition of value type vs. reference type is correct. These
definitions come from how the language behaves. structs are value types
and classes are reference types.
structs are the most powerful because they can be used to provide value
semantics or reference semantics.
Ali
More information about the Digitalmars-d-learn
mailing list