From: | "Smith, Peter" <peters(at)fast(dot)au(dot)fujitsu(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Joe Nelson <joe(at)begriffs(dot)com>, Isaac Morland <isaac(dot)morland(at)gmail(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 06:39:57 |
Message-ID: | 201DD0641B056142AC8C6645EC1B5F62014B92104E@SYD1217 |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> Sent: Friday, 4 October 2019 2:08 PM
>> #define INIT_ALL_ELEMS_ZERO {0}
>> #define INIT_ALL_ELEMS_FALSE {false}
>I would say that's 100% wrong. The entire point here is that it's memset-equivalent, and therefore writes zeroes, regardless of what the datatype is.
I agree it is memset-equivalent.
All examples of the memset code that INIT_ALL_ELEMS_ZERO replaces looked like this:
memset(values, 0, sizeof(values));
Most examples of the memset code that INIT_ALL_ELEMS_FALSE replaces looked like this:
memset(nulls, false, sizeof(nulls));
~
I made the 2nd macro because I anticipate the same folk that don't like setting 0 to a bool will also not like setting something called INIT_ALL_ELEMS_ZERO to a bool array.
How about I just define them both the same?
#define INIT_ALL_ELEMS_ZERO {0}
#define INIT_ALL_ELEMS_FALSE {0}
>As a counterexample, the coding you have above looks a lot like it would work to add
>
>#define INIT_ALL_ELEMS_TRUE {true}
> which as previously noted will *not* work. So I think the one-size-fits-all approach is what to use.
I agree it looks that way; in my previous email I should have provided more context to the code.
Below is the full fragment of the last shared patch, which included a note to prevent anybody from doing such a thing.
~~
/*
* Macros for C99 designated-initialiser syntax to set all array elements to 0/false.
*
* Use these macros in preference to explicit {0} syntax to avoid giving a misleading
* impression that the same value is always used for all elements.
* e.g.
* bool foo[2] = {false}; // sets both elements false
* bool foo[2] = {true}; // does NOT set both elements true
*
* Reference: C99 [$6.7.8/21] If there are fewer initializers in a brace-enclosed list than there
* are elements or members of an aggregate, 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
*/
#define INIT_ALL_ELEMS_ZERO {0}
#define INIT_ALL_ELEMS_FALSE {false}
~~
Kind Regards,
--
Peter Smith
Fujitsu Australia
From | Date | Subject | |
---|---|---|---|
Next Message | Amit Kapila | 2019-10-04 06:50:29 | Re: Proposal: Make use of C99 designated initialisers for nulls/values arrays |
Previous Message | Magnus Hagander | 2019-10-04 05:54:16 | Re: Transparent Data Encryption (TDE) and encrypted files |