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

C > *

Name: Anonymous 2008-05-15 5:55

#include <stdio.h>
#include <stdlib.h>

typedef int(*intfunc_t)(int);

typedef struct {
 intfunc_t call;
 intfunc_t first;
 intfunc_t second;
} composed_func;

void compose(intfunc_t a, intfunc_t b, composed_func *ret){
 ret->first = a;
 ret->second = b;
 int f(int n){
  return((*(ret->first))((*(ret->second))(n)));
 }
 ret->call = &f;
}

int main(){
 int n = arc4random() % 64;
 int f(int n){
  return n << 1;
 }
 printf("f(%d) = %d\n", n, f(n));
 printf("f(f(%d)) = %d\n", n, f(f(n)));
 composed_func c;
 compose(f, f, &c);
 printf("compose(f,f)(%d) = %d\n", n, c.call(n));
 return 0;
}

Name: Anonymous 2008-05-15 6:14

>>2-3
valid gnu C.

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