home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / CLISP-2.LHA / CLISP960530-ki.lha / ffcall / trampoline / test1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  973 b   |  40 lines

  1. /* Trampoline test */
  2.  
  3. /*
  4.  * Copyright 1995 Bruno Haible, <haible@ma2s2.mathematik.uni-karlsruhe.de>
  5.  *
  6.  * This is free software distributed under the GNU General Public Licence
  7.  * described in the file COPYING. Contact the author if you don't have this
  8.  * or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
  9.  * on this software.
  10.  */
  11.  
  12. #include <stdio.h>
  13.  
  14. #include "trampoline.h"
  15.  
  16. #define MAGIC1  0x9db9af42
  17. #define MAGIC2  0x614a13c9
  18.  
  19. static int magic = MAGIC1;
  20.  
  21. typedef int (*function)();
  22.  
  23. void* function_data;
  24.  
  25. int f (x)
  26.   int x;
  27. { return *(int*)function_data + x; }
  28.  
  29. int main ()
  30. {
  31.   function cf = alloc_trampoline(&f, &function_data, &magic);
  32.   /* calling cf shall set  function_data = &magic  and then call f(x),
  33.    * thus returning  magic + x.
  34.    */
  35.   if (((*cf)(MAGIC2) == MAGIC1+MAGIC2) && (function_data = &magic))
  36.     { free_trampoline(cf); printf("Works, test1 passed.\n"); exit(0); }
  37.   else
  38.     { printf("Doesn't work!\n"); exit(1); }
  39. }
  40.