1

I need to compile some older c data acquisition code with a cpp compiler. I am running into trouble using signal( ).

Currently I have the following:

 signal(SIGINT, close_datalog);
 signal(SIGTERM, close_datalog);

With close_datalog() defined the following way:

void close_datalog()
{
   ..do stuff here

   exit(1);
}

I am encountering the following error when I try to compile the program using my makefile:

g++    -c -o xdatalog.o xdatalog.cpp
xdatalog.cpp: In function ‘int main(int, char**)’:
xdatalog.cpp:108:26: error: invalid conversion from ‘void (*)()’ to ‘__sighandler_t {aka void (*)(int)}’ [-fpermissive]

Any help would be greatly appreciated. I am fairly new to cpp.

1 Answers1

0

Judging by the error message, it would be sufficient to just change signature to

void close_datalog(int /*exit_code*/)
{
// ....
}

It wants function accepting int.

Ilya Kobelevskiy
  • 5,245
  • 4
  • 24
  • 41
  • Thank you! That seemed to work. This may be a silly question but why does this matter in cpp and not in c? – user3216648 Jan 20 '14 at 21:16
  • I'm not 100% sure, but it seems like casting void(*)() to void(*)(int) is not conforming to the standard, but is supported by some compilers - it might work in c++ too if you set a flag, take a look at http://stackoverflow.com/questions/8843818/what-does-the-fpermissive-flag-do – Ilya Kobelevskiy Jan 20 '14 at 21:28