[ASP.net教程]Compiler 1.6.5 —1.6.7
Compiler 1.6.5 —1.6.7
Technically, any scoping policy is dynamic if it is based on factor(s) that can be known only when the program executes.
A use of a name x refers to
the declaration of x in the most recently called procedure with such a declaration.
declarations and definitions
The apparently similar terms "declaration" and "definition" for program ming-language concepts are actually quite different. Declarations tell us about the types of things, while definitions tell us about their values . Thus, int i is a declaration of i, while i = 1 is a definition of i.
int i is a declaration of i ,while i =1 is a definition of i .S
In fact, in order to interpret x, we must use the usual dynamic-scope rule. We examine all the function calls that are currently active, and we take the most recently called function that has a declaration of x. It is to this declaration that the use of x refers.
Dynamic scope resolution is also essential for polymorphic procedures ,those that have two or more definitions for the same name ,depending only on the types of the arguments .
Analogy Between Static and Dynamic Scoping
In a sense, the dynamic rule is to time as the static rule is to space. While the static rule asks us to find the declaration whose unit (block) most closely surrounds the physical location of the use, the dynamic rule asks us to find the declaration whose unit (procedure invocation) most closely surrounds the time of the use.
1.6.6 parameter passing mechanisms
In this section, we shall consider
how the actual parameters (the parameters used in the call of a procedure) are associated with the formal parameters (those used in the procedure definition ).
The great majority of languages use either "call-by-value," or "call-by-reference," or both. We shall explain these terms, and another method known as "call-by-name," that is primarily of historical interest.
Call-by-value has the effect that all computation involving the
formal parameters done by the called procedure is local to that procedure, and the actual parameters themselves cannot be changed.
However，that in c we can pass a pointer to a variable to allow that variable to be changed by the collee.
In call-by-reference, the address of the actual parameter is passed to the cailee as the value of the corresponding formal parameter.
Uses of the formal parameter in the code of the callee are implemented by following this pointer to the location indicated by the caller.
Changes to the formal parameter thus appear as changes to the actual parameter.
1.6.7 Aliasing 别名
It is possible that two formal parameters can refer to the same location;
such variables are said to be aliases of one another. As a result, any two variables, which may appear to take their values from two distinct formal parameters, can become aliases of each other, as well.