How to cause function having only its address???

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

How to cause function having only its address???

2,030 次查看
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.
标签 (1)
0 项奖励
回复
4 回复数

684 次查看
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 项奖励
回复

684 次查看
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 项奖励
回复

684 次查看
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 项奖励
回复

684 次查看
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 项奖励
回复