[net.lang.c] Arcane C Hacks

cottrell@NBS-VMS.ARPA (COTTRELL, JAMES) (03/12/86)

/*
> > 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@nbs
*/
------

henry@utzoo.UUCP (Henry Spencer) (03/16/86)

> > ...  a pointer
> > to a function is not necessarily a pointer to the bytes comprising its
> > code....
> 
> 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.

The 32000 series does give you the option of doing this.  It's superficially
attractive, but not only does it cause problems with debuggers etc., it's
also pretty slow.  Unless you are doing something like dynamic linking where
you *must* resolve the name->address mapping at runtime, it's a loss.  There
are other machines, alas, where you don't get a choice.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry