Date: Fri, 14 Sep 2001 12:23:44 +0400 From: Yar Tikhiy <yar@freebsd.org> To: Mike Smith <msmith@freebsd.org> Cc: hackers@freebsd.org, msmith@mass.dis.org Subject: Re: Driver structures & alignment Message-ID: <20010914122344.A38530@snark.rinet.ru> In-Reply-To: <200109132309.f8DN9vX03967@mass.dis.org>; from msmith@freebsd.org on Thu, Sep 13, 2001 at 04:09:57PM -0700 References: <yar@freebsd.org> <200109132309.f8DN9vX03967@mass.dis.org>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010914122344.A38530>
