Warning pictures on cigarette packs have helped smokers kick the ________ and prevented others
from becoming addicted.[ ]
A. manner
B. custom
C. leisure
D. habit
答案:D
Warning pictures on cigarette packs have helped smokers kick the ________ and prevented others
from becoming addicted.[ ]
A. manner
B. custom
C. leisure
D. habit
答案:D
阅读以下说明和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)
{
/*局部变量声明,略*/
/*驱动程序代码,略*/
【问题1】 请用C语言的函数指针变量,对manage_device函数进行改造,完成下面C语言代码中的(1)、(2)、(3)和(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, iht arg2); extern int Dev_drv3(int arg1, int arg2); extern int Dev_drv4(int arg1, int arg2); #define NOERROR 0 typedef struct { int _fd; (1) 函数指针变量说明;/* 变量名用process */ } TYP_DEV_TAB; TYP_DEV_TAB dev_tab[50]= {{101, Dev_drv1},{99, Dev_drv2}, {80, Dev_drv3},{120, Dev_dry4},}; /* 程序 */ void manage_device(int devid, int arg1, int arg2) { iht place ; int ret; (2) 函数指针变量说明;/*局部变量,变量名用ProcAction */ for(place=0 ; place<50 ; place++) { if(dev_tab [place]._fd == devid) { (3) 语句1;/* 变量名胜ProcAction, 得到具体函数的入口地址 */ break; } } if(place>=50) printf("NO DEVICE fd = %d\n",devid); (4) 语句2; if(ret!=NOERROR) printf("DEVICE %d error!", devid); } |