Date: Fri, 24 Sep 1999 16:18:15 -0400 (EDT) From: Zhihui Zhang <zzhang@cs.binghamton.edu> To: Alfred Perlstein <bright@wintelcom.net> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: A program that causes "bus error" Message-ID: <Pine.GSO.3.96.990924161314.23327B-100000@sol.cs.binghamton.edu> In-Reply-To: <Pine.BSF.4.05.9909241303460.6368-100000@fw.wintelcom.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 24 Sep 1999, Alfred Perlstein wrote: > > 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. > Thanks. This code is taken from the book "Expert C Programming - Deep C Secrets". It is a good book. The auther must be very familiar with SunOS. -Zhihui 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.GSO.3.96.990924161314.23327B-100000>