A simple question about returning an array from a procedure
Posted: Sun Feb 08, 2026 3:19 pm
Hi all !
The question is in the topic title.
The point is that the array is multidimensional !
Sorry if this is a stupid question.
If you write it like this (as we are used to doing for a one-dimensional array):
, it will be a mistake. By the way, chatgpt suggested me this code as a solution to the problem.
Further...
chatgpt suggests this to me (via poke and peek):
Maybe there is a better version ?
Thanks in advance.
The question is in the topic title.
The point is that the array is multidimensional !
Sorry if this is a stupid question.
If you write it like this (as we are used to doing for a one-dimensional array):
Code: Select all
Procedure SomeProc(Array try(1,1))Further...
chatgpt suggests this to me (via poke and peek):
Code: Select all
Procedure.i Create2DArray(width, height)
*mem = AllocateMemory(SizeOf(Integer) * width * height)
For x = 0 To width - 1
For y = 0 To height - 1
PokeI(*mem + (x * height + y) * SizeOf(Integer), x * 100 + y)
Next
Next
ProcedureReturn *mem
EndProcedure
width = 3
height = 4
*matrix = Create2DArray(width, height)
For x = 0 To width - 1
For y = 0 To height - 1
Debug PeekI(*matrix + (x * height + y) * SizeOf(Integer))
Next
Next
FreeMemory(*matrix)
Thanks in advance.