functions returning pointers to functions
    Dave Martindale 
    dmmartindale at watrose.UUCP
       
    Sun Dec 18 12:27:03 AEST 1983
    
    
  
The declaration
	int (*getroutine(name,table))()
declares a function of two arguments which returns a pointer to a function
(taking an unknown number of arguments) which returns an integer.
At first glance, I would expect that the declaration
	int (*getroutine())(name,table))
would declare a routine of zero arguments which returns a pointer to
a function of two arguments which returns an integer.
But in a declaration of a function, you declare only the parameters to
that function, not the parameters which would be passed to any function
to which this function may return a pointer.  So the declaration should
read
	int (*getroutine())()
if getroutine takes no arguments, regardless of what sort of arguments
the pointed-to function wants.
All of the above applies to the actual function definition.  In an
external declaration, no arguments to any of the functions are specified,
and you would use
	int (*getroutine())();
for both of the cases discussed.
IF C were a language in which the types of arguments were checked and
type conversion done automatically, you would see declarations like
	int (*getroutine(name,table))(value,new,old)
	char *name;
	struct tab *table;
	int value;
	struct entry *new, **old;
where the arguments of both getroutine itself and the routine it returns
must be declared.  But it isn't - you're responsible for getting the
number and types of arguments correct yourself.  And since you're not
even syntactically allowed to put in the "extra" information about
the arguments of the returned routine, there isn't anything for lint
to check your code against.  Caveat programmer.
	Dave Martindale
    
    
More information about the Comp.unix
mailing list