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

problem with casting for arm compiler

Hi all
I have a strange problem when I'm trying to cast buffers by arm compiler.
Here an example:

char* pbuf;
...
unsigned short val = *((unsigned short*)(pbuf+3));


When I compile this code, my generated assembly code uses LDRH,STRH. Then because my pbuf+3 is not multiple of 2 and those 2 instruction can only work with even value addresses, processor hangs up.
What I should to do that compiler generates a code that works in all cases?

Regards

Parents
  • Hi Per,

    Many thanks to your explanation.

    I remember that I had read some other threads discussing the data alignment issues, and I did encountered a data alignment problem, and fixed that problem with the hints from the KEIL forum.

    I think that I must mix something up, and then got confused.

    Bit field is something implementation dependent.
    Data alignment rule within a struct or union is defined by C-Standard or Processor-Architecture.
    __packed is a feature that KEIL provides.

    These stuff are really difficult to me.

Reply
  • Hi Per,

    Many thanks to your explanation.

    I remember that I had read some other threads discussing the data alignment issues, and I did encountered a data alignment problem, and fixed that problem with the hints from the KEIL forum.

    I think that I must mix something up, and then got confused.

    Bit field is something implementation dependent.
    Data alignment rule within a struct or union is defined by C-Standard or Processor-Architecture.
    __packed is a feature that KEIL provides.

    These stuff are really difficult to me.

Children
No data