C/C++: Static function in header file, what does it mean?

后端 未结 6 1722
清酒与你
清酒与你 2020-12-02 08:57

I know what it means when static function is declared in source file. I am reading some code, found that static function in header files could be invoke in other files.

6条回答
  •  -上瘾入骨i
    2020-12-02 09:51

    There is not semantic difference in defining in source file or header file, basically both means the same in plain C when using static keyword that, you are limiting the scope.

    However, there is a problem in writing this in header file, this is because every time you include the header in a source file you'll have a copy of the function with same implementation which is much similar to have a normal function defined in header file. By adding the definition in header you are not achieving the what the static function is meant for.

    Therefore, I suggest you should have your implementation only in your source file and not in header.

提交回复
热议问题