Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id D6F8EB54C94 for ; Mon, 7 Nov 2011 11:09:20 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 19674-01 for ; Mon, 7 Nov 2011 15:08:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 8EBF25C64EC for ; Mon, 7 Nov 2011 11:07:53 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id pA7F7oIx024643; Mon, 7 Nov 2011 10:07:50 -0500 (EST) To: Robert Haas cc: Peter Eisentraut , pgsql-hackers Subject: Re: -Wcast-qual cleanup, part 1 In-reply-to: References: <1320642785.25734.13.camel@vanquo.pezone.net> Comments: In-reply-to Robert Haas message dated "Mon, 07 Nov 2011 07:47:59 -0500" Date: Mon, 07 Nov 2011 10:07:50 -0500 Message-ID: <24642.1320678470@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.101 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201111/333 X-Sequence-Number: 197824 Robert Haas writes: > On Mon, Nov 7, 2011 at 12:13 AM, Peter Eisentraut wrote: >> typedef struct ErrorContextCallback >> { >> struct ErrorContextCallback *previous; >> - void (*callback) (void *arg); >> - void *arg; >> + void (*callback) (const void *arg); >> + const void *arg; >> } ErrorContextCallback; > Why should the callback be forced to treat its private argument as const? Yes, the above seems like a seriously bad idea. It's probably true that most existing callbacks could afford to declare their callback args as const, but it does not follow that we should legislate that in the API. All that that will accomplish is to move the need to cast away const from some places to some other places. >> #define XLogRecGetData(record) ((char*) (record) + SizeOfXLogRecord) >> +#define XLogRecGetConstData(record) ((const char*) (record) + SizeOfXLogRecord) > IMHO, this is an example of everything that's wrong with const. Yes, this seems pretty horrid as well. Not so much just the one instance as the implications of this sweeping requirement: >> 2. Macros accessing structures should come in two variants: a "get" >> version, and a "set"/anything else version, so that the "get" version >> can preserve the const qualifier. I'm not prepared to buy into that as a general coding rule. Maybe it would be better to just add -Wno-cast-qual to CFLAGS. regards, tom lane