Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Forward Reference for Typedef'd Type?

Reply
Thread Tools

Re: Forward Reference for Typedef'd Type?

 
 
SM Ryan
Guest
Posts: n/a
 
      05-19-2006
Michael B Allen <(E-Mail Removed)> wrote:
# 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?

You can use
typdef struct foo foo_t;
and then subsequently
struct foo {
type field; ...
};

If you're only using a pointer to a struct, you don't have to define
the struct: all struct pointers look the same. This means you can
possibly arrange your declarations as

typedef struct A A;
typedef struct B B;
typedef struct C C;
...
other declarations using (A*), (B*), and (C*);
...
struct A {
type field;...
A *a; B *b; C *c;
};
struct B {
type field;...
A *a; B *b; C *c;
};
struct C {
type field;...
A *a; B *b; C *c;
};
...
declarations and functions that use the struct fields
...

You can possibly divide this into a header and compile file like

something.h
typedef struct A A;
typedef struct B B;
typedef struct C C;
...
other declarations using (A*), (B*), and (C*);
...
something.c
#include "something.h"
struct A {
type field;...
A *a; B *b; C *c;
};
struct B {
type field;...
A *a; B *b; C *c;
};
struct C {
type field;...
A *a; B *b; C *c;
};
...
declarations and functions that use the struct fields
...


--
SM Ryan http://www.rawbw.com/~wyrmwif/
One of the drawbacks of being a martyr is that you have to die.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forward Reference for Typedef'd Type? Michael B Allen C Programming 7 05-19-2006 12:13 AM
Forward reference mess Razvan Java 8 10-04-2004 07:23 AM
Forward class reference in Java? Ken Java 4 07-04-2004 09:33 PM
Re-forward declaration of types which were already forward declared qazmlp C++ 1 02-15-2004 07:00 PM
forward reference to a class... Francesco C++ 5 09-16-2003 11:55 AM



Advertisments