GCC 2.9.5, Solaris 2.8, SPARC - alignment issue - PLEASE HELP!

Alexandre Oliva aoliva@redhat.com
Thu Jul 26 16:23:00 GMT 2001


On Jul 24, 2001, Rob Newberry <robnewberry@grouplogic.com> wrote:

>         char    key[256];

> 	// this causes a SIGSEGV on SPARC
>         *((long*)&key[2]) = value;

> I know this is cruddy, but I would _EXPECT_ the compiler to essentially
> catch this and (more-or-less) rewrite it as something similar to:

> 	memcpy( &key[2], &value, sizeof(long));

Except that, when you tell it it's accessing a long, it's free to
assume it can do it efficiently, without using the byte access
instructions.  If you mean to do byte-per-byte access, use memcpy
explicitly.

> Is there a solution to my problem on Sun OS 5.8 with GCC?

It might be possible to use signal handlers to trap bus errors and
adjust unaligned accesses.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me



More information about the Gcc-help mailing list