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

From Joe Nelson
Subject Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays
Date
Msg-id e50d0213-6e59-4325-8e75-8b46bf4b3bc5@www.fastmail.com
Whole thread Raw
In response to Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays  (Stephen Frost <sfrost@snowman.net>)
Responses Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers
> > I don't understand why this is an issue worth deviating from the
> > standard for.
> 
> Because this use and the way the standard is defined in this case is
> confusing and could lead later hackers to misunderstand what's going on
> and end up creating bugs-

The two possible misunderstandings seem to be:

1. how 0 is interpreted in various contexts such as bool
2. that the x in {x} applies to only the first element

IMHO we should expect people to be familiar with (1), and we have the
INIT_ALL_ELEMS_ZERO macro to avoid (2). However the more I look at the
code using that macro the less I like it. The {0} initializer is more
idiomatic.

My vote would be to use {0} everywhere and avoid constructions like
{false} which might exacerbate misunderstanding (2).

> I figured it was common knowledge that gcc/clang supported it just fine,
> which covers something like 90% of the buildfarm.  I haven't got easy
> access to check others.

As Amit pointed out, {} doesn't work with MSVC-2017, nor is there any
reason it should, given that it isn't part of the C standard.



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Declaring a strict function returns not null / eval speed
Next
From: Chapman Flack
Date:
Subject: Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays