[libcamera-devel] [PATCH 01/17] meson: Allow partially initializing objects
Kieran Bingham
kieran.bingham at ideasonboard.com
Fri May 31 12:10:10 CEST 2019
Hi Niklas,
On 29/05/2019 22:13, Kieran Bingham wrote:
> Hi Niklas, Jacopo,
>
> On 27/05/2019 10:18, Jacopo Mondi wrote:
>> Hi Niklas,
>>
>> 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.)
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',
>>> ]
>>>
>>> --
>>> 2.21.0
>>>
>>> _______________________________________________
>>> libcamera-devel mailing list
>>> libcamera-devel at lists.libcamera.org
>>> https://lists.libcamera.org/listinfo/libcamera-devel
>>>
>>> _______________________________________________
>>> libcamera-devel mailing list
>>> libcamera-devel at lists.libcamera.org
>>> https://lists.libcamera.org/listinfo/libcamera-devel
>
--
Regards
--
Kieran
More information about the libcamera-devel
mailing list