Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by madpower2000. 07/22/26 14:01
ZorroGPT
by TipmyPip. 07/21/26 17:54
New Zorro version 3.11
by jcl. 07/21/26 13:42
Lapsa's very own thread
by Lapsa. 07/18/26 13:40
Purchase A8 full licence version
by ukgamer. 07/17/26 05:52
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (AndrewAMD, 1 invisible), 9,798 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
riggi89, shuhari, KD1990, Ephraim, Student_64151
19223 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
mapping structs over skills #246014
01/13/09 03:43
01/13/09 03:43
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
I have this struct:
Code:
typedef struct { int x, y; float hello; } Foo ;

Foo*  asFoo(ENTITY* e) {
  Foo* r = (Foo*)(&e->skill[70]);
  return r;
}


This is being used to map the block of memory occupied by skill[0..99] over the Foo structure.

Oddly, this works sometimes and others it returns NULL!?!?

Seems to be a weird casting issue with the skill array.

Can anyone tell me why this happens?

Re: mapping structs over skills [Re: DavidM] #246026
01/13/09 09:18
01/13/09 09:18
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Pointers make my head hurt, but a quick look suggests to me that
you are trying to map an array of VAR's (the entity skills) over the
top of a structure of varied elements (two ints and a float).
VARS, INTs and FLOATs are stored in four bytes of memory, BUT the
format they are store in varies greatly.
Your concept could 'possibly' work while all the values are zero,
but after that, all bets are off.

Change your struct to be all VARs and it looks to be workable.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: mapping structs over skills [Re: EvilSOB] #246073
01/13/09 14:10
01/13/09 14:10
Joined: Dec 2008
Posts: 43
D
DavidM Offline OP
Newbie
DavidM  Offline OP
Newbie
D

Joined: Dec 2008
Posts: 43
Thanks for the info, evil.

I would still like to learn *why* it doesn't work (maybe post this in 'ask the devs'?).

Since a 'var' is 4 bytes, e->skill should be a pointer to a block of 400 bytes. Why shouldn't this work every time?

The semantics of Lite-C seem to second guess the developer, or at least it appears so.

Re: mapping structs over skills [Re: DavidM] #246127
01/13/09 19:08
01/13/09 19:08
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
It will be a block of 400 bytes, but each 4-byte block is going to
be expected to be in the VAR format when looked at from the skills angle,
and will be expected to be INT or FLOAT format when looked at from the struct side.
By 'type' format I mean which of the 4 bytes is the Most-Signifigant byte,
which is the least, which is a multiplier and that sort of thing.

Its not a lite-c thing, its a true C thing. Try looking around some C or C++
tutorial sites and you may find how INTs and FLOATs are internally structured,
but you'll need to ask the Devs about how the VAR is structured.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

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

Gamestudio download | 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