Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays
Date
Msg-id 7318.1570031161@sss.pgh.pa.us
Whole thread Raw
In response to Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays  (Joe Nelson <joe@begriffs.com>)
Responses Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays  (Mark Dilger <hornschnorter@gmail.com>)
RE: Proposal: Make use of C99 designated initialisers fornulls/values arrays  ("Smith, Peter" <peters@fast.au.fujitsu.com>)
Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays  (Amit Kapila <amit.kapila16@gmail.com>)
List pgsql-hackers
Joe Nelson <joe@begriffs.com> writes:
> Isaac Morland wrote:
>> I hope you'll forgive a noob question. Why does the "After"
>> initialization for the boolean array have {0} rather than {false}?

> I think using a value other than {0} potentially gives the incorrect
> impression that the value is used for *all* elements of the
> array/structure, whereas it is only used for the first element.

There's been something vaguely bothering me about this proposal,
and I think you just crystallized it.

> Using {false} may encourage the unwary to try
>     bool foo[2] = {true};
> which will not set all elements to true.

Right.  I think that in general it's bad practice for an initializer
to not specify all fields/elements of the target.  It is okay in the
specific case that we're substituting for a memset(..., 0, ...).
Perhaps we could make this explicit by using a coding style like

/* in c.h or some such place: */
#define INIT_ALL_ZEROES  {0}

/* in code: */
    Datum values[N] = INIT_ALL_ZEROES;

and then decreeing that it's not project style to use a partial
initializer other than in this way.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Joe Nelson
Date:
Subject: Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays
Next
From: Robert Haas
Date:
Subject: Re: WIP: Generic functions for Node types using generated metadata