Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by AndrewAMD. 12/05/23 10:56
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (AndrewAMD, alibaba, fairtrader, ozgur, TipmyPip, Quad), 622 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
struct prototype #111063
02/06/07 15:28
02/06/07 15:28
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline 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] #111064
02/06/07 15:39
02/06/07 15:39
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
You need some kind of predefine, so that the compiler knows the keyword
Code:

typedef struct STRUCT2;

typedef struct STRUCT1
{
STRUCT2* data;
} STRUCT1;
typedef struct STRUCT2
{
STRUCT1* data
} STRUCT2;



Re: struct prototype [Re: TWO] #111065
02/06/07 15:44
02/06/07 15:44
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
It says "STRUCT2 (Struct) undeclared indentifier" now

Re: struct prototype [Re: sheefo] #111066
02/06/07 16:17
02/06/07 16:17
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

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: jcl] #111067
02/06/07 16:22
02/06/07 16:22
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
It still says the same error message

Re: struct prototype [Re: sheefo] #111068
02/06/07 16:25
02/06/07 16:25
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
I see. I'll check and post the solution. - You can indeed not define a circular struct definition. I thought struct prototypes were allowed in C, but I have indeed not found them in the C online tutorial above.

The solution it using a general pointer:

typedef struct STRUCT1
{
void* data;
} STRUCT1;

typedef struct STRUCT2
{
STRUCT1 *data;
} STRUCT2;

...
STRUCT1 mystruct1;
STRUCT2 mystruct2;

mystruct1.data = &mystruct2;

Re: struct prototype [Re: jcl] #111069
02/06/07 17:19
02/06/07 17:19
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
It doesn't seem to work. It stays as a void. When I access an attribute in STRUCT2 through the pointer defined in STRUCT1, it says something like "attribute is not a member of VOID"

PS: I took long to reply because I was munching on McDonalds

Re: struct prototype [Re: sheefo] #111070
02/06/07 17:31
02/06/07 17:31
Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
T
TWO Offline

Serious User
TWO  Offline

Serious User
T

Joined: Jan 2006
Posts: 1,829
Neustadt, Germany
McD is unhealthy man

I donīt know if CL has and needs typeconversations;

mystruct1.data = (void*)&mystruct2;

Re: struct prototype [Re: sheefo] #111071
02/06/07 17:37
02/06/07 17:37
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

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.htm

Work 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.

Re: struct prototype [Re: jcl] #111072
02/06/07 18:22
02/06/07 18:22
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
It's still not working. Have you tested it, maybe I am doing something wrong?

This is giving me a headache... this and the McDonalds

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1