Re: pgsql: Assume that we have signed integral types and flexible array mem

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-committers <pgsql-committers(at)lists(dot)postgresql(dot)org>
Subject: Re: pgsql: Assume that we have signed integral types and flexible array mem
Date: 2020-02-21 21:56:06
Message-ID: CAH2-Wzm2NSUmHML6S4z7qBskXqe0oVsGwcKs2ego2G3p765T0w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Fri, Feb 21, 2020 at 11:31 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Assume that we have signed integral types and flexible array members.

I see this change to c.h:

+/*
+ * We require C99, hence the compiler should understand flexible array
+ * members. However, for documentation purposes we still consider it to be
+ * project style to write "field[FLEXIBLE_ARRAY_MEMBER]" not just "field[]".
+ * When computing the size of such an object, use "offsetof(struct s, f)"
+ * for portability. Don't use "offsetof(struct s, f[0])", as this doesn't
+ * work with MSVC and with C++ compilers.
+ */
+#define FLEXIBLE_ARRAY_MEMBER /* empty */

Why not just get rid of the FLEXIBLE_ARRAY_MEMBER hack altogether?

I don't think that we need it as a way of drawing attention to the
fact that "offsetof(struct s, f[0])" should not be used. That's not
idiomatic style anyway. If somebody makes this mistake, then I believe
that their code will reliably fail to compile once it hits CF Tester
or the buildfarm.

--
Peter Geoghegan

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2020-02-21 22:52:17 Re: pgsql: Assume that we have signed integral types and flexible array mem
Previous Message Tom Lane 2020-02-21 21:14:15 pgsql: Adjust Solution.pm to set HAVE_STDINT_H.