On Fri, Jan 11, 2019 at 03:21:11PM -0800, William Ahern wrote:
> On Fri, Jan 11, 2019 at 10:43:25AM +0100, Stefan Fritsch wrote:
> <snip>
> > /* only used for sizeof, not actually allocated */
> > extern struct virtio_pci_common_cfg ccfg;
> <snip>
> > #define CREAD(sc, memb) _cread(sc, \
> > offsetof(struct virtio_pci_common_cfg, memb), sizeof(ccfg.memb))
> >
> > The compiler should optimize this to the same code as the complicated
> > macro above. You think this variant is acceptable?
>
> Maybe I'm missing something, but these are the more idiomatic constructs
>
> sizeof ((struct virtio_pci_common_cfg *)0)->memb
> sizeof ((struct virtio_pci_common_cfg){ 0 }).memb
>
No, expanding the offsetof macro and avoiding __builtin_offsetof misses
the point of it.