#include <stdio.h> #include <at89x52.h>
static void Exchange1(int *first,int *second); static void Process(int *m,int *n,void (*fun)(int,int)); static void PORT_UartInit(void);
static void Exchange1(int *first,int *second) { int temp; temp=*first; *first=*second; *second=temp; }
static void Process(int *m,int *n,void (*fun)(int,int)) { (*fun)(m,n);//此句有编译时候有警告 }
static void PORT_UartInit(void) { SCON = 0x50; TMOD |= 0x20; PCON |= 0x80; TH1 = 0xff; TL1 = 0xff; TR1 = 1; TI = 1; ES = 0; }
int main() { int a=20,b=80; int *pt1,*pt2; void (*temp)(); temp=Exchange1; PORT_UartInit(); while(1) { pt1=&a; pt2=&b; printf("num1=%d,num2=%d\n",*pt1,*pt2); Process(pt1,pt2,temp); printf("num1=%d,num2=%d\n",*pt1,*pt2); } }
keil编译时候的警告: POINTER FUNCTION.C(18): warning C214: 'Argument': conversion: pointer to non-pointer
我的疑惑: 程序有什么问题,出错在哪?
如果在WIN-TC 1.91中就可以顺利运行,难道keil对指针函数不支持?
#include <stdio.h>
static void Exchange1(int *first,int *second); static void Process(int *m,int *n,void (*fun)(int,int)); static void PORT_UartInit(void);
static void Exchange1(int *first,int *second) { int temp; temp=*first; *first=*second; *second=temp; }
static void Process(int *m,int *n,void (*fun)()) { (*fun)(m,n); }
int main() { int a=20,b=80; int *pt1,*pt2; void (*temp)(); temp=Exchange1; while(1) { pt1=&a; pt2=&b; printf("num1=%d,num2=%d\n",*pt1,*pt2); Process(pt1,pt2,temp); printf("num1=%d,num2=%d\n",*pt1,*pt2); } }
|