Newsgroups: comp.lang.c
Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps
From: flaps@jarvis.csri.toronto.edu (Alan J Rosenthal)
Subject: Re: Set function address into absolute memory?
Message-ID: <1989Jul7.171017.2108@jarvis.csri.toronto.edu>
Organization: Dynamic Graphics Project, University of Toronto
References: <2954@helios.ee.lbl.gov>
Distribution: usa
Date: Fri, 7 Jul 89 17:10:17 GMT


mikec@ux1.lbl.gov (Mike Chin) writes:
...
>void	vector();
...
>	void 		(*funcpoint)();
>	functype	*funcstruct;
>/*
>	this won't pass lint
>	funcpoint=(void*) malloc (4);
>	*funcpoint = vector;
>	*funcpoint();
>*/

The declaration of funcpoint should be void (**funcpoint)();.  The function
address you are storing is a pointer to function returning void, so the pointer
to the memory it should be stored into is a pointer to pointer to function
returning void.

The cast of malloc's return value should be redundant as it should be declared
as returning void * in memory.h.

To keep your program portable (possibly only between compiler upgrades, if your
program is machine-specific anyway), rather than "malloc(4)" write
"malloc(sizeof(void (*)()))".

ajr
