pointers to freshly minted functions.

throopw at dg_rtp.UUCP throopw at dg_rtp.UUCP
Fri Mar 7 09:48:33 AEST 1986


> Some machines won't let you do what you want at all, in fact,
> because on them, code is code and data is data and never the twain shall
> meet.  (Examples:  a pdp11 running split-space; a segmented machine that
> makes a distinction between code and data segments.)

Taking "what you want" to be "creating an instruction stream, and then
executing it", I think that what Henry says here is mildly misleading
(though, not surprisingly, correct).  Consider a C function which
creates an instruction stream, and returns a pointer to a function which
when invoked will execute this instruction stream.  Here is a definition
and an invocation of such a function (and an invocation of the function
it returns a pointer to, for good measure).

    { void (*(make_callable_istream()))(); ...
        (*(make_callable_istream( &proto_istream )))();
        ...
    }

It must *always* be possible to implement this function, otherwise
compilers would not be possible, since compilers are simply programs
that treat code as data (though sometimes an implementation of the above
function will have to start one or more new processes...) So, a machine
where it is strictly true that "code is code and data is data and never
the twain shall meet" makes compilers impossible.  A more accurate
phrasing of the restriction that Henry was thinking of might be "within
a single process, code is code and data is data and never the twain
shall meet".

Now it may well be that the implementation of this function is so
expensive to execute that it is impractical for some given application.
This seems to be the case for the original query, which seemed to be
about how to shave a few microseconds off of a "case" or "jump-table"
construct.  So it goes.

> Henry Spencer {allegra,ihnp4,linus,decvax}!utzoo!henry
--
(So I like to pick nits.  What can I say?)
-- 
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!dg_rtp!throopw



More information about the Comp.lang.c mailing list