idiomatic D: what to use instead of pointers in constructing a tree data structure?
via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Jan 14 12:56:40 PST 2015
On Wednesday, 14 January 2015 at 20:23:26 UTC, H. S. Teoh via
Digitalmars-d-learn wrote:
> Huh? ints have value semantics, yet you can take the address of
> a local
> int variable. What's your point?
Strictly speaking the "int" looses its value semantics if you
take the address of it, hold it and give it a new name (assign it
to a pointer). It is forced to be an object with an identity
(cannot sit in a register and is no longer alias free and
indistinguishable from other ints with same value). Same issue
with your struct, you turn it into an object with identity by
holding the identity, yet keep acting if it is a value.
C's type system has questionable soundness, but I guess it could
be corrected with behavioural typing... I.e. the preceding events
and the state is part of the type and determines what actions it
can participate it. Like a behavioural type for a file would make
it an error at compile time to close a file before opening it.
You could do something similar for taking the address of an int.
(Which is kinda what linear typing tries to do.)
More information about the Digitalmars-d-learn
mailing list