sizeof(function) - preproposal survey
Richard A. O'Keefe
ok at quintus.UUCP
Mon Feb 22 13:42:53 AEST 1988
In article <395 at imagine.PAWL.RPI.EDU>, kyriazis at pawl11.pawl.rpi.edu (George Kyriazis) writes:
> It is *not* useless. I wanted to get the sizeof() a function when I was
> writing a program for the PC. Concider writing device drivers and keeping
> them in a file. The application program can then read the sizeof() the
> function and then read() the function. On the developers point of view having
> a sizeof(f()) option will make life a lot easier. Write the function, debug
> it, and then compile it together with a program that gets the function's size
> and write()'s it to a file. Any comments??
>
Given that C is supposed to make sense on machines with separate
instruction and data space (such as some PDP-11s, the Ridge (I think),
the ICL version of the PERQ, and many many others), this doesn't seem
like something that belongs in standard C.
Having (sizeof fn) in C isn't going to help much when a function is in
several discontiguous pieces (some UNIX systems generate code in as many
as three separate chunks, which is then pasted together, but the code
for a single function may not be contiguous). It isn't going to help
with the relocation of the function (I haven't heard the phrase
"position- independent code" in AGES, is it still fashionable?). Bearing
in mind that in some architectures, the size of an identical sequence of
symbolic instructions may depend on where they are loaded (anyone
remember page-relative addressing?) even a contiguous function may not
HAVE a definite size. It isn't going to help when the function requires
other functions. There may be (I am thinking of a real case) a global
optimisation pass in the link-editor. And so on, and so on.
We provide a dynamic loading facility in our product. It runs under VMS
and both BSD and Missed'Em V UNIX (and other things too). Not only did
we not need a (sizeof fn) in C to support this, we never do find out how
big a function is. What you need is a loader which is willing to load a
file relative to an existing symbol table, and a fairly basic facility
for finding out how big the result is. It's not the size of a function
that matters, but the size of a *file*.
If you are using a system where this kind of operation makes sense,
you had better be able to read .obj files (or whatever they are called).
Ask the linker how big functions are, not the compiler.
More information about the Comp.lang.c
mailing list