34 lines
861 B
C
34 lines
861 B
C
/* K&R source for the M4 differential function-pointer golden.
|
|
*
|
|
* The 1987 TI compiler (GSP C Compiler 2.01) does not accept a typedef for a
|
|
* function pointer, nor the volatile qualifier on the local, so the callback
|
|
* is spelled as a plain `int (*f)()` parameter and the local pointer is
|
|
* unqualified. `apply` is the call-through-pointer proof: the caller pushes
|
|
* `x` and the callback, saves STK, and calls through the loaded pointer (TI
|
|
* `CALL A7`, ours `CALL A?`). The direct calls to `apply` from `test()` stay
|
|
* `CALLA _apply`.
|
|
*/
|
|
int inc(x) int x; { return x + 1; }
|
|
int dec(x) int x; { return x - 1; }
|
|
|
|
int apply(f, x)
|
|
int (*f)();
|
|
int x;
|
|
{
|
|
return (*f)(x);
|
|
}
|
|
|
|
int (*g_dec)() = dec;
|
|
|
|
int test()
|
|
{
|
|
int (*vf)();
|
|
int a;
|
|
int b;
|
|
|
|
vf = inc;
|
|
a = apply(inc, 41);
|
|
b = apply(vf, 41);
|
|
return apply(g_dec, 43) + a + b;
|
|
}
|