-2

I know why we use the static function, I bother about if I use a function as a static then any overhead of my application(in term of execution speed and memory)? Note:- My query about function not for a static variable.

  • You're worrying about overhead where you shouldn't. – DeiDei Oct 29 '17 at 15:30
  • @StoryTeller as you suggest I remove C++ and my query about in C language.please help me out so understand – GC Solution Oct 29 '17 at 15:31
  • @DeiDei yes I am worried about any overhead on my application in term of memory and execution speed. – GC Solution Oct 29 '17 at 15:33
  • Good start. But still unclear and quite broad. There are many types of overhead (space, build time, run time). Asking an unqualified question is not a good way to go. You should also present a use-case where you think it could matter. – StoryTeller - Unslander Monica Oct 29 '17 at 15:33
  • @StoryTeller thanks for your suggestion, as per your suggestion I mention all term – GC Solution Oct 29 '17 at 15:37
  • 1
    `static` on a function is a linkage specifier. The speed of the function should be the same as linkage affects visibility. Maybe the answer is, it does not matter. Also see [What does “static” mean in C?](https://stackoverflow.com/q/572547/608639) and [The static keyword and its various uses in C++](https://stackoverflow.com/q/15235526/608639). – jww Oct 29 '17 at 15:48
  • Why my question downvote? am I ask wrong question or something else? – GC Solution Oct 29 '17 at 16:35

1 Answers1

0

On many architectures, calls to static functions are more efficient than calls to non-static functions. To address this, SQLite and some other projects have a compilation mode called the almalgamation, where almost everything is compiled as a single source file, and internal functions are static.

When compiling with optimization, GCC will also automatically inline static functions which are only called once because this is almost always beneficial to do so.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92