[PATCH 3/6] Change the OSTC3 macros to have a ; in the end

Anton Lundin glance at acc.umu.se
Tue Oct 28 07:30:12 PDT 2014


On 27 October, 2014 - Dirk Hohndel wrote:

> On Mon, Oct 27, 2014 at 02:13:54PM -0700, Linus Torvalds wrote:
> > On Mon, Oct 27, 2014 at 12:37 PM, Anton Lundin <glance at acc.umu.se> wrote:
> > >
> > > -#define READ_SETTING(_OSTC3_SETTING, _DEVICE_DETAIL) \
> > > +#define READ_SETTING(_OSTC3_SETTING, _DEVICE_DETAIL); \
> > 
> > That extra ';' as the first token in the macro definition seems entirely broken.
> > 
> > >                         rc = hw_ostc3_device_config_read(m_data->device, _OSTC3_SETTING, uData, sizeof(uData)); \
> > >                         if (rc == DC_STATUS_SUCCESS) \
> > >                                 m_deviceDetails->_DEVICE_DETAIL(uData[0]);
> > 
> > I'd also suggest enclosing it all in a "do { } while (0)" (*without* a
> > semicolon at the end - the final semicolon should come from the user),
> > because otherwise
> > 
> >     if (x)
> >         READ_SETTING(..)
> >     else
> >         READ_SETTING(..);
> > 
> > ends up parsing cleanly by the compiler, but doing completely bogus
> > crap (the "else" ends up pairing with the "if" inside the macro,
> > instead of the "if" in the code).
> 
> Needless to say, I agree with both statements. What the heck is that first
> semicolon for, Anton?
> 

Dunno. I remembered that i thought that, "Hey that do {} while (0)
pattern should probably be used here". I think i wrote that code on the
plane i blame a malfunctioning brain.

I'll re-roll to something more sane.

//Anton

-- 
Anton Lundin	+46702-161604


More information about the subsurface mailing list