Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Jump from variable -> define variable as function

2006-02-23 by Jean-Rene David

* Marko Pavlin <mp@...>:
> >  How can I call function where address is in
> >  pointer? Something like this:
> >
> > void test1(void){
> >    puts("blah");
> > }
> >
> >
> > void *exec;
> >
> > void main(void) {
> >     exec = (void *)test1;
> >     __asm
> >     {
> >           BL             exec
> >     }

You need to declare exec as a function pointer.
Then you can assign it the address of any function
with the same prototype and call it like any other
function:

void test1(void){
   puts("blah");
}

void (*exec)(void); // Declare as function pointer.

void main(void) {
    exec = test1;
    exec();
}

* Jim Parziale <nuncio.bitis@...>:
> After setting:
>     exec = (void *)test1;
> Just call via exec:
>      exec();
> 

exec must be declared as a function pointer,
otherwise the compiler won't know how to set up
the parameters and pick up the return value for
the function (even if there are none in this
case.)

-- 
JR

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.