[comp.lang.c] Size of a function

LINNDR%VUENGVAX.BITNET@wiscvm.wisc.edu (01/03/87)

        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.

David Linn
LINNDR%VUENGVAX.BITNET@WISCVM.WISC.EDU          | Internet
...!psuvax1!vuengvax.bitnet!linndr              | UUCP

tps@sdchem.UUCP (Tom Stockfisch) (01/04/87)

In article <2100@brl-adm.ARPA> LINNDR%VUENGVAX.BITNET@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@sdcsvax.UCSD

jgh@miduet.UUCP (01/23/87)

In article <609@sdchema.sdchem.UUCP> tps@sdchemf.UUCP (Tom Stockfisch) writes:
>In article <2100@brl-adm.ARPA> LINNDR%VUENGVAX.BITNET@wiscvm.wisc.edu writes:
>> ... 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.
>>
>>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.  

I had a need to pass a copy of a function to another task. Sizeof( function )
would have been handy....

(That
should
put
the
cat
among
the
pigeons!)

(I don't speak for my employer)
Jeremy Harris	jgh@gec-mi-at.co.uk	...!mcvax!ukc!hrc63!miduet!jgh
-- 
Jeremy Harris	jgh@gec-mi-at.co.uk	...!mcvax!ukc!hrc63!miduet!jgh

ark@alice.UUCP (01/25/87)

In article <500@gec-mi-at.co.uk>, jgh@gec-mi-at.co.uk (Jeremy Harris) writes:
> I had a need to pass a copy of a function to another task. Sizeof( function )
> would have been handy....

Maybe yes, maybe no.  You would also need:

	1. A way of actually getting at the function text.

	2. A guarantee that it was all contiguous.

	3. Some way of getting the copy to work.

The first is impossible on some architectures (such as the PDP-11).
The third assumes that either your object code is self-relocating
or you know how to relocate it somehow.

All these things may indeed be useful, but it is clear that they
would be a major addition to C.  sizeof(function) isn't nearly enough.