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

function pointer


Hi:

 I have some questions about function pointers? Any suggestion is highly
appreciated. 


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 standard 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?


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.          


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