Bryan Bullard <re***@to.group.com> scribbled the following:
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:cf**********@oravannahka.helsinki.fi... Bryan Bullard <re***@to.group.com> scribbled the following: > I have a cyclical dependency problem very much like the one listed below. > Does anyone have a solution? > struct A;
> struct B;
> struct A
> {
> struct B b;
> };
> struct B
> {
> struct A a;
> };
> int main() { return 0; }
This code is impossible to compile, as you very well know. Both of your
structs contain themselves as elements, which means that their size is
infinite.
The solution is, of course, pointers.
Well, in this instance I need the actual struct resident not pointers.
Here is a closer example:
/* file A.h * * * * * * */
#ifndef A_H
#define A_H
#include "B.h"
struct A
{
struct B b;
};
#endif
/* file B.h * * * * * * */
#ifndef B_H
#define B_H
#include "A.h" /* some other resource in A.h is needed */
struct B
{...};
#endif
/* main.c * * * * * * */
#include "A.h" /* needs resources in A.h and B.h */
#include "B.h"
int main() { return 0; }
This can become a problem when I must always be assured that "B.h" is
preprocessed before "A.h".
I don't understand this at all. The code in your closer example here is
completely different from your original code. Your original code was
impossible to compile, even theoretically, as you had structures that
included themselves.
This code, however, has a structure including a structure including
something unknown. As long as that unknown isn't either of these two
structures, your program can be solved with careful attention to
preprocessing.
What are the "resources" you speak of? Structures? Typedefs? Macros?
Actual code? Knowing this is *very* important to determine whether
your problem can be solved.
Do you mean that "A.h" must use types defined in "B.h" and vice versa?
I don't see any way of doing this other than making a separate header
file including all the types that either file needs from the other and
making both #include it.
It's just strange that between your two posts, the entire problem
changed from a struct type problem to a preprocessing problem.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\--
http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The trouble with the French is they don't have a word for entrepreneur."
- George Bush