Date: Fri, 24 Sep 1999 13:07:30 -0700 (PDT) From: Alfred Perlstein <bright@wintelcom.net> To: Zhihui Zhang <zzhang@cs.binghamton.edu> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: A program that causes "bus error" Message-ID: <Pine.BSF.4.05.9909241303460.6368-100000@fw.wintelcom.net> In-Reply-To: <Pine.GSO.3.96.990924151823.23327A-100000@sol.cs.binghamton.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 24 Sep 1999, Zhihui Zhang wrote:
>
> The following program causes "bus error" on a Sun workstation whether I
> compile it with cc or gcc:
>
> #include <stdio.h>
> main()
> {
> union {
> char a[10]; int i;
> } u;
> int * p = (int *) &(u.a[1]);
> * p = 17;
> printf("%d\n", *p);
> }
You are violating sparc's alignment restrictions by doing this,
a x86 machine will deal with the alignment issues in hardware however
a sparc will trap to the OS (SIGBUS) if non-aligned accesses are
attempted.
-Alfred
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.05.9909241303460.6368-100000>
