From 3f56f36dfb2f38cd5b99488fb6b1346985585476 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 18 Mar 2019 21:22:39 -0700 Subject: [PATCH] Modulo (%) wrapping of negative numbers behaves differently on different platforms. This fixes that. --- conway.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/conway.c b/conway.c index 396c0f0..d191130 100644 --- a/conway.c +++ b/conway.c @@ -6,10 +6,10 @@ #include #include -#define CELL(cells, x, y) cells[((y) % H)*W + ((x) % W)] +#define CELL(cells, x, y) cells[(((y)+H) % H)*W + (((x)+W) % W)] static char rules[2][9] = {{0,0,0,1,0,0,0,0,0}, {0,0,1,1,0,0,0,0,0}}; -static int W, H, DEAD = 0, ALIVE = 7; +static unsigned int W, H, DEAD = 0, ALIVE = 7; static void update(const char *cells, char *future_cells) {