Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays

From: Andres Freund <andres(at)anarazel(dot)de>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Chapman Flack <chap(at)anastigmatix(dot)net>, Ashwin Agrawal <aagrawal(at)pivotal(dot)io>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Jacob Champion <pchampion(at)pivotal(dot)io>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays
Date: 2019-10-04 20:43:38
Message-ID: 20191004204338.rmrkbtreg6fbqcjm@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2019-10-04 16:31:29 -0400, Bruce Momjian wrote:
> On Fri, Oct 4, 2019 at 02:05:41PM -0400, Chapman Flack wrote:
> > On 10/4/19 1:44 PM, Ashwin Agrawal wrote:
> >
> > > macro exist in first place will be hard to remember. So, irrespective
> > > in long run, {0} might get used in code and hence seems better
> > > to just use {0} from start itself instead of macro/wrapper on top.

It already is in somewhat frequent use, fwiw.

> > > Plus, even if someone starts out with thought {1} sets them all to ones,
> > > I feel will soon realize by exercising the code isn't the reality.
> >
> > I wish ISO C had gone the same place gcc (and C++ ?) went, and allowed
> > the initializer {}, which would eliminate any chance of it misleading
> > a casual reader.
> >
> > If that were the case, I would be +1 on just using the {} syntax.
> >
> > But given that the standard is stuck on requiring a first element,
> > I am +1 on using the macro, just to avoid giving any wrong impressions,
> > even fleeting ones.
>
> Yeah, it is certainly weird that you have to assign the first array
> element to get the rest to be zeros. By using a macro, we can document
> this behavior in one place.

IDK, to me this seems like something one just has to learn about C, with
the macro just obfuscating that already required knowledge. It's not
like this only applies to stack variables initializes with {0}. It's
also true of global variables, or function-local static ones, for
example.

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2019-10-04 20:46:57 Re: Transparent Data Encryption (TDE) and encrypted files
Previous Message Andres Freund 2019-10-04 20:39:38 Re: Tighten error control for OpenTransientFile/CloseTransientFile