Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] (PR#12458) avoid multi-field C99 initializers
Home

[Freeciv-Dev] (PR#12458) avoid multi-field C99 initializers

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12458) avoid multi-field C99 initializers
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 7 Mar 2005 22:04:33 -0800
Reply-to: bugs@xxxxxxxxxxx

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

I don't know what to call them other than "multi-field inititializers". 
  gcc 2.95 doesn't support initializers like

   struct foo_struct foo = {.a.b = 5};

but does support nested/recursive forms of the C99 standard like

   stcut foo_struct foo = {.a = {.b = 5}};

this patch rewrites all instances of the former to be like the latter. 
This should allow freeciv to compile on gcc 2.95 (and perhaps other 
compilers, who knows...).

-jason

? foo.c
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.201
diff -u -r1.201 aicity.c
--- ai/aicity.c 8 Mar 2005 00:43:26 -0000       1.201
+++ ai/aicity.c 8 Mar 2005 06:02:34 -0000
@@ -247,7 +247,7 @@
   struct government *gov = get_gov_pplayer(pplayer);
   struct req_source source = {
     .type = REQ_BUILDING,
-    .value.building = id
+    .value = {.building = id}
   };
 
   /* Base want is calculated above using a more direct approach. */
Index: ai/aidata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aidata.c,v
retrieving revision 1.53
diff -u -r1.53 aidata.c
--- ai/aidata.c 5 Mar 2005 13:37:04 -0000       1.53
+++ ai/aidata.c 8 Mar 2005 06:02:34 -0000
@@ -61,7 +61,7 @@
   impr_type_iterate(id) {
     struct req_source source = {
       .type = REQ_BUILDING,
-      .value.building = id
+      .value = {.building = id}
     };
 
     ai->impr_calc[id] = AI_IMPR_ESTIMATE;
Index: client/gui-gtk-2.0/spaceshipdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/spaceshipdlg.c,v
retrieving revision 1.16
diff -u -r1.16 spaceshipdlg.c
--- client/gui-gtk-2.0/spaceshipdlg.c   4 Mar 2005 17:42:55 -0000       1.16
+++ client/gui-gtk-2.0/spaceshipdlg.c   8 Mar 2005 06:02:34 -0000
@@ -279,7 +279,7 @@
 void spaceship_dialog_update_image(struct spaceship_dialog *pdialog)
 {
   struct canvas store = {.type = CANVAS_PIXMAP,
-                        .v.pixmap = pdialog->image_canvas->window};
+                        .v = {.pixmap = pdialog->image_canvas->window}};
 
   put_spaceship(&store, 0, 0, pdialog->pplayer);
 }
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.23
diff -u -r1.23 effects.c
--- common/effects.c    7 Feb 2005 23:14:23 -0000       1.23
+++ common/effects.c    8 Mar 2005 06:02:35 -0000
@@ -380,7 +380,7 @@
   for (i = 0; i < ARRAY_SIZE(ruleset_cache.reqs.buildings); i++) {
     struct req_source source = {
       .type = REQ_BUILDING,
-      .value.building = i
+      .value = {.building = i}
     };
     struct effect_list *plist = get_req_source_effects(&source);
 
@@ -802,7 +802,7 @@
 
     struct req_source source = {
       .type = REQ_BUILDING,
-      .value.building = id
+      .value = {.building = id}
     };
     struct effect_list *plist = get_req_source_effects(&source);
 
Index: m4/c99.m4
===================================================================
RCS file: /home/freeciv/CVS/freeciv/m4/c99.m4,v
retrieving revision 1.5
diff -u -r1.5 c99.m4
--- m4/c99.m4   27 Jan 2005 02:14:40 -0000      1.5
+++ m4/c99.m4   8 Mar 2005 06:02:35 -0000
@@ -48,9 +48,14 @@
 
 # Check C99-style initializers (required):
 #
-# struct timeval tv = {.tv_sec = 0, .tv_usec = 500000};
-# int fibonacci[6] = {[0] = 0, [1] = 1, [2] = 1, [3] = 2, [4] = 3, [5] = 5};
-#
+# Examples:
+#   struct timeval tv = {.tv_sec = 0, .tv_usec = 500000};
+#   int fibonacci[6] = {[0] = 0, [1] = 1, [2] = 1, [3] = 2, [4] = 3, [5] = 5};
+# Note we do not check for multi-field initializers like
+#   struct { struct { int b; } a; } = {.a.b = 5}
+# which are not supported by many compilers.  It is best to avoid this
+# problem by writing these using nesting.  The above case becomes
+#   struct { struct { int b; } a; } = {.a = {.b = 5}}
 AC_DEFUN([AC_C99_INITIALIZERS],
 [
   dnl Check for C99 initializers
@@ -66,7 +71,6 @@
         ],
         [struct foo bar = {.an_array = {0, [3] = 2, [2] = 1, [4] = 3},
                            .an_integer = 999,
-                           .an_array[1] = 1,
                            .a_string = "does it work?",
                            .a_union = {.y = 243}};],
         [ac_cv_c99_initializers=yes],

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12458) avoid multi-field C99 initializers, Jason Short <=