内联块和功能块有什么不同?
在编程语言理论中,
与栈帧相关的Block有两种。内联块和功能块。
内联块和功能块有什么不同?
并假设有如下代码。
int x = 1;
g(z) = z + x;
根据 In-line block,函数 g 是否嵌套到变量 x?
In Programming Language Theory,
Block which is related with stack frame has two kinds. In-line block and function block.
What is different between In-line block and function block?
And assume there is code like below.
int x = 1;
g(z) = z + x;
According to In-line block, Is function g nested to variable x?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
功能块:
无效函数(){...}; // 在 c 或 c++ 中
(defun func ...) // 在 clisp 中
fun func() = ... // 在 ml 中
函数块是包装函数的块。
在C中,当函数返回时,函数的激活记录将从堆栈中删除。
然而,在像ML、CLISP这样的函数式语言中,函数的返回并不总是意味着堆栈帧的删除。
因为这个功能以后还可以用。
行内块是显示嵌套结构的块。
当函数g使用In-line块时,函数g将变量x取1。函数g仅凭函数g的激活记录不知道x的值。然而函数g之所以能知道x的值是因为它使用了静态链接,而静态链接指向最近的嵌套块。
函数块和内联块之间的区别在于,函数返回时函数块始终不会从堆栈帧中删除。
Function block :
void func(){...}; // in c or c++
(defun func ...) // in clisp
fun func() = ... // in ml
The Function Block is the block that wraps the function.
In C, when the function returns, the function's activation records is deleted from stack.
however, In functional language like ML, CLISP, function's return don't always means deletion of stack frame.
Because the function can be used later.
In-line block is the block that shows nested structure.
When the function g uses In-line block, the function g takes the variable x as 1. the function g don't know x's value with only the function g's activation record. however the reason the function g can know x's value is it use static link, and static link points the most nearest nesting block.
The difference between function block and inline block is that function block always is not deleted from stack frame when the function returns.