Mercurial > hg > CbC > CbC_gcc
view CbC-examples/loto6.c @ 155:da32f4b04d38
fix __code name conflict
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 17:51:46 +0900 (2020-05-25) |
parents | 24d2e7cdba67 |
children |
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> __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); }