Re: Use C99 designated initializers for some structs
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Chapman Flack <chap@anastigmatix.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, David Steele <david@pgmasters.net>, Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2018-08-30T04:55:31Z
Lists: pgsql-hackers
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 actually emits for a > designated initializer giving a field a compile-time known constant zero. > Is it sure to eat any more cycles than the same initializer with the field > unmentioned? It's unlikely that any compiler worth its salt will emit redundant zero initializations after a struct initialization (it's dead trivial to recognize than in any SSA like form, which I think most compilers use these days, certainly gcc and clang). What it can't optimize away however is the x = makeNode(SomeType); x->foo = EquivalentToZero; case. Currently the compiler has no way to know that the memory is zero initialized (except for the type member, which the compiler can see being set). Greetings, Andres Freund
Commits
-
Use C99 designated initializers for some structs
- 98afa68d9352 12.0 landed