Intentional usage of old style function declarations?

Started by Andres Freundover 10 years ago2 messageshackers
Jump to latest
#1Andres Freund
andres@anarazel.de

Hi,

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? Fixing it would
imply adding a fair number of (Node *) casts as there's suddenly actual
parameter type checking done.

Greetings,

Andres Freund

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#1)
Re: Intentional usage of old style function declarations?

Andres Freund <andres@anarazel.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

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers