From 2e8729fb21d5d5d67b371d501c295dde3d9d33a1 Mon Sep 17 00:00:00 2001 From: Neil Mclean Date: Tue, 17 Jul 2012 00:00:54 +0100 Subject: [PATCH] Resolving compiler warnings on gcc 4.7 Const and casting type fixes. 1lib.c - function capturable_group() was'nt declared inline util.h - Changed WIN32 function prototype to match that in MinGW winbase.h --- chat.c | 5 +++-- gtp.c | 4 ++-- gtp.h | 2 +- network.c | 2 +- ownermap.c | 6 ++++-- patternplay/patternplay.c | 4 +++- tactics/1lib.c | 2 +- util.h | 4 ++-- 8 files changed, 17 insertions(+), 12 deletions(-) diff --git a/chat.c b/chat.c index 16a7bec..76d8a4e 100644 --- a/chat.c +++ b/chat.c @@ -3,6 +3,7 @@ #include #include #include +#include #define DEBUG @@ -58,10 +59,10 @@ void chat_init(char *chat_file) { } } if (!feof(f)) - fprintf(stderr, "syntax error around line %ld in %s\n", entry - chat_table, chat_file); + fprintf(stderr, "syntax error around line %u in %s\n", (uintptr_t)(entry - chat_table), chat_file); fclose(f); if (DEBUGL(1)) - fprintf(stderr, "Loaded %ld chat entries from %s\n", entry - chat_table, chat_file); + fprintf(stderr, "Loaded %u chat entries from %s\n", (uintptr_t)(entry - chat_table), chat_file); } void chat_done() { diff --git a/gtp.c b/gtp.c index 7827305..644b4b1 100644 --- a/gtp.c +++ b/gtp.c @@ -107,10 +107,10 @@ static char *known_commands = /* Return true if cmd is a valid gtp command. */ bool -gtp_is_valid(char *cmd) +gtp_is_valid(const char *cmd) { if (!cmd || !*cmd) return false; - char *s = strcasestr(known_commands, cmd); + const char *s = strcasestr(known_commands, cmd); if (!s) return false; if (s != known_commands && s[-1] != '\n') return false; diff --git a/gtp.h b/gtp.h index 697dbe9..8f8aec3 100644 --- a/gtp.h +++ b/gtp.h @@ -16,7 +16,7 @@ enum parse_code { enum parse_code gtp_parse(struct board *b, struct engine *e, struct time_info *ti, char *buf); void gtp_reply(int id, ...); -bool gtp_is_valid(char *cmd); +bool gtp_is_valid(const char *cmd); #define is_gamestart(cmd) (!strcasecmp((cmd), "boardsize")) #define is_reset(cmd) (is_gamestart(cmd) || !strcasecmp((cmd), "clear_board") || !strcasecmp((cmd), "kgs-rules")) diff --git a/network.c b/network.c index 025a14c..02c986e 100644 --- a/network.c +++ b/network.c @@ -51,7 +51,7 @@ port_listen(char *port, int max_connections) server_addr.sin_port = htons(atoi(port)); server_addr.sin_addr.s_addr = INADDR_ANY; - int val = 1; + const char val = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val))) die("setsockopt"); if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1) diff --git a/ownermap.c b/ownermap.c index 9f8b392..906b5ed 100644 --- a/ownermap.c +++ b/ownermap.c @@ -69,9 +69,11 @@ board_ownermap_judge_groups(struct board *b, struct board_ownermap *ownermap, st } else if (judge->gs[g] != GS_UNKNOWN) { /* Update group state. */ enum gj_state new; - if (pj == color) { + + // Comparing enum types, casting (int) avoids compiler warnings + if ((int)pj == (int)color) { new = GS_ALIVE; - } else if (pj == stone_other(color)) { + } else if ((int)pj == (int)stone_other(color)) { new = GS_DEAD; } else { assert(pj == PJ_DAME); /* Exotic! */ diff --git a/patternplay/patternplay.c b/patternplay/patternplay.c index fb12c70..d4a857a 100644 --- a/patternplay/patternplay.c +++ b/patternplay/patternplay.c @@ -49,9 +49,11 @@ patternplay_evaluate(struct engine *e, struct board *b, struct time_info *ti, fl struct patternplay *pp = e->data; struct pattern pats[b->flen]; - floating_t total = pattern_rate_moves(&pp->pat, b, color, pats, vals); + pattern_rate_moves(&pp->pat, b, color, pats, vals); #if 0 + // unused variable 'total' in above call to pattern_rate_moves() + floating_t total = pattern_rate_moves(&pp->pat, b, color, pats, vals); /* Rescale properly. */ for (int f = 0; f < b->flen; f++) { probs[f] /= total; diff --git a/tactics/1lib.c b/tactics/1lib.c index be237b1..8b6a1dd 100644 --- a/tactics/1lib.c +++ b/tactics/1lib.c @@ -37,7 +37,7 @@ can_play_on_lib(struct board *b, group_t g, enum stone to_play) * liberty to either capture or escape). */ /* Note that @to_play is important; e.g. consider snapback, it's good * to play at the last liberty by attacker, but not defender. */ -static __attribute__((always_inline)) bool +static inline __attribute__((always_inline)) bool capturable_group(struct board *b, enum stone capturer, coord_t c, enum stone to_play) { diff --git a/util.h b/util.h index 2711c6d..ad332a0 100644 --- a/util.h +++ b/util.h @@ -9,8 +9,8 @@ #include #define sleep(seconds) Sleep((seconds) * 1000) -#define __sync_fetch_and_add(ap, b) InterlockedExchangeAdd((unsigned long *) (ap), (b)); -#define __sync_fetch_and_sub(ap, b) InterlockedExchangeAdd((unsigned long *) (ap), -(b)); +#define __sync_fetch_and_add(ap, b) InterlockedExchangeAdd((LONG volatile *) (ap), (b)); +#define __sync_fetch_and_sub(ap, b) InterlockedExchangeAdd((LONG volatile *) (ap), -(b)); #include static inline const char * -- 2.11.4.GIT