Mercurial > hg > CbC > old > DPP
changeset 4:b7d63c5499e7
Remove warnings in dpp
author | Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 25 Dec 2015 16:00:52 +0900 |
parents | 6bf69a0f2e24 |
children | a04eccfc69ae |
files | Makefile dpp_common.h main.cbc |
diffstat | 3 files changed, 66 insertions(+), 65 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Sun Dec 20 16:46:24 2015 +0900 +++ b/Makefile Fri Dec 25 16:00:52 2015 +0900 @@ -1,7 +1,7 @@ CC=clang MCC=cbc-clang TARGET=dpp dpp2 tableau tableau2 tableau3 -MCCFLAGS=-S -c -g +MCCFLAGS=-c -g CFLAGS=-I. -g -Wall .SUFFIXES: .cbc .c .o
--- a/dpp_common.h Sun Dec 20 16:46:24 2015 +0900 +++ b/dpp_common.h Fri Dec 25 16:00:52 2015 +0900 @@ -2,13 +2,16 @@ #define _DPP_COMMON_H_ #define NULL (0) +#include<stdio.h> +#include<stdlib.h> + typedef struct phils { int id; struct fork *right_fork; struct fork *left_fork; struct phils *right; struct phils *left; - __code (*next)(struct phils *, struct task *); + __code (*next)(struct phils *); } Phils, *PhilsPtr; typedef struct fork {
--- a/main.cbc Sun Dec 20 16:46:24 2015 +0900 +++ b/main.cbc Fri Dec 25 16:00:52 2015 +0900 @@ -7,115 +7,113 @@ #define NUM_PHILOSOPHER 5 /* A number of philosophers must be more than 2. */ -__code (*ret)(int); void *env; PhilsPtr phils_list = NULL; __code run(PhilsPtr self) { - goto thinking(self); + goto thinking(self); } __code init_final(PhilsPtr self) { - self->right = phils_list; - self->right_fork = phils_list->left_fork; - printf("init all\n"); + self->right = phils_list; + self->right_fork = phils_list->left_fork; + printf("init all\n"); - goto run(phils_list); + goto run(phils_list); } __code init_phils2(PhilsPtr self, int count, int id) { - PhilsPtr tmp_self; + PhilsPtr tmp_self; - tmp_self = (PhilsPtr)malloc(sizeof(Phils)); - if (!tmp_self) { - goto die("Can't allocate Phils\n"); - } - self->right = tmp_self; - tmp_self->id = id; - tmp_self->right_fork = NULL; - tmp_self->left_fork = self->right_fork; - tmp_self->right = NULL; - tmp_self->left = self; - tmp_self->next = thinking; + tmp_self = (PhilsPtr)malloc(sizeof(Phils)); + if (!tmp_self) { + goto die("Can't allocate Phils\n"); + } + self->right = tmp_self; + tmp_self->id = id; + tmp_self->right_fork = NULL; + tmp_self->left_fork = self->right_fork; + tmp_self->right = NULL; + tmp_self->left = self; + tmp_self->next = thinking; - count--; - id++; + count--; + id++; - if (count == 0) { - goto init_final(tmp_self); - } else { - goto init_fork2(tmp_self, count, id); - } + if (count == 0) { + goto init_final(tmp_self); + } else { + goto init_fork2(tmp_self, count, id); + } } __code init_fork2(PhilsPtr self, int count, int id) { - ForkPtr tmp_fork; + ForkPtr tmp_fork; - tmp_fork = (ForkPtr)malloc(sizeof(Fork)); - if (!tmp_fork) { - goto die("Can't allocate Fork\n"); - } - tmp_fork->id = id; - tmp_fork->owner = NULL; - self->right_fork = tmp_fork; + tmp_fork = (ForkPtr)malloc(sizeof(Fork)); + if (!tmp_fork) { + goto die("Can't allocate Fork\n"); + } + tmp_fork->id = id; + tmp_fork->owner = NULL; + self->right_fork = tmp_fork; - goto init_phils2(self, count, id); + goto init_phils2(self, count, id); } __code init_phils1(ForkPtr fork, int count, int id) { - PhilsPtr self; + PhilsPtr self; - self = (PhilsPtr)malloc(sizeof(Phils)); - if (!self) { - goto die("Can't allocate Phils\n"); - } - phils_list = self; - self->id = id; - self->right_fork = NULL; - self->left_fork = fork; - self->right = NULL; - self->left = NULL; - self->next = thinking; + self = (PhilsPtr)malloc(sizeof(Phils)); + if (!self) { + goto die("Can't allocate Phils\n"); + } + phils_list = self; + self->id = id; + self->right_fork = NULL; + self->left_fork = fork; + self->right = NULL; + self->left = NULL; + self->next = thinking; - count--; - id++; + count--; + id++; - goto init_fork2(self, count, id); + goto init_fork2(self, count, id); } __code init_fork1(int count) { - ForkPtr fork; - int id = 1; + ForkPtr fork; + int id = 1; - fork = (ForkPtr)malloc(sizeof(Fork)); - if (!fork) { - goto die("Can't allocate Fork\n"); - } - fork->id = id; - fork->owner = NULL; + fork = (ForkPtr)malloc(sizeof(Fork)); + if (!fork) { + goto die("Can't allocate Fork\n"); + } + fork->id = id; + fork->owner = NULL; - goto init_phils1(fork, count, id); + goto init_phils1(fork, count, id); } __code die(char *err) { - printf("%s\n", err); - goto ret(1); + printf("%s\n", err); + exit(1); } int main(void) { - ret = __return; - env = __environment; + env = __environment; - goto init_fork1(NUM_PHILOSOPHER); + goto init_fork1(NUM_PHILOSOPHER); } /* end */