forward declaration for typedef of unnamed structs

J

Jordi Vilar

Hi all,

Is it possible to do a forward declaration for a typedef of an
incomplete anonymous struct? for example, if I have a type declared
(in a 3rd part header file that I cannot modify) as:

typedef struct
{
...
} mytype;

how can I forward declare such mytype type?

thanks in advance,

Jordi Vilar
 
P

Peter Pichler

Jordi Vilar said:
Is it possible to do a forward declaration for a typedef of an
incomplete anonymous struct? for example, if I have a type declared
(in a 3rd part header file that I cannot modify) as:

typedef struct
{
...
} mytype;

how can I forward declare such mytype type?

You could if the structure had a tag. You are in bad luck with anonymous
structures. One more reason to avoid typedefing structures.

Peter
 
J

Jonathan Turkanis

Peter Pichler said:
You could if the structure had a tag. You are in bad luck with anonymous
structures. One more reason to avoid typedefing structures.

At best, this is one more reason to avoid anonymous structures.

Jonathan
 
S

Squider

Jordi said:
Hi all,

Is it possible to do a forward declaration for a typedef of an
incomplete anonymous struct? for example, if I have a type declared
(in a 3rd part header file that I cannot modify) as:

typedef struct
{
...
} mytype;

how can I forward declare such mytype type?

thanks in advance,

Jordi Vilar

Maybe the author had something that seemed to be a good reason to
make it anonymous and to have only one of them running around.
 
D

Derk Gwen

(e-mail address removed) (Jordi Vilar) wrote:
# Hi all,
#
# Is it possible to do a forward declaration for a typedef of an
# incomplete anonymous struct? for example, if I have a type declared
# (in a 3rd part header file that I cannot modify) as:
#
# typedef struct
# {
# ...
# } mytype;
#
# how can I forward declare such mytype type?

typedef struct A A;
typedef struct B B;

struct A {
B *b;
};
struct B {
A *a;
};
 
J

Jonathan Turkanis

Derk Gwen said:
(e-mail address removed) (Jordi Vilar) wrote:
# Hi all,
#
# Is it possible to do a forward declaration for a typedef of an
# incomplete anonymous struct? for example, if I have a type declared
# (in a 3rd part header file that I cannot modify) as:
#
# typedef struct
# {
# ...
# } mytype;
#
# how can I forward declare such mytype type?

typedef struct A A;
typedef struct B B;

struct A {
B *b;
};
struct B {
A *a;
};

How does this solve the original problem?

Jonathan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top