pointfunc1.c
来自「单片及c语言轻松入门的随书光盘」· C语言 代码 · 共 25 行
C
25 行
#pragma code symbols debug oe
#include <reg51.h> /* special function register declarations */
#include <stdio.h> /* prototype declarations for I/O functions */
void func1(int d) { /* function #1 */
printf("In FUNC1(%d)\n", d);
}
void func2(int i) { /* function #2 */
printf("In FUNC2(%d)\n", i);
}
void main(void) {
void (*f)(int i); /* Declaration of a function pointer */
/* that takes one integer arguments */
/* and returns nothing */
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xf3; /* TH1: reload value for 2400 baud */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
while( 1 ) {
f = (void *)func1; /* f points to function #1 */
f(1);
f = (void *)func2; /* f points to function #2 */
f(2);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?