By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,903 Members | 1,626 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,903 IT Pros & Developers. It's quick & easy.

using struct pointer before declaration

P: n/a
How can I get the following to compile?

typedef struct Y
{
void (*f)(X *x);
} Y;

typedef struct X
{
int x;
} X;

Just forward declaring X doesn't work and I can't put the word struct before
X, because the code is generated.
Nov 13 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Serve Laurijssen <ik@hier.nl> wrote:
typedef struct Y
{
void (*f)(X *x);
} Y;

typedef struct X
{
int x;
} X;


Did you try:

typedef struct X
{
int x;
} X;

typedef struct Y
{
void (*f)(X *x);
} Y;

?

Famous last words: Works for me.
--
== Eric Gorr ========= http://www.ericgorr.net ========= ICQ:9293199 ===
"Therefore the considerations of the intelligent always include both
benefit and harm." - Sun Tzu
== Insults, like violence, are the last refuge of the incompetent... ===
Nov 13 '05 #2

P: n/a
Serve Laurijssen wrote:

How can I get the following to compile?

typedef struct Y
{
void (*f)(X *x);
} Y;

typedef struct X
{
int x;
} X;

Just forward declaring X doesn't work and I can't put the word struct before
X, because the code is generated.


The only way to get the code to compile as it stands
is to use a compiler for some non-C language.

An obvious way to fix it is to move the declaration of
`X' so it appears before the first use. But since you say
that another obvious fix isn't allowable, it's not clear
that this fix is applicable, either.

Fixing the program that generates the code is another
possibility.

--
Er*********@sun.com
Nov 13 '05 #3

P: n/a
On Fri, 25 Jul 2003 20:25:49 +0200
"Serve Laurijssen" <ik@hier.nl> wrote:
How can I get the following to compile?

typedef struct Y
{
void (*f)(X *x);
} Y;

typedef struct X
{
int x;
} X;


You probably mean a solution like this:

typedef struct Y Y;
typedef struct X X;

struct Y {
void (*f)(X *x);
};

struct X {
int x;
};

--
main(int c,char*k,char*s){c>0?main(0,"adceoX$_k6][^hn","-7\
0#05&'40$.6'+).3+1%30"),puts(""):*s?c=!c?-*s:(putchar(45),c
),putchar(main(c,k+=*s-c*-1,s+1)):(s=0);return!s?10:10+*k;}
Nov 13 '05 #4

P: n/a
On Fri, 25 Jul 2003 20:25:49 +0200, "Serve Laurijssen" <ik@hier.nl>
wrote:
How can I get the following to compile?

typedef struct Y
{
void (*f)(X *x);
} Y;

typedef struct X
{
int x;
} X;


You could just swap the order of both typedefs. Or:

struct X;
typedef struct X X;

typedef struct Y
{
void (*f)(X *x);
} Y;

struct X
{
int x;
};

Nick.

Nov 13 '05 #5

P: n/a

On Fri, 25 Jul 2003, Serve Laurijssen wrote:

"Pieter Droogendijk" <gi*@binky.homeunix.org> wrote in message

typedef struct Y Y;
typedef struct X X;

struct Y {
void (*f)(X *x);
};

struct X {
int x;
};


This certainly looks like it's working. I don't mean to be an ass, but
it is correct C right?


Yes.
Nov 13 '05 #6

P: n/a
On Fri, 25 Jul 2003, Eric Sosman wrote:
How can I get the following to compile?
...


The only way to get the code to compile as it stands
is to use a compiler for some non-C language.
Fixing the program that generates the code is another
possibility.


Hmmm.. generalizing:

generatecode foo.almostc
fixcode foo.almostc foo.c
cc foo.c

The two first lines are the fixed generator and the last
two a non-C compiler.

Nov 13 '05 #7

P: n/a
In 'comp.lang.c', "Serve Laurijssen" <ik@hier.nl> wrote:
How can I get the following to compile?

typedef struct Y
{
void (*f)(X *x);
} Y;

typedef struct X
{
int x;
} X;

Just forward declaring X doesn't work and I can't put the word struct
before X, because the code is generated.


Sounds obvious, but wat's wrong with:

typedef struct
{
int x;
}
X;

typedef struct
{
void (*f)(X *x);
}
Y;

--
-ed- em**********@noos.fr [remove YOURBRA before answering me]
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
<blank line>
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.