Thread: Intentional usage of old style function declarations?

Intentional usage of old style function declarations?

From
Andres Freund
Date:
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



Re: Intentional usage of old style function declarations?

From
Tom Lane
Date:
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