qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jamie Lokier <jamie@shareable.org>
To: Juan Quintela <quintela@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 00/25] VMState cleanups and conversion of network drivers
Date: Mon, 19 Oct 2009 22:11:49 +0100	[thread overview]
Message-ID: <20091019211149.GB9954@shareable.org> (raw)
In-Reply-To: <m38wf7m8c4.fsf@neno.mitica>

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

  reply	other threads:[~2009-10-19 21:11 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-19 18:42 [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 01/25] vmstate: Add support for partial buffers transmission Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 02/25] serial: use post_load version_id field and remove pre_load function Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 03/25] vnmstate: fix name for uint8_equal Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 04/25] vmstate: add VMSTATE_UINT16_EQUAL[_V] Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 05/25] vmstate: Rename VMS_VARRAY to VMS_VARRAY_INT32 Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 06/25] vmstate: fix indentation Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 07/25] vmstate: factor vmstate_offset_value Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 08/25] vmstate: factor vmstate_offset_pointer Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 09/25] vmstate: factor vmstate_offset_array Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 10/25] vmstate: factor vmstate_offset_buffer Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 11/25] vmstate: factor VMSTATE_*BUFFER* definitions Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 12/25] vmstate: Unfold VMSTATE_INT32_VARRAY() only use and remove it Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 13/25] vmstate: add VMS_VARRAY_UINT16_UNSAFE (varrays with uint16 indexes) Juan Quintela
2009-10-19 18:42 ` [Qemu-devel] [PATCH 14/25] vmstate: Add version arg to VMSTATE_SINGLE_TEST() Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 15/25] vmstate: Add VMSTATE_BUFFER_UNUSED Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 16/25] vmstate: Introduce the concept of sub-arrays Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 17/25] rtl8139: port TallyCounters to vmstate Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 18/25] rtl8139: port " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 19/25] eeprom93xx: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 20/25] eepro100: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 21/25] pcnet: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 22/25] ne2000: " Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 23/25] e1000: unfold mac_reg_tosave array Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 24/25] e1000: unfold mac_regarraystosave array Juan Quintela
2009-10-19 18:43 ` [Qemu-devel] [PATCH 25/25] e1000: port to vmstate Juan Quintela
2009-10-19 19:15 ` [Qemu-devel] [PATCH 00/25] VMState cleanups and conversion of network drivers Jamie Lokier
2009-10-19 20:34   ` [Qemu-devel] " Juan Quintela
2009-10-19 21:11     ` Jamie Lokier [this message]
2009-10-20 15:41   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091019211149.GB9954@shareable.org \
    --to=jamie@shareable.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).