Re: Coding style point: "const" in function parameter declarations - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Coding style point: "const" in function parameter declarations
Date
Msg-id 2487.1308760870@sss.pgh.pa.us
Whole thread Raw
In response to Re: Coding style point: "const" in function parameter declarations  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: Coding style point: "const" in function parameter declarations
Re: Coding style point: "const" in function parameter declarations
List pgsql-hackers
Merlin Moncure <mmoncure@gmail.com> writes:
> On Tue, Jun 21, 2011 at 5:51 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Declarations like "const structtype *param" are fine, because those
>> create a real, enforced contract on what the function can do to data
>> that is visible to its caller.  But I don't see any value at all in
>> const-ifying the parameter itself.

> What about making a separate typedef for that (like ConstRelation)?

Well, any change along this line would require pretty widespread
changes, as you'd have to const-ify from the bottom up, or else hold
your nose and cast-away-const in assorted calls (which I think is so
evil you might as well not have the const in the first place).

If we were thinking of moving in that direction, I would argue that
we should get rid of typedef'd pointers altogether, ie, change
"Relation" to be a typedef for the struct and write "Relation *rel"
not "Relation rel".  Then, attaching a const to the front is easy,
natural, and does what the naive reader would expect.  But this would
be a sufficiently sweeping change that I'm not sure the benefits
would be worth the cost.
        regards, tom lane


pgsql-hackers by date:

Previous
From: "Kevin Grittner"
Date:
Subject: Re: Repeated PredicateLockRelation calls during seqscan
Next
From: Alvaro Herrera
Date:
Subject: Re: [v9.2] DROP Reworks Part.0 - 'missing_ok' support of get_object_address