How to cause function having only its address???

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to cause function having only its address???

2,031 Views
admin
Specialist II
Greetings, prompt as it is possible to solve a following problem: it is necessary to cause function, but there is only its address. I write in C++ on CW4.7 for S12XDP. Thought it will be possible to use Assembler inserts, but at me nothing has left.
Labels (1)
0 Kudos
Reply
4 Replies

685 Views
CrasyCat
Specialist III
Hello
 
Not sure I understand the question here.
 
Are you looking for a way to call a function which reside at a specified address from a ANSI C function?
 
If this is what you are looking for you can use a constant function pointer to call the function.
 
Something as follows:  
   void (*const fktPtr)(void) = (void(*)(void))0x1234;
   void main(void) {
     fktPtr();
   }
 
This will call function located at address 0x1234.
 
CrasyCat
0 Kudos
Reply

685 Views
admin
Specialist II
Thanks for the help, I also had it in view of. I believed that for nonstatic function such design will not work. Thanks :smileywink:
0 Kudos
Reply

685 Views
Lundin
Senior Contributor IV
C++ will not allow you to convert the address of a non-static member function of a class to a function pointer. For such cases you have to use non-standard extensions to the language, such as inline assembler.

This is one of the reasons why C++ is less suitable than C for embedded systems.
0 Kudos
Reply

685 Views
admin
Specialist II
Hello Lundin.

Lundin wrote: C++ will not allow you to convert the address of a non-static member function of a class to a function pointer. For such cases you have to use non-standard extensions to the language, such as inline assembler.
Completely with you it agree, I on tried to use the assembler, but at me that it has not turned out...... Has not refused if somebody has helped me in the decision of the given problem....
0 Kudos
Reply