Arcane C Hacks

COTTRELL, JAMES cottrell at NBS-VMS.ARPA
Thu Mar 13 01:57:29 AEST 1986


/*
> > 2)  Is there a machine independent way to coerce non-pointer-
> >     to-function values to pointer-to-function values?
> 
> No, because on some machines they are very different animals:  a pointer
> to a function is not necessarily a pointer to the bytes comprising its
> code.  Some machines want a rather more elaborate structure, in which a
> pointer to a function is a module identifier and a function-within-module
> identifier, and there is extra information somewhere that allows the
> machine to interpret this.  Which leads to...

Interestingly enuf, Sequent, which uses the ns32032 micro with
exactly this type of architecture, has backed away from it. Evidently
they decided it was too much overhead to hack the debuggers and such.
Their calling sequence now looks much like a 68000.
 
> > ...Further, many machines (for instance, the VAX)
> > insist on particular prologues and epilogues for procedures
> > which I have no interest in and do not wish to generate
> > code for.
> 
> If you want to treat something as a function, you *must* observe the
> conventions that your machine (and your compiler) want to see.  There
> is no portable way around this.  

Really! Hey that's what the machine *does*. The only other alternative
is to hack the assembly output with a sed script, changing (on a vax)
the CALLS instructions to JSR's. But that's not portable either.

> In fact, there's no entirely portable
> way to do what you want at all, because the basic nature of the conventions
> (never mind the details of them!) is machine-dependent.  For example,
> machines that use a module+function form of function pointer will need
> some sort of module dictionary somewhere, which you're going to have to
> build.  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.)
> -- 
> 				Henry Spencer @ U of Toronto Zoology

In regards to the code/data split, I dislike this idea. It may be
necessary on machines with small address space, but limits the
usefulness and generality of the programs one can write. It becomes
impossible to insert arbitrary breakpoints for debugging for one.

	jim		cottrell at nbs
*/
------



More information about the Comp.lang.c mailing list