Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (rki), 405 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
structs A <-> B: forward declaration? #463290
11/26/16 19:50
11/26/16 19:50
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Hello!
I have two structs, like this:

Code:
[???]
struct A
{
	int x;
	struct B *b;
};

struct B
{
	int y;
	[...]
	struct A *a;
};


struct A now needs a forward declaration of struct B (right?). No matter what I write, the lite-C compiler only gives me error messages (for example a simple "struct B;" results in "B (Struct) undeclared identifier" in the same line).
The only workaround I can think of right now is using a void pointer in A. Any ideas/ what am I doing wrong?


EDIT:
Does it do any harm if I declare/ define struct B first with let's say one dummy member, then define it differently some lines later? Does not work. Second definition is ignored.

Last edited by Superku; 11/26/16 21:58.

"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: structs A <-> B: forward declaration? [Re: Superku] #463300
11/27/16 11:58
11/27/16 11:58
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
You could try a forward declaration, not sure if lite-c supports it, though.
Otherwise, using a void* might be the only solution.

Edit: looks like lite-c doesn't support it..

Last edited by Kartoffel; 11/27/16 12:03.

POTATO-MAN saves the day! - Random
Re: structs A <-> B: forward declaration? [Re: Kartoffel] #463301
11/27/16 13:00
11/27/16 13:00
Joined: Feb 2012
Posts: 371
Dico Offline
Senior Member
Dico  Offline
Senior Member

Joined: Feb 2012
Posts: 371
I think it's the limit of litec .

Re: structs A <-> B: forward declaration? [Re: Dico] #463302
11/27/16 13:23
11/27/16 13:23
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
void* and cast will work fine even though it looks bad.
Maybe you should switch to C++ instead? grin

Re: structs A <-> B: forward declaration? [Re: Ch40zzC0d3r] #463308
11/27/16 18:26
11/27/16 18:26
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Yeah well, so it's not possible in lite-C, right? -.-
I have it all changed to void pointers now. It works with casting but as the (new) project is heavily based on a lot of those structs it gets quite messy, esp. when there are more than 1 void-cast-dereference-operations (like ((B*)((A*)a)->b)->...).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: structs A <-> B: forward declaration? [Re: Superku] #463341
11/28/16 21:21
11/28/16 21:21
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kinda sucks...

I'm not sure how much code you've already written with your structs (might be a lot of work to change everything) but maybe there's a way to avoid this kind of "loop" definition. I guess it depends on the specific situation but I once ran into the same problem and was able to work my way around it with some changes to the structs I use and how they work together.


POTATO-MAN saves the day! - Random
Re: structs A <-> B: forward declaration? [Re: Kartoffel] #463353
11/29/16 13:45
11/29/16 13:45
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
That's true, maybe I can find a better system/ approach. However, it's the easiest this way (I think) because I can for example just loop through all OBJECTs in a ROOM or know in which ROOM an OBJECT is (without having to use search functions or additional structures).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: structs A <-> B: forward declaration? [Re: Superku] #463357
11/29/16 18:27
11/29/16 18:27
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Yeah, I don't see a fancy way of avoiding that problem in this case... so void* is pretty much all that's left.

I think I'd use a void pointer (like void * pParentRoom;) in the OBJECT struct since it's probably not being used as much as the pointer for the other direction. And everytime I want to access it I'd just quickly cast it:

ROOM * pRoom = object->pParentRoom;
pRoom->...


But that's probably how you're doing it already so... grin

Last edited by Kartoffel; 11/29/16 18:35.

POTATO-MAN saves the day! - Random
Re: structs A <-> B: forward declaration? [Re: Kartoffel] #463372
11/30/16 12:26
11/30/16 12:26
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline OP
Senior Expert
Superku  Offline OP
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Yeah I'm doing it like that. wink It's not a game breaker but it's annoying extra work/ lines of code, esp. because there's a bunch of nested structs, now with a void pointer each, already (like door->room->area->superarea and so on).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

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