Hi,
I need to write a function that returns a pointer on a function. Is it
possible, and which is the syntax ?
Thanks.
Boris 3 1141
"Boris Sargos" <bs*****@wanado o.fr> wrote in message
news:c6******** **@news-reader4.wanadoo .fr... 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)(voi d); // 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
"John Harrison" <jo************ *@hotmail.com> wrote in message
news:c6ahbn$9pp kf$1@ID-> "Boris Sargos" <bs*****@wanado o.fr> 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)(voi d); // 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)(voi d); // or whatever
But what about
void (*)(*some_funct ion())();
Just guessing. Could be wrong.
"Siemel Naran" <Si*********@RE MOVE.att.net> wrote in message
news:c7******** ************@bg tnsc04-news.ops.worldn et.att.net... "John Harrison" <jo************ *@hotmail.com> wrote in message news:c6ahbn$9pp kf$1@ID-> "Boris Sargos" <bs*****@wanado o.fr> 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)(voi d); // 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)(voi d); // or whatever
But what about
void (*)(*some_funct ion())();
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: amit kumar |
last post by:
I am calling a function which returns pointer to a map.
The declaration of the map is map<int,vectxyz*>. vectxyz is a vector
containing pointer to a class xyz.
For map<int,vectxyz*>* p1
In the called function, I am using p1->find(1) which is returning a
valid iterator and not going to the end. I am returning p1 from the
called function.
But in the calling function, find(1) is going to the end, i.e unable
to find the key 1, which was...
|
by: Dirk Vanhaute |
last post by:
I have only small knowledge of c++, but I would like to compile the
example in
http://support.microsoft.com/kb/q246772/
HOWTO: Retrieve and Set the Default Printer in Windows
I included "#include <Windows.h>" at the start, and the following goes
wrong :
BOOL DPGetDefaultPrinter(LPTSTR pPrinterName, LPDWORD pdwBufferSize)
{
....
|
by: Tweaxor |
last post by:
Hey,
I was trying to figure out was it possible in C to pass the values in an array
from one function to another function. Is the possible in C?
ex. y is the array that holds seven values
If possible how could one pass these seven values in the array
to a function that would check the values.
I tried return y but it didn't work
|
by: Marco Loskamp |
last post by:
Dear list,
I'm trying to dynamically generate functions; it seems that what I
really want is beyond C itself, but I'd like to be confirmed here.
In the minimal example below, I'd like to create content to put at
the address pointed to by f. In particular, I'd like to avoid/replace
the memcpy line.
Possible application (inspired by Paul Graham, "ANSI Common Lisp",
|
by: Razzel |
last post by:
I created this as a test:
#include <time.h>
main(){
printf(X1: %s\n", putim());
printf(X2: %s\n", putim());
}
putim() {
time_t t;
time(&t);
return(ctime(&t));
| |
by: ranjmis |
last post by:
Hi all,
I have come across a piece of code wherein a function returns a
function pointer as it seems to me but not very clear from the
prototype.
As shown below - although return type is void - (*master())() returns a
function pointer some_func & meanwhile calls that function and prints
the message "hi from some_func"
|
by: I.M. !Knuth |
last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until
I started goofing around with this:
================================================================================
/* A function that returns a pointer-of-arrays to the calling function. */
#include <stdio.h>
int *pfunc(void);
|
by: Beta What |
last post by:
Hello,
I have a question about casting a function pointer. Say I want to make
a generic module (say some ADT implementation) that requires a function
pointer from the 'actual/other modules' that takes arguments of type
(void *) because the ADT must be able to deal with any type of data.
In my actual code, I will code the function to take arguments of their
real types, then when I pass this pointer through an interface
function, I...
|
by: Jeffrey Spoon |
last post by:
Hello, I am trying to make a simple function that returns a pointer to
another function. In my header file I've declared my function pointer:
void (*pStateFunction) (void); //assume the function pointed to returns
void
and the actual function that returns the pointer:
void* getState(CString myString);
|
by: Antoninus Twink |
last post by:
What's the correct syntax to define a function that returns a pointer to
a function? Specifically, I'd like a function that takes an int, and
returns a pointer to a function that takes an int and returns a string.
I tried this:
gchar *(*f(gint n))(gint)
{
/* logic here */
}
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |