Re: const correctness

Поиск
Список
Период
Сортировка
От Florian Pflug
Тема Re: const correctness
Дата
Msg-id 18271B89-7547-4D4F-817E-5AC626002346@phlo.org
обсуждение исходный текст
Ответ на Re: const correctness  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
On Nov9, 2011, at 22:38 , Tom Lane wrote:
> I think that "const" works materially better in C++ where you can
> overload foo(struct *) and foo(const struct *) and let the compiler sort
> out which is being called.  In C, the impedance match is a lot worse,
> so you have to pick and choose where const is worth the trouble.

Yup. In fact, C++ even *forces* you to use const in a few instances - you
aren't, for example, allowed to call non-const member functions on temporary
objects (i.e., myclass().nonconstmember() fails to compile where as
myclass().constmember() works as expected). Also, in C++ const influences
actual run-time behaviour - there's a very real difference in the life-time
of temporary objects depending on whether they're assigned to a const or
a non-const reference.

So, while C++ and C are similar in a lot of aspects, the situation regarding
const is very different.

best regards,
Florian Pflug



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

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: 9.1.2 ?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Disable OpenSSL compression