03 |
typedef unsigned short UNSIGNED16; |
04 |
typedef unsigned char UNSIGNED8; |
05 |
typedef UNSIGNED16 (*DEMO_CYCLE)( void ); |
07 |
static UNSIGNED16 lp_demo( void ); |
08 |
static UNSIGNED16 ap_demo( void ); |
09 |
static UNSIGNED16 md_demo( void ); |
10 |
static UNSIGNED16 mixed_demo( void ); |
12 |
DEMO_CYCLE p_demo_cycle = NULL; |
13 |
DEMO_CYCLE p_demo_cycle_group[4] = {lp_demo, ap_demo, md_demo, mixed_demo}; |
16 |
static UNSIGNED16 lp_demo( void ) |
18 |
printf ( "lp_demo執行這裏\n" ); |
21 |
static UNSIGNED16 ap_demo( void ) |
23 |
printf ( "ap_demo執行這裏\n" ); |
26 |
static UNSIGNED16 md_demo( void ) |
28 |
printf ( "md_demo執行這裏\n" ); |
31 |
static UNSIGNED16 mixed_demo( void ) |
33 |
printf ( "mixed_demo執行這裏\n" ); |
37 |
int main( int argc, char *argv[]) |
39 |
UNSIGNED16 result = 0; |
40 |
printf ( "%d\n" ,demo_type); |
42 |
p_demo_cycle = p_demo_cycle_group[demo_type]; |
44 |
result = (*p_demo_cycle)(); |
#include <stdio.h>
typedef unsigned short UNSIGNED16;
typedef unsigned char UNSIGNED8;
typedef UNSIGNED16 (*DEMO_CYCLE)(void);
static UNSIGNED16 lp_demo(void);
static UNSIGNED16 ap_demo(void);
static UNSIGNED16 md_demo(void);
static UNSIGNED16 mixed_demo(void);
DEMO_CYCLE p_demo_cycle = NULL;
DEMO_CYCLE p_demo_cycle_group[4] = {lp_demo, ap_demo, md_demo, mixed_demo};
UNSIGNED8 demo_type;
static UNSIGNED16 lp_demo(void)
{
printf("lp_demo執行這裏\n");
return 0;
}
static UNSIGNED16 ap_demo(void)
{
printf("ap_demo執行這裏\n");
return 0;
}
static UNSIGNED16 md_demo(void)
{
printf("md_demo執行這裏\n");
return 0;
}
static UNSIGNED16 mixed_demo(void)
{
printf("mixed_demo執行這裏\n");
return 0;
}
int main(int argc, char *argv[])
{
UNSIGNED16 result = 0;
printf("%d\n",demo_type);
//獲取函數地址
p_demo_cycle = p_demo_cycle_group[demo_type];
//利用函數地址調用函數
result = (*p_demo_cycle)();
return 0;
}
函數名字符串指針:利用函數地址調用函數.同時利用數組的形式.以更加方便的形式進行操做