Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11213) Making client headers compatible with C++
Home

[Freeciv-Dev] (PR#11213) Making client headers compatible with C++

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11213) Making client headers compatible with C++
From: "Frédéric Brière" <fbriere@xxxxxxxxxxx>
Date: Fri, 26 Nov 2004 16:29:01 -0800
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=11213 >

I've started working on a QPE/Qtopia/OPIE Freeciv client to run on the
Zaurus (and possibly other PDAs), based on Rob Fisher's earlier work.
(His version is at <http://www.robfisher.net/zaurus/freeciv.html>.)

Since Qt/Embedded requires writing this client in C++, I've hit a few
snags where some Freeciv header files weren't compatible.  Although I
believe bool is a lost battle (I'll content myself to #define it to int
before any #include), the rest shouldn't be too hard to fix.  I'm
attaching a patch for some small stuff, but there are three issues that
will require renaming or moving things:


1.  client/citydlg_common.h has a definition of struct citizen_type that
    includes an anonymous enum, with CITIZEN_LAST as one of its values.
    C++ therefore restricts the scope of CITIZEN_LAST to the enclosing
    struct.  However, there is an instance of it in client/tilespec.h
    (through a #define as NUM_TILES_CITIZEN), so the enum needs to be
    taken out of the struct.  (I'm not familiar with Freeciv's naming
    policy, but if you let me know what this enum should be called, I
    can provide a patch.)

2.  common/fc_types.h typedefs Specialist_type_id as an enum
    specialist_type, which hasn't been defined at that point.  This
    isn't allowed in C++, as enums are no longer of fixed size.
    Unfortunately, common/city.h #includes fc_types.h *before* defining
    enum specialist_type, so there's a circular dependency.  Breaking it
    will involve either moving the enum, moving the typedef, or
    replacing the typedef with a #define.  (I can confirm that the last
    option works, but I suspect you'll want to try a more elegant
    approach.)

3.  common/nation.h defines struct nation_type as having a member named
    class, which is a reserved keyword in C++.  There are several
    occurrences of it in seven other files, so the renaming will be a
    bit more intrusive.  (I hope you won't mind.)  I can provide a patch
    if I'm told what to rename this member to.


-- 
             Frédéric Brière    <*>    fbriere@xxxxxxxxxxx

 =>  <fbriere@xxxxxxxxxx> IS NO MORE:  <http://www.abacomsucks.com>  <=

diff -ruN freeciv-2.0.0-beta4/client/climisc.h tmp/client/climisc.h
--- freeciv-2.0.0-beta4/client/climisc.h        2004-09-28 22:24:56.000000000 
-0400
+++ tmp/client/climisc.h        2004-11-26 18:04:31.000000000 -0500
@@ -78,7 +78,11 @@
 bool city_building_present(struct city *pcity, cid cid);
 
 struct item {
+#ifdef __cplusplus
+  ::cid cid;
+#else
   cid cid;
+#endif
   char descr[MAX_LEN_NAME + 40];
 
   /* Privately used for sorting */
diff -ruN freeciv-2.0.0-beta4/utility/speclist.h tmp/utility/speclist.h
--- freeciv-2.0.0-beta4/utility/speclist.h      2004-09-17 19:37:11.000000000 
-0400
+++ tmp/utility/speclist.h      2004-11-26 14:43:33.000000000 -0500
@@ -98,7 +98,7 @@
 
 static inline SPECLIST_TYPE *SPECLIST_FOO(_list_get) (const SPECLIST_LIST 
*tthis, int index)
 {
-  return genlist_get(&tthis->list, index);
+  return (SPECLIST_TYPE *)genlist_get(&tthis->list, index);
 }
 
 static inline void SPECLIST_FOO(_list_insert_back) (SPECLIST_LIST *tthis, 
SPECLIST_TYPE *pfoo)
diff -ruN freeciv-2.0.0-beta4/utility/specvec.h tmp/utility/specvec.h
--- freeciv-2.0.0-beta4/utility/specvec.h       2004-09-25 21:15:45.000000000 
-0400
+++ tmp/utility/specvec.h       2004-11-26 14:43:33.000000000 -0500
@@ -93,7 +93,7 @@
   if (size > tthis->size_alloc) {
     int new_size = MAX(size, tthis->size_alloc * 2);
 
-    tthis->p = fc_realloc(tthis->p, new_size * sizeof(*tthis->p));
+    tthis->p = (SPECVEC_TYPE *)fc_realloc(tthis->p, new_size * 
sizeof(*tthis->p));
     tthis->size_alloc = new_size;
   }
   tthis->size = size;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11213) Making client headers compatible with C++, Frédéric Brière <=