以下哪项是正确的?
I. A programming language which does not permit global variables of any
kind and has no nesting of procedures/functions, but permits recursion
can be implemented with static storage allocation
II. Multi-level access link (or display) arrangement is needed to arrange
activation records only if the programming language being implemented
has nesting of procedures/functions
III. Recursion in programming languages cannot be implemented with dynamic
storage allocation
IV. Nesting of procedures/functions and recursion require a dynamic heap
allocation scheme and cannot be implemented with a stack-based allocation
scheme for activation records
V. Programming languages which permit a function to return a function as its
result cannot be implemented with a stack-based storage allocation scheme
for activation records
(A)仅II和V
(B)仅I,III和IV
(C)仅I,II和V
(D)仅II,III和V答案: (A)
说明: I.递归不能通过静态存储分配来实现。静态分配意味着编译器必须决定函数调用的大小。在递归的情况下,编译器无法决定,因为递归的深度取决于递归参数,递归参数也可能是用户的输入。
二。是正确的。支持嵌套子例程的编程语言在调用框架中还具有一个字段,该字段指向最紧密封装被调用者(即被调用者的直接作用域)的过程的最新激活的堆栈框架。这称为访问链接或静态链接(因为它在动态和递归调用期间跟踪静态嵌套),并在每次嵌套时向例程(以及它可能调用的任何其他例程)提供对其封装例程的本地数据的访问。等级。某些体系结构,编译器或优化案例为每个封闭级别(而不只是立即封闭)存储一个链接,因此访问浅层数据的深层嵌套例程不必遍历多个链接。这种策略通常称为“展示广告” [来源:https://en.wikipedia.org/wiki/Call_stack]
三,递归可以与任何类型的动态存储分配方案来实现。
IV。嵌套功能始终使用STACK和NOT Heap以某种语言实现。 (有关详细信息,请参见上述第二点)
V.是正确的。在基于堆栈的分配方案中,一旦函数返回,就将其从函数调用堆栈中删除。因此,从函数返回函数看起来不太可能。
这个问题的测验