I while back there was a post about the use of memcpy and how it can get you
into
data access problems (ARM4VI). I sort of understand the problem. Steve
offered two solutions:
Use the #pragma function(memcpy) or the macro UNALIGNED.
I understand that the #pragma function "undoes" the inlining but I would
like to know why this works?

Also what does the UNALIGNED macro exactly do?
Where is it defined?

Re: UNALIGNED macro?? by Steve

Steve
Fri Jun 25 09:30:19 CDT 2004

did you search the headers for UNALIGNED? it's just a define for the
compilers __unaligned modifier. It marks a variable as needing special
access as it may not be properly aligned so the compiler generates code to
handle that when accessing variables marked __unaligned.

The reason the pragma works is because it turn off the inlining of the
memcpy. The only reason that memcpy "trick" works is because a pointer to
the value is placed on the stack as an argument to memcpy and then the data
is copied byte by byte. However, in an optimized retail build using a const
for the length, like sizeof() does, the compiler will optimize the memcpy to
a DWORD access and not a byte by byte copy. Thus generating the exception.
Personally I consider this a bug in the compiler from over aggressive
optimization as it can cause unaligned accesses when not expected. It should
not do that on RISC CPUs.

--
Steve Maillet (eMVP)
EmbeddedFusion
smaillet_AT_EmbeddedFusion_DOT_com