Hello Guy
I've improved the concept, this time without using inline assembly. I used the intrinsic XLONGAT().
I verified that user-defined types located on the stack (because they are declared local to a function) are stored in two parts: a pointer to the contiguous memory region and the region itself.
Therefore, we should change the value of the pointer so that it points to the actual data (in the example, the heap) instead of the stack region where it was declared.
As we know, the XLONG type refers to a natural processor address, so XLONGAT() means "the address of the address" and that's what we should change.
So the composite variable is the pointer (the address) of the data, and in the example it is written like this: &aux. But since the intrinsic operator works with the address of the address, it finally becomes: &&aux. Hence the double address operator.
The proof of concept is:
PROGRAM "nodo_dyn"
EXPLICIT
CONSOLE
IMPORT "xst"
TYPE Node_t
USHORT .dato
XLONG .siguiente
END TYPE
DECLARE FUNCTION Entry()
DECLARE FUNCTION GetFirstNode()
FUNCTION Entry()
XLONG ptr
Node_t aux
ptr = GetFirstNode()
XLONGAT(&&aux) = ptr
PRINT HEXX$(aux.dato)
PRINT HEXX$(aux.siguiente)
Xfree(ptr)
RETURN 0
END FUNCTION
FUNCTION GetFirstNode()
XLONG ret
Node_t aux
ret = 10
ret = Xcalloc(SIZE(Node_t))
XLONGAT(&&aux) = ret
aux.dato = 0xDEAD
aux.siguiente = -1
RETURN ret
END FUNCTION
The auxiliary composite type can be declared in any position in the list of local variables.
By the way, where can I get the updated source code for viXen and WinX?
Thanks!
Best regards