Re: const correctness - Mailing list pgsql-hackers

From Florian Pflug
Subject Re: const correctness
Date
Msg-id 18271B89-7547-4D4F-817E-5AC626002346@phlo.org
Whole thread Raw
In response to Re: const correctness  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 by date:

Previous
From: Greg Smith
Date:
Subject: Re: 9.1.2 ?
Next
From: Tom Lane
Date:
Subject: Re: Disable OpenSSL compression