SIGBUS on Solaris 10 Sparc

Hi all,

I have met a strange problem while I use GCC to compile a very simple

src:

int main()

{

short p[10];

int *pp = (int*)&p[1];

*pp = 1;

return 1;

}

Whe the src is compiled with GCC gcc (GCC) 3.4.3

(csl-sol210-3_4-branch+sol_rpath) and3.3.2

), it will generate core dump for SIGBUS.

I know this is due to unaligned memory access for SPARC.

So I add the type attribute for the short array;

short p[10] __attribute__ ((aligned (4)));

But it doesn't take effect for the memory alignment and still generates

a coredump.

The compile command is also very simple: /usr/sfw/bin/gcc align.c

Does anybody know how to make this piece of code execute sucessfully

with changing src.

Your solution and comments are highly appreciated.

[884 byte] By [adam.zhang] at [2007-11-26 11:54:18]
# 1
Adam,Did you ever find a solution to your problem? I am having a similiar issue with some source being ported from Solaris running in an x86 environment.Any lessons learned would be greatly appreciated.Tom
tfortmann@xcapesolutionsnet at 2007-7-7 12:11:57 > top of Java-index,Solaris Operating System,Solaris Essentials - General Technical Questions...