#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define setarr(a) [sizeof(a)-1] = (a) // remove NULL from end of string
void my_char_plus(const void *a, const void *b, void *c)
{
char tmp = (*(char*)a + *(char*)b);
memcpy(c
,(void*)(&tmp
),sizeof(char)); }
void my_char_minus(const void *a, const void *b, void *c)
{
char tmp = (*(char*)a - *(char*)b);
memcpy(c
,(void*)(&tmp
),sizeof(char)); }
void operation(const void *funct(const void*,const void*,void*),
const void *a, const void *b, void *c )
{
funct(a,b,c);
}
char ret_last_arg(const void *funct(const void*,const void*,void*),
const void *a, const void *b)
{
char c;
funct(a,b,(void*)&c);
return c;
}
int main(void)
{
char a, b;
a = 5; b = 7;
void *plus = &my_char_plus; char c;
operation(plus, (const void*)&a, (const void*)&b, (void*)&c);
void *minus = &my_char_minus;
char d = ret_last_arg(minus, (const void*)&a, (const void*)&b);
// LISP LISP LISP
#define LISP(ar,aa,bb) ret_last_arg(ar, (const void*)&(char){aa}, (const void*)&(char){bb} )
char e = LISP(plus,2,LISP(plus,2,2));
printf("( + 2 ( + 2 2 ) = %i\n", e
);
return 0;
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgojaW5jbHVkZSA8dW5pc3RkLmg+CgojZGVmaW5lIHNldGFycihhKSAgW3NpemVvZihhKS0xXSA9IChhKSAvLyByZW1vdmUgTlVMTCBmcm9tIGVuZCBvZiBzdHJpbmcgCgp2b2lkIG15X2NoYXJfcGx1cyhjb25zdCB2b2lkICphLCBjb25zdCB2b2lkICpiLCB2b2lkICpjKQp7CiAgY2hhciB0bXAgPSAgKCooY2hhciopYSArICooY2hhciopYik7CiAgbWVtY3B5KGMsKHZvaWQqKSgmdG1wKSxzaXplb2YoY2hhcikpOwp9Cgp2b2lkIG15X2NoYXJfbWludXMoY29uc3Qgdm9pZCAqYSwgY29uc3Qgdm9pZCAqYiwgdm9pZCAqYykKewogIGN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GNoYXIgZSA9IExJU1AocGx1cywyLExJU1AocGx1cywyLDIpKTsKICBwcmludGYoIiggKyAyICggKyAyIDIgKSA9ICVpXG4iLCBlKTsKICAKICByZXR1cm4gMDsKfQ==