I'm currently porting code that I wrote for some other embedded system to a STM Evalution Board (STM32F407). I used malloc in the following way on the old board (Simplified for clarity):
float* values = (float*)malloc(sizeof(float)*NO_OF_ATT);
values[0] = 1.0;
values[1] = 2.0;
values[2] = 3.0;
values[3] = 4.0;
This code was working as expected. However on the STM board when I run this code it seems that I cannot access the array in this way, instead of the values it just outputs values like 3.85205412e-034. I thought in C notation x[y] is equivalent to *(x + y)? Anybody can help me in trying to understand what's happening? Thanks in advance!
edit: Here is the non-simplified code:
l = (dllist*)calloc(sizeof(dllist),0);
l->Distance = 0;
for (int i = 0; i < NO_OF_ATT; i++)
{
l->Value[i] = featureValues[i];
if (i == (NO_OF_ATT - 1))
{
l->Value[i] = (int)featureValues[i];
}
}
sglib_dllist_add(&queryList, l);
The featureValues array has the correct values but l->value array doesn't.
Screenshot:
Edit 2:
Struct definition:
typedef struct dllist {
float Value[NO_OF_ATT];
float Distance;
struct dllist *ptr_to_next;
struct dllist *ptr_to_previous;
} dllist;
I just want to clarify: My code runs fine in Visual Studio and my second embedded system. It's just not working as expected on my STM board.