This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

void type

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);
}

Parents
  • [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.

Reply
  • [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.

Children