Nubcake wrote:...So I should use .i ?
What's wrong with this code?
Code: Select all
Structure Pixel
x.i
y.i
EndStructure
Procedure proc(*p.Pixel, param)
*p\x = param
*p\y = param * 2
EndProcedure
Define p.Pixel
proc(@p, 32)
Debug p\x
Debug p\y
Hello Nubcake. The default type for PureBasic is the
integer. So, if a variable is not explicitly declared, or defined without a type, PureBasic would automatically define it as an integer.
With reference to your code, if your requirement is simply to automate the assignment of values and the such, you may not wish to bother with all the memory management stuff. Instead, you could simply pass the address of the active structure to the procedure, and perform the required calculations and assignments on it directly; no pointers, no memory to allocate or free, and nothing to return either:
Code: Select all
Structure Pixel
x.i
y.i
EndStructure
Procedure proc(*p.Pixel, param)
*p\x = param
*p\y = param * 2
EndProcedure
Define p.Pixel
proc(@p, 32)
Debug p\x ;returns 32
Debug p\y ;returns 64
In fact, this is the approach that STARGÅTE had illustrated above.
