The difference between static function and non-stationary function in C

I am developing an embedded application on VxWorks.

I know that a static function is called only in a specific file, and a non-static function is called in any file in the original project.

I am wondering if there is a difference between the execution time of static and non-static functions and regarding memory

+4
source share
3 answers

There is absolutely no difference in performance. The only thing the static keyword does for functions is the internal linkage , which means that they are only available in the file that they are defined in.

+11
source

There is no difference in runtime or runtime memory requirements.

Some (many?) Linkers will find it easier to detect unused static functions and discard them so that they can encourage a smaller code size.

+2
source

It depends on your compiler. Static functions can theoretically be better optimized because the compiler will know all the places where they are called. You should be able to get the listing of the assembly from your compiler and find out if they are more efficient.

+2
source

Source: https://habr.com/ru/post/1436841/


All Articles