From owner-freebsd-questions Fri Sep 24 12:50:48 1999 Delivered-To: freebsd-questions@freebsd.org Received: from fw.wintelcom.net (ns1.wintelcom.net [209.1.153.20]) by hub.freebsd.org (Postfix) with ESMTP id D837E150F6 for ; Fri, 24 Sep 1999 12:50:44 -0700 (PDT) (envelope-from bright@wintelcom.net) Received: from localhost (bright@localhost) by fw.wintelcom.net (8.9.3/8.9.3) with ESMTP id NAA01384; Fri, 24 Sep 1999 13:07:30 -0700 (PDT) Date: Fri, 24 Sep 1999 13:07:30 -0700 (PDT) From: Alfred Perlstein To: Zhihui Zhang 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, 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. -Alfred To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message