
C Header files including header files, mutually referencing typedefs
Hello,
Using the approach of header files including the other header files
that it needs I have hit a bit of a snag. The problem is easiest to
explain via an example:
Lets say we have four source files, IMSG.C & .H and IKNL.C & .H.
Here's the code :
(1) IMSG.H -
#ifndef IMSG_H
#define IMSH_H
#include "iknl.h"
typedef struct io_msg
{
Tphandle phandle;
Quote:
} Tio_msg;
#endif
(2) IMSG.C -
#include "iknl.h"
#include "imsg.h"
(3) IKNL.H -
#ifndef IKNL_H
#define IKNL_H
#include "imsg.h"
typedef short Tphandle[10];
void func(Tio_msg *var); /* OR void func(struct io_msg *var) */
#endif
(4) IKNL.C
#include "imsg.h"
#include "iknl.h"
** Each header file needs a typedef from the other!
** imsg.c will NOT compile because imsg.h ends up getting included
first and Tphandle does not exist!
** iknl.c will ONLY compile if the "struct io_msg" version of the func
declaration is used!
Any suggestions?
Possible solutions :
(a) Stop having header files including header files. If the #include's
were removed from the header files and the #includes for iknl.c were
swapped (ie. iknl.h before imsg.h) then both will compile!
(b) A suggestion is to have two different header files, one for
function prototype's and one for definitions, eg. create new file's
called imsgd.h and iknld.h, (d = definitions). That might work!
I'm not sure what the best way to go is! Any guidance/wisdom would be
much appreciated.
Thanks,
Greg Old
Insession Labs.
* Sent from RemarQ http://www.*-*-*.com/ The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!