Size of a function

Tom Stockfisch tps at sdchem.UUCP
Sun Jan 4 17:30:25 AEST 1987


In article <2100 at brl-adm.ARPA> LINNDR%VUENGVAX.BITNET at wiscvm.wisc.edu writes:
>        To the best of my knowledge, there is no way currently defined in
>C to get the size of a function, in any units. My immediate interest is
>in telling what function an address belongs during run-time. The only
>solutions I know of involve an intimate knowledge of the relocatable file
>(esp. the symtab) format. Is there a good way to determine this value?
>
>It might be nice if sizeof(function_name) could be defined to return this
>value.

The trouble is that any such scheme will not be implementable on a machine
with a segmented architecture.  On such a machine, different functions might
not belong to the same address space, and thus pointers into each of them
could not be meaningfully compared.  

If you have gotten an address that points somewhere in the *middle* of a
function then you must have gotten it outside the confines of C (you
can't apply "++" to a function pointer).  You have no hope of doing this
portably.

If you want to know to which function you belong, and you are *not* on
a segmented machine, why don't you just keep an ordered list of function
addresses and find where your mystery address fits in the list?

|| Tom Stockfisch, UCSD Chemistry	tps%chem at sdcsvax.UCSD



More information about the Comp.lang.c mailing list