From 32f5ea88cf437049ce568b4dfa5e53c3baf83180 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Thu, 21 Nov 2002 13:04:08 +0000 Subject: [PATCH] Avoid g++ -Wold-style-cast warnings. --- ChangeLog | 10 ++++++++++ src/bool-array.icc | 3 ++- src/gen-perf.cc | 16 ++++++++-------- src/hash-table.cc | 6 +++--- src/input.cc | 4 ++-- src/key-list.cc | 6 +++--- src/keyword.cc | 4 ++-- src/options.cc | 4 ++-- src/output.cc | 4 ++-- 9 files changed, 34 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index f1c5d82..8987435 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2002-11-02 Bruno Haible + Avoid g++ -Wold-style-cast warnings. + * src/bool-array.icc: Use new-style casts. + * src/gen-perf.cc: Likewise. + * src/input.cc: Likewise. + * src/key-list.cc: Likewise. + * src/keyword.cc: Likewise. + * src/options.cc: Likewise. + * src/output.cc: Likewise. + * src/hash-table.cc: Likewise. Remove (char *) cast in memset argument. + * src/keyword-list.h (KeywordExt_List): Don't inherit from KeywordExt. (KeywordExt_List::KeywordExt_List): Take a KeywordExt* as argument. (KeywordExt_List::_car): New field. diff --git a/src/bool-array.icc b/src/bool-array.icc index bc85076..38d3874 100644 --- a/src/bool-array.icc +++ b/src/bool-array.icc @@ -35,7 +35,8 @@ Bool_Array::Bool_Array (unsigned int size) memset (_storage_array, 0, size * sizeof (_storage_array[0])); if (option[DEBUG]) fprintf (stderr, "\nbool array size = %d, total bytes = %d\n", - _size, (unsigned int) (_size * sizeof (_storage_array[0]))); + _size, + static_cast (_size * sizeof (_storage_array[0]))); } /* Sets the specified bit to true. diff --git a/src/gen-perf.cc b/src/gen-perf.cc index cdd62a6..b04cec7 100644 --- a/src/gen-perf.cc +++ b/src/gen-perf.cc @@ -58,7 +58,7 @@ Gen_Perf::Gen_Perf () if (option[RANDOM]) { - srand ((long) time (0)); + srand (reinterpret_cast(time (0))); for (int i = 0; i < ALPHA_SIZE; i++) _asso_values[i] = (rand () & asso_value_max - 1); @@ -139,7 +139,7 @@ Gen_Perf::sort_set (char *union_set, int len) char tmp; for (curr = i + 1, tmp = union_set[curr]; - curr > 0 && _occurrences[(unsigned char)tmp] < _occurrences[(unsigned char)(union_set[curr-1])]; + curr > 0 && _occurrences[static_cast(tmp)] < _occurrences[static_cast(union_set[curr-1])]; curr--) union_set[curr] = union_set[curr - 1]; @@ -157,7 +157,7 @@ Gen_Perf::hash (KeywordExt *key_node) const char *p = key_node->_selchars; int i = key_node->_selchars_length; for (; i > 0; p++, i--) - sum += _asso_values[(unsigned char)(*p)]; + sum += _asso_values[static_cast(*p)]; return key_node->_hash_value = sum; } @@ -171,7 +171,7 @@ Gen_Perf::hash (KeywordExt *key_node) inline bool Gen_Perf::affects_prev (char c, KeywordExt *curr) { - int original_char = _asso_values[(unsigned char)c]; + int original_char = _asso_values[static_cast(c)]; int total_iterations = !option[FAST] ? get_asso_max () : option.get_iterations () ? option.get_iterations () : keyword_list_length (); @@ -181,8 +181,8 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr) { int collisions = 0; - _asso_values[(unsigned char)c] = - (_asso_values[(unsigned char)c] + (option.get_jump () ? option.get_jump () : rand ())) + _asso_values[static_cast(c)] = + (_asso_values[static_cast(c)] + (option.get_jump () ? option.get_jump () : rand ())) & (get_asso_max () - 1); /* Iteration Number array is a win, O(1) intialization time! */ @@ -208,7 +208,7 @@ Gen_Perf::affects_prev (char c, KeywordExt *curr) } /* Restore original values, no more tries. */ - _asso_values[(unsigned char)c] = original_char; + _asso_values[static_cast(c)] = original_char; /* If we're this far it's time to try the next character.... */ return true; } @@ -247,7 +247,7 @@ Gen_Perf::change (KeywordExt *prior, KeywordExt *curr) if (option[DEBUG]) { fprintf (stderr, " by changing asso_value['%c'] (char #%d) to %d\n", - *p, p - union_set + 1, _asso_values[(unsigned char)(*p)]); + *p, p - union_set + 1, _asso_values[static_cast(*p)]); fflush (stderr); } return; /* Good, doesn't affect previous hash values, we'll take it. */ diff --git a/src/hash-table.cc b/src/hash-table.cc index 8830cb6..be04eb4 100644 --- a/src/hash-table.cc +++ b/src/hash-table.cc @@ -37,7 +37,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ Hash_Table::Hash_Table (KeywordExt **table_ptr, int s, bool ignore_len): _table (table_ptr), _size (s), _collisions (0), _ignore_length (ignore_len) { - memset ((char *) _table, 0, _size * sizeof (*_table)); + memset (_table, 0, _size * sizeof (*_table)); } Hash_Table::~Hash_Table () @@ -61,8 +61,8 @@ Hash_Table::~Hash_Table () "\ndumping the hash table\n" "total available table slots = %d, total bytes = %d, total collisions = %d\n" "location, %*s, keyword\n", - _size, _size * (int) sizeof (*_table), _collisions, - field_width, "keysig"); + _size, _size * static_cast(sizeof (*_table)), + _collisions, field_width, "keysig"); for (int i = _size - 1; i >= 0; i--) if (_table[i]) diff --git a/src/input.cc b/src/input.cc index c7b23f6..1f48d54 100644 --- a/src/input.cc +++ b/src/input.cc @@ -217,7 +217,7 @@ parse_line (const char *line, const char *delimiters) } if (code > UCHAR_MAX) fprintf (stderr, "octal escape out of range: %s\n", line); - *kp = (char) code; + *kp = static_cast(code); break; } case 'x': @@ -240,7 +240,7 @@ parse_line (const char *line, const char *delimiters) fprintf (stderr, "hexadecimal escape without any hex digits: %s\n", line); if (code > UCHAR_MAX) fprintf (stderr, "hexadecimal escape out of range: %s\n", line); - *kp = (char) code; + *kp = static_cast(code); break; } case '\\': case '\'': case '"': diff --git a/src/key-list.cc b/src/key-list.cc index c1ff2cd..cb16327 100644 --- a/src/key-list.cc +++ b/src/key-list.cc @@ -218,7 +218,7 @@ Key_List::get_occurrence (KeywordExt *ptr) const char *p = ptr->_selchars; unsigned int i = ptr->_selchars_length; for (; i > 0; p++, i--) - value += _occurrences[(unsigned char)(*p)]; + value += _occurrences[static_cast(*p)]; return value; } @@ -232,7 +232,7 @@ Key_List::set_determined (KeywordExt *ptr) const char *p = ptr->_selchars; unsigned int i = ptr->_selchars_length; for (; i > 0; p++, i--) - _determined[(unsigned char)(*p)] = true; + _determined[static_cast(*p)] = true; } /* Returns TRUE if PTR's key set is already completely determined. */ @@ -245,7 +245,7 @@ Key_List::already_determined (KeywordExt *ptr) const char *p = ptr->_selchars; unsigned int i = ptr->_selchars_length; for (; is_determined && i > 0; p++, i--) - is_determined = _determined[(unsigned char)(*p)]; + is_determined = _determined[static_cast(*p)]; return is_determined; } diff --git a/src/keyword.cc b/src/keyword.cc index 5f3f6d3..1175540 100644 --- a/src/keyword.cc +++ b/src/keyword.cc @@ -69,7 +69,7 @@ void KeywordExt::init_selchars (Vectors *v) if (option[ALLCHARS]) /* Use all the character positions in the KEY. */ for (int i = _allchars_length; i > 0; k++, ptr++, i--) - v->_occurrences[(unsigned char)(*ptr = *k)]++; + v->_occurrences[static_cast(*ptr = *k)]++; else /* Only use those character positions specified by the user. */ { @@ -88,7 +88,7 @@ void KeywordExt::init_selchars (Vectors *v) else /* Out of range of KEY length, so we'll just skip it. */ continue; - v->_occurrences[(unsigned char)*ptr]++; + v->_occurrences[static_cast(*ptr)]++; ptr++; } diff --git a/src/options.cc b/src/options.cc index 6078798..2389056 100644 --- a/src/options.cc +++ b/src/options.cc @@ -346,14 +346,14 @@ int PositionStringParser::nextPosition () case '$': _str++; return _end_word_marker; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': - for (_curr_value = 0; isdigit ((unsigned char)(*_str)); _str++) + for (_curr_value = 0; isdigit (static_cast(*_str)); _str++) _curr_value = _curr_value * 10 + (*_str - '0'); if (*_str == '-') { for (_size = 1, _upper_bound = 0; - isdigit ((unsigned char)(*++_str)); + isdigit (static_cast(*++_str)); _upper_bound = _upper_bound * 10 + (*_str - '0')); if (_upper_bound <= _curr_value || _upper_bound > _high_bound) diff --git a/src/output.cc b/src/output.cc index b2498c0..06f5279 100644 --- a/src/output.cc +++ b/src/output.cc @@ -217,7 +217,7 @@ output_string (const char *key, int len) putchar ('"'); for (; len > 0; len--) { - unsigned char c = (unsigned char) *key++; + unsigned char c = static_cast(*key++); if (isprint (c)) { if (c == '"' || c == '\\') @@ -1020,7 +1020,7 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash { int part1 = num_switches / 2; int part2 = num_switches - part1; - int size1 = (int)((double)size / (double)num_switches * (double)part1 + 0.5); + int size1 = static_cast(static_cast(size) / static_cast(num_switches) * static_cast(part1) + 0.5); int size2 = size - size1; KeywordExt_List *temp = list;