This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
function pointer
- To: gcc at gcc dot gnu dot org
- Subject: function pointer
- From: Fu-hau Hsu <fhsu at ic dot sunysb dot edu>
- Date: Sun, 15 Oct 2000 22:04:10 -0400 (EDT)
- cc: fhsu at ic dot sunysb dot edu
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?
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.