I have written a program that i compiled and ran under Linux. It worked correctly. I was then forced to port it to QNX.
I did and when i tried to compile it there (qnx with momentics) I got a cryptic error:
timer_t * timer = malloc(sizeof(timer_t)); <---- invalid conversion from 'void*' to 'timer_t*'
here i get another error of a (i guess) similar type:
static void signalor(int sig, siginfo_t *si, void *uc)
timer_t *tidptr;
tidptr = si->si_value.sival_ptr;<----- invalid conversion from 'void*' to 'timer_t*'
Does anyone know why i get this error? Or how to fix it?
thanks in advance.
Credits go to @rici as he answered ages ago but in order to move this to closure, the following code resolves the issue:
#include <malloc.h>
#include <time.h>
#include <signal.h>
int main() {
timer_t * timer = (timer_t*)malloc(sizeof(timer_t));
siginfo_t si = {0};
timer_t *tidptr;
tidptr = (timer_t*)si.si_value.sival_ptr;
return 0;
}
bash-3.2$ ntoarmv7-g++ tst.c -Wall
tst.c: In function 'int main()':
tst.c:7: warning: unused variable 'timer'
bash-3.2$
The issue is as explained by both the compiler and rici above: c++ does not permit assigning pointers of incompatible type. The original code would build happily with gcc (instead of g++).