view test/fact.c @ 560:d6ff45d719a5 string-shared

string sharing
author kono
date Sat, 07 Jan 2006 18:11:53 +0900
parents 0c256ea2a97e
children 388baa7d4bee
line wrap: on
line source

#include "stdio.h"

int
main(ac,av)
int ac;
char *av[];
{
    int n;
    // n = atoi(av[1]);
    n = 10;
    goto factorial(n,1,n,print,return,environment);
}

code print(n,result,orig,print,exit1,exit1env)
int n,result,orig;
code (*print)(),(*exit1)();
void *exit1env;
{
    printf("#0018:%d! = %d\n",n, result);
    goto (*exit1)(0),exit1env;
}

code factorial(n,result,orig,print,exit1,exit1env)
int n,result,orig;
code (*print)();
code (*exit1)();
void *exit1env;
{
    if (n<0) {
	printf("#0029:err %d!\n",n);
	goto (*exit1)(0),exit1env;
    }
    if (n==0)
	goto (*print)(n,result,orig,print,exit1,exit1env); 
	/* goto print(n,result,orig,print,exit1,exit1env); */
    else {
	result *= n;
	n--;
	goto factorial(n,result,orig,print,exit1,exit1env);
    }
}