fork(1) download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5.  
  6. #define setarr(a) [sizeof(a)-1] = (a) // remove NULL from end of string
  7.  
  8. void my_char_plus(const void *a, const void *b, void *c)
  9. {
  10. char tmp = (*(char*)a + *(char*)b);
  11. memcpy(c,(void*)(&tmp),sizeof(char));
  12. }
  13.  
  14. void my_char_minus(const void *a, const void *b, void *c)
  15. {
  16. char tmp = (*(char*)a - *(char*)b);
  17. memcpy(c,(void*)(&tmp),sizeof(char));
  18. }
  19.  
  20.  
  21.  
  22. void operation(const void *funct(const void*,const void*,void*),
  23. const void *a, const void *b, void *c )
  24. {
  25. funct(a,b,c);
  26. }
  27.  
  28. char ret_last_arg(const void *funct(const void*,const void*,void*),
  29. const void *a, const void *b)
  30. {
  31. char c;
  32. funct(a,b,(void*)&c);
  33. return c;
  34. }
  35.  
  36.  
  37.  
  38. int main(void)
  39. {
  40.  
  41. char a, b;
  42. a = 5; b = 7;
  43.  
  44.  
  45. void *plus = &my_char_plus; char c;
  46. operation(plus, (const void*)&a, (const void*)&b, (void*)&c);
  47. printf("5 + 7 = %i\n", c);
  48.  
  49.  
  50. void *minus = &my_char_minus;
  51. char d = ret_last_arg(minus, (const void*)&a, (const void*)&b);
  52. printf("5 - 7 = %i\n", d);
  53.  
  54.  
  55. // LISP LISP LISP
  56. #define LISP(ar,aa,bb) ret_last_arg(ar, (const void*)&(char){aa}, (const void*)&(char){bb} )
  57.  
  58. char e = LISP(plus,2,LISP(plus,2,2));
  59. printf("( + 2 ( + 2 2 ) = %i\n", e);
  60.  
  61. return 0;
  62. }
Success #stdin #stdout 0s 1788KB
stdin
Standard input is empty
stdout
5 + 7 = 12
5 - 7 = -2
( + 2 ( + 2 2 ) = 6