Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Functional C

Name: Anonymous 2011-12-12 12:06

is it possible to write C in a functional manner?

Name: Anonymous 2011-12-12 22:58


debian:~/host/prog$ cat lambda.c
#include <stdio.h>
#define lambda(return_type, function) \
        ({ \
        return_type __fn__ function __fn__; \
        })

int main()
{
        int (*max)(int,int) = lambda(int, (int x,int y) { return x > y ? x : y; });
        printf("max of 2,6: %d | max of 4,2: %d\n",max(2,6),max(4,2));
        return 0;
}
debian:~/host/prog$ gcc lambda.c
debian:~/host/prog$ ./a.out
max of 2,6: 6 | max of 4,2: 4

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List