Re: -Wcast-qual cleanup, part 1

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: -Wcast-qual cleanup, part 1
Date: 2011-11-07 15:07:50
Message-ID: 24642.1320678470@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On Mon, Nov 7, 2011 at 12:13 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> 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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-11-07 15:12:08 Re: synchronous commit vs. hint bits
Previous Message Robert Haas 2011-11-07 14:45:09 Re: synchronous commit vs. hint bits