ARM memcpy on unaligned pointers and -O2

Jason R Thorpe thorpej@wasabisystems.com
Thu Dec 13 10:33:00 GMT 2001


On Thu, Dec 13, 2001 at 09:53:01AM -0700, Shaun Jackman wrote:

 > I recognized that afterwords and cast the arguments to memcpy()
 > 
 > uint32
 > ld32( const uint32* p)
 > {
 > 	uint32 ret;
 > 	memcpy( &ret, (uint8*)p, sizeof( ret));
 > 	return ret;
 > }
 > 
 > void
 > str32( uint32* p, uint32 val)
 > {
 > 	memcpy( (uint8*)p, &val, sizeof( *p));
 > }
 > 
 > It seems the behaviour persists though. In fact, it has the exact same 
 > behaviour if I change the parameters from uint32* to void*.

This behavior matches my experience with GCC, as well.  Other compilers
(such as Digital Unix's) to honor the casts in this case, but for GCC,
you have to actually do this:

	char *cp = (char *) src;
	memcpy(&ret, cp, sizeof(ret));

I think GCC should honor the cast, like other compilers do.

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>



More information about the Gcc-bugs mailing list