Documentation of "scope" function parameters

Michel Fortin michel.fortin at michelf.com
Sun Mar 30 04:08:57 PDT 2008


I'm reading the Functions section of the D 2.0 documentation.
<http://www.digitalmars.com/d/2.0/function.html#parameters>.
Under Function Parameters, I read this:

	Parameter storage classes are in, out, ref, lazy, final, const, 
invariant, or scope.

then this:

	 The in storage class is equivalent to const scope.

But there is no explaination how scope affect things.

If I go find scope in the Attributes section
<http://www.digitalmars.com/d/2.0/attribute.html#scope>
I can find this which may be relevant to the case of a funciton parameter:

	For local declarations, scope implements the RAII (Resource Acquisition
	Is Initialization) protocol. This means that the destructor for an object is
	automatically called when the reference to it goes out of scope.

Is this really what it does? It sounds pretty silly that the function
destroys the object the caller has passed to it, so I guess it doesn't.

However, this part may apply when talking about function parameters:

	Assignment to a scope, other than initialization, is not allowed.
	Rationale: These restrictions may get relaxed in the future if a compelling
	reason to appears.

which would mean you just can't reassign a new value to a scope parameter
inside the function. That's just a guess of what it does, and to me it sounds
pointless and misnamed.

What is it in reality?

Anyhow, I think what scope does with a function parameters should be better
documented in the Functions section.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list