My function receives a char* Pointer for DATA_LOCATION, and needs to pass a unsgined int* Pointer for the same DATA_LOCATION.
i.e.
Input: char *Data8;
Output: unsgined int *Data32;
I'm afraid to do the following conversion, due to alignment problem:
C:
Data32 = (unsigned int *) Data8;
That is a problem since Data8 is aligned to 8-bit addresses, while Data32 should be aligned to 32-bit addresses.
Hi Ian,
It's a problem, since when you will perform: *Data32
Then,
Some cores expect the Address pointed by Data32 to be 32-bit aligned, because *Data32 Operation fetches 32-bit.
Otherwise, you'll get a Bus Exception.
But the address pointed to by Data8 is only 8-bit aligned.
If you have unaligned pointer, then any aligned pointer will not be for the same location. So, it's either same location or aligned pointer. Take your pick.
So you're actually saying that there's no way to work it out - i.e. the function which gets 8-bit aligned pointer, can't (somehow) convert it to 32-bit aligned.
The best it can do is to allocate temporary aligned memory, copy data pointed to by the incoming pointer into there, then pass the pointer to this area to the route which requires aligned pointers. Once the routine is done, it should copy the [possibly] changed data to the space pointed to by the original pointer, then deallocate the temporary memory. To do that, your program must know the size.