From fab3f206e4fae1cf329e82a47a0b9d50975dd1b7 Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 20 Mar 2016 20:13:42 +0100 Subject: [PATCH] avoid warning in generated code, with -Cf warning: conversion to 'unsigned int' from 'int' may change the sign of the result [-Wsign-conversion] --- src/flex.skl | 8 +++----- src/gen.c | 6 +++--- src/main.c | 5 +---- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/flex.skl b/src/flex.skl index 4c7d322..e9e3ba3 100644 --- a/src/flex.skl +++ b/src/flex.skl @@ -257,12 +257,10 @@ m4_ifdef( [[M4_YY_NO_ANSI_FUNC_PROTOS]], %ok-for-header %not-for-header -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. +/* Promotes a possibly negative, possibly signed char to an + * integer in range [0..255] for use as an array index. */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) %ok-for-header diff --git a/src/gen.c b/src/gen.c index d10b737..1e65d6c 100644 --- a/src/gen.c +++ b/src/gen.c @@ -752,7 +752,7 @@ void gen_next_compressed_state (char *char_map) out_dec ("if ( yy_current_state >= %d )\n", lastdfa + 2); ++indent_level; - indent_puts ("yy_c = yy_meta[(unsigned int) yy_c];"); + indent_puts ("yy_c = yy_meta[yy_c];"); --indent_level; } @@ -760,7 +760,7 @@ void gen_next_compressed_state (char *char_map) --indent_level; indent_puts - ("yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c];"); + ("yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];"); } @@ -814,7 +814,7 @@ void gen_next_match (void) indent_puts ("YY_CHAR yy_c;\n"); indent_put2s ("for ( yy_c = %s;", char_map); indent_puts - (" (yy_trans_info = &yy_current_state[(unsigned int) yy_c])->"); + (" (yy_trans_info = &yy_current_state[yy_c])->"); indent_puts ("yy_verify == yy_c;"); indent_put2s (" yy_c = %s )", char_map_2); diff --git a/src/main.c b/src/main.c index e1edac3..bc1a8bd 100644 --- a/src/main.c +++ b/src/main.c @@ -1609,10 +1609,7 @@ void readin (void) outn ("\n#define FLEX_DEBUG"); OUT_BEGIN_CODE (); - if (csize == 256) - outn ("typedef unsigned char YY_CHAR;"); - else - outn ("typedef char YY_CHAR;"); + outn ("typedef flex_uint8_t YY_CHAR;"); OUT_END_CODE (); if (C_plus_plus) { -- 2.40.0