From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KYLw3-0007AR-IL for qemu-devel@nongnu.org; Wed, 27 Aug 2008 10:23:47 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KYLw1-00079j-9I for qemu-devel@nongnu.org; Wed, 27 Aug 2008 10:23:47 -0400 Received: from [199.232.76.173] (port=34107 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KYLw0-00079f-UW for qemu-devel@nongnu.org; Wed, 27 Aug 2008 10:23:45 -0400 Received: from bsdimp.com ([199.45.160.85]:62431 helo=harmony.bsdimp.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KYLw0-0008Dq-6I for qemu-devel@nongnu.org; Wed, 27 Aug 2008 10:23:44 -0400 Date: Wed, 27 Aug 2008 08:20:35 -0600 (MDT) Message-Id: <20080827.082035.619298951.imp@bsdimp.com> Subject: Re: [Qemu-devel] [PATCH 1/4] add byteordered types and accessor functions to qemu. From: "M. Warner Losh" In-Reply-To: <1219844723-17469-1-git-send-email-kraxel@redhat.com> References: <1219844723-17469-1-git-send-email-kraxel@redhat.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, kraxel@redhat.com In message: <1219844723-17469-1-git-send-email-kraxel@redhat.com> Gerd Hoffmann writes: : +typedef struct { uint16_t le; } le16 __attribute__((__aligned__(2))); : +typedef struct { uint32_t le; } le32; : +typedef struct { uint64_t le; } le64; : +typedef struct { uint16_t be; } be16 __attribute__((__aligned__(2))); : +typedef struct { uint32_t be; } be32; : +typedef struct { uint64_t be; } be64; This is likely still wrong. There's no packing to ensure that these structures are the right size. There's no asserts to make sure that these structures really are the right size. They are using raw GCCisms, which is both verbose and non-portable. This may not be a concern in qemu. #define packed(x) __attribute__((__aligned__(x))) __attribute__((__packed__)) typedef struct { uint16_t le; } le16 packed(2); typedef struct { uint32_t le; } le32 packed(4); typedef struct { uint64_t le; } le64 packed(8); typedef struct { uint16_t be; } be16 packed(2); typedef struct { uint32_t be; } be32 packed(4); typedef struct { uint64_t be; } be64 packed(8); #undef packed However, something just feels wrong with this approach. I'm sure there's other subtleties that will bite you with it... Warner