[libcamera-devel] [PATCH 01/17] meson: Allow partially initializing objects

Laurent Pinchart laurent.pinchart at ideasonboard.com
Sat Jun 8 18:20:56 CEST 2019


Hi Kieran,

On Fri, May 31, 2019 at 11:10:10AM +0100, Kieran Bingham wrote:
> On 29/05/2019 22:13, Kieran Bingham wrote:
> > On 27/05/2019 10:18, Jacopo Mondi wrote:
> >> On Mon, May 27, 2019 at 02:15:27AM +0200, Niklas Söderlund wrote:
> >>> There are valid use-cases where one might wish to partially initialize a
> >>> structure when creating it without needing to initialize all members.
> >>> This is especially common when working with V4L2.
> >>>
> >>> struct foo {
> >>>     int bar;
> >>>     int baz;
> >>> };
> >>>
> >>> struct foo f = {
> >>>     .bar = 1;
> >>> };
> >>>
> >>> Without -Wno-missing-field-initializers fails to compile with the error,
> >>
> >> I asked for the same a few weeks ago, so I welcome this change
> >> Acked-by: Jacopo Mondi <jacopo at jmondi.org>
> > 
> > I was uncertain before, but I can't deny it would be useful to simplify
> > code /iff/ you know certain members do not need to be initialised.
> > 
> > We'll have to watch our reviews more closely on initialising structures :-)
> > 
> > Acked-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
> 
> Errr,,, uhmmm ... sorry - Ack retracted? :-(
> 
> This breaks compilation on GCC v5 and GCC v6.
> 
> (Raspbian has GCC v6.3, and compilation on the target fails.)

Could you please share the error messages ?

> To fix, I had to make the following change for this series.
> Other solutions may also exist :-)
> 
> > @@ -309,15 +309,15 @@ std::vector<unsigned int> V4L2Subdevice::enumPadCodes(unsigned int pad)
> >  {
> >  	std::vector<unsigned int> codes;
> >  	int ret;
> >  
> >  	for (unsigned int index = 0;; index++) {
> > -		struct v4l2_subdev_mbus_code_enum mbusEnum = {
> > -			.pad = pad,
> > -			.index = index,
> > -			.which = V4L2_SUBDEV_FORMAT_ACTIVE,
> > -		};
> > +		struct v4l2_subdev_mbus_code_enum mbusEnum;
> > +
> > +		mbusEnum.pad = pad;
> > +		mbusEnum.index = index;
> > +		mbusEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> >  
> >  		ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_MBUS_CODE, &mbusEnum);
> >  		if (ret)
> >  			break;
> >  
> > @@ -340,16 +340,16 @@ std::vector<SizeRange> V4L2Subdevice::enumPadSizes(unsigned int pad,
> >  {
> >  	std::vector<SizeRange> sizes;
> >  	int ret;
> >  
> >  	for (unsigned int index = 0;; index++) {
> > -		struct v4l2_subdev_frame_size_enum sizeEnum = {
> > -			.index = index,
> > -			.pad = pad,
> > -			.code = code,
> > -			.which = V4L2_SUBDEV_FORMAT_ACTIVE,
> > -		};
> > +		struct v4l2_subdev_frame_size_enum sizeEnum;
> > +
> > +		sizeEnum.index = index;
> > +		sizeEnum.pad = pad;
> > +		sizeEnum.code = code;
> > +		sizeEnum.which = V4L2_SUBDEV_FORMAT_ACTIVE;
> >  
> >  		ret = ioctl(fd_, VIDIOC_SUBDEV_ENUM_FRAME_SIZE, &sizeEnum);
> >  		if (ret)
> >  			break;
> > 
> >>>     error: missing initializer for member ‘foo::baz’ [-Werror=missing-field-initializers]
> >>>
> >>> Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
> >>> ---
> >>>  meson.build | 1 +
> >>>  1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/meson.build b/meson.build
> >>> index 4d3e99d3e58f71d5..90ad58328f9a2bd5 100644
> >>> --- a/meson.build
> >>> +++ b/meson.build
> >>> @@ -22,6 +22,7 @@ endif
> >>>
> >>>  common_arguments = [
> >>>      '-Wno-unused-parameter',
> >>> +    '-Wno-missing-field-initializers',
> >>>      '-include', 'config.h',
> >>>  ]
> >>>

-- 
Regards,

Laurent Pinchart


More information about the libcamera-devel mailing list