Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5H9k-00053z-7k for pgsql-committers@arkaria.postgresql.org; Fri, 21 Feb 2020 22:52:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j5H9i-0007LE-Q4 for pgsql-committers@arkaria.postgresql.org; Fri, 21 Feb 2020 22:52:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j5H9i-0007L6-Fd for pgsql-committers@lists.postgresql.org; Fri, 21 Feb 2020 22:52:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j5H9g-00050a-3i for pgsql-committers@lists.postgresql.org; Fri, 21 Feb 2020 22:52:21 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id 01LMqH1v003767; Fri, 21 Feb 2020 17:52:17 -0500 From: Tom Lane To: Peter Geoghegan cc: pgsql-committers Subject: Re: pgsql: Assume that we have signed integral types and flexible array mem In-reply-to: References: Comments: In-reply-to Peter Geoghegan message dated "Fri, 21 Feb 2020 13:56:06 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3765.1582325537.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Fri, 21 Feb 2020 17:52:17 -0500 Message-ID: <3766.1582325537@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Geoghegan 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 t= o be > + * project style to write "field[FLEXIBLE_ARRAY_MEMBER]" not just "fiel= d[]". > + * 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 does= n'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