From owner-freebsd-questions Fri Sep 24 13:33:28 1999 Delivered-To: freebsd-questions@freebsd.org Received: from bingnet2.cc.binghamton.edu (bingnet2.cc.binghamton.edu [128.226.1.18]) by hub.freebsd.org (Postfix) with ESMTP id 1651E1516A for ; Fri, 24 Sep 1999 13:33:23 -0700 (PDT) (envelope-from zzhang@cs.binghamton.edu) Received: from sol.cs.binghamton.edu (cs1-gw.cs.binghamton.edu [128.226.171.72]) by bingnet2.cc.binghamton.edu (8.9.3/8.9.3) with SMTP id QAA08220; Fri, 24 Sep 1999 16:32:29 -0400 (EDT) Date: Fri, 24 Sep 1999 16:18:15 -0400 (EDT) From: Zhihui Zhang To: Alfred Perlstein Cc: freebsd-questions@FreeBSD.ORG Subject: Re: A program that causes "bus error" In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 > > 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