We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I want to know that supply void type in keil c51 REV 7.XX following is program #include <reg52.h> #include <stdio.h> #define NUMBER 2 typedef struct Test { void (*FuncP)(void *); void *Farg; } Test; int max(int a[NUMBER]) { int z; if (a[0]>a[1]) z=a[0]; else z=a[1]; return(z); } main() { int a[NUMBER]={1,2}; void i; Test *TmrTest; TmrTest->FuncP=(void *)max; TmrTest->Farg=(void *)&a[0]; i=(*TmrTest->FuncP)(TmrTest->Farg); } error infomation: error c136: 'i': 'void' on variable error c186: invalid dereference or #include <reg52.h> #include <stdio.h> #define NUMBER 2 typedef struct Test { void (*FuncP)(void *); void *Farg; } Test; int max(int a[NUMBER]) { int z; if (a[0]>a[1]) z=a[0]; else z=a[1]; return(z); } main() { int a[NUMBER]={1,2}; int i; Test *TmrTest; TmrTest->FuncP=(void *)max; TmrTest->Farg=(void *)&a[0]; i=(int *)(*TmrTest->FuncP)(TmrTest->Farg); } error infomation: error c215:illegal type conversion ,follow is OK, functin max isn't ..... #include <reg52.h> #include <stdio.h> #define NUMBER 2 typedef struct Test { void (*FuncP)(void *); void *Farg; } Test; int max(int a[NUMBER]) { int z; if (a[0]>a[1]) z=a[0]; else z=a[1]; return(z); } main() { int a[NUMBER]={1,2}; Test *TmrTest; TmrTest->FuncP=(void *)max; TmrTest->Farg=(void *)&a[0]; (*TmrTest->FuncP)(TmrTest->Farg); }
void itself is not a valid data type in ANSI C. However, you can define a void *i, that defines a pointer to an unspecified object.
[What exactly are you hoping to achieve by posting the same question three times in a row?] error c136: 'i': 'void' on variable That message is absolutely correct. Your program is buggy. A variable cannot have type 'nothing', i.e. void. error c215:illegal type conversion You omitted to point out the precise place in the source you got this error for. But your code assigns a void (the "result" of calling through that function pointer) to an int. That's nonsensical.
"[What exactly are you hoping to achieve by posting the same question three times in a row?]" That could well be a fault with the Forum, rather than the poster; Keil Support themselves have been known to repeat the same reply up to about 7 times!!! :-0