E
EventHelix.com
Hi,
I've recently started programming C after many years using "the other
language"... I just wanted to find out the common practice for
organising source files.
Specifically, consider a moderately complicated library module, mylib.c.
Obviously its "public interface" (i.e. non-static function
declarations, typedefs, any global variables) need to go in mylib.h.
The question is: what about private (i.e. static) functions and struct
declarations and typedefs only used in the private implementation?
Is it more usual to put these in the mylib.h file, or to put them at the
top of the mylib.c file, or to create a separate mylib_private.h file?
And a similar question for #includes: let's suppose that one of the
public functions declared in mylib.h takes a FILE* parameter.
Obviously, I'll need to #include<stdio.h> at the top of mylib.h to get
the FILE structure defined.
But say in the implementation, in mylib.c, I need to use (for example)
malloc. Then I need to #include<stdlib.h> as well. Should I put the
#include at the top of mylib.h or at the top of mylib.c?
Thanks for any input!
DM
The following article should help with defining a strategy for header
file includes.
http://www.eventhelix.com/RealtimeMantra/HeaderFileIncludePatterns.htm
The article is written for C++ but most of the ideas presented here
are applicable to C as well.