Signal Processing in C ++

Type argument is void (*)(int)not compatible with type parameter__sighnd64_t

Below is my simple code:

#include <iostream>
#include <string>
#include <signal.h>
#include <ctype>
#include <stdlib.h>
#include <stdio.h>
typedef struct mystrcut
{

  int a;
  char *b;

} mystr;

void set_string ( char **, const char * );
void my_handler(int s)
{
    printf("Caught signal %d\n",s);
    exit(1);

}

int main()
{
    const std::string str1[] = {"hello1", "hello2"};
    char str2[50];
    size_t size1 = str1[1].size();
    cout << size1;
    memcpy (str2, str1[1].c_str(), size1);

    cout << str2;
    mystr *m = NULL;
    m = new mystrcut;
    m->a = 5;

    set_string(&m->b, "hello");

    cout << m->b;
    delete []m->b;
//    void (*prev_fn)(int);
    signal (SIGINT,my_handler);
    return 0;
}
void set_string ( char **a, const char *b)
{
    *a = new char [strlen(b)+1];
    strcpy (*a, b);
}

I am working on openvms. Can I avoid a compilation error by some type of casting? My compiler expects `__sighnd64_t __64_signal (int, __sighnd64_t);

Work on the extern c handler worked. Thanks

+5
source share
1 answer

Signal processing is not C ++, but C. This error is a bit strange ...

extern "C" ( C), https://stackoverflow.com/users/775806/n-m . <signal.h> openvms extern "C" : http://wasd.vsm.com.au/conan/sys$common/syslib/decc$rtldef.tlb?key=SIGNAL&title=Library%20/sys$common/syslib/decc$rtldef.tlb&referer=http%3A/wasd.vsm.com.au/conan/sys$common/syshlp/helplib.hlb.

HP docs C, ++.

, () C

 void func(int signo);
+3

All Articles