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

From: Isaac Morland <isaac(dot)morland(at)gmail(dot)com>
To: Joe Nelson <joe(at)begriffs(dot)com>
Cc: "Smith, Peter" <peters(at)fast(dot)au(dot)fujitsu(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays
Date: 2019-10-02 16:02:54
Message-ID: CAMsGm5cgbPXzYPn2MpVMk7LW=CH9FvRL2wMAppnneQ5bDLXMRQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 2 Oct 2019 at 11:34, Joe Nelson <joe(at)begriffs(dot)com> wrote:

> 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. "The
> remainder of the aggregate shall be initialized implicitly the same as
> objects that have static storage duration."
>
> The rest of the elements are being initialized to zero as interpreted by
> their types (so NULL for pointers, 0.0 for floats, even though neither
> of them need be bitwise zero). Setting the first item to 0 matches that
> exactly.
>
> Using {false} may encourage the unwary to try
>
> bool foo[2] = {true};
>
> which will not set all elements to true.
>

Thanks for the explanation. So the first however many elements are in curly
braces get initialized to those values, then the rest get initialized to
blank/0/0.0/false/...?

If so, I don't suppose it's possible to give empty braces:

bool nulls[Natts_pg_attribute] = {};

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-10-02 16:03:05 Re: WIP: Generic functions for Node types using generated metadata
Previous Message Robert Haas 2019-10-02 15:52:38 Re: WIP: Generic functions for Node types using generated metadata