Re: const correctness

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Thomas Munro" <munro(at)ip9(dot)org>,<pgsql-hackers(at)postgresql(dot)org>
Subject: Re: const correctness
Date: 2011-11-09 23:49:08
Message-ID: 4EBABD140200002500042C60@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> In general I don't have an objection to adding "const" to
> individual routines, so long as it doesn't create propagating
> requirements to const-ify other code. This may be the only way to
> do it.

As I understand it (although I'm no C expert), a "const" qualifier
on a function parameter declaration is a promise that the function
will not modify what is thus qualified. That means that it can't
pass a const parameter to another function as a parameter not also
declared const. It doesn't say anything about the object itself or
what is returned from the function.

So a non-const parameter in can be passed to a const parameter in a
call, but not vice versa. And a variable need not be declared const
to pass it to a function as a const parameter. I don't know if this
meets your conditions for non-propagation.

-Kevin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2011-11-09 23:56:21 Re: 9.1.2 ?
Previous Message José Arthur Benetasso Villanova 2011-11-09 23:48:09 Re: [patch] Include detailed information about a row failing a CHECK constraint into the error message