4 ms·
Global variables in C are dynamically scoped. They tend to be useful from time to time.
by Derbasti 13y ago
Global variables in C are dynamically scoped. They tend to be useful from time to time.
- mikeash 13y agoI'm not very familiar with dynamic scoping, so maybe I've misunderstood it, but that doesn't appear to be true. What variable a name binds to is determined entirely at runtime, which happens for globals too. You cannot end up accessing a variable in your caller unless they explicitly pass in a reference to it, and it's not possible to write a function which refers to a single global variable in the code, but which can refer to different variables at runtime depending on the caller.
- justinpombrio 13y agoYou are correct. C is lexically (a.k.a. statically) scoped, through and through.