Re: -Wcast-qual cleanup, part 1

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: -Wcast-qual cleanup, part 1
Дата
Msg-id CA+TgmoaBFM4ok9G1Ro16Lto16oYSe=_8tXTQxuO4fkCN6U+6Yg@mail.gmail.com
обсуждение исходный текст
Ответ на -Wcast-qual cleanup, part 1  (Peter Eisentraut <peter_e@gmx.net>)
Ответы Re: -Wcast-qual cleanup, part 1  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Mon, Nov 7, 2011 at 12:13 AM, Peter Eisentraut <peter_e@gmx.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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: Storing hot members of PGPROC out of the band
Следующее
От: Peter Padua Krauss
Дата:
Сообщение: xslt_process() need