I have an array
uint8_t b[size];
and i'm currently using
struct data_status ds[size / sizeof(struct data_status)];
memcpy(ds, b, size);
to copy the content of the b array into an array of structures. By doing so i have the problem that i need to allocate 2x the bytes i need. Is it safe to cast the b array assuming ds is "packed" by doing so?
ds = (struct data_status*)&b;
Do i have to pay attention to something in particular?
The code above to cast has not been tested, i'm still in the thinking phase.
Am i really saving space by doing so? I guess no since ds must be declared, the best idea would be to use the following: wherever i use
ds[i].a;
i use
(struct data_status*)&b.a;
EDIT1: size is indeed a multiple of sizeof(struct data_status)
EDIT2: Thank you for the answer but i noticed i haven't fully explain you the purpose of this.
What i want to achieve is to read from a flash memory the content between some addresses, the API forces me to use uint8_t pointers (or array). What is written in the flash memory is what i've written previously using a predefined data structure. The code above has just to retrieve the content of the memory and then i have to interpretate them approprietly (using data_status). Clearly the array "b" can die after it reaches its purpose, the best thing would be if "b" is either removed to begin with or it becomes a data_status directly.