This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

how to code global indirect branches ?


Hey all,

My goal is to pass a function pointer to a function, and then do the
operation that is pointed to by the function pointer, like the following:
======in kernel.cpp===========

void show()
{
   cout<<"a piece of mystery";
}
=======in wrapper.cpp=========
typedef void (*fpr)();
wrapper(fpr kernel)
{
  (*kernel)(); 
  Check_error();
}

Main()
{
   ...
   fpr kernel = show;
   wrapper(kernel);
   ...
}
=================================
Now, I need to achieve the same goal without using function calls(and
therefore no function pointers). So, I am thinking about indirect jumps. I
tend to define a unique code label within each kernel operator, and then I
can pass the indirect jump's target address to the mymain function, which
can then jump to the right instruction. But I don't know how to do it. It
can be something like the following:

============in kernel.cpp============
void show()
{
LABEL_SHOW:
   cout<<"a piece of mystery";
   goto END_MAIN;
}

=======in wrapper.cpp=========
wrapper(unsigned long  target_address)
{
  goto target_address;
END_MAIN:
  Check_error();
}

Main()
{
   ...
   unsigned long target_address = LEBEL_SHOW;
   wrapper(target_address);
   ...
}
=================================
Can anyone help me? I appreciate it a lot!

Thanks!

Jiayuan






Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]