Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
There is basically only one reason not to use static functions in C, as opposed to functions with global scope. That's if you want to access the function from outside the module. Otherwise, if th...
Answer
#2: Post edited
There is basically only one reason not to use static functions in C, as apposed to functions with global scope. That's if you want to access the function from outside the module.Otherwise, if the function is only used in the specific module, then it's beneficial to not export it to the whole world. By making is <tt>static</tt> (a bad name for not global, but that's C) you know that the only callers to the function are local to the module.- It also means the function is only in the namespace of the module, and you don't have to worry about being unique within the global scope. For example multiple modules can have local functions called <tt>init_state</tt> without any problems.
- So overall, the answer is to make functions <tt>static</tt> in C unless they are meant to be called from outside the module.
- There is basically only one reason not to use static functions in C, as opposed to functions with global scope. That's if you want to access the function from outside the module.
- Otherwise, if the function is only used in the specific module, then it's beneficial to not export it to the whole world. By making it <tt>static</tt> (a bad name for "not global", but that's C) you know that the only callers to the function are local to the module.
- It also means the function is only in the namespace of the module, and you don't have to worry about being unique within the global scope. For example multiple modules can have local functions called <tt>init_state</tt> without any problems.
- So overall, the answer is to make functions <tt>static</tt> in C unless they are meant to be called from outside the module.
#1: Initial revision
There is basically only one reason not to use static functions in C, as apposed to functions with global scope. That's if you want to access the function from outside the module. Otherwise, if the function is only used in the specific module, then it's beneficial to not export it to the whole world. By making is <tt>static</tt> (a bad name for not global, but that's C) you know that the only callers to the function are local to the module. It also means the function is only in the namespace of the module, and you don't have to worry about being unique within the global scope. For example multiple modules can have local functions called <tt>init_state</tt> without any problems. So overall, the answer is to make functions <tt>static</tt> in C unless they are meant to be called from outside the module.