1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

static scoping in C

Discussion in 'C' started by dano, Jun 21, 2009.

  1. dano

    dano New Member

    Joined:
    Jun 21, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hello all,

    I have a question in understanding static scoping. i have a this as an example.

    Code:
    void fun(void) {
        int a, b, c;     /*definition 1 */
        
        while (…) {
           int b, c, d;     /*definition 2 */
               …            ← 1
                while (…) {
                    int c, d, e;     /* definition 3 */
                           …        ← 2
                       }
                           …            ← 3
            }
             …            ← 4
        }
    for each of the four marked points in this function, list each visible variable, along with the number of definition statement that defines it.

    can any one help me understand static scoping using this example?

    Thank you in advance.
     
    Last edited by a moderator: Jun 21, 2009
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Opps. My mistake
     
  5. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    @ dano :

    Code:
    void fun(void) {
        int a, b, c;     /*definition 1 */
       
        while (…) {
           int b, c, d;     /*definition 2 */
               …            ← 1
                while (…) {
                    int c, d, e;     /* definition 3 */
                           …        ← 2
                       }
                           …            ← 3
            }
             …            ← 4
        }
    Point 1 : (i) a is visible as per definition 1.
    xxxxxxx#(ii) b is visible as per definition 2.
    xxxxxxxx(iii) c is visible as per definition 2.
    xxxxxxxx(iv) d is visible as per definition 2.

    Point 2 : (i) a is visible as per definition 1.
    xxxxxxx#(ii) b is visible as per definition 2.
    xxxxxxxx(iii) c is visible as per definition 3.
    xxxxxxxx(iv) d is visible as per definition 3.
    xxxxxxx#(v) e is visible as per definition 3.

    Point 3 : Same as Point 1.

    Point 4 : (i) a is visible as per definition 1.
    xxxxxxx#(ii) b is visible as per definition 1.
    xxxxxxxx(iii) c is visible as per definition 1.

    If you don't understand Static Scoping, look at the link I mentioned for shabbir (in the post above).
     
  6. dano

    dano New Member

    Joined:
    Jun 21, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Thank you that helped.
     

Share This Page