qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v5 4/6] introduce new vma archive format


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v5 4/6] introduce new vma archive format
Date: Mon, 25 Feb 2013 08:12:39 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130219 Thunderbird/17.0.3

On 02/24/2013 11:37 PM, Dietmar Maurer wrote:

>> Do we care about EBCDIC, in which case you should be using raw hex values
>> instead of relying on ASCII conversion of your magic number?
>> That is, I'd much rather see:
>>
>> #define VMA_MAGIC 0x564D4100 /* ascii "VMA\0" */
> 
> The other code in qemu (for example block/qcow2.h) also use this style:
> 
> #define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb)

Hmm, then that means our existing code base is ascii-centric; so I guess
no one cares, and you may safely match existing style (or someone does
care, and will fix things in a separate patch).


>>> +    VmaDeviceInfoHeader dev_info[256]; } VmaHeader;
>>
>> Is it worth a compile-time assertion that this header is a fixed size, to 
>> make sure
>> that future edits evenly reduce the size of reserved when carving out new 
>> fields?
> 
> I tried to do that, but it seems that gcc does not support sizeof in 
> preprocessor conditionals,
> so I added a runtime check in vma_writer_create().

Then you've never written a compile-time assertion, have you :)   No
preprocessor magic is needed.

> 
> Do you have an example how I can add a compile-time assertion that this 
> header is a fixed size?

struct foo { ... };
struct verify_foo_size {
    char dummy[sizeof(struct foo) == 256 ? 1 : -1];
};

That uses the compiler to enforce that struct foo is exactly 256 bytes,
because the compiler will fail to create an array of negative size if
struct foo ever ends up with a different size.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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