16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
| //Test.c
#include <stdlib.h>
#include <stdio.h>
int Test1()
{
int i;
for (i=0; i<30; i++)
{
printf("The %d th charactor is: %c\n", i, (char)('a' + i%26));
}
return 0;
}
int Test2(int num)
{
int i;
for (i=0; i<num; i++)
{
printf("The %d th charactor is: %c\n", i, (char)('a' + i%26));
}
return 0;
}
void Caller1(void (*ptr)())//指向函數(shù)的指針作函數(shù)參數(shù)
{
(*ptr)();
do other something;
}
void Caller2(int n, int (*ptr)())//指向函數(shù)的指針作函數(shù)參數(shù),這里第一個(gè)參數(shù)是為指向函數(shù)的指針?lè)?wù)的,
{ //不能寫(xiě)成void Caller2(int (*ptr)(int n));這樣的定義語(yǔ)法錯(cuò)誤。
(*ptr)(n);
do other something;
return;
}
int main()
{
printf("************************\n");
Caller1(Test1); //相當(dāng)于調(diào)用Test2();
printf("&&&&&&************************\n");
Caller2(30, Test2); //相當(dāng)于調(diào)用Test2(30);
return 0;
}
異步調(diào)用更困惑了,資料上說(shuō)異步調(diào)用是一種類似消息或事件的機(jī)制,不過(guò)它的調(diào)用方向剛好相反,接口的服務(wù)在收到某種訊息或發(fā)生某種事件時(shí),會(huì)主動(dòng)通知客戶方(即調(diào)用客戶方的接口)。我的理解是被調(diào)用方反過(guò)來(lái)去通知調(diào)用方,具體怎么實(shí)現(xiàn)的呢
|