(e-mail address removed) (Dan Pop) writes:
|> In <
[email protected]> "Martin Johansen"
|> >take the function:
|> >char f(){
|> > return(-1);
|> >}
|> >f is the function pointer, i know how it is used to call a function.
|> >But, what exactly does the pointer point to?
|> It provides the necessary information for calling that function.
|> When this information doesn't fit into a pointer, it points to a
|> place containig this information.
Since the implementation decides just how big a function pointer is, it
can always make it big enough for whatever information is necessary.
|> For example, on the IA64 architecture, two 64-bit addresses are
|> needed for this purpose and a function pointer actually points to a
|> function descriptor that contains these addresses. So, it takes a
|> double indirection to dereference a function pointer on that
|> platform.
A much simpler solution would simply be to make a function pointer twice
as big.
I suspect here that the reason has nothing to do with C, but with the
broken interface which Posix imposes on dlsym (and maybe other
functions).
|> >Where is the return value stored?
|> That's entirely irrelevant to function pointers. Return values are
|> typically stored in registers, these days.
More often, it depends on the type being returned. Different types can
be, and usually are, returned in different ways.
|> >Is it possible to get the code segment address, data segment
|> >address or the size of the whole function in memory?
|> On common implementations, function pointers store the function's
|> entry address in the text segment.
On a lot of implementations, segments are just an artifice of the
compiler/loader anyway. At the hardware level, either there is no such
thing as a segment, or the OS and compiler work together to make it seem
that way (even when it means artificially limiting the capacities of the
processor, as is the case with IA-32 architectures). Actual addressing
is linear, so code segment address and data segment address have no real
meaning.
|> The function itself "knows" the addresses of the objects it has to
|> manipulate. However, there are exceptions from this simple and
|> common model, AS/400 being even more exotic than IA64: function
|> pointers are 768-bit (or so) entities on this platform.