cancel
Showing results for 
Search instead for 
Did you mean: 

Bug with array of pointers to functions in Cosmic V4.5.5?

davids
Associate II
Posted on July 26, 2007 at 04:24

Bug with array of pointers to functions in Cosmic V4.5.5?

3 REPLIES 3
davids
Associate II
Posted on July 23, 2007 at 02:27

I think I may have found a bug in the Cosmic compiler V4.5.5. This indirect call with one parameter compiles perfectly:

*******************************

int FunctionOne(unsigned int x)

{

}

void main(void)

{

int FunctionOne(unsigned int);

const int (*jumpTable[])(unsigned int) =

{

&FunctionOne

};

jumpTable[0](1);

}

*******************************

But, when you add another parameter, the compiler says ''invalid indirect call'':

*******************************

int FunctionTwo(unsigned int x, unsigned int y)

{

}

void main(void)

{

int FunctionTwo(unsigned int, unsigned int);

const int (*jumpTable[])(unsigned int, unsigned int) =

{

&FunctionTwo

};

jumpTable[0](1, 2);

}

*******************************

Am I doing something wrong?

-David

luca239955_st
Associate III
Posted on July 24, 2007 at 06:33

Hello,

static memory models and functions called by pointer do not work well together: if you limit the arguments at 2 bytes it will still do because the arguments are passed in registers, but if you need more you must declare the called function @stack (or use a non static memory model).

Regards,

Luca (Cosmic)

davids
Associate II
Posted on July 26, 2007 at 04:24

Thank you!