[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/4] add byteordered types and accessor function

From: M. Warner Losh
Subject: Re: [Qemu-devel] [PATCH 1/4] add byteordered types and accessor functions to qemu.
Date: Wed, 27 Aug 2008 08:20:35 -0600 (MDT)

In message: <address@hidden>
            Gerd Hoffmann <address@hidden> 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...


reply via email to

[Prev in Thread] Current Thread [Next in Thread]