From: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Joe Nelson <joe(at)begriffs(dot)com>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, "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-04 03:31:38 |
Message-ID: | CAA4eK1+rwvuMMEv0NPS5V4oRH8eevUfpCjj3bPtVPuAgcAf+=Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Oct 2, 2019 at 9:16 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Joe Nelson <joe(at)begriffs(dot)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;
>
This is a good idea, but by reading the thread it is not completely clear
if we want to pursue this or want to explore something else or leave the
current code as it is. Also, if we want to pursue, do we want to
use INIT_ALL_ZEROES for bool arrays as well?
--
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Smith, Peter | 2019-10-04 03:51:48 | RE: Proposal: Make use of C99 designated initialisers for nulls/values arrays |
Previous Message | Joe Nelson | 2019-10-04 03:23:50 | Re: Change atoi to strtol in same place |