Re: Avoid unncessary always true test (src/backend/storage/buffer/bufmgr.c)

From: Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>
To: Gurjeet Singh <gurjeet(at)singh(dot)im>
Cc: Karina Litskevich <litskevichkarina(at)gmail(dot)com>, Richard Guo <guofenglinux(at)gmail(dot)com>, Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, michael(at)paquier(dot)xyz, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Avoid unncessary always true test (src/backend/storage/buffer/bufmgr.c)
Date: 2023-07-06 19:22:23
Message-ID: CAEudQAqDiRe06A0LVS+fahDz+pfVCbXJOCPij-xPvRYG7G+M3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Em qui., 6 de jul. de 2023 às 16:06, Gurjeet Singh <gurjeet(at)singh(dot)im>
escreveu:

> On Thu, Jul 6, 2023 at 8:01 AM Karina Litskevich
> <litskevichkarina(at)gmail(dot)com> wrote:
> >
> >
> >> EB_SMGR and EB_REL are macros for making new structs.
> >> IMO these are buggy, once make new structs without initializing all
> fields.
> >> Attached a patch to fix this and make more clear when rel or smgr is
> NULL.
> >
> >
> > As long as a structure is initialized, its fields that are not present in
> > initialization are initialized to zeros and NULLs depending on their
> types.
> > See C99 Standard 6.7.8.21 and 6.7.8.10. This behaviour is quite well
> known,
> > so I don't think this place is buggy. Anyway, if someone else says the
> code
> > is more readable with these fields initialized explicitly, then go on.
>
> Even though I am not a fan of the Designated Initializers feature, I
> agree with Karina. Per the standard, the unmentioned fields get
> initialized to zeroes/NULLs, so the explicit initialization to
> zero/null that this additional patch does is unnecessary. Moreover, I
> feel that it makes the code less pleasant to read.
>
> C99, 6.7.8.21:
> > If there are fewer initializers in a brace-enclosed list than there are
> > elements or members of an aggregate, or fewer characters in a string
> literal
> > used to initialize an array of known size than there are elements in the
> array,
> > the remainder of the aggregate shall be initialized implicitly the same
> as
> > objects that have static storage duration.
>
> C99, 6.7.8.10:
> > If an object that has automatic storage duration is not initialized
> explicitly,
> > its value is indeterminate.

The key points are here.
The object is not static storage duration.
The object is struct with "automatic storage duration".

And not all compilers follow the standards,
they tend to vary quite a bit.

regards,
Ranier Vilela

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2023-07-06 20:10:16 Re: Setting restrictedtoken in pg_regress
Previous Message Gurjeet Singh 2023-07-06 19:19:42 Re: [PATCH] Add GitLab CI to PostgreSQL