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

前端 未结 6 680
别跟我提以往
别跟我提以往 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:15

    In my experience it is generally a bad idea to define a function in a .h file, and i've never had cause to do so, doing so by accident once caused me no end of headaches.

    Though i guess it would allow each file that includes the header to have its own separate implementation of the function which, if the function has static vars, may be the desired behaviour e.g. if you want/need to keep track of some information separately for each file.

提交回复
热议问题