|
|
struct prototype
#111063
02/06/07 15:28
02/06/07 15:28
|
Joined: Jul 2006
Posts: 783 London, UK
sheefo
OP
User
|
OP
User
Joined: Jul 2006
Posts: 783
London, UK
|
I have a problem with defining two structs. They both contain require a pointer to the other struct. I have do idea how I can define it, in this example it crashes while compiling because the other struct is not reconised, no matter the order. Is there a way to define a struct prototype? Code:
typedef struct STRUCT1 { STRUCT2* data; } STRUCT1; typedef struct STRUCT2 { STRUCT1* data } STRUCT2;
|
|
|
Re: struct prototype
[Re: sheefo]
#111066
02/06/07 16:17
02/06/07 16:17
|
Joined: Jul 2000
Posts: 27,967 Frankfurt
jcl

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 27,967
Frankfurt
|
The first line was wrong - typedef is for defining types and not for prototypes. struct STRUCT2; typedef struct STRUCT1 { STRUCT2* data; } STRUCT1; typedef struct STRUCT2 { STRUCT1* data } STRUCT2; Working with structs and typedefs exceeds the scope of the lite-C Workshop, which is more targeted towards beginners. For exploring lite-C more in depth you need some 'real' C knowledge. I suggest that you get a normal C book or tutorial. Otherwise you'll permanently run into problems like this one. There are many C tutorials on the internet, like http://lib.daemon.am/Books/C/For the differences between C and lite-C, see http://manual.conitec.net/litec_c.htm
|
|
|
Re: struct prototype
[Re: sheefo]
#111071
02/06/07 17:37
02/06/07 17:37
|
Joined: Jul 2000
Posts: 27,967 Frankfurt
jcl

Chief Engineer
|

Chief Engineer
Joined: Jul 2000
Posts: 27,967
Frankfurt
|
STRUCT2* pstruct2 = (STRUCT2*)mystruct1.data; pstruct2->data = ... Look here: http://lib.daemon.am/Books/C/ch11/ch11.htmWork through the Sam's workshops about structs and pointers. They are quite well explained. One workshop takes no longer than munching something down on McDonalds, but is a lot more healthy. 
|
|
|
|