pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: [BUGS] Breakage with VACUUM ANALYSE + partitions
Date: Thu, 5 May 2016 09:32:48 +0200 (CEST)
Message-ID: <alpine.DEB.2.10.1605050738290.30701@sto> (raw)
In-Reply-To: <13345.1462383078@sss.pgh.pa.us>
References: <20160429235837.b63wkjw4dduf56wt@alap3.anarazel.de>
	<CA+TgmoZirJKnSAkjZHt8cVRW9Y7yHyWFLNENnT-LkFtBi6oBfw@mail.gmail.com>
	<20160502164111.cpupbbkab6ik7wwd@alap3.anarazel.de>
	<CA+Tgmoajiv-4840wHpx0o-LJ7mqSGrnCtRH8MOoJkL2A-GF2Ww@mail.gmail.com>
	<20160502165438.yu6inlsyv4babyie@alap3.anarazel.de>
	<alpine.DEB.2.10.1605022146390.927@sto>
	<20160502203634.hmjgdumfgqrldo6n@alap3.anarazel.de>
	<alpine.DEB.2.10.1605022346490.927@sto>
	<20160502221419.shvm4vuhi4jh5hoe@alap3.anarazel.de>
	<alpine.DEB.2.10.1605030712070.927@sto>
	<20160503234810.vzbxwxq4jincgdng@alap3.anarazel.de>
	<alpine.DEB.2.10.1605040727090.27782@sto>
	<6502.1462373742@sss.pgh.pa.us>
	<alpine.DEB.2.10.1605041750420.30701@sto>
	<13345.1462383078@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>


Hello Tom,

>> I understood the point and I do not see real disadvantages. The C standard
>> really says that an enum is an int, and compilers just do that.
>
> No, it doesn't say that, and compilers don't just do that.
> A compiler is specifically allowed to store an enum in char or short if 
> the enum's declared values would all fit into that width.

Hmm. That is a bit of a subtle one:

Spec says that enum *constants* are ints "The identifiers in an enumerator 
list are declared as constants that have type int and may appear wherever 
such are permitted."  But indeed, as you point out, per spec the storage 
could be made smaller.

However, I'm yet to meet a compiler which does not do ints:

   typedef enum { false, true } boolean;
   assert(sizeof(boolean) == sizeof(int)); // ok with gcc & clang

I can guess why: such a compiler would not be able to work with libraries 
compiled with gcc or clang, which would be an pretty annoying feature. Now 
it does not mean that such a compiler does not exist in some realm (8/16 
bits architectures maybe? but then ints would be 16 bits on these...).

> (Admittedly, if you're choosing the values as powers of 2, an OR of them 
> would still fit;

Yep.

> but if you think "oh, an enum is just an int", you will get burned.)

In theory, yes. In practice, the compiler writer would have get burned 
before me:-).

> * compiler warnings if you forget some members of the enum in a switch

Sure. Using a switch on a bitfield is an uncommon pattern, though.

> * debugger ability to print variables symbolically

Yep.

Names are lost by defines, which is my preliminary concern to try to avoid 
them, even at the price of beting against the spec letter:-)

> At that point you might as well use the #defines rather than playing
> language lawyer about whether what you're doing meets the letter of
> the spec.

Hmmm... the compilers are the real judges, the spec is just the law:-)

> I note that C99 specifically mentions this as something a compiler might 
> warn about: [...]

Indeed. Neither gcc nor clang emit such warnings... but they might some 
day, which would be a blow for my suggestion!

Another option would have been explicit bitfields, something like:

   typedef struct {
     int create : 1,
         return_null : 1,
         fail : 1,
         create_in_recovery : 1,
         // ...
         ;
   } extension_bitfield_t;

   void foo(extension_bitfield_t behavior)
   {
     if (behavior.create) printf("create...\n");
     if (behavior.return_null) printf("null...\n");
     if (behavior.fail) printf("fail...\n");
     if (behavior.create_in_recovery) printf("recovery...\n");
   }

   void bla(void)
   {
     foo((extension_bitfield_t) { .fail = 1, .create_in_recovery = 1 });
   }

With gdb it is quite readable:

   // (gdb) p behavior
   // $1 = {create = 0, return_null = 0, fail = -1, create_in_recovery = -1}

Anyway, thanks for the discussion!

-- 
Fabien.


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (64+ messages)  latest in thread

Message-ID: <alpine.DEB.2.10.1605050738290.30701@sto>
Permalink:  ../alpine.DEB.2.10.1605050738290.30701@sto/
Also on:    postgresql.org/message-id/alpine.DEB.2.10.1605050738290.30701@sto

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: coelho@cri.ensmp.fr, tgl@sss.pgh.pa.us, pgsql-hackers@postgresql.org
  Subject: Re: [BUGS] Breakage with VACUUM ANALYSE + partitions
  In-Reply-To: <alpine.DEB.2.10.1605050738290.30701@sto>
  References: <20160429235837.b63wkjw4dduf56wt@alap3.anarazel.de> <CA+TgmoZirJKnSAkjZHt8cVRW9Y7yHyWFLNENnT-LkFtBi6oBfw@mail.gmail.com> <20160502164111.cpupbbkab6ik7wwd@alap3.anarazel.de> <CA+Tgmoajiv-4840wHpx0o-LJ7mqSGrnCtRH8MOoJkL2A-GF2Ww@mail.gmail.com> <20160502165438.yu6inlsyv4babyie@alap3.anarazel.de> <alpine.DEB.2.10.1605022146390.927@sto> <20160502203634.hmjgdumfgqrldo6n@alap3.anarazel.de> <alpine.DEB.2.10.1605022346490.927@sto> <20160502221419.shvm4vuhi4jh5hoe@alap3.anarazel.de> <alpine.DEB.2.10.1605030712070.927@sto> <20160503234810.vzbxwxq4jincgdng@alap3.anarazel.de> <alpine.DEB.2.10.1605040727090.27782@sto> <6502.1462373742@sss.pgh.pa.us> <alpine.DEB.2.10.1605041750420.30701@sto> <13345.1462383078@sss.pgh.pa.us> <alpine.DEB.2.10.1605050738290.30701@sto>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox