Value vs. reference semantics, and pointers

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue Mar 21 00:41:04 PST 2006


Hi,

I will just give you a few quick comments.

Scott L. Burson wrote:
>  Similarly, I would discourage the use of the
> ampersand to reify a function; I think the ampersand should at least be optional
> (as indeed it is in C) -- I don't see anything in the docs that says it's
> required, but you seem to use it in all the examples. 

I guess the reason is that D allows function calling (property like) 
without trailing parentheses (). Meaning func is identical to func() in 
most cases. The ampersand is needed to distinguish function calls from 
function references.

> I've been skimming the material on the D Web site and want to be sure I
> understand some things.  I gather that structs and unions have value semantics,
> while arrays and classes have reference semantics.  That is, assignment to a
> variable of struct or union type copies the contents, while assignment to a
> variable of array or class type copies a reference to the contents.  Is that
> correct?  You might want to clarify this in the docs, as it's pretty
> fundamental.

That is correct.

> I also have a question about the treatment of pointers.  I understand that
> out/inout parameters and reference semantics for classes and arrays will
> eliminate the vast majority of occasions calling for explicit pointers, but
> still, I'm curious.  In D, can you make a pointer to a single object as in C, or
> does it have to be in an array?

You can still make pointers to anything just like in C.

/Oskar



More information about the Digitalmars-d mailing list