error: invalid conversion from ‘void (*)()’ to ‘void (*)(int)’
2015-05-24 20:29
393 查看
void signaldemo_test(void) { struct itimerval tv, otv; signal(SIGALRM, sigFunc);
//how long to run the first time tv.it_value.tv_sec = 3; tv.it_value.tv_usec = 0;
//after the first time, how long to run next time tv.it_interval.tv_sec = 5; tv.it_interval.tv_usec = 0;
if (setitimer(ITIMER_REAL, &tv, &otv) != 0) //定时每隔5s执行一次 { printf("setitimer err %d\n", errno); }
while(1) { sleep(2);
//隔2s打印一遍 printf("otv: %d, %d, %d, %d\n", otv.it_value.tv_sec, otv.it_value.tv_usec, otv.it_interval.tv_sec, otv.it_interval.tv_sec); } }
void sigFunc() { static int iCnt = 0; printf("The %d Times: my girl maybe in SZ library \n", iCnt++);}
} 以上这段代码在用g++编译是会有如下错误: /mnt/hgfs/Linux/cleanCup/src/signaldemo.cpp:9: error: invalid conversion from ‘void (*)()’ to ‘void (*)(int)’ /mnt/hgfs/Linux/cleanCup/src/signaldemo.cpp:9: error: initializing argument 2 of ‘void (* signal(int, void (*)(int)))(int)’ 值得注意的是在gcc编译时不会出错,但是用g++就会有问题,究其原因就是C语言编译器允许隐含性的将一个通用指针转换为任意类型的指针,而C++不允许。
void sigFunc(int) { static int iCnt = 0; printf("The %d Times: my girl maybe in SZ library \n", iCnt++);}
}
相关文章推荐
- ip_tables.h:217: error:invalid conversion from 'void*' to 'xt_entry_target*'
- c++创建线程的常见问题:error: invalid conversion from 'void*' to 'void* (*)(void*)'
- x86_64 xercexc: error: cast from 'const void*' to 'long int' loses precision [-fpermissive]
- 解决“invalid conversion from void* to char*”和“deprecated conversion from string constant to 'char*' "
- 使用dlsym时出现invalid conversion from void* to
- invalid conversion from ‘void*’ to ‘void* (*)
- 一个建立线程时常见的问题:invalid conversion from `void*' to `void*(*)(void*)
- 一个建立线程时常见的问题:invalid conversion from `void*' to `void*(*)(void*)
- 【Linux开发技术之常见问题】一个建立线程时常见的问题:invalid conversion from `void*' to `void*(*)(void*)
- 一个建立线程时常见的问题:invalid conversion from `void*' to `void*(*)(void*)
- gcc编译错误(invalid conversion from 'int' to enum)
- invalid conversion from 'void* (*)()' to 'void* (*)(void*)'
- LinkIssue: Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or co
- paip.invalid conversion from FormWdg* to SOCKET {aka unsigned int}
- 关于vs2010 error: LNK1123: failure during conversion to COFF: file invalid or corrupt 错误的解决...
- error C2664: 'cvSetMouseCallback' : cannot convert parameter 2 from 'void (__cdecl *)(int,int,int,int)' to 'CvMouseCallback' 的解决
- 【error】LINK1123: failure during conversion to COFF: file invalid or corrupt
- 原创血泪教训【error】LINK1123: failure during conversion to COFF: file invalid or corrupt
- malloc: *** error for object 0x6080000bd200: Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug
- LinkIssue: Error 'LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or cor