473,320 Members | 2,094 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,320 software developers and data experts.

Using C signal handler in my class

Ben
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?

Oct 19 '07 #1
7 4897
Ben wrote:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?
You've not read the FAQ before posting. Search for "callback" in
the FAQ, it should hopefully clear some stuff up.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 19 '07 #2
Ben
On Oct 20, 7:53 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Ben wrote:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?

You've not read the FAQ before posting. Search for "callback" in
the FAQ, it should hopefully clear some stuff up.

V
Thanks, V. Just wondering is there a direct link to the FAQ? I found
it using search.
Oct 19 '07 #3
On 2007-10-19 23:07, Ben wrote:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?
signal() expects a function pointer and not a member function pointer.
You can not have a member function as a callback for C functions, only
plain functions will work.

--
Erik Wikström
Oct 19 '07 #4
Erik Wikström wrote:
On 2007-10-19 23:07, Ben wrote:
>The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?

signal() expects a function pointer and not a member function pointer.
You can not have a member function as a callback for C functions, only
plain functions will work.
Plain functions with extern "C" linkage.

--
Ian Collins.
Oct 19 '07 #5
Ben
On Oct 20, 8:48 am, Ian Collins <ian-n...@hotmail.comwrote:
Erik Wikström wrote:
On 2007-10-19 23:07, Ben wrote:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?
signal() expects a function pointer and not a member function pointer.
You can not have a member function as a callback for C functions, only
plain functions will work.

Plain functions with extern "C" linkage.

--
Ian Collins.
Speaking of extern linkage, do I need to apply this to those c headers
like "unistd.h", "fcntl.h"?

Oct 20 '07 #6
On 2007-10-20 00:32, Ben wrote:
On Oct 20, 7:53 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>Ben wrote:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?

You've not read the FAQ before posting. Search for "callback" in
the FAQ, it should hopefully clear some stuff up.

V
Thanks, V. Just wondering is there a direct link to the FAQ? I found
it using search.
Normally the FAQ can be found at www.parashift.com but it seems to be
down at the moment, till it comes up again use the copy at
http://www.coders2020.com/cplusplus-...ned/index.html

--
Erik Wikström
Oct 20 '07 #7
Ben wrote:
On Oct 20, 8:48 am, Ian Collins <ian-n...@hotmail.comwrote:
>Erik Wikström wrote:
>>On 2007-10-19 23:07, Ben wrote:
The signal() is the one in signal.h (csignal), in my class I defined a
SIGALRM handler and then in my constructor I wrote signal(SIGALRM,
myHandler), but the compiler gave me the error:
error: argument of type 'void (myClass::)(int)' does not match 'void
(*)(int)'
Where have I done wrong?
signal() expects a function pointer and not a member function pointer.
You can not have a member function as a callback for C functions, only
plain functions will work.
Plain functions with extern "C" linkage.
*Please* don't quote signatures.
>
Speaking of extern linkage, do I need to apply this to those c headers
like "unistd.h", "fcntl.h"?
No, they will have their own C++ wrappers.

--
Ian Collins.
Oct 20 '07 #8

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

Similar topics

0
by: rh0dium | last post by:
Hi all, I don't understand the signal module. I guess I understand what it does in principle but I can't figure out how to use it to timeout an external rsh command after a 5 seconds. Does...
3
by: rh0dium | last post by:
Hi all, Another newbie question. So you can't use signals on threads but you can use select. The reason I want to do this in the first place it I need a timeout. Fundamentally I want to run a...
0
by: Jack Orenstein | last post by:
I'd like to create a program that invokes a function once a second, and terminates when the user types ctrl-c. So I created a signal handler, created a threading.Thread which does the invocation...
3
by: Martin McCormick | last post by:
A C program contains several signal statements to remove a lock file if the program gets killed: /*Set up interrupt handler to catch ctrl-C so that lock file can be removed.*/...
11
by: Jackie | last post by:
Hi everyone, I'd like to know when and how signals are used (e.g. SIGFPE, SIGABRT, SIGTERM, SIGSEGV, SIGINT)? Thank you so much.
4
by: san | last post by:
Greetings, I have a C++ problem. I am implementing a signal handler inside a class SignalClass. The code looks as follows: SignalClass is an Singleton class. class SignalClass { private:...
20
by: bubunia2000 | last post by:
Hi all, I heard that strtok is not thread safe. So I want to write a sample program which will tokenize string without using strtok. Can I get a sample source code for the same. For exp:...
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
5
by: david | last post by:
I'm developing a program that runs using an asyncore loop. Right now I can adequately terminate it using Control-C, but as things get refined I need a better way to stop it. I've developed...
3
by: pradeep | last post by:
Hello again friends: I'm now trying to get a signal handler to work. I have made the example code below to check I can make it work, but there is a compiler error, argument of type ‘void...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.