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)())//指向函数的指针作函数参数
{
(*ptr)();
do other something;
}
void Caller2(int n, int (*ptr)())//指向函数的指针作函数参数,这里第一个参数是为指向函数的指针服务的,
{ //不能写成void Caller2(int (*ptr)(int n));这样的定义语法错误。
(*ptr)(n);
do other something;
return;
}
int main()
{
printf("************************\n");
Caller1(Test1); //相当于调用Test2();
printf("&&&&&&************************\n");
Caller2(30, Test2); //相当于调用Test2(30);
return 0;
}
异步调用更困惑了,资料上说异步调用是一种类似消息或事件的机制,不过它的调用方向刚好相反,接口的服务在收到某种讯息或发生某种事件时,会主动通知客户方(即调用客户方的接口)。我的理解是被调用方反过来去通知调用方,具体怎么实现的呢
|