From: Tom Lane <t...@sss.pgh.pa.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