Re: Use C99 designated initializers for some structs

2018-09-07 Thread Peter Eisentraut
On 30/08/2018 22:14, Andres Freund wrote: > I think we should have as rules: > > 1) Members should be defined in the same order as in the struct, that's >the requirement C++ standard is going to impose. Think it's also >reasonable stylistically. > 2) It's OK to omit setting members if zero

Re: Use C99 designated initializers for some structs

2018-08-30 Thread Tom Lane
Mark Dilger writes: > I tried doing this perhaps a year ago, and there are a few files with arrays > of structs whose representations get much larger when you change the format > in this way. For instance, in guc.c: > ... > What should the general rule be for initializing arrays of structs such a

Re: Use C99 designated initializers for some structs

2018-08-30 Thread Andres Freund
Hi, On 2018-08-30 13:54:41 -0300, Alvaro Herrera wrote: > On 2018-Aug-30, Mark Dilger wrote: > > > static struct config_bool ConfigureNamesBool[] = > > { > > { > > {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD, > > gettext_noop("Enables the planner's use of sequential

Re: Use C99 designated initializers for some structs

2018-08-30 Thread Robert Haas
On Wed, Aug 29, 2018 at 6:51 PM, Tom Lane wrote: > I agree that assuming that they're physically zeroes is OK from a > portability standpoint, because we'd have a whole lot of other issues > if they weren't. But I have a different point to make, which is that > it's fairly standard practice for u

Re: Use C99 designated initializers for some structs

2018-08-30 Thread Alvaro Herrera
On 2018-Aug-30, Mark Dilger wrote: > static struct config_bool ConfigureNamesBool[] = > { > { > {"enable_seqscan", PGC_USERSET, QUERY_TUNING_METHOD, > gettext_noop("Enables the planner's use of sequential-scan > plans."), > NULL > }, > &enable_s

Re: Use C99 designated initializers for some structs

2018-08-30 Thread Mark Dilger
> On Aug 29, 2018, at 1:51 PM, David Steele wrote: > > On 8/29/18 5:14 AM, Peter Eisentraut wrote: >> On 29/08/2018 12:13, Peter Eisentraut wrote: >>> Here is a patch to change some struct initializations to use C99-style >>> designated initializers. These are just a few particularly egregiou

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Andres Freund
Hi, On 2018-08-29 18:51:24 -0400, Tom Lane wrote: > I agree that assuming that they're physically zeroes is OK from a > portability standpoint, because we'd have a whole lot of other issues > if they weren't. But I have a different point to make, which is that > it's fairly standard practice for

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Andres Freund
Hi, On 2018-08-29 20:35:57 -0400, Chapman Flack wrote: > On 08/29/18 18:51, Tom Lane wrote: > > > As against that, of course, explicitly zeroing fields that you know very > > well are already zero eats some cycles. I've occasionally wondered if > > I haven't checked what a smart C99 compiler ac

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Chapman Flack
On 08/29/18 18:51, Tom Lane wrote: > As against that, of course, explicitly zeroing fields that you know very > well are already zero eats some cycles. I've occasionally wondered if I haven't checked what a smart C99 compiler actually emits for a designated initializer giving a field a compile-t

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Tom Lane
Andres Freund writes: > On 2018-08-29 15:51:07 -0500, David Steele wrote: >> One thing: I'm not sure that excluding the InvalidOid assignment in the >> TopTransactionStateData initializer is a good idea. That is, it's not clear >> that InvalidOid is 0. >> NULL, false, and 0 seem like no-brainers,

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Thomas Munro
On Thu, Aug 30, 2018 at 8:51 AM David Steele wrote: > On 8/29/18 5:14 AM, Peter Eisentraut wrote: > > On 29/08/2018 12:13, Peter Eisentraut wrote: > >> Here is a patch to change some struct initializations to use C99-style > >> designated initializers. These are just a few particularly egregious

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Andres Freund
Hi, On 2018-08-29 15:51:07 -0500, David Steele wrote: > One thing: I'm not sure that excluding the InvalidOid assignment in the > TopTransactionStateData initializer is a good idea. That is, it's not clear > that InvalidOid is 0. > > NULL, false, and 0 seem like no-brainers, but maybe it would b

Re: Use C99 designated initializers for some structs

2018-08-29 Thread David Steele
On 8/29/18 5:14 AM, Peter Eisentraut wrote: On 29/08/2018 12:13, Peter Eisentraut wrote: Here is a patch to change some struct initializations to use C99-style designated initializers. These are just a few particularly egregious cases that were hard to read and write, and error prone because of

Re: Use C99 designated initializers for some structs

2018-08-29 Thread Peter Eisentraut
//www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services From 8af20d62778b44fc5bfe91f2f8fe7991ffc09bb9 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 29 Aug 2018 08:36:30 +0200 Subject: [PATCH 1/2] Use C99 designated initializers for some structs

Use C99 designated initializers for some structs

2018-08-29 Thread Peter Eisentraut
Here is a patch to change some struct initializations to use C99-style designated initializers. These are just a few particularly egregious cases that were hard to read and write, and error prone because of many similar adjacent types. (The PL/Python changes currently don't compile with Python 3