I will try to give some light...

Originally Posted By: EpsiloN

I have a struct for weapons in my project. I'm initializing the first weapon:
Code:
WEAPONSTRUCT* glock = malloc(sizeof(WEAPONSTRUCT));
...
	weaponsList[0] = &glock;



'malloc' allocates some static memory and returns the first bytes address that is saved into the pointer. So there are two memory areas in play in your first code line: the allocated struct and the declared pointer. Your code references the pointer to the struct, not the struct itself. So the memory address that is saved into 'weaponList[0]' is the address of the pointer!

Let's play a bit around this. Imagine the data is declared static (global):
Code:
typedef struct WEAPON
{
   int ammo;
} WEAPON;

WEAPON weapon;
WEAPON *weaponPtr;



When you need a pointer to a global struct you need to reference it.
Code:
weaponPtr = &weapon; // save the address of the first byte of 'weapon' global struct



Your first code line does mostly the same of this code line, but the compiler has no name to identify the memory of the static struct (dynamically allocated).
Code:
weaponPtr = malloc ( sizeof(WEAPON) );



Building a list of weapons is managed same:
Code:
WEAPON weapon;
WEAPON *weaponPtrList[2];
weaponPtrList[0] = &weapon;
weaponPtrList[1] = malloc ( sizeof(WEAPON );



Notice that you could also declare a static array of weapons:
Code:
WEAPON weaponList[10];



and save pointers to them in the order you want:
Code:
WEAPON *playerWeaponPtrList[10];
playerWeaponPtrList[0] = &weaponList[8];
playerWeaponPtrList[1] = &weaponList[0];
...
// or cheaper
playerWeaponPtrList[0] = weaponList + 8; // When you increase a pointer by one, the compiler encreases the address saved into the pointer by the length of the pointer type
playerWeaponPtrList[1] = weaponList; // + 0  !!Notice that the array name with no index is a pointer to the first member of the array
...



Ok, enough about pointers. Lets talk about castings and comparisions.

When you save a pointer into a skill, you are casting the type of the pointer from an integer to a fixed point variable. Their interpreted value of the same bit group is different depending on the type. A var uses last 10 bits for mantissa, so an int and a var with the same interpreted value are displaced 10 bits in the real memory.

The problem comes when the compiler makes things easy and let you compare a var and an int throught their interpreted values instead of the bits of each own.

Code:
int i = 1; // all the bits are 0 but the last
var v = 1; // all the bits are 0 but the 11th
if ( i == v ) 
   printf ( "equal!" );
...
int i = 1; // all the bits are 0 but the last
var v = *((var*)(&((int)1)));  // all the bits are 0 but the last
if ( i != v )
   printf ( "not equal!" );
v <<= 10; // displace the only positive bit (the last) to 11th position from the tail
if ( i == v )
   printf ( "equal!" );



So when you need to compare a pointer and a pointer casted to a var (skill), you will need to cast back the skill in order to avoid any interpretation (as Wjbender pointed out).

Code:
WEAPON *weaponPtr = malloc ( sizeof(WEAPON) );
my->weapon = (var)weaponPtr;

if ( (WEAPON*)my->weapon == weaponPtr )
   printf ( "same weapon" );



Hope it helps
Salud!