dynamically allocate a 2D array

Technical questions regarding the XTC tools and programming with XMOS.
tom3
Member++
Posts: 16
Joined: Mon Jun 19, 2023 9:32 pm

dynamically allocate a 2D array

Post by tom3 »

Hello
I have an 2D array

Code: Select all

my_array[i][j]
. "i" is a fixed number but i want "j" to be chosen by the user ( like an input). Then i want to create the 2D array using the input given by the user. I have tried several methods to do that, but the problem is that it won't let me do that. For example , i can't define

Code: Select all

int **my_array 
. The error says " cannot declare pointer to aliasing pointer".
Of course , i have checked the AN10001 to pass an alias pointer as argument, but since i want to use the code :

Code: Select all

my_array=(int **)malloc(input_user * sizeof(int *));
, it makes everything a little more difficult because of the "int **" since this isn't a variable but just a type.

Does somebody know a trick to do that ? I would be very grateful. I have seen many methods online, but they can't be applied to XMOS programming because of the restrictions it has .

Thank you in advance

Best regards


User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »