开发者

static variables local to a function

In Linux, "static" variables are present in the BSS segment (in a code that is not running) and "local" variables are present in the "stack". This means开发者_如何学Python that static variables local to a function are present in the BSS area. How is the book-keeping done to ensure that the scope is within the function itself?


Where a variable is stored has nothing to do with scope. It's usually the compiler itself that restricts scope (access to the variable). When you have a statement like:

static int xyzzy;

within a function, xyzzy will not be allowed to be accessed by code outside that function, regardless of the fact that it has static storage duration.

Any attempt to do so will be a compile-time error, not a run-time check.

In fact, you can affect the local static variable but with something like a buffer overflow (running into the storage area where it exists), not via its name (which the compiler will disallow).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜