Re: const correctness

Поиск
Список
Период
Сортировка
От Greg Jaskiewicz
Тема Re: const correctness
Дата
Msg-id 492BF2E0-833A-493F-ACDC-1FB4D2E0D937@pointblue.com.pl
обсуждение исходный текст
Ответ на Re: const correctness  (Peter Geoghegan <peter@2ndquadrant.com>)
Список pgsql-hackers
On 9 Nov 2011, at 15:33, Peter Geoghegan wrote:

> On 9 November 2011 15:24, Tom Lane <tgl@sss.pgh.pa.us> wrote:.
>> If you go down this road you soon start needing duplicate functions
>> for no other reason than that one takes/returns "const" and one doesn't.
>
> Why would you have to do that?
>
> To my mind, the fact that const "spreads" is a feature, not a deficiency.
>
+1.


I would go as far as compiling most of my stuff using C++ compiler, because it is much more strict about
const-correctness.(but then I have rule about making source files small). 
C compilers (and standard) allows you to do silly things like :
 char *foo = "barbar"; foo[1] = '4';


Not an option in C++ and if you use const correctness.
I had few bugs like that in the past, where pointer was passed around (in C code), and one of the pointers was pointing
toconst string - but since compiler was fine with it... You know what happened.  
And that was on an embedded platform which made it even harder to trace down.

The point is, const correctness is deeply unappreciated.
Added bonus is the fact that compiler can make extra optimisations based on the const keyword. Kind of like read-only
transactionsin the database.  


Probably the most extreme and tedious way of introducing full const correctness in PostgreSQL would be to rename all
filesto .cpp, and let c++ compiler tell you what you need to fix.  



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

Предыдущее
От: Greg Jaskiewicz
Дата:
Сообщение: Re: new warning
Следующее
От: Greg Smith
Дата:
Сообщение: Re: 9.1.2 ?