Reputation: 665
I am studying for a quiz tomorrow (c++) and had a quick question.
Global functions can be accessed anywhere, but (according to my notes), making a global function static restricts access to the defining file.
Thanks for the help again guys, you save me a lot of headaches in CSC, and I hope to return the favor when more knowledgeable.
Upvotes: 0
Views: 111
Reputation: 1409
Yes, making a global function static would restrict its access to the same file only (in which it is defined).
Still it will be accessible to other functions within the file (its like a restricted global function). It has the benefits of minimizing name clashes to other files in the software.
Also, if you don't need a function in other files then you can restrict its access hence avoiding the chances of data corruption of global data in other files (if any).
Upvotes: 1
Reputation: 87959
Yes
Yes but that's sometimes what you want. It's a bit like a poor man's version of private in a C++ class declaration.
Upvotes: 1