Discussion Forum

Error in Two long variable Passing in Funciton to Pointer

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Niraj Patel
Posted
6-Jan-2006 12:27 GMT
Toolset
C51
New! Error in Two long variable Passing in Funciton to Pointer
Hi,
I am using Function to Pointer. i have definded this functin poiter in one structure with two long variable argument.
it is giving me error below.

Error C212: indirect call: parameters do not fit within registers.

though it is given in c51.pdf that it will pass funciton argument with two long variable, i face this error.

expecting solution as soon as possible

code is like this

typedef struct
{
unsigned long var1;
unsigned long var2;
void (*funptr) (unsigned long var1,unsigned long var2);

}test;

void main()
{

struct test *pt,t;

t.vars1 = 6550;
t.vars2 = 6551;
t.funptr = TESTING;
// where TESTING is fucntion definition macro

pt->funptr(pt->var1,pt->var2);
// here i get error listed above
}

thanks
niraj
Read-Only
Author
Andy Neil
Posted
6-Jan-2006 14:11 GMT
Toolset
C51
New! Could've found with just a 'Search'...
"I am using Function to Pointer"

Due to the nature of the 8051 architecture, C51 has some limitations using function pointers.
You need to read the following very carefully:

http://www.keil.com/appnotes/docs/apnt_129.asp
http://www.keil.com/support/docs/2066.htm

http://www.keil.com/support/docs/210.htm
http://www.keil.com/support/docs/806.htm
Read-Only
Author
Hongbing Shen
Posted
8-Jan-2006 07:15 GMT
Toolset
C51
New! RE: Error in Two long variable Passing in Funciton to Pointer
Try this:

typedef struct
{
unsigned long var1;
unsigned long var2;
void (*funptr) (unsigned long xdata* var1,unsigned long xdata* var2);

}test;

void TESTING(unsigned long xdata * var1,unsigned long xdata * var2)
{
unsigned long tmp;
tmp=*var1;
*var1=*var2;
*var2=tmp;
}

void main()
{

xdata test t;

t.var1 = 6550;
t.var2 = 6551;
t.funptr = TESTING;

t.funptr(&t.var1,&t.var2);
}
Read-Only
Author
Dharmesh Shah
Posted
12-Jan-2006 04:04 GMT
Toolset
C51
New! RE: Error in Two long variable Passing in Funciton to Pointer
Hi dear Dharmesh
you solution is working nice for keil

again one another solution i found is
to pass structure pointer in that pointer to function.

so that i can use my code for keil and another compiler also like VC++


typedef struct
{
unsigned long aa;
unsigned long bb;
void (*funptr) (test *ts);

}test;

void TESTING(test *ts)
{
unsigned long var1,var2;
unsigned long tmp;

var1 = ts->aa;
var2 = ts->bb;

tmp=var1;
var1=var2;
var2=tmp;
}

void main()
{

test t;

t.aa = 6550;
t.bb = 6551;
t.funptr = TESTING;

t.funptr(&t);
}

Next Thread | Thread List | Previous Thread Start a Thread | Settings