When to put static function definitions in header files in C?

前端 未结 6 678
别跟我提以往
别跟我提以往 2020-12-01 05:53

I\'ve come across some code that has a large static function in a header file and i\'m just curious when it is/is not ok to do this. For example, if many .c fil

6条回答
  •  臣服心动
    2020-12-01 06:08

    If the function has external linkage, it should be declared in a .h file.

    If the function is static, and therefore has no external linkage, the function should only be declared in the .c file in which it is defined.

    It is never OK to have a function defined in a header file.

提交回复
热议问题