作者eeturtur (The End)
看板EE_DSnP
标题Re: [问题] 请问compile c跟c++的问题
时间Wed Nov 29 21:04:10 2006
※ 引述《ijb ()》之铭言:
: 最近写作业, 还到某个c跟c++的问题
: 希望有高手帮忙我解答
我不是高手 只是闲闲没事上网帮忙查了一下^^""
: source code:
: http://narcissus.ee.ntu.edu.tw/~yufu/emos_yufu.c
: http://narcissus.ee.ntu.edu.tw/~yufu/emos_yufu.cpp
: 其中,emos_yufu.c用
: gcc emos_yufu.c -lncurses -lpthread -o hw --> ok,没任何错误
: emos_yufu.cpp用
: g++ emos_yufu.cpp -lncurses -lpthread -o hw --> fail,错误讯息如下:
: emos_yufu.cpp: In function 'int main()':
: emos_yufu.cpp:32: error: invalid conversion from 'void* (*)()' to 'void* (*)(void*)'
: emos_yufu.cpp:32: error: initializing argument 3 of 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)'
我查到 pthread_create(&ThreadA,NULL,task1,NULL);的用法
其中ThreadA是一个pthread_t的变数 和你用的一样
而传入的第二和第四个参数也和你一样都是传入NULL
但task1的function protype是长这样 void *task1(void *)
我视过如果将你的void *A_Thread_Queue(); 改成 ==> void *A_Thread_Queue(void* i);
就可以work了
所以我想你的error应该是你传入的东西和它定义的不同吧
我参考的网页如下
http://www.phptr.com/articles/article.asp?p=169479&seqNum=7&rl=1
: emos_yufu.cpp:37: error: invalid conversion from 'void*' to 'void* (*)(void*)'
: emos_yufu.cpp:37: error: initializing argument 3 of 'int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)'
这个和前一段的问题是一样的
: emos_yufu.cpp:48: error: void value not ignored as it ought to be
我查了在struct sigaction中的 sighanlder_t 有以下这样的叙述
sa_hanlder 保存函数的地址,该函数带一个整型参数,没有返回值。
它还可以是两个特别值之一:SIG_DFL 和 SIG_IGN。
然後void func_name(int)就是一个不回传值的function
当然就不能把它的结果assign给另一个变数吧??
这是我查到的网页
http://www.vckbase.com/document/viewdoc/?id=1363
希望没有帮错忙^^||
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.4.242