When I write software in C, should I put static and inline functions in the .h or in the .c file?
 
    
    - 23,346
- 16
- 78
- 134
- 
                    3Their declaration or definition ? – VAndrei Apr 25 '15 at 17:06
- 
                    2You should not put `static` functions in a `.h` file, because if you need to, then the function should not be static. – Iharob Al Asimi Apr 25 '15 at 17:08
2 Answers
Do not put the declaration nor definition of a static function (or variable) in a .h file.  That defeats the points of static - keeping functions/variables local.
inline is another matter - it depends on the scope meant for the function.  An inline function in a .h is meant for global usage and scope.  An inline function in a .c is meant for local usage only.  This is much the same strategy as would be used for a #define
inline functions can be extern, static or unspecified.  @Christoph well explains inline scope issues.  
 
    
    - 1
- 1
 
    
    - 143,097
- 13
- 135
- 256
- 
                    True, except you usually want your inline functions static. At least I rarely bother to instantiate external inline definitions. – doynax Apr 25 '15 at 20:59
- 
                    1A good read about the why and how of inline and static functions in C, is [**Inline Functions In C**](http://www.greenend.org.uk/rjk/tech/inline.html) – David C. Rankin Apr 26 '15 at 01:21
Assuming multiple C source files include the .h file, then inline functions in the .h file are ok, but I'm not sure why you'd want a static function in a .h file, to end up being duplicated, once for each C source file. The compiler may be smart enough to not generate code for static functions that are not called within a C source file.
 
    
    - 27,407
- 3
- 36
- 61