2020-07-10 11:00 AM
In my code, I write many casting from char* to uint64_t*. Someone success, and someone get failure. I thought I used the unallocated memory, but I rewrote by casting to uint32_t, and then no error happened. Is this normal?
My code:
--------------------------------------
uint32_t sz_t, sz_h;
sz_t = ((uint32_t*)bptr)[0];
bptr += sizeof(sz_t);
sz_h = ((uint32_t*)bptr)[0];
bptr += sizeof(sz_h);
-------------------------------------
Solved! Go to Solution.
2020-07-10 11:11 AM
>>Is this normal?
Yes, LDRD/STRD instructions will fault on unaligned (32-bit) reads, so can't randomly cast pointers safely. Problem for uint64_t and doubles, most frequently.
Typical method in ARM's old and new, is to memcpy() to an aligned buffer and read out of that.
The Cortex-M0(+) is even more unforgiving 32-bit reads can't be misaligned.
2020-07-10 11:11 AM
>>Is this normal?
Yes, LDRD/STRD instructions will fault on unaligned (32-bit) reads, so can't randomly cast pointers safely. Problem for uint64_t and doubles, most frequently.
Typical method in ARM's old and new, is to memcpy() to an aligned buffer and read out of that.
The Cortex-M0(+) is even more unforgiving 32-bit reads can't be misaligned.
2020-07-10 11:25 AM
Ok, thanks.