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 5:55

>>1
Your code isn't even valid. (look into your main)
you fail.

Name: Anonymous 2008-05-15 5:57

int f(int n){
  return n << 1;
 }

This is not C

Name: Anonymous 2008-05-15 6:02

Aww isn't it cute. Just like when a baby first learns to say papa, OP just learned about function pointers and aliasing with typedef.

Name: Anonymous 2008-05-15 6:14

>>2-3
valid gnu C.

Name: Anonymous 2008-05-15 7:01

>>5
Enjoy rewriting your code to run on whatever becomes fashionable after Linux.

Name: Anonymous 2008-05-15 7:12

>>6
gcc != linux

Name: Anonymous 2008-05-15 7:55

ololololllloolol
OP IS A RETNOOB roflroflrolf

Name: 2008-05-15 7:58

                                               

Name: Anonymous 2008-05-15 8:04

>>3
Troll?

Name: Anonymous 2008-05-15 8:07

C sucks ass. No sane person would ever use such a shit ass language.

Name: Anonymous 2008-05-15 8:25

http://dis.4chan.org/read/prog/1208910000/4-5
It takes a retard to not notice the difference when you see either a shift or streams.
It looks like >>3 proved you wrong.

Name: Anonymous 2008-05-15 9:50

int f(int n){

Please tell me what the shit that is.

Name: Anonymous 2008-05-15 9:57

>>13
you best be joking, nigger.

Name: Anonymous 2008-05-15 10:02

Also, where is arc4random() supposed to be defined?

I call BS on this program.

Name: Anonymous 2008-05-15 10:44

Greenspun's Tenth Rule:

"Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp."

Name: Anonymous 2008-05-15 10:45

Superior.

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

#define COMPOSE(f, g) ({ int fog(int n) { return f(g(n)); } fog; })

int f(int n) { return n << 1; }

int main(void)
{
   printf("(f ° f)(16) = %d\n", COMPOSE(f, f)(16));
   printf("(f ° f ° f)(16) = %d\n",
      COMPOSE(f, COMPOSE(f, f))(16));
   return 0;
}

Name: Anonymous 2008-05-15 11:51

Actually, C = x (forall x:programming language).
Proof. This is an inmediate consequence of Church's thesis. QED.

Name: Anonymous 2008-05-15 12:14

>>12
I really hope you're ``trolling'', and not actually thinking I mistook this shift for C++ i/o. But if that's not the case: C can't have nested functions, and that's what I pointed out in >>3

Name: Anonymous 2008-05-15 12:20

>>19
C can't, but you can get pretty damn close in C++

#include <iostream>

struct IFoo {
    virtual int func() = 0;
};

struct Bar {
    IFoo* make_ifoo() {
        struct Foo : IFoo {
            virtual int func() {
                return 42;
            }
        };
        return new Foo();
    }
};

int main( int argc, char *argv[] ) {
    Bar b; std::cout << b.make_ifoo()->func() << std::endl;
    return 0;
}


hur hur hurrr.

Name: Anonymous 2008-05-15 13:08

>>20
HAHAHA, OH WOW

Name: Anonymous 2008-05-15 13:17

>>19
Well it should.

Name: Anonymous 2008-05-15 13:26

>>19
GNU C > *

Name: Anonymous 2008-05-15 14:18

>>17
doesn't work if you store the result of compose in a variable, change f, and then try to call your "composed" function. >>1 does.

Name: Anonymous 2008-05-15 14:34

>>24
I do not understand what you mean.

Name: >>25 2008-05-15 14:47

>>24
I think I understand now. If the f you are refering to is a local function pointer, then >>17 won't even compile, since nested functions can not refer to local variables of the enclosing function.

Name: >>25 2008-05-15 14:52

Disregard >>26, nested functions can refer to local variables of the enclosing function. >>24 is right.

Name: Anonymous 2008-05-15 14:56

let's just not discuss gnu's C hacks at all.

Name: Anonymous 2008-05-15 15:20

>>24
In >>1, every time you call compose, all prior results of composed are set to the last one. That's because variables of the enclosing function that are referred to by a nested function, are compiled as static variables.

Name: Anonymous 2008-05-15 15:57

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

#define COMPOSE(f, g) \
({ int2int_t _f = f, _g = g; \
   int _(int n) { return _f(_g(n)); } \
   _; \
 })   

typedef int (*int2int_t)(int);

int f(int n) { return n * 2; }
int g(int n) { return n * 3; }

int main(void)
{
   int2int_t fog = COMPOSE(f, g);

   printf("(f ° g)(16) = %d\n", fog(16));
   printf("(f ° g ° f)(16) = %d\n", COMPOSE(f, COMPOSE(g, f))(16));
   printf("(f ° g)(16) = %d\n", fog(16));
   return 0;
}

Name: Anonymous 2008-05-15 16:13

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

#define COMPOSE(f, g) \
({ int2int_t _f = f, _g = g; \
   int _(int n) { return _f(_g(n)); } \
   _; \
 })   

typedef int (*int2int_t)(int);

int f(int n) { return n * 2; }
int g(int n) { return n * 3; }

int main(void)
{
   int2int_t fog = COMPOSE(f, g);
   int2int_t fogof = COMPOSE(fog, f);

   printf("(f ° g)(16) = %d\n", fog(16));

   fog = COMPOSE(g, g);

   printf("(f ° g ° f)(16) = %d\n", fogof(16));
   printf("(f ° g)(16) = %d\n", fog(16));

   return 0;
}

Name: Anonymous 2008-05-15 16:47

>[+,-[]++-+>[[,>]<<,[-->+<]-,-<[>]<<--]+<--><>-+<].]<<+<-<><
-[-><<,++,<]-+-<>->[,+]->-<<<<<<-,>,+,-<+-+<+--<<<]->>]-+>]+
[><>[+-<[++<-+<>>],++>+++<>[--][[><,->-[+>-->-.]>+.+>+->].]<
-[-<]+>++[---,+>++]+>+>[<<++][[<-><]+>>-<-<]+-]>-,-<++<+<<+]
]+.>>[-<[[-><><+-[<.><+[-+[-<-[+>+>+->.<->+<<]<-<+->->>++]>-
,][.>]-+-<+.<+[]]<>++]>>+<-+++[+++]-++<++<----.[.>[<><+-.>>]
>+.>[[+++<>>---++.<+++<<-><]+-][.-<,-+<-<>.+>>,]<[--+-<-[<+-
->++>.]]<>><--]-,><]+>><<[<>[[-,]].++><-<+[+[-]->-<[[-<,<>><
<[+]-,+><>++,>-]>][+]>>[-]>].<-+]<+>+>]+<[<>+[>++><-,<-->+,<
+>[+-<><-[>,+>+[->[+[.>[<--<]+---+><>>+]<-,+-+[<-<,<,[[-]++-
+.<<[<++-+-<.+++.>->->]]-]>-<-]-[+<-[++>]>>-.>+<>>-><+<<-<<[
+<[+.+<.+<[[,><-<<<[+++++--<<+[.-+<<-><+>>[]+<>+<++-<>,---<[
-+<[-++<+-<>+<><[]+<>+-><+[+>>++,+.-[>]],-<.+[<<<>]+]>+]--[>
><]><[<+-+>><,>[<>[<>]-+]-><,-<[<-,<[<]><].<+[-<<>]-<-++><>-
->>-]<]+<-][-+,.>>]<+-<[>[-+->]+><><+>,+---+-.[-++<+],>><>.-
>>-><[---<]<[]>>-<<>[-[<-,[.->>]>-[++[>-<+>[->[].->->-]]><>+
[[+<>[+->-+-<+]<]+<-,>--+>>-<[-]<]+[.>+>-+[]++>[><>,[<+<]<,>
<+-[[<>>+,]>>><>[]<],<>.+>+[++->+>-<><+-+>[<+->>+[><>-]-]-++
]--><[-><]>-,<<+][]<-<>+<[->--><+<+><--<<><]<->[-++,]<>+[>+,
<<+-,[>>+[>.[->]-++<]-+<-.>+-[+>[-[<]]]+->+<+>>+>.<>+,+<]+>>
<>>[+--<]<-+<>->]<++<>-+[<---+++++.+.>+-+]<+<>>-<<]-><->>-<>
>>><>><>>,]--+><+]>>[<[.++.--<>-[--+<]>+<.[><+-+,++]++]>+>,>
<->->]]>>++<+-><]<+][-[<<<--<<<.+[.-[<[<-]-++[.[<]---]-++-]<
<<,>->--+[<<->+<<<<]><-<<-->-->--.-->>><-[>+<>++<<,]--.+-,+<
-[],>-.<<+>+<<<+>,.<]-++]>]-+>>[]+->>->+-,>+.,++<+<-<---<+<-
,<+<<+<+.+.-[[>-.>>>->.<[<[]<[+>[++]>]<<+>[>+<].>>>-+->>>-->
>-]<>++->--->[<<.<.<+-<.>.-[][[+]+>><[]+>+-+<><>++-<->><<+>+
<+>-+-[<++>-++<-++>-]>,<[[><]>,-<-<+<<<<->.-+-++<,].>->[+-[.
-[><>-[<..-[[>[]]>[+-<>>>+++]<<-+][<]->-]><]+<[-<[+[-><<-[+>
-+-<+]-+<]++[-,]]<<<.>++>]>,--><>[>]+>><<->>>[>-,-[]>]-++<<<
+>.-+--<->><>[[+-+[>+-->>-+->]><>>-<[]-++-><.]->[<+.]>>>[[-[
+[+[><+[<++-<+--<->-+<[-+-[+-><<].[-+]--++-,-->+>+-++,>]><[]
>]<<,-]-[-]+-<[-,<<-<><,<->.,<><[->-->>[++>-][,++][+<+]+<.]>

Name: Anonymous 2009-03-06 5:59


The root of the   more gratifying and   fun tutorials and   found out that   because I was   under the impression   factory classes are   needed one can   read C and   C As you   leave the parking   lot where your   stack pointer is.

Name: Anonymous 2009-03-06 11:49

The definition of the array list but   the smart ones   will go away   or want to   read about the   substance only mirroring.

Name: Anonymous 2011-02-04 19:28

Name: Anonymous 2012-01-15 17:25

]

Name: Anonymous 2012-01-15 17:25

[]

Name: Sgt.Kabukiman닗僅 2012-05-23 5:41

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

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