[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of networ
From: |
Jamie Lokier |
Subject: |
[Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of network drivers |
Date: |
Mon, 19 Oct 2009 22:11:49 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Juan Quintela wrote:
> I have good error messages, I don't have good ideas about how to trick
> the compiler. Error messages are clear.
>
> Example:
>
> struct FOO {
> unt16_t foo[0];
> }
> #define vmstate_offset_pointer(_state, _field, _type) \
> (offsetof(_state, _field) + \
> type_check_pointer(_type, typeof_field(_state, _field)))
>
> Called with (after doing substitutions)
> type_check_pointer(uint16_t, struct FOO, foo);
>
> Give that, we try several definitions for type_check_pointer:
>
> #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
>
> Gives the following error:
>
> /scratch/qemu/hw/eeprom93xx.c:144: error: invalid operands to binary -
> (have ‘uint16_t **’ and ‘uint16_t (*)[]’)
>
> Another try:
>
> #define type_check_pointer(t1,t2) ((t1(*)[])0 - (t2*)0)
>
> gives
>
> /scratch/qemu/hw/eeprom93xx.c:148: error: arithmetic on pointer to an
> incomplete type
>
> Another one:
>
> #define type_check_pointer(t1,t2) ((t1(*)[0])0 - (t2*)0)
>
> gives:
>
> /scratch/qemu/hw/eeprom93xx.c:151: error: initializer element is not constant
> /scratch/qemu/hw/eeprom93xx.c:151: error: (near initialization for
> ‘vmstate_eeprom’)
#define type_check_pointer(t1,t2) (0*sizeof((t1(*)[0])0 - (t2*)0))
Or if you want foo[] to work:
#define type_check_pointer(t1,t2) (0*sizeof((t1(**)[])0 - (t2**)0))
Dubiously, but fortunately, the second one works with foo[] and foo[0]
in GCC.
Enjoy :-)
-- Jamie
- [Qemu-devel] [PATCH 19/25] eeprom93xx: port to vmstate, (continued)
- [Qemu-devel] [PATCH 19/25] eeprom93xx: port to vmstate, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 21/25] pcnet: port to vmstate, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 18/25] rtl8139: port to vmstate, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 22/25] ne2000: port to vmstate, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 20/25] eepro100: port to vmstate, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 24/25] e1000: unfold mac_regarraystosave array, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 23/25] e1000: unfold mac_reg_tosave array, Juan Quintela, 2009/10/19
- [Qemu-devel] [PATCH 25/25] e1000: port to vmstate, Juan Quintela, 2009/10/19
- Re: [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers, Jamie Lokier, 2009/10/19