functions returning pointers to functions 
Author Message
 functions returning pointers to functions

Quote:

> I've come across a problem trying to define a function that returns a
> pointer to another function type (without using typedefs :).

blp:~(0)$ cdecl
Type `help' or `?' for help
cdecl> declare function returning pointer to function returning int;
int (*f())()
cdecl>


Sat, 06 Apr 2002 03:00:00 GMT  
 functions returning pointers to functions
Hi,

I've come across a problem trying to define a function that returns a
pointer to another function type (without using typedefs :).

I've come up with the following which I thought would have been right,
but it's not!

int (*)(int) func(void)
{
    ...

Quote:
}

Here, func should return a pointer to a function taking an int as
a parameter and returning an int. Is there any way to do this, or
do you have to use typedefs?

furos

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 07 Apr 2002 03:00:00 GMT  
 functions returning pointers to functions

Quote:

> I've come across a problem trying to define a function that returns a
> pointer to another function type
> (without using typedefs :).

ah, a {*filter*}  :-)

Quote:

> I've come up with the following which I thought would have been right,
> but it's not!

> int (*)(int) func(void)
> {
>     ...
> }

> Here, func should return a pointer to a function taking an int as
> a parameter and returning an int. Is there any way to do this, or
> do you have to use typedefs?

Try:-
    int (*func (void)) (int);
It gave me a headache.

Isn't this easier:-
  typedef int (*Ifunc) (int);
  typedef Ifunc (*Ffunc) (void);
  Ffunc func;

IMHO the only reason to know the first way is work out what someone is
trying to do then you can replace it with something human beings can
understand.

Take a look at the definition of signal() if you *really* want to hurt
your mind...

--

It isn't a program, it's a 1000 patches flying in
loose formation.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sun, 07 Apr 2002 03:00:00 GMT  
 functions returning pointers to functions

Quote:

> Hi,

> I've come across a problem trying to define a function that returns a
> pointer to another function type (without using typedefs :).

> I've come up with the following which I thought would have been right,
> but it's not!

> int (*)(int) func(void)
> {
>     ...
> }

> Here, func should return a pointer to a function taking an int as
> a parameter and returning an int. Is there any way to do this, or
> do you have to use typedefs?

Take it one step at a time.  For these kinds of problems, I work from
the outside in.

1.  int f (int x)  -- f is a function taking one int parameter
                      and returning an int
2.  f = (*g)       -- g is a pointer.  Substitute for f in (1) to get
                      int (*g)(int x).  g is a pointer to a function
                      taking one int parameter and returning an int.
3.  g = h(void)    -- h is a function.  Substitute for g in (2) to get
                      int (*h(void))(int x).  h is a function which
                      takes no parameters and returns a pointer to a
                      function which takes one int parameter and
                      returns int.

Hope the derivation makes sense.  It's a lot easier on everyone to just
use typedefs, though.

--
www.biggerhammer.com | Low Technology Solutions for
                     | High Technology Problems

Sent via Deja.com http://www.deja.com/
Before you buy.



Sun, 07 Apr 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Pointer to function returning pointer to function returning...

2. Function returning pointers to functions (repost)

3. Function returning pointers to functions

4. (member) function returning pointer to functions like itself?

5. QUESTION: functions returning pointers to functions

6. How do I define function returning pointer to function returning int?

7. Question about signal()/pointers to functions that return pointers to functions

8. How to use (pointer to function), and function and pointer to (pointer to function)

9. Function returning a function-pointer - how to prototype ?

10. Declaring static function returning pointer to extern function

11. About function that returns function pointer

12. Function returning a function pointer.

 

 
Powered by phpBB® Forum Software