Block variable and activation record

I understand that local variables (along with other things) are placed in the activation record . And the activation record must exist before the function starts execution. Consider the following function:

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

Looking at this function, it seems that the variable jmay or may not exist, completely dependent on user input at runtime. In this case

  • Will the variable be placed jin the activation record?
  • Is this implementation defined (in other words, will any compiler generate equivalent code jdeclared outside and above the if` block)?
  • , j , ? , j if?

C11. .

+4
1

, . , :

Q1. j ?

A1: , .

Q2. ( , - , j, if?)

A2: . , j .

Q3. , j , ? , , j if?

A3: , C .

0

Source: https://habr.com/ru/post/1690717/


All Articles