Using C signal handler in my class

Discussion in 'C++' started by Ben, Oct 19, 2007.

  1. Ben

    Ben Guest

    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?
     
    Ben, Oct 19, 2007
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Oct 19, 2007
    #2
    1. Advertising

  3. Ben

    Ben Guest

    On Oct 20, 7:53 am, "Victor Bazarov" <> 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.
     
    Ben, Oct 19, 2007
    #3
  4. 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
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 19, 2007
    #4
  5. Ben

    Ian Collins Guest

    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.
     
    Ian Collins, Oct 19, 2007
    #5
  6. Ben

    Ben Guest

    On Oct 20, 8:48 am, Ian Collins <> 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"?
     
    Ben, Oct 20, 2007
    #6
  7. On 2007-10-20 00:32, Ben wrote:
    > On Oct 20, 7:53 am, "Victor Bazarov" <> 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-explained/index.html

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Oct 20, 2007
    #7
  8. Ben

    Ian Collins Guest

    Ben wrote:
    > On Oct 20, 8:48 am, Ian Collins <> 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.
     
    Ian Collins, Oct 20, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Pronath
    Replies:
    1
    Views:
    1,217
    Diez B. Roggisch
    Jan 3, 2005
  2. rh0dium
    Replies:
    0
    Views:
    391
    rh0dium
    Aug 22, 2005
  3. Bram Stolk
    Replies:
    2
    Views:
    399
    Bram Stolk
    Sep 13, 2005
  4. Jack Orenstein

    threading.Thread vs. signal.signal

    Jack Orenstein, Sep 18, 2005, in forum: Python
    Replies:
    0
    Views:
    491
    Jack Orenstein
    Sep 18, 2005
  5. Weng Tianxiang
    Replies:
    2
    Views:
    679
    Jonathan Bromley
    Jan 30, 2007
Loading...

Share This Page