Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   static scoping in C (http://www.go4expert.com/forums/static-scoping-c-t18137/)

dano 21Jun2009 08:44

static scoping in C
 
Hello all,

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

Code: C

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.

shabbir 21Jun2009 08:48

Re: static scoping in C
 
Check out All about Static in C++. It has everything you would like to know about Statics in C++

SaswatPadhi 21Jun2009 08:55

Re: static scoping in C
 
Quote:

Originally Posted by shabbir (Post 50207)
Check out All about Static in C++. It has everything you would like to know about Statics in C++

The article you mentioned talks about static variables in c++, not about static scoping.
Static scoping is different : http://en.wikipedia.org/wiki/Scope_%...ynamic_scoping.

shabbir 21Jun2009 09:00

Re: static scoping in C
 
Opps. My mistake

SaswatPadhi 21Jun2009 09:02

Re: static scoping in C
 
@ dano :

Code: C

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).

dano 23Jun2009 00:46

Re: static scoping in C
 
Thank you that helped.


All times are GMT +5.5. The time now is 05:19.