From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rusty Russell Subject: Re: [PATCH RFC] virtio-pci: new config layout: using memory BAR Date: Wed, 29 May 2013 14:03:03 +0930 Message-ID: <87mwremmm8.fsf@rustcorp.com.au> References: <20130528160342.GA29915@redhat.com> <87bo7vvxej.fsf@codemonkey.ws> <20130528173257.GC30296@redhat.com> <51A4ECDE.1020207@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Anthony Liguori , virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, KONRAD Frederic , Peter Maydell , Stefan Hajnoczi , Laszlo Ersek To: Paolo Bonzini , "Michael S. Tsirkin" Return-path: Received: from ozlabs.org ([203.10.76.45]:36680 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752672Ab3E2FHj (ORCPT ); Wed, 29 May 2013 01:07:39 -0400 In-Reply-To: <51A4ECDE.1020207@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Paolo Bonzini writes: > Il 28/05/2013 19:32, Michael S. Tsirkin ha scritto: >>>> > > + >>>> > > + switch (addr) { >>>> > > + case offsetof(struct virtio_pci_common_cfg, device_feature_select): >>>> > > + return proxy->device_feature_select; >>> > >>> > Oh dear no... Please use defines like the rest of QEMU. >> Any good reason not to use offsetof? > > I'm not sure it's portable to use it in case labels. IIRC, the > definition ((int)&(((T *)0)->field)) is not a valid C integer constant > expression. Laszlo? It's defined to yield an integer constant expression in the ISO standard (and I think ANSI too, though that's not at hand): 7.19, para 3: ...offsetof(type, member-designator) which expands to an integer constant expression that has type size_t, ... The real question is whether compilers qemu cares about meet the standard (there's some evidence that older compilers fail this). If not, we'll have to define them as raw offsets... Cheers, Rusty.