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

From Ashwin Agrawal
Subject Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays
Date
Msg-id CALfoeitRcpmLiqHNQLGweJX0eP8HQEmPQLPPGG5PsA-ChCPwrA@mail.gmail.com
Whole thread Raw
In response to Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers

On Fri, Oct 4, 2019 at 8:49 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Jacob Champion <pchampion@pivotal.io> writes:
> On Fri, Oct 4, 2019 at 7:51 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I concur with Joe here.  The reason why some of the existing
>> memset's use "false" is for symmetry with other places where we use
>> "memset(p, true, n)" to set an array of bools to all-true.

> Why introduce a macro at all for the universal zero initializer, if it
> seems to encourage the construction of other (incorrect) macros?

Well, the argument is that some people might think that if {0} is enough
to set all array elements to 0, then maybe {1} sets them all to ones
(as, indeed, one could argue would be a far better specification than
what the C committee actually wrote).  Using a separate macro and then
discouraging direct use of the incomplete-initializer syntax should help
to avoid that error.

Seems avoidable overhead to remind folks on macro existence. Plus, for such a thing 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.

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. If such code is written and nothing fails, that itself seems bigger issue.

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Problem with repalloc downsizing patch
Next
From: Chapman Flack
Date:
Subject: Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays