Mercurial > hg > CbC > CbC_examples
view loto6.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 | 35d6eabeadb0 |
children | 586096c45873 |
line wrap: on
line source
/* * Nov 10, 2009 * created by gongo. * * Nov 10, 2009 * modified by kent. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #ifdef CLANG // for clang/LLVM #define _CbC_return __return #define _CbC_environment __environment #endif __code (*ret)(int, void*); void *env; __code print(int *numbers) { printf("%d-%d-%d-%d-%d-%d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4], numbers[5]); free(numbers); goto ret(0, env); } __code take(int *array, int size, int length) { int *taked = (int*)malloc(sizeof(int)*length); memcpy(taked, array, sizeof(int)*length); free(array); goto print(taked); } __code shuffle(int *array, int size, int idx) { int j = random() % size; int tmp = array[idx]; array[idx] = array[j]; array[j] = tmp; if (++idx < size) { goto shuffle(array, size, idx); } else { goto take(array, size, 6); } } __code range_loop(int *array, int idx, int from, int to, int step, int size) { array[idx] = from; if (from+step > to) { goto shuffle(array, size, 0); } else { goto range_loop(array, idx+1, from+step, to, step, size); } } __code range(int from, int to, int step) { int size = (to-from+1)/step; int *array = (int*)malloc(sizeof(int)*size); goto range_loop(array, 0, from, to, step, size); } int main() { srand(time(NULL)); ret = _CbC_return; env = _CbC_environment; goto range(1, 43, 1); }