Re: -Wcast-qual cleanup, part 1

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: -Wcast-qual cleanup, part 1
Date: 2011-11-07 12:47:59
Message-ID: CA+TgmoaBFM4ok9G1Ro16Lto16oYSe=_8tXTQxuO4fkCN6U+6Yg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 7, 2011 at 12:13 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> Anyway, attached is the first patch for your amusement.

I can't help but wonder if the cure isn't worse than the disease. I
mean, I very much like the fact that our code compiles without
warnings, and I'm glad you're willing to put in the time to make that
happen ... but aren't these warnings incredibly pedantic?

const is like kudzu. Once you start using it, you find that you need
it everywhere ... but your life is no better than it was before,
except that now you have const.

I'm suspicious of this hunk, for example:

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?

#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. The
result will, I suppose, be const if and only if record is const. But
there's no way to express that cleanly, so we have to duplicate the
macro definition. And anyone who is not using the right compiler
version will have to stare at the code and scratch their head to
figure out which one to use.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Padua Krauss 2011-11-07 13:20:08 xslt_process() need
Previous Message Robert Haas 2011-11-07 12:28:57 Re: Storing hot members of PGPROC out of the band