Question about static variables


#1

The book states that “A static variable is like a global variable in that it is declared outside of any function. However, a static variable is only accessible from the code in the file where it was declared.”

I did some Googling about static variables, and it seems that many of the examples involve declaring static variable inside of a function in order to keep them in memory after the function exits, so it is still around for the next call of that function. I also found references to your usage, static variables as globally defined variables outside of any function, but limited in scope to just the single file in which it was declared.

My question is, are both usage cases valid in C/objective C, and it’s just something you chose not to expose to the reader yet, or am I picking up C++ usage on the web that isn’t applicable in C/Objective C?


#2

You are right: both uses are valid, and I did not consider both.

Sorry. I’ll fix it in the next edition.