Set function address into absolute memory?

Alan J Rosenthal flaps at jarvis.csri.toronto.edu
Sat Jul 8 03:10:17 AEST 1989


mikec at 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



More information about the Comp.lang.c mailing list