阅读以下说明和C语言代码,回答问题1至问题4,将解答填入对应栏内。
【说明】
在嵌入式操作系统设备管理的实现上,常使用到C语言的函数指针变量,由统一的管理函数调用不同的设备驱动程序。下面的一段C语言代码是驱动管理程序 manage_device调用4个不同设备驱动程序,但没有用到函数指针变量。
【C语言代码】
/*变量与类型说明*/
#include "stdio.h"
#include "stdlib.h"
extern int sys_status;
extern int Dev_drv1(int arg1, int arg2);
extern int Dev_drv2(int arg1, int arg2);
extern int Dev_drv3(int arg1, int arg2);
extern int Dev_drv4(int arg1, iht arg2);
#define NOERROR 0
type struct {
int _fd;
} TYP_DEV_TAB;
TYP DEV_TAB dev_tab[50]= {101,99, 80, 120,};
/*程序代码*/
void manage_device(int devid, int arg1, int arg2)
{ int place ;
int ret;
for(place=0 ; place<50 ; place++)
if dev_tab [place]. fd == devid) break;
if(place>=50)
printf(" NO DEVICE fd = %d\n ",devid);
switch(dev_tab [place]._fd) {
case 80:
ret = Dev_drv3(int arg1,int arg2);
break;
case 99:
ret = Dev_drv2(int arg1,int arg2);
break;
case 101:
ret = Dev_drv1(int arg1,int arg2);
break;
case 120:
ret = Dev_drv4(int arg1,int arg2);
break;
}
if (ret!=NOERROR)
printf(" DEVICE %d error!\n ", devid);
}
int Dev_drv1(int arg1,int arg2)
{
/*局部变量声明,略*/
/*驱动程序代码,略*/
}
int Dev_drv2(int arg1,int arg2)
{
/*局部变量声明,略*/
/*驱动程序代码,略*/
}
int Dev_drv3(int arg1,int arg2)
{
/*局部变量声明,略*/
/*驱动程序代码,略*/
}
int Dev_drv4(int arg1,int arg2)
{
/*局部变量声明,略*/
/*驱动程序代码,略*/