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

Pages: 1-

Recursion without recursion... or is it?

Name: Anonymous 2011-06-15 22:03

This works on 32-bit x86 Linux with gcc as long as you don't enable optimization.


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

static void factorial(int in, int *out) {
        *(&in-1)-=5-5*(1/in);
        *out*=in--;
}

int main(int argc, char **argv) {
        int result=1;
        int number=0;

        if(argc!=2) {
                exit(1);
        }

        number=atoi(argv[1]);

        if(number<1) {
                exit(2);
        }

        factorial(number, &result);

        printf("%d! = %d\n", number, result);

        return 0;
}

$ ./factorial 3
3! = 6
$ ./factorial 5
5! = 120

Name: Anonymous 2011-06-15 22:15

./factorial 100
Doesn't work anymore.

Name: Anonymous 2011-06-15 22:56

that will break on gcc 4+

Name: Anonymous 2011-06-16 1:52

forgot your [code]

Name: Anonymous 2011-06-16 5:40

<>

Name: Anonymous 2011-06-16 6:24

care to explain this black magic, OP?

Name: Anonymous 2011-06-16 6:32

>>6 SEPPLES IS NOT MAGIC, FAGGOT

Name: Anonymous 2011-06-16 7:07

Quit FUCKING HAVING ANAL SEX WITH POINTERS.

Name: Anonymous 2011-06-16 7:29

SEX OFFENDERS NEED ACCESS TO CHILDREN TOO!

Name: Anonymous 2011-06-16 7:35

Your code exploited a buffer overflow in my compiler which caused the instruction pointer to jump to a low-level API that opens the CD-ROM drive. I had a CD burning there, so it flew out of the drive and cut my cat's throat. Now my only friend is dead. Thanks a lot.

Name: Anonymous 2011-06-16 8:05

>>10
You think you're doing bad? I don't have any friends in the first place! ;_;

Name: Anonymous 2011-06-16 10:32

>>10
Why don't you have a backup cat?

Name: Anonymous 2011-06-16 10:53

>>12
My backup cat is in cold storage

Name: Anonymous 2011-06-16 10:57

>>13
My other cat is a tac

Name: Anonymous 2011-06-16 10:59

cat and cdr?

Name: VIPPER 2011-06-16 11:15

>>14,15
FAIL!
cdt

Name: Anonymous 2011-06-16 11:24

>>16
hey vipman how you feeling about the reddit niggaz?

Name: Anonymous 2011-06-16 11:26

>>16 is correct.

Name: VIPPER 2011-06-16 11:26

>>17
I love them and so should you, fucking anus h4x0r.

Name: Anonymous 2011-06-16 11:36

>>16
Cuddet?

Name: VIPPER 2011-06-16 12:09

>>19
You are not a true VIPPER.
The redditers are imageboard scum and should be treated like that.

As for you >>19san, you do not deserve the tag of VIPPER, i hope you will burn in hell.

Name: VIPPER 2011-06-16 12:15

>>21
I have infiltrated your base and I will destroy it from the inside.

Name: VIPPER 2011-06-16 13:10

VIPPER is a fag

Name: Alfe 2011-06-17 5:50

Very nice! :-)

AFAICS the first statement in factorial() warps the return address pointer on the stack 5 bytes back (unless 'in' is 1), so after returning from factorial, the PC is back on the statement of jumping to the subroutine factorial() again.  So, effectively Anonymous loops by doing this.

But I've never seen this done in C before, so thank you for the inspiring idea!

Name: Java Suit 2011-06-17 6:31

JAVA

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