Using C signal handler in my class - c++

This is a discussion on Using C signal handler in my class - c++ ; 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 ...

+ Reply to Thread
Results 1 to 9 of 9

Using C signal handler in my class

  1. Default Using C signal handler in my class

    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?


  2. Default Re: Using C signal handler in my class

    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



  3. Default Re: Using C signal handler in my class

    On Oct 20, 7:53 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
    > 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.



  4. Default Re: Using C signal handler in my class

    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

  5. Default Re: Using C signal handler in my class

    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.

  6. Default Re: Using C signal handler in my class

    On Oct 20, 8:48 am, Ian Collins <ian-n...@hotmail.com> wrote:
    > 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"?


  7. Default Re: Using C signal handler in my class

    On 2007-10-20 00:32, Ben wrote:
    > On Oct 20, 7:53 am, "Victor Bazarov" <v.Abaza...@comAcast.net> wrote:
    >> 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

  8. Default Re: Using C signal handler in my class

    Ben wrote:
    > On Oct 20, 8:48 am, Ian Collins <ian-n...@hotmail.com> wrote:
    >> 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.

  9. Default Re: Using C signal handler in my class

    Hi people! I have the same problem, but I haven't solved it. First of all, I want to say that before writing here I was searching for the solutions, I have read the C++ FAQ and so on, but I still haven't solved it.

    I always get the fallowing failure:

    error: argument of type ‘void (WATCHDOG:()’ does not match ‘void (*)(int)’

    Here is the text of the program (before trying to edit it so as it can work)


    void
    WATCHDOG::cleanup() {
    /* Show obtained data */
    if (debug > 0) {
    nei->ShowAllNeighbours(&neigs);
    }
    printf("\n\tFinishing watchdog...\t\tok!\n\n");
    ShowStatistics();
    close(sock);
    nei->DeleteAllNeighbours(&neigs);
    if (printPercentage) {
    fclose(statistics);
    }
    exit(0);

    }

    void
    WATCHDOG::setSignals() {
    signal(SIGHUP, SIG_IGN);
    signal(SIGINT, Cleanup);
    signal(SIGTERM, Cleanup);
    signal(SIGKILL, Cleanup);
    signal(SIGQUIT, Cleanup);
    }


    This was the first variant of the code. After I got 4 errors in the last 4 lines I was trying to look for the solution. And accoeding to this: http://www.parashift.com/c++-faq-lit...o-members.html I thought I found it. Here is the modification:


    void
    WATCHDOG::cleanup() {
    /* Show obtained data */
    if (debug > 0) {
    nei->ShowAllNeighbours(&neigs);
    }
    printf("\n\tFinishing watchdog...\t\tok!\n\n");
    ShowStatistics();
    close(sock);
    nei->DeleteAllNeighbours(&neigs);
    if (printPercentage) {
    fclose(statistics);
    }
    exit(0);

    }

    void
    WATCHDOG::Watchdog_memberFn_wrapper() {
    object_which_will_handle_the_signal->cleanup();
    }


    void
    WATCHDOG::setSignals() {
    signal(SIGHUP, SIG_IGN);
    signal(SIGINT, Watchdog_memberFn_wrapper);
    signal(SIGTERM, Watchdog_memberFn_wrapper);
    signal(SIGKILL, Watchdog_memberFn_wrapper);
    signal(SIGQUIT, Watchdog_memberFn_wrapper);
    }


    But it still doesn't work. Please if there is anyone that can help me, help, cause I really don't know what to do.
    What's more, I have this program written on C, and it works, but I know that signal.h works a little bit different in C++.

    Thank you.

+ Reply to Thread

Similar Threads

  1. signal handler question
    By Application Development in forum C
    Replies: 11
    Last Post: 11-21-2007, 09:57 PM
  2. Event handler not responding on new instance of class
    By Application Development in forum DOTNET
    Replies: 6
    Last Post: 09-25-2007, 03:41 PM
  3. decorator and signal handler
    By Application Development in forum Python
    Replies: 1
    Last Post: 09-05-2007, 05:33 AM
  4. signal HANDLER in perl
    By Application Development in forum Perl
    Replies: 3
    Last Post: 04-27-2007, 01:39 PM
  5. FindClass cannot locate a class from a signal handler from C
    By Application Development in forum Java
    Replies: 0
    Last Post: 03-01-2004, 09:33 AM