Mercurial > hg > CbC > CbC_examples
view fact-rectype.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 | bacef8675607 |
children |
line wrap: on
line source
#include <stdio.h> #define __environment _CbC_environment #define __return _CbC_return __code factorial(int n, int result, __rectype *print, __rectype *exit1, void *envp) { if(n<0) { print("#0008:err %dn",n); goto (*exit1)(0, envp); } if (n==0) goto (*print)(n,result,print,exit1, envp); else { result *= n; n--; goto factorial(n, result, print,exit1, envp); } } __code print(int n, int result, __rectype *print ,__rectype *exit1 ,void *envp); int main(int argc, char *argv[]) { int n; n = 10; goto factorial(n,1,print,__return,__environment); } __code print(int n, int result, __rectype *print ,__rectype *exit1,void *envp){ printf("#0032:%d = %d\n", n, result); goto (*exit1)(0,envp); }