Re: Intentional usage of old style function declarations?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Intentional usage of old style function declarations?
Date: 2015-08-11 17:07:43
Message-ID: 24801.1439312863@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Andres Freund <andres(at)anarazel(dot)de> writes:
> We have a bunch of callbacks that use old-style C function
> declarations. I.e. functions with empty parens allowing all types of
> data being passed:

> E.g.
> extern bool expression_tree_walker(Node *node, bool (*walker) (),
> void *context);
> extern Node *expression_tree_mutator(Node *node, Node *(*mutator) (),
> void *context);

> I find that to be fairly ugly. Was that intentional?

Yes. If we had the signature of the walker written out explicitly as say

bool (*walker) (Node *node, void *context)

then every walker function would have to be declared that way (rather than
being declared with its true context pointer type), requiring casting away
from void * inside the walker. Or else we could explicitly cast walker
function names to a typedef for walker_function everywhere we call
expression_tree_walker. Both are notationally pains in the rear, and
what's more, either solution totally destroys the argument that you've
gained any type-safety. I don't think a forced cast is better than a weak
declaration.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2015-08-11 17:10:40 Re: pg_dump and search_path
Previous Message Robert Haas 2015-08-11 17:06:51 Re: WIP: SCRAM authentication