473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C Callbacks

The functions I am using are not standard, but this is a standard question.

I was under the understanding that you could create a Functor and use it
in place of the function pointer argument to C functions. I haven't
been able to so either I am doing it wrong or I misunderstood.

I am trying to override my signal handler for the SIGCHLD unix signal:

Engine::SIGHandler Engine::sigchld_handler;

Engine::SIGHandler::SIGHandler()
{
signal(SIGCHLD, (void (*)(int))*this);
/*
The above was also tried with (void (*)(int))this which compiles but
blows up with SIGSEGV "in Engine::sigchld_handler ()".
*/
}
void Engine::SIGHandler::operator()(int sig)
{
int status, exit_val;
pid_t pid;

if ((pid = waitpid(-1, &status, WNOHANG)) < 0)
return;

map<pid_t, Engine*>::iterator f = engine_processes.find(pid);
if (f != engine_processes.end())
f->second->handleSigChld(status);
}

So then, the question...

Is what I am attempting possible? How is it done if so?

thanks,
NR

Jul 19 '05 #1
2 1608

"Noah Roberts" <nr******@dontemailme.com> wrote in message
news:3F**************@dontemailme.com...
The functions I am using are not standard, but this is a standard question.
I was under the understanding that you could create a Functor and use it
in place of the function pointer argument to C functions. I haven't
been able to so either I am doing it wrong or I misunderstood.


Sorry but you misunderstood. C functions can only accept function pointers.
I think you are confusing the situation with template classes and template
functions which can accept funciton pointers or functors.

john
Jul 19 '05 #2
John Harrison wrote:
"Noah Roberts" <nr******@dontemailme.com> wrote in message
news:3F**************@dontemailme.com...
The functions I am using are not standard, but this is a standard
question.
I was under the understanding that you could create a Functor and use it
in place of the function pointer argument to C functions. I haven't
been able to so either I am doing it wrong or I misunderstood.

Sorry but you misunderstood. C functions can only accept function pointers.
I think you are confusing the situation with template classes and template
functions which can accept funciton pointers or functors.


DOH!

thanks.

john

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Melissa Wallis | last post by:
I have a class with 5 callbacks. Two of the callbacks work fine but the others don't. The main difference is that the callbacks that don't work are composed of a sequence of structs. I noticed a...
2
by: Mike C. Fletcher | last post by:
I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate __del__ methods (and the memory leaks they create). Looking at the docs for 2.3's weakref.ref, there's no mention of whether...
1
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion returns a pointer to a structure to its callback fucntion.The user should collect those...
0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: johny smith | last post by:
I cannot seem to figure out how to do instance based callbacks for some reason. I found one site on functors but I did not find it that helpful actually I just don't understand it. I have no...
5
by: Christopher Jastram | last post by:
I'm a self-taught programmer, so this might be a pretty dumb question. If it is, please point me in the right direction and I shall apologize profusely. I have a question regarding C++ and...
4
by: womanontheinside | last post by:
I have a library which was written in C, you call a function, it provides the result by a callback to specific function names. I am trying to wrap the calls to this inside a class, but this causes...
0
by: anilkoli | last post by:
I want clear cut idea about callbacks and also of delegates I have doughts about callbacks, I feel callbacks are used for 1. recursion 2. dynamically calling a perticular method out of many...
9
by: zholthran | last post by:
Hi folks, after reading several threads on this issue (-> subject) I fear that I got a problem that cannot easily be solved by the offered workarounds in an acceptable way, at least not with my...
13
by: noone | last post by:
consider the following problem: You have a C style library and API that uses callbacks to implement functionality. Examples of this are X11 API, OpenGL/GLUT...The List goes on. The power of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.