From owner-freebsd-questions Fri Apr 3 19:21:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id TAA13643 for freebsd-questions-outgoing; Fri, 3 Apr 1998 19:21:29 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from gdi.uoregon.edu (gdi.uoregon.edu [128.223.170.30]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id TAA13633 for ; Fri, 3 Apr 1998 19:21:21 -0800 (PST) (envelope-from dwhite@gdi.uoregon.edu) Received: from localhost (dwhite@localhost) by gdi.uoregon.edu (8.8.7/8.8.8) with SMTP id TAA11419; Fri, 3 Apr 1998 19:21:10 -0800 (PST) (envelope-from dwhite@gdi.uoregon.edu) Date: Fri, 3 Apr 1998 19:21:10 -0800 (PST) From: Doug White Reply-To: Doug White To: xiaominy@newton.ccs.tuns.ca cc: freebsd-questions@FreeBSD.ORG, ifair@newton.ccs.tuns.ca, Larry.Hughes@StMarys.ca Subject: Re: bit and byte alignment on FreeBSD? In-Reply-To: <352594BA.2E58B3B8@tuns.ca> 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, 3 Apr 1998, Xiaomin Ye wrote: > Dear Sir/Madam, > We encountered a strange problem while using FreeBSD. > The following structure can be compacted to be 8 bytes by means of cc > compiler on Open-VMS platform. But on FreeBSD, 12 bytes will be formed. Well, checking this between an Alpha and an Intel is comparing apples and oranges. They're completely different processors. > #pragma nomember_alignment > > struct example_structure > { > unsigned type : 3; > unsigned c : 1; > signed mem1 : 12; > signed mem2 : 24; > signed mem2 : 24; > }; > > It seems that on FreeBSD the compiler can only provide one, two or > four bytes alignment, > "type" occupies 1 byte, "c" occupies 1, "mem1" 2 , "mem2" 4 bytes and > "mem3" 4 bytes, because is no bit alignment and 3-byte alignment. > However, on Open-VMS the compiler can provide the bit alignment, > "type", "c" and "mem1" take 2 byte space, and "mem2", "mem3" will occupy > 3 bytes respectively. The total space will be only 8 bytes. > Is there any solution to this problem? Your kind will be very much > appreciated. The Intel architecture may not allow this type of alignment. I think most everything has to be word-aligned anyway, so it'll be expanded. Others are encouraged to point out my lack of knowledge of Intel processor specifics. :) Doug White | University of Oregon Internet: dwhite@resnet.uoregon.edu | Residence Networking Assistant http://gladstone.uoregon.edu/~dwhite | Computer Science Major To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message