pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Peter Eisentraut <peter_e@gmx.net>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: -Wcast-qual cleanup, part 1
Date: Mon, 07 Nov 2011 10:07:50 -0500
Message-ID: <24642.1320678470@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TgmoaBFM4ok9G1Ro16Lto16oYSe=_8tXTQxuO4fkCN6U+6Yg@mail.gmail.com>
References: <1320642785.25734.13.camel@vanquo.pezone.net>
	<CA+TgmoaBFM4ok9G1Ro16Lto16oYSe=_8tXTQxuO4fkCN6U+6Yg@mail.gmail.com>

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



view thread (4+ messages)  latest in thread

Message-ID: <24642.1320678470@sss.pgh.pa.us>
Permalink:  ../24642.1320678470@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24642.1320678470@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, robertmhaas@gmail.com, peter_e@gmx.net
  Subject: Re: -Wcast-qual cleanup, part 1
  In-Reply-To: <24642.1320678470@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