全部博文(92)
分类: 嵌入式
2010-06-15 20:56:44
通过指针数组来调用指针函数
首先定义一个由指针函数组成的指针数组:
void * nand_func[][2]=
{
(void *)Print_Id, "Read ID ",
(void *)Nand_Reset, "Nand reset ",
(void *)Test_Block_Erase, "Block erase ",
(void *)Test_Page_Read, "Page read ",
(void *)Test_Page_Write, "Page write ",
(void *)PrintBadBlockNum, "Check Badblock ",
0,
};
调用这个指针数组里的函数:
( (void (*)(void)) (nand_func[i][0]) )();
实现函数:
void Print_Id(void)
{
U16 id;
U8 maker, device;
id = ReadChipId();
device = (U8)id;
maker = (U8)(id>>8);
Uart_Printf("\nMaker:%x, Device:%x\n", maker, device);
}