Type of function returning function.

Checkpoint Technologies ckp at grebyn.com
Fri Jul 13 17:25:18 AEST 1990


In article <1990Jul10.024205.17382 at media.uucp> rmf at media.uucp (Roger Fujii) writes:
>So, just how does one type a function returning a pointer to a function?
                                                                ^^^^^^^^
To start with, function-ness is not a "terminating" data type.  What you
really mean to say is I want a TYPE representing a pointer to a function
returning an *int* (as in your example).

>Example:
>
>int foo(buff)
>char	*buff;
>{
>	return atoi(buff);
>}
>
>TYPE bar()
>{
>	return foo;
>}

You could think about it this way:

typedef int (*TYPE)(); /* TYPE is a pointer to a function returning int */

or, with prototypes for the above example:

typedef int (*TYPE)(char *buff);

This typedef would make the above example work (I think).  Without the
typedef, bar() would be defined as:

int (*)() bar()  /* well, this DOES look weird... */
{
...
}
er, or maybe...
int (*) (bar()) ()  /* nah, I think the first one is right... */
{
...
}

>I would have thought that it would be something like
>int ((*)()), but gcc doesn't agree.  Help...

Well, try the second one above.

>Roger Fujii - Media Cybernetics		Phone: (301)495-3305
>Internet: rmf%media at uunet.uu.net 	UUCP: {uunet,hqda-ai}!media!rmf

Chris

-- 
First comes the logo: C H E C K P O I N T  T E C H N O L O G I E S      / /  
                                                                    \\ / /    
Then, the disclaimer:  All expressed opinions are, indeed, opinions. \  / o
Now for the witty part:    I'm pink, therefore, I'm spam!             \/



More information about the Comp.lang.c mailing list