How to cause function having only its address???

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to cause function having only its address???

2,029件の閲覧回数
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 返答(返信)

683件の閲覧回数
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 件の賞賛
返信

683件の閲覧回数
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 件の賞賛
返信

683件の閲覧回数
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 件の賞賛
返信

683件の閲覧回数
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 件の賞賛
返信