Mercurial > hg > CbC > CbC_examples
view fact-a.c @ 25:6324b8df04f1
lj_as2: fix segmentation fault
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 31 Jan 2016 21:44:55 +0900 |
parents | 0d306982c8b9 |
children | 586096c45873 |
line wrap: on
line source
#ifdef GCC #define __environment _CbC_environment #define __return _CbC_return #endif #include "stdio.h" __code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env) { if (n<0) { printf("#0008:err %d!\n",n); goto (*exit1)(0,exit1env); } if (n==0) goto (*print)(n,result,orig,print,exit1,exit1env); else { result *= n; n--; goto factorial(n,result,orig,print,exit1,exit1env); } } int main( int ac, char *av[]) { int n; n = 10; goto factorial(n,1,n,print,__return,__environment); } __code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env) { printf("#0032:%d! = %d\n",orig, result); goto (*exit1)(0,exit1env); }