From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Geoghegan <pg@bowt.ie>
Cc: pgsql-committers <pgsql-committers@lists.postgresql.org>
Subject: Re: pgsql: Assume that we have signed integral types and flexible array mem
Date: Fri, 21 Feb 2020 17:52:17 -0500
Message-ID: <3766.1582325537@sss.pgh.pa.us> (raw)
In-Reply-To: <CAH2-Wzm2NSUmHML6S4z7qBskXqe0oVsGwcKs2ego2G3p765T0w@mail.gmail.com>
References: <E1j5E1U-0003kx-86@gemulon.postgresql.org>
<CAH2-Wzm2NSUmHML6S4z7qBskXqe0oVsGwcKs2ego2G3p765T0w@mail.gmail.com>
Peter Geoghegan <pg@bowt.ie> writes:
> 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?
As I said in the comment, I think it's good style.
Even if you disagree, we shouldn't remove the macro, because that will
just gratuitously break third-party code.
> 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.
I'm not 100% sure that aspect of the comment is still correct anyway.
I just copied that advice from the Autoconf output --- but it might well
be referring to the behavior of pre-C99 MSVC versions. However, if it
is correct, why are you sure that violating the advice will lead to
a compile error and not to silently-wrong size calculations?
regards, tom lane
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-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us, pg@bowt.ie
Subject: Re: pgsql: Assume that we have signed integral types and flexible array mem
In-Reply-To: <3766.1582325537@sss.pgh.pa.us>
References: <E1j5E1U-0003kx-86@gemulon.postgresql.org> <CAH2-Wzm2NSUmHML6S4z7qBskXqe0oVsGwcKs2ego2G3p765T0w@mail.gmail.com> <3766.1582325537@sss.pgh.pa.us>
* 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