10-01-2020 12:47 PM
Hello, i'm new of this forum, i try to use the API of "bmx160.h" files with an 8-bit microcntroller in C- language but there is a declaretion of an array inside a function that needed dinamic allocation of memory.
In the file attached the array is named "uint8_t temp_buf[temp_len];" and the dimension of array "temp_len" is a parameter passed to the function.
The compiler give me this error: "BMX160_drivers/bmi160.c:1369:21: error: variable length arrays are not supported" .
Does anyone know what needs to be done to make the compiler allocate memory?
Thank you!
Solved! Go to Solution.
10-01-2020 05:05 PM
I was about to create thread with same error. in BMI085 API, i get two errors while compiling, by dynamicly alocating array in wrong way.
static int8_t get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bmi08x_dev *dev)
{
int8_t rslt = BMI08X_OK;
uint16_t index;
uint32_t temp_len = len + dev->dummy_byte;
uint8_t temp_buff[temp_len]; //Error[Pe028]:temp_len expression must have a constant value
10-07-2020 08:53 AM
Hello Kilohercas, thank you for your post.
I tried to identify the maximum number of registers that the array could contain: the registers of the BMX160 device are 126, for safety I added 16 bytes so I declared that vector as "static uint8_t temp_buf [142];" this allows it to compile but i have yet to try if it works. Has anyone ever tried to do it this way?
10-08-2020 05:09 AM
in C, you can do like this:
uint8_t *pointer;
pointer = malloc(temp_len * sizeof(uint8_t ));
I guess it's right way to do it.
10-08-2020 10:34 AM