GEOS Programming: 2.4 Goc and C: Using Routine Pointers in Goc

Up: GEOS SDK TechDocs | Up | Prev: 2.3 Macros in Goc | Next: 2.5 Esoteric Source-Code Management
ProcCallFixedOrMovable_cdecl(), ProcCallFixedOrMovable_pascal()

Most GEOS code is kept in movable resources. If you call a routine explicitly from source code the Goc preprocessor generates appropriate directives to see to it that the resource is loaded into memory when it is called. However, if you call a routine with a routine-pointer, GEOS cannot take these precautions. Accordingly, when you are calling a routine with a pointer, you must either see to it that the resource is loaded, or use one of the two ProcCallFixedOrMovable routines to instruct the kernel to lock the appropriate resource.

If you know the routine is in a resource which is locked or fixed in memory, you can use the routine pointer exactly the way you would in standard C. This is usually because the calling routine is in the same resource as the routine or routines which may be called.

If you are not sure that the resource is loaded, you should call the routine with either ProcCallFixedOrMovable_cdecl() or ProcCallFixedOrMovable_pascal() . Each of these routines is passed the following arguments:

Both routines return whatever the called routine returns.

If the routine to be called was defined with standard C calling conventions (the default), you should use ProcCallFixedOrMovable_cdecl() . If the routine was declared with the keyword _pascal , it uses Pascal's calling conventions; you must then use the routine ProcCallFixedOrMovable_pascal() . Most kernel and system-library routines are declared with Pascal's calling conventions.

Code Display 5-3 Using ProcCallFixedOrMovable_cdecl()

extern int
SomeRoutineCalledViaAPointer(int anArg, int anotherArg, const char *someText);
int (*funcPtr) (int, int, const char *);					/* A function pointer */
funcPtr = SomeRoutineCalledViaAPointer;
/* We want to do
 *	SomeRoutineCalledViaAPointer(1, 2, "Franklin T. Poomm");
 * but we want to call it through the pointer, even though it's in another 
 * resource:
 */
ProcCallFixedOrMovable_cdecl(funcPtr,					/* The pointer to the routine */
				1, 2, "Franklin T. Poomm");

Up: GEOS SDK TechDocs | Up | Prev: 2.3 Macros in Goc | Next: 2.5 Esoteric Source-Code Management