<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39383 >

William Allen Simpson wrote:
> There's a warning, because the current resource list is const, and this
> modifies the pointer.  Updating the const can happen later.
> 
trunk revision 12977
S2_1 revision 12978

Remaining "const struct resource *" caused 1 warning, and a report that
gcc 4.1 (or a stricter compile option) escalated it to a compile error.

Most "const" removed; 5 remain in function parameters, causing no warnings.

This is the S2_1 patch for posterity.  The trunk is nearly identical
(different line numbers).

Happy hacking!  Please let me know of any more problems!

Index: server/generator/mapgen.c
===================================================================
--- server/generator/mapgen.c   (revision 12977)
+++ server/generator/mapgen.c   (working copy)
@@ -1361,7 +1361,7 @@
     }
     if (!is_ocean(pterrain) || near_safe_tiles (ptile)) {
       int i = 0;
-      const struct resource **r;
+      struct resource **r;
 
       for (r = pterrain->resources; *r; r++) {
        /* This is a standard way to get a random element from the
Index: server/ruleset.c
===================================================================
--- server/ruleset.c    (revision 12977)
+++ server/ruleset.c    (working copy)
@@ -2788,7 +2788,7 @@
 
   terrain_type_iterate(pterrain) {
     const int i = pterrain->index;
-    const struct resource **r;
+    struct resource **r;
 
     packet.id = i;
 
Index: server/maphand.h
===================================================================
--- server/maphand.h    (revision 12977)
+++ server/maphand.h    (working copy)
@@ -40,7 +40,7 @@
 struct player_tile {
   struct terrain *terrain; /* May be NULL for unknown tiles. */
   bv_special special;
-  const struct resource *resource;
+  struct resource *resource;
   unsigned short seen_count[V_COUNT];
   unsigned short own_seen[V_COUNT];
   /* If you build a city with an unknown square within city radius
Index: server/savegame.c
===================================================================
--- server/savegame.c   (revision 12977)
+++ server/savegame.c   (working copy)
@@ -746,7 +746,7 @@
   ch is the character read from the map, and n is the number of the special
   (0 for special_1, 1 for special_2).
 ****************************************************************************/
-static void set_savegame_old_resource(const struct resource **r,
+static void set_savegame_old_resource(struct resource **r,
                                      const struct terrain *terrain,
                                      char ch, int n)
 {
@@ -769,7 +769,7 @@
 /****************************************************************************
   Return the resource for the given identifier.
 ****************************************************************************/
-static const struct resource *identifier_to_resource(char c)
+static struct resource *identifier_to_resource(char c)
 {
   if (c == RESOURCE_NULL_IDENTIFIER) {
     return NULL;
Index: common/combat.c
===================================================================
--- common/combat.c     (revision 12977)
+++ common/combat.c     (working copy)
@@ -601,10 +601,10 @@
     struct unit *punit = unit_list_get(ptile->units, 0);
 
     freelog(LOG_ERROR, "get_defender bug: %s's %s vs %s's %s (total %d"
-            " units) on %s at (%d,%d). ", unit_owner(attacker)->name,
+            " units) on \"%s\" at (%d,%d). ", unit_owner(attacker)->name,
             unit_type(attacker)->name, unit_owner(punit)->name,
             unit_type(punit)->name, unit_list_size(ptile->units), 
-            terrain_name_translation(ptile->terrain), ptile->x, ptile->y);
+            ptile->terrain->name_rule, ptile->x, ptile->y);
   }
 
   return bestdef;
Index: common/tile.c
===================================================================
--- common/tile.c       (revision 12977)
+++ common/tile.c       (working copy)
@@ -114,7 +114,7 @@
 /****************************************************************************
   Set the given resource at the specified tile.
 ****************************************************************************/
-void tile_set_resource(struct tile *ptile, const struct resource *presource)
+void tile_set_resource(struct tile *ptile, struct resource *presource)
 {
   ptile->resource = presource;
 }
Index: common/tile.h
===================================================================
--- common/tile.h       (revision 12977)
+++ common/tile.h       (working copy)
@@ -30,7 +30,7 @@
   int index; /* Index coordinate of the tile. */
   struct terrain *terrain; /* May be NULL for unknown tiles. */
   bv_special special;
-  const struct resource *resource; /* available resource, or NULL */
+  struct resource *resource; /* available resource, or NULL */
   struct city *city;        /* city standing on the tile, NULL if none */
   struct unit_list *units;
   bv_player tile_known, tile_seen[V_COUNT];
@@ -62,7 +62,7 @@
                      enum tile_special_type to_test_for);
 void tile_set_special(struct tile *ptile, enum tile_special_type spe);
 const struct resource *tile_get_resource(const struct tile *ptile);
-void tile_set_resource(struct tile *ptile, const struct resource *presource);
+void tile_set_resource(struct tile *ptile, struct resource *presource);
 void tile_clear_special(struct tile *ptile, enum tile_special_type spe);
 void tile_clear_all_specials(struct tile *ptile);
 void tile_set_continent(struct tile *ptile, Continent_id val);
Index: common/terrain.c
===================================================================
--- common/terrain.c    (revision 12977)
+++ common/terrain.c    (working copy)
@@ -234,10 +234,10 @@
 /****************************************************************************
   Return the translated name of the resource.
 ****************************************************************************/
-const char *resource_name_translation(const struct resource *presource)
+const char *resource_name_translation(struct resource *presource)
 {
   if (NULL == presource->name_translated) {
-    /* delayed (unified) translation, ignore warning */
+    /* delayed (unified) translation */
     presource->name_translated = ('\0' == presource->name_rule[0])
                           ? presource->name_rule : Q_(presource->name_rule);
   }
Index: common/terrain.h
===================================================================
--- common/terrain.h    (revision 12977)
+++ common/terrain.h    (working copy)
@@ -114,7 +114,7 @@
 
   int output[O_MAX];
 
-  const struct resource **resources; /* NULL-terminated */
+  struct resource **resources; /* NULL-terminated */
 
   int road_trade_incr;
   int road_time;
@@ -186,7 +186,7 @@
 
 struct resource *get_resource_by_number(Resource_type_id id);
 struct resource *get_resource_by_rule_name(const char *name);
-const char *resource_name_translation(const struct resource *presource);
+const char *resource_name_translation(struct resource *presource);
 
 /* Functions to operate on a general terrain type. */
 bool is_terrain_near_tile(const struct tile *ptile,
Index: manual/civmanual.c
===================================================================
--- manual/civmanual.c  (revision 12977)
+++ manual/civmanual.c  (working copy)
@@ -226,7 +226,7 @@
               _("Airbase"), _("Fortress"), _("Rail"),
               _("Clean pollution"), _("Clean fallout"));
       terrain_type_iterate(pterrain) {
-        const struct resource **r;
+        struct resource **r;
 
         if ('\0' == pterrain->name_rule[0]) {
           /* Must be a disabled piece of terrain */
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
--- client/gui-gtk-2.0/helpdlg.c        (revision 12977)
+++ client/gui-gtk-2.0/helpdlg.c        (working copy)
@@ -1046,8 +1046,8 @@
     gtk_label_set_text(GTK_LABEL(help_tlabel[0][4]), buf);
 
     buf[0] = '\0';
-    if (pterrain->resources[0]) {
-      const struct resource **r;
+    if (*(pterrain->resources)) {
+      struct resource **r;
 
       for (r = pterrain->resources; *r; r++) {
        sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
Index: client/gui-xaw/helpdlg.c
===================================================================
--- client/gui-xaw/helpdlg.c    (revision 12977)
+++ client/gui-xaw/helpdlg.c    (working copy)
@@ -979,7 +979,8 @@
 
     buf[0] = '\0';
     if (*(pterrain->resources)) {
-      const struct resource **r;
+      struct resource **r;
+
       for (r = pterrain->resources; *r; r++) {
        sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
       }
Index: client/gui-win32/helpdlg.c
===================================================================
--- client/gui-win32/helpdlg.c  (revision 12977)
+++ client/gui-win32/helpdlg.c  (working copy)
@@ -575,9 +575,10 @@
 
     buf[0] = '\0';
     if (*(pterrain->resources)) {
-      const struct resource **r;
+      struct resource **r;
+
       for (r = pterrain->resources; *r; r++) {
-       sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
+        sprintf (buf + strlen (buf), " %s,", resource_name_translation(*r));
       }
       buf[strlen (buf) - 1] = '.';
     } else {
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to