Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > A function that returns a pointer on a function

Reply
Thread Tools

A function that returns a pointer on a function

 
 
Boris Sargos
Guest
Posts: n/a
 
      04-23-2004
Hi,

I need to write a function that returns a pointer on a function. Is it
possible, and which is the syntax ?

Thanks.
Boris



 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      04-23-2004

"Boris Sargos" <> wrote in message
news:c6ag98$dkg$...
> Hi,
>
> I need to write a function that returns a pointer on a function. Is it
> possible, and which is the syntax ?
>
> Thanks.
> Boris
>


Trying to do that without using a typedef is a real test of your
understanding of type declarations. The easy way is with a typedef

typedef void (*FUNC_PTR)(void); // or whatever

FUNC_PTR some_function()
{
...
}

It is however impossible to define a function that returns a pointer to
itself, that would mean an infinite recursion in the type of that function.

john


 
Reply With Quote
 
 
 
 
Siemel Naran
Guest
Posts: n/a
 
      04-23-2004
"John Harrison" <> wrote in message
news:c6ahbn$9ppkf$1@ID-> "Boris Sargos" <> wrote in
message

> > I need to write a function that returns a pointer on a function. Is it
> > possible, and which is the syntax ?


> Trying to do that without using a typedef is a real test of your
> understanding of type declarations. The easy way is with a typedef


Without typedef I think this is it:

void (*some_function())();

This is a function some_function taking no arguments and returning a pointer
to a function taking no arguments and returning a void. It's similar to a
function taking a reference to an array of elements. But of course, what
you have below is cleaner:

> typedef void (*FUNC_PTR)(void); // or whatever
>
> FUNC_PTR some_function()
> {
> ...
> }
>
> It is however impossible to define a function that returns a pointer to
> itself, that would mean an infinite recursion in the type of that

function.

This makes sense, because of

typedef FUNC_PTR (*FUNC_PTR)(void); // or whatever

But what about

void (*)(*some_function())();

Just guessing. Could be wrong.


 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      04-23-2004

"Siemel Naran" <> wrote in message
news:c7cic.28057$...
> "John Harrison" <> wrote in message
> news:c6ahbn$9ppkf$1@ID-> "Boris Sargos" <> wrote in
> message
>
> > > I need to write a function that returns a pointer on a function. Is it
> > > possible, and which is the syntax ?

>
> > Trying to do that without using a typedef is a real test of your
> > understanding of type declarations. The easy way is with a typedef

>
> Without typedef I think this is it:
>
> void (*some_function())();
>


That's right.

> This is a function some_function taking no arguments and returning a

pointer
> to a function taking no arguments and returning a void. It's similar to a
> function taking a reference to an array of elements. But of course, what
> you have below is cleaner:
>
> > typedef void (*FUNC_PTR)(void); // or whatever
> >
> > FUNC_PTR some_function()
> > {
> > ...
> > }
> >
> > It is however impossible to define a function that returns a pointer to
> > itself, that would mean an infinite recursion in the type of that

> function.
>
> This makes sense, because of
>
> typedef FUNC_PTR (*FUNC_PTR)(void); // or whatever
>
> But what about
>
> void (*)(*some_function())();
>
> Just guessing. Could be wrong.
>


Syntax error on my compiler. If it's not possible with a typedef I don't see
why you think it might be possible without a typedef.

john

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Pointer to pointer Vs References to Pointer bansalvikrant@gmail.com C++ 4 07-02-2009 10:20 AM
passing the address of a pointer to a func that doesnt recieve a pointer-to-a-pointer jimjim C Programming 16 03-27-2006 11:03 PM
Function that returns a pointer to a function of the same signature? sqweek C Programming 2 01-13-2006 05:34 PM
Pointer-to-pointer-to-pointer question masood.iqbal@lycos.com C Programming 10 02-04-2005 02:57 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57