I've found some old posts on this issue but the answer was a bit vague
to me. The problem I am trying to solve is the following:
/***** a.h ***********/
#include "b.h"
/* Forward declaration */
struct type2;
typedef struct type1
{
int x;
int y;
type2 *ptr;
} type1;
void foo1(type1 *ptr, type2 *ptr2);
/********* b.h *********/
#include "a.h"
/* Forward declaration */
struct type1;
typedef struct type2
{
int x;
type1 y;
} type2;
The problem I have here is that for this to work I can't just use the
typedef'd name in the declaration of function foo1, I have to prefix
it with struct type1 *ptr, etc. Furthermore, the forward declaration
only will work for pointer types and won't work in the case of the
struct type2 which contains a member of type1 rather than pointer to
type1.
What is a good solution for this issue? Please don't get into
arguments about typedefs being bad in this case, I'd like to get a
solution to the problem I posed above.
Thanks.
to me. The problem I am trying to solve is the following:
/***** a.h ***********/
#include "b.h"
/* Forward declaration */
struct type2;
typedef struct type1
{
int x;
int y;
type2 *ptr;
} type1;
void foo1(type1 *ptr, type2 *ptr2);
/********* b.h *********/
#include "a.h"
/* Forward declaration */
struct type1;
typedef struct type2
{
int x;
type1 y;
} type2;
The problem I have here is that for this to work I can't just use the
typedef'd name in the declaration of function foo1, I have to prefix
it with struct type1 *ptr, etc. Furthermore, the forward declaration
only will work for pointer types and won't work in the case of the
struct type2 which contains a member of type1 rather than pointer to
type1.
What is a good solution for this issue? Please don't get into
arguments about typedefs being bad in this case, I'd like to get a
solution to the problem I posed above.
Thanks.
Comment