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

From Smith, Peter
Subject Proposal: Make use of C99 designated initialisers for nulls/valuesarrays
Date
Msg-id 201DD0641B056142AC8C6645EC1B5F62014B919631@SYD1217
Whole thread Raw
Responses Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays
Re: Proposal: Make use of C99 designated initialisers fornulls/values arrays
List pgsql-hackers
Dear Hackers,

I have identified some OSS code which maybe can make use of C99 designated initialisers for nulls/values arrays.

~

Background:
There are lots of tuple operations where arrays of values and flags are being passed.
Typically these arrays are being previously initialised 0/false by memset.
By modifying code to use C99 designated initialiser syntax [1], most of these memsets can become redundant.
Actually, this mechanism is already being used in some of the existing OSS code. This patch/proposal just propagates
thesame idea to all other similar places I could find. 

~

Result:
Less code. Removes ~200 unnecessary memsets.
More consistent initialisation.

~

Typical Example:
Before:
    Datum        values[Natts_pg_attribute];
    bool        nulls[Natts_pg_attribute];
    ...
    memset(values, 0, sizeof(values));
    memset(nulls, false, sizeof(nulls));
After:
    Datum        values[Natts_pg_attribute] = {0};
    bool        nulls[Natts_pg_attribute] = {0};


---
[1] REF C99 [$6.7.8/21] If there are fewer initializers in a brace-enclosed list than there are elements or members of
anaggregate,  
or fewer characters in a string literal used to initialize an array of known size than there are elements in the array,

the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration

~

Please refer to the attached patch.

Kind Regards,

---
Peter Smith
Fujitsu Australia





Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Declaring a strict function returns not null / eval speed
Next
From: "Moon, Insung"
Date:
Subject: Re: Transparent Data Encryption (TDE) and encrypted files