Set function address into absolute memory?
Mike Chin
mikec at ux1.lbl.gov
Fri Jul 7 11:02:02 AEST 1989
Is there a reasonable way to place the address of a function into
an absolute location? I need to do this to set up the vector table in
an 80186. I would have thought that something like "a pointer to a function"
set to the table address would work, but it seems I have to wrap it inside
of a structure. Here's an example that shows the structure, and in comments what
seems should be OK. This lints with Gimpel, and runs under MSC 5.1
in large model...
----------------------------------------------------
/*
instead of malloc, for an real vector table I would use
absolute addresses
*/
#include <stdio.h>
#include <malloc.h>
typedef struct {
void (*oopa)();
}functype;
void vector();
void main()
{
void (*funcpoint)();
functype *funcstruct;
/*
this won't pass lint
funcpoint=(void*) malloc (4);
*funcpoint = vector;
*funcpoint();
*/
funcstruct=(functype *) malloc(4);
funcstruct->oopa=vector;
funcstruct->oopa();
}
void vector()
{
printf ("this is the stuff\n");
}
----------------------------------------------------
Mike Chin
MJChin at lbl.gov
More information about the Comp.lang.c
mailing list