static function in C

前端 未结 7 1606
天涯浪人
天涯浪人 2020-11-30 17:11

What is the point of making a function static in C?

7条回答
  •  被撕碎了的回忆
    2020-11-30 17:36

    The static keyword in C is used in a compiled file (.c as opposed to .h) so that the function exists only in that file.

    Normally, when you create a function, the compiler generates cruft the linker can use to, well, link a function call to that function. If you use the static keyword, other functions within the same file can call this function (because it can be done without resorting to the linker), while the linker has no information letting other files access the function.

提交回复
热议问题