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