Static Function Invocation Thru Pointer

Andrew M. Choi labc-1ia at web-3g.berkeley.edu
Sun Mar 3 10:22:50 AEST 1991


Hi.  This article is about the question of invoking a static
function in another file through the use of pointer to
function.  Please consider the following:

/* In file "foo.c" */

int (*function_pointer)();

static int function()
{
	printf("This is from function\n");
}

setFunctionPointer()
{
	function_pointer = function;
}

/* In file "bar.c" */

main()
{
	extern int (*function_pointer)();

	setFunctionPointer();
	(*function_pointer)();	/* Is this legal?  Note that "function" */
				/* is a static function .. unknown to */
				/* "bar.c" */
}

Personally, I think the above is *ALWAYS* legal (can't think of any
reason why this will fail).  Is this true for all machine
architectures?

I thank you in advance for your help.


Name:  Andrew Choi	Internet Addr:  achoi at cory.berkeley.edu
Tel:   (415)848-5658
#include <std/disclaimer.h>



More information about the Comp.lang.c mailing list