This is the mail archive of the gcc@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]

Re: function pointer


Hi folks:

 I have a C program fragment as follows:

some_function()
{
 int   (*fp)(int a, int b);
       :
 fp=another_function;
 (*fp)(3,7); 
       :
}

another_function(a,b)
int a,b;
{


}

A fragment of the assembly translation of the above code is as follows:

     :
     :
  call  *%ebx;
     :

It seems that in the assembly translation the address of
another_function() is pushed into register %ebx first, and then a
indirect call(i.e. call *%ebx) is used to transfer control flow to
another_function(). Is this the standare way that gcc handles function
calls which are invoked through function pointer variable? I would like 
to
add some assembly instructions right before every this kind of indirect 
funciton call? (i.e. so every fucntion call invoked through function
pointer will be tranlated as follows:


          :
          :
 New added assembly code
 call  *%ebx
          :
          :

Does anyone know how to do this?




>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Are you doing a gcc port or do you want to include code
from your C program?
In the first case, you could use the define_expand of the
standard pattern names "call", "call_value" etc...
Take a look at http://gcc.gnu.org/onlinedocs/gcc_16.html#SEC189
In the second case ... you could add some __asm statements...

bye
Benedetto
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<



Besides, as you know the C source code will be translated into RTL form
first. Then the RTL form will be tranlated into assembly code and the
assembly code will be saved into a temporary file. After all the 
assembly
code is generated and saved into the temporary file, what function of 
the
gcc souce code is called to process the temporary assembly file? If I 
add
some assembly instructions into the temporary file right before it is
further processed, will this caused any problem?

 Any suggestion is highly appreciated, thanks .



                                V. H. 
  



___________________________________________________________
Attiva la tua Email gratuita al sito: http://www.infinito.it

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