Pointer typecasts may write to incorrect addresses on ARM?

Andrew Haley aph@redhat.com
Thu Sep 24 08:33:00 GMT 2009


Subramanyam Badri wrote:
> Hi,
>  
> I am using a GCC compiler for ARM and see an alignment problem with pointer typecasting.  We're porting code to ARM and found some writes to incorrect addresses.  Can you help?  For example:
>  
> char * pChar = (char *)0x100000;  /* hardcoded for example purposes */
> pChar[0] = 0x0;
> *(int *)&pChar[1] = 0x11223344;
>  
> /* We really want pChar[0] to equal 0x00, but it equals 0x44 on ARM!!!! */
> printf ("pChar[0] = 0x%02x\n", pChar[0]);
> 
> My understanding is that non-aligned memory access is allowed on ARM,

No, that's not true.  *Some* versions of ARM have some support for unaligned
memory accesses, some don't.  You need to be sure which one you've got.

Andrew.



More information about the Gcc-help mailing list