On Thu, 18 May 2006 21:48:51 +0000, Keith Thompson wrote:
Michael B Allen <mb*****@ioplex .com> writes: I have a forward reference like:
struct foo;
int some_fn(struct foo *param);
Because the parameter is a pointer the compiler is satisfied.
But now I wan to change 'struct foo' to a typedef'd type like 'foo_t'. The
following all fail to compile:
foo_t;
typedef foo_t;
typedef struct foo_t;
Is there any way to declare a forward refernce for a tyepdef'd type?
Marc Thrun already answered your question, but I have a question for you:
Why do you want to do this? Your type already has a perfectly good
name, "struct foo". What do you want another name for the same thing?
If your answer is "to save typing", that's not a good reason.
Actually that's not why. In fact I don't like typedefs. They hide far too
much. Is it a pointer? Is it a structure or an integer? Bah.
The reason I need a typedef here is because I'm dynamically generating
code and the first parameter of the generated functions is a 'user
defined type' specified to the generator. Currently I'm using a standard
struct type:
struct user_defined_ty pe;
int dynamic_fn(stru ct user_defined_ty pe *p1);
But frequently an 'existing type' unknown to the generated code would
be suitable to use directly as the 'user defined type'. Therefore I
would like it to be a typedef so that the user can define it as the
'existing type' using a simple typedef:
typedef struct existing_type user_defined_ty pe_t;
and then somehow forward reference the 'user defined type':
typedef user_defined_ty pe_t; /* forward reference */
int dynamic_fn(user _defined_type_t *p1);
I suppose the answer is to either pass the 'existing type' to the
generator or embed it in another struct that can be forward referenced.
Mike