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 2 of 2 1 2
Re: struct prototype [Re: sheefo] #111073
02/06/07 18:56
02/06/07 18:56
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
Note you're missing a ; in your 2nd struct definition. Using a void* pointer is working fine:

struct_test.h:
Code:

#ifndef STRUCT_TEST_H
#define STRUCT_TEST_H


typedef struct
{
void* data;
}STRUCT1;

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

#endif



struct_test.c:
Code:

///////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

#include "struct_test.h"
///////////////////////////////////////////////////////////////

STRING* value_str = "#12";
TEXT* debug_txt =
{
string (value_str);
flags = VISIBLE;
}

///////////////////////////////////////////////////////////////
function main()
{
STRUCT1 foo;
STRUCT2 bar;

bar.value = 42;
foo.data = (void*)&bar;
str_for_num(value_str, ((STRUCT2*)(foo.data))->value);
while (1)
{

wait(1);
}

}





This example also shows that using a void* Pointer will lead to some nasty typecasts later on. You should avoid this!

Re: struct prototype [Re: FBL] #111074
02/20/07 01:30
02/20/07 01:30
Joined: Nov 2005
Posts: 94
Texas
3
3Dski Offline
Junior Member
3Dski  Offline
Junior Member
3

Joined: Nov 2005
Posts: 94
Texas
Good discourse on structs! I was just getting ready to play around with this new Lite-C capability, so was helpful to read through these posts : )

Re: struct prototype [Re: 3Dski] #111075
02/20/07 13:22
02/20/07 13:22
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
hm...

but i came across c header files with empty typedefs like that:

typedef struct SomeType{} SomeType;
SOME_API int SomeFunction (const SomeType* st);

lite-c complains about this typedef so how would i have to rewrite it?

Re: struct prototype [Re: ventilator] #111076
02/20/07 15:49
02/20/07 15:49
Joined: Jul 2000
Posts: 27,967
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,967
Frankfurt
The above is not a struct prototype, but a dummy struct without member. I'm not sure if this is allowed by ANSI C - normally structs must have at least one member.

typedef struct SomeType{ void* dummy; } SomeType;

Re: struct prototype [Re: jcl] #111077
02/21/07 06:06
02/21/07 06:06
Joined: Nov 2005
Posts: 94
Texas
3
3Dski Offline
Junior Member
3Dski  Offline
Junior Member
3

Joined: Nov 2005
Posts: 94
Texas
For sure, the manual does say that the struct has to already be "defined", or itself, in order to be used inside a struct definition. You will be stuck with the use of "void *", which is rather nasty, or re-look at the problem you're trying to solve and come at it from a different angle. This is a interesting problem, so I'll keep looking at it to see if I see an general alternative.

AFTER THOUGHT:

Since A and B are obviously paired with one another in a prescribed way, why not just have a wrapper struct that contains the pointers to each? A and B would just contain their specific data. I see that this could potentially cause a problem if you had to look for a particular A or B with a series of C (container of A and B), but maybe you could place some kind of key in C that identifies the A-B pair (if you see you have to look them up):

typedef struct A{
... data
} A;

typedef struct B{
... data
} B;

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

... just a thought to play with.


Last edited by 3Dski; 02/21/07 06:20.
Re: struct prototype [Re: 3Dski] #111078
02/21/07 13:45
02/21/07 13:45
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
Yes, that would be the cleanest way. Two structs pointing to each other isnīt very pro;

Re: struct prototype [Re: TWO] #111079
02/21/07 14:27
02/21/07 14:27
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Woah, I just needed that today, thanks to you.

Though, I heavily suggest to implement incomplete types for crossreferencing and so on.

Re: struct prototype [Re: HeelX] #111080
02/21/07 14:33
02/21/07 14:33
Joined: Jul 2006
Posts: 783
London, UK
sheefo Offline OP
User
sheefo  Offline OP
User

Joined: Jul 2006
Posts: 783
London, UK
I've given up on this, even if you found a solution.

I am trying to save multiple structs to a file, but I don't know where to start. I know there is a pre-defined function to save a single struct to a file, then it closes it after. I need to put struct in a file an read them from their position in bytes.

I can make another topic asking. If anyone know...?

Page 2 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