This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Dealing with non-aligned data

Hello,

A colleague of mine, while processing some binary data, transfered a RAM memory address to a function. That address was not even (ARM7 architecture) so the LDR instruction behaved exactly as the assembly manual specifies it should in case of a misaligned address - round in the address + some more shift magic, which created a memory access off by 1 byte. My question is: Is there a way to deal with this runtime error in advance?

Parents
  • My question is: Is there a way to deal with this runtime error in advance?

    Sure there is. You can use __packed pointers (feature of Realview) to access unaligned data. You can detect unaligned pointers using some arithmetics:

    if ((uintptr_t)ptr & 3 != 0)
    {
        /* Error: bad pointer alignment */
    }
    

Reply
  • My question is: Is there a way to deal with this runtime error in advance?

    Sure there is. You can use __packed pointers (feature of Realview) to access unaligned data. You can detect unaligned pointers using some arithmetics:

    if ((uintptr_t)ptr & 3 != 0)
    {
        /* Error: bad pointer alignment */
    }
    

Children
No data