Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
0 registered members (), 730 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Struct Casting #395636
02/25/12 19:42
02/25/12 19:42
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline OP
Expert
Rei_Ayanami  Offline OP
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Hello!

I possibly just discovered a bug:

When I am casting a void * to a struct pointer and then try to access an element, it does not return the desired member. When I however create a struct pointer and assign this pointer to the void * and then access the members, everything is okay. Both versions work in C++ (tested by copy/paste)

The problem occurred this way:
I have a struct that contains a void pointer (and some other things). The void * points to a struct instance. The struct, it points to, consists of 2 ints.
The following code does not work, and returns the same variable diags the same variable two time.
Code:
diag_var("\nUnscaledScreenWidth	-> %.0f", (((ESscreenStruct*)testDefStruct->specific)->unscaledScreenWidth));
diag_var("\nUnscaledScreenHeight-> %.0f", (((ESscreenStruct*)testDefStruct->specific)->unscaledScreenHeight));



However, this does work and returns the real content of the second variable:
Code:
ESscreenStruct *tempStruct = testDefStruct->specific;
diag_var("\nUnscaledScreenWidth	-> %.0f", tempStruct->unscaledScreenWidth);
diag_var("\nUnscaledScreenHeight-> %.0f", tempStruct->unscaledScreenHeight);




As already said, I am not sure if I am wrong, but I assume that the code is right, as it works in C++.

Thanks,
Marian Frische

Re: Struct Casting [Re: Rei_Ayanami] #395639
02/25/12 20:19
02/25/12 20:19
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Have you tried
(ESscreenStruct*)(testDefStruct->specific)
instead of
(ESscreenStruct*)testDefStruct->specific
?


"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: Struct Casting [Re: Superku] #395640
02/25/12 20:25
02/25/12 20:25
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline OP
Expert
Rei_Ayanami  Offline OP
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Yes, that does not work either.

(Also not: ((ESscreenStruct*)(testDefStruct->specific)))

Last edited by Rei_Ayanami; 02/25/12 20:29.
Re: Struct Casting [Re: Rei_Ayanami] #395650
02/25/12 23:53
02/25/12 23:53
Joined: Nov 2002
Posts: 913
Berlin, Germany
S
SchokoKeks Offline
User
SchokoKeks  Offline
User
S

Joined: Nov 2002
Posts: 913
Berlin, Germany
EDIT: misunderstood you, sry

Last edited by SchokoKeks; 02/25/12 23:55.
Re: Struct Casting [Re: SchokoKeks] #395766
02/27/12 14:49
02/27/12 14:49
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Make sure you placed the parentheses at the correct places. Otherwise you have a good chance of casting the wrong struct.

Don't write this:

(ESscreenStruct*)testDefStruct->specific

Correct is either this:

((ESscreenStruct*)testDefStruct)->specific

Or this:

((ESscreenStruct*)(testDefStruct->specific))

dependent on what you want to cast.

Re: Struct Casting [Re: jcl] #395774
02/27/12 15:12
02/27/12 15:12
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline OP
Expert
Rei_Ayanami  Offline OP
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
I want to cast the "specific" to ESscreenStruct, which should work by your last example, but actually does not.

Re: Struct Casting [Re: Rei_Ayanami] #395781
02/27/12 16:10
02/27/12 16:10
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
I can not confirm such a problem - can you please post a simple example?

Re: Struct Casting [Re: jcl] #395784
02/27/12 16:21
02/27/12 16:21
Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
Rei_Ayanami Offline OP
Expert
Rei_Ayanami  Offline OP
Expert

Joined: Feb 2009
Posts: 3,207
Germany, Magdeburg
I cannot reproduce that behavior in a small script (going to take a look again later however).

(The whole system is external btw, I only access it via liteC)


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