C Header files including header files, mutually referencing typedefs 
Author Message
 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!



Thu, 30 May 2002 03:00:00 GMT  
 C Header files including header files, mutually referencing typedefs
Perhaps you should reexamine how you've divided up your program. Do
functions on mutally recursive types really deserve different files? Could
you extract the types from the different files and place them together in
a single file?

--
CACS: Collective Against Consensual Sanity       v0.123
Now a text site map! http://www.angelfire.com/ca3/cacs/
pretty?     http://www.geocities.com/SoHo/Studios/5079/
There is no sanctuary.   I am an Andrea Chen plush toy.



Fri, 31 May 2002 03:00:00 GMT  
 C Header files including header files, mutually referencing typedefs
How about #including both header files in both C files.

Sam


Quote:
> 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;
> } 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.remarq.com The Internet's Discussion Network
*
> The fastest and easiest way to search and participate in Usenet - Free!



Fri, 31 May 2002 03:00:00 GMT  
 C Header files including header files, mutually referencing typedefs
Thanks for the Guidance! It seems there is no elegant way to fix my
problem so I have re-examined and changed the location of the typedefs
so they are in the same file.

Thanks again,

Greg Old
Insession Labs.

* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



Fri, 31 May 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Header files shall not #include any other headers

2. STL header files vs non-STL header files

3. Fortran include file to C header file conversion

4. How to include header files and other files??

5. How to include header files and other files??

6. typedefs IN header files

7. header in header files

8. #ifndef/#ifdef problems in my header file (conditional header inclusion)

9. Order of including header files

10. create or include the macro def in header file

11. including cross-compiler header files

12. help! can't include header file

 

 
Powered by phpBB® Forum Software