From owner-freebsd-hackers Fri Sep 14 1:26:28 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from snark.rinet.ru (snark.rinet.ru [195.54.192.73]) by hub.freebsd.org (Postfix) with ESMTP id 8EF4237B409; Fri, 14 Sep 2001 01:26:20 -0700 (PDT) Received: (from yar@localhost) by snark.rinet.ru (8.11.6/8.11.6) id f8E8Nib38763; Fri, 14 Sep 2001 12:23:44 +0400 (MSD) (envelope-from yar) Date: Fri, 14 Sep 2001 12:23:44 +0400 From: Yar Tikhiy To: Mike Smith Cc: hackers@freebsd.org, msmith@mass.dis.org Subject: Re: Driver structures & alignment Message-ID: <20010914122344.A38530@snark.rinet.ru> References: <200109132309.f8DN9vX03967@mass.dis.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200109132309.f8DN9vX03967@mass.dis.org>; from msmith@freebsd.org on Thu, Sep 13, 2001 at 04:09:57PM -0700 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Thu, Sep 13, 2001 at 04:09:57PM -0700, Mike Smith wrote: > > > > Is there a single blessed way to define packed structures > > for use in drivers? I suspect that using "#pragma pack(1)" > > will lead to alignment errors in non-Intel architectures. > > Any form of packing is going to cause problems for items that are > located in illegal fashions. > > Having said that, I recommend using __attribute__ ((packed)) > to explicitly request that a structure be packed. Should the __attribute__ be supplied to each structure's member? Or can it be the whole structure's attribute? > > And is it OK to rely on specially crafted structures, like > > "struct fs" in /sys/ufs/ffs/fs.h where multi-byte elements > > are pre-aligned by the structure's design, being contiguous? > > "rely" in what fashion? E.g., will the following structure: struct foo { int16_t a; int16_t b; int32_t c; /* 4-byte boundary */ int64_t d; /* 8-byte boundary */ int8_t e[4]; int32_t f; /* 4-byte boundary */ }; contain alignment holes in any architecture/compiler? -- Yar To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message