Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

超怪的c function prototype....:-Q

0 views
Skip to first unread message

堅忍卓絕

unread,
Mar 15, 2000, 3:00:00 AM3/15/00
to
真的很奇怪,不管看幾次都看不太懂說...

int pthread_create(pthread_t * thread, pthread_attr_t *
attr, void * (*start_routine)(void *), void * arg);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

這到底是指什麼意思呢?

連用法都不只一種說...(如下)

第一種:

void print_message_function( void *ptr );
.
.
.
pthread_t thread1;
char *message1 = "Hello";
pthread_create( &thread1, pthread_attr_default,
(void*)&print_message_function, (void*) message1);

第二種:


void print_message_function( void *ptr );
.
.
.
pthread_t thread1;
char *message1 = "Hello";
pthread_create( &thread1, pthread_attr_default,
(void*)print_message_function, (void*) message1);


--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>

lgd

unread,
Mar 28, 2000, 3:00:00 AM3/28/00
to

"堅忍卓絕" <Leesu...@cis.nctu.edu.tw> wrote in message news:3ZPkRa$4...@bbs.cis
.nctu.edu.tw...

> 真的很奇怪,不管看幾次都看不太懂說...
>
> int pthread_create(pthread_t * thread, pthread_attr_t *
> attr, void * (*start_routine)(void *), void * arg);
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> 這到底是指什麼意思呢?
>
> 連用法都不只一種說...(如下)

傳名呼叫吧…很多C語言的書都有…
你標起來的那一段大概是說…
pthread_create會傳入一函數,此函數有一void指標的參數…而且會傳回一void指標…

…這個程式是在做什麼的呀?


Engel Cof.:95%.....

unread,
Mar 28, 2000, 3:00:00 AM3/28/00
to
==> 在 [Leesu...@cis.nctu.edu.tw] 文中提到:
: s_
: 來 源: ks42-152.dialup.seed.net.tw
: 真的很奇怪,不管看幾次都看不太懂說...

: int pthread_create(pthread_t * thread, pthread_attr_t *
: attr, void * (*start_routine)(void *), void * arg);
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
start_routine是一個函式指標 他可以用來指向 引入參數為void *且

傳回型態為void *的函數 .也就是說 用這樣的方式來呼叫 pthread_create:

int_number=pthread_create(參數一,參數二,ld(參數三),參數四);

其中ld()需為先宣告為一void*(*ld)(void*)並初始化指向一型態相同的函數

或者也可以寫成pthread_create(參數一,參數二,void*(*ld)(void*)=cl(參數三),

參數四);

其中 要先宣告 void *cl(void*);

ps:呼叫中的ld(參數三)也可以寫成(*ld)(參數三)
--
歡迎大家鬥陣來飲茶...
Ξ Origin: 中興大學天樞資訊網 <b...@bbs.nchu.edu.tw> [FROM: sysnux.ev.nchu.]

0 new messages