Well
Code:
/************mylib.h************/
#ifndef MYLIB_H
#define MYLIB_H
#include <mystring.h>
#include <myio.h>
#endif /* MYLIB_H */
Code:
/**********myio.h****************/
#ifndef MYIO_H
#define MYIO_H
/* All myio public stuff */
#endif /* MYIO_H */
/********************************/
If you want to make sure that they only include mylib.h and don't sneak around and directly include myio.h, then do something like this
Code:
/************mylib.h************/
#ifndef MYLIB_H
#define MYLIB_H
#include <mystring.h>
/* check myio was not included already from somewhere else */
#ifdef MYIO_H
#error Don't include myio.h yourself, only include mylib.h
#endif
#include <myio.h>
#endif /* MYLIB_H */
/**********myio.h****************/
#ifndef MYIO_H
#define MYIO_H
/* were we included from mylib? */
#ifndef MYLIB_H
#error myio.h included without mylib.h
#endif
/* All myio public stuff */
#endif
/********************************/
OK, they may figure out that
#define MYLIB_H
#include <myio.h>
works, but then you have a real excuse to use this
> just putting them in those seperate headers would be enough?
That would be enough
> could I declare them in say pmystring.h and include that from mystring.h?
Putting them in pmystring.h is good
#include "pmystring.h" in mystring.h is bad
It kinda offers temptation to the more curious library user to go looking inside pmystring.h to see what goodies there are.
Your source code should be like this
Code:
/* mystring.c */
#include <mylib.h> // gotta obey your own rules
#include "pmystring.h" // our private stuff
...
Here's a bit more on nested include files
http://www.eskimo.com/~scs/cclass/int/sx6b.html
I think it's OK to use nested includes in your lib.h, since this makes it simple for your users to
#include <mylib.h>
and not worry about what else they need to include.
But I would stay away from
Code:
/* mystring.c */
#include "everything.h"
...
as a means of saving yourself a bit of typing. In a large project, such techniques create far too many pseudo-dependencies, which cause tools like "make" to recompile a whole bunch of stuff which didn't need recompling.
It also makes it difficult for you to figure out "what does this module depend on" if you're planning any porting or re-use of code.