Author: Stan Eisenstat
Subject: Re: [Cs223] scope
Date: Sunday, 01 Mar 2020, 11:26:57
> Message Posted By: Unknown > > 1. What is "(un)knowable outside" in the scope handout? Outside the file? > ONE is knowable outside, but it's not known in the other file bar.c. The phrase "knowable outside" refers to non-static functions and global variables, which can be linked to from other object files by using an extern statement. The phrase "unknowable outside" refers to static functions and static global variables which can not be accessed from other object files. C uses "static" for two different purposes. Here it means private rather than persistent (as in static local variables). ===== > 2. What does extern do to a variable? Why is E1 only accessible till the > end of the block, though it is declared as extern? Doesn't extern make a > variable accessible everywhere? If so, is it everywhere in the file or in > the program? The keyword "extern" means that the variable is defined (i.e., allocated storage) somewhere else, which will be revealed at link time. ===== > 3. What does static do to a variable? A static local variable has its > value persist even after function has ended. But can it be accessed > outside that function? For a static global, does static just mean it can > only be accessed within the file? A static local variable is persistent and retains it value when the function returns. A static global variable or function is private and can only be accessed from within the file where it is defined. --Stan-PREV INDEX NEXT