标签: activation-record

块作用域变量和激活记录

我知道,局部变量(以及其他内容)被放置在激活记录中。并且在函数开始执行之前,激活记录必须存在。考虑以下功能:

void f(void)
{
    int i;
    scanf("%d", &i);
    if (i > 10) {
        int j = 22;
        // do some operations on j here.
    }
    // more code below...
}
Run Code Online (Sandbox Code Playgroud)

查看此函数,似乎该变量j可能存在或可能不存在,完全取决于运行时用户的输入。在这种情况下,

  1. 变量j将被放置在激活记录中吗?
  2. 是否定义了此实现(换句话说,某些编译器会生成等同于j在if`块之外和之上声明的代码)吗?
  3. 或者,j如果需要,将在执行期间将其简单地分配到堆栈段上吗?但是,在这种情况下,如何jif块之后超出范围?

我在C11规范中找不到关于此的太多信息。提前致谢。

c activation-record

5
推荐指数
1
解决办法
81
查看次数

主要在C中有返回地址,动态链接或返回值吗?

根据我们的书,每个函数在C中的运行时堆栈中都有一个激活记录.每个激活记录都有一个返回地址,动态链接和返回值.主要还有这些吗?

c stack program-entry-point activation-record

4
推荐指数
1
解决办法
1903
查看次数

激活记录长度

前三个问题分别得到6,4,3,但我不知道怎么弄清楚最后一个问题.但是,解决方案手册显示了7,5,4,18作为答案.

int sum(int x[], int N) {
  int k = 0;
  int s = 0;
  while (k < N) {
    s = s + x[k];
    k = k + 1;
  }
  return s; // the activation record for sum will be ____________ locations
}

int fred(int a, int b) {
  return a + b;  // (2) the activation record for fred will be ____________ locations
}

void barney(int x) {
  x = fred(x, x);//(2) the activation record for barney will …
Run Code Online (Sandbox Code Playgroud)

c activation-record

0
推荐指数
1
解决办法
1446
查看次数

标签 统计

activation-record ×3

c ×3

program-entry-point ×1

stack ×1