Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2004:
[Freeciv-Dev] (PR#11255) Disabling bool definition for C++
Home

[Freeciv-Dev] (PR#11255) Disabling bool definition for C++

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11255) Disabling bool definition for C++
From: "Frédéric Brière" <fbriere@xxxxxxxxxxx>
Date: Mon, 29 Nov 2004 13:20:07 -0800
Reply-to: rt@xxxxxxxxxxx

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

The attached patch disables the definition of bool in shared.h for C++.
Although care is taken to #define bool instead of typedef it (which
neatly solves the reserved keyword issue), it eventually must be
undef'ed later to avoid conflicts with other C++ declarations.  The
problem is that shared.h can only be included once, so:


In foo.h:

  extern "C" {
  #include "shared.h"
  bool fc_foo;  /* Freeciv bool */
  #undef bool
  }

  bool foo();  /* C++ bool -- can't live without it */


In bar.h:

  #include "foo.h"

  extern "C" {
  #include "shared.h"  /* Already included */
  bool fc_bar;  /* C++ bool -- oops! */
  }


(I'm ashamed to admit it took me several hours to figure this out.)


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

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

Index: utility/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/utility/shared.h,v
retrieving revision 1.138
diff -u -r1.138 shared.h
--- utility/shared.h    26 Nov 2004 22:28:43 -0000      1.138
+++ utility/shared.h    29 Nov 2004 20:55:04 -0000
@@ -27,6 +27,7 @@
 #include <posix/be_prim.h>
 #define __bool_true_false_are_defined 1
 #else
+#ifndef __cplusplus
 #ifdef HAVE_STDBOOL_H
 #include <stdbool.h>
 #else /* Implement <stdbool.h> ourselves */
@@ -40,6 +41,7 @@
 #define __bool_true_false_are_defined 1
 typedef unsigned int fc_bool;
 #endif /* ! HAVE_STDBOOL_H */
+#endif /* __cplusplus */
 #endif /* ! __BEOS__ */
 
 /* Want to use GCC's __attribute__ keyword to check variadic

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11255) Disabling bool definition for C++, Frédéric Brière <=