Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2002:
[Freeciv-Dev] Re: (PR#2461) bool type already exists
Home

[Freeciv-Dev] Re: (PR#2461) bool type already exists

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2461) bool type already exists
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Sun, 1 Dec 2002 10:34:38 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Sun, Dec 01, 2002 at 12:19:43AM -0800, Jason Short via RT wrote:
> 
> Someone was trying to compile freeciv-test (SDL client) on a BeOS
> variant.  They got the following error:
> 
> <[Be]rnd>  gcc -DHAVE_CONFIG_H -I. -I. -I.. -I../intl    -g -Wall
> -Wno-multichar -c `test -f 'connection.c' || echo './'`connection.c
> <[Be]rnd>  In file included from
> /boot/develop/headers/be/kernel/OS.h:15,
> <[Be]rnd>                   from
> /boot/develop/headers/be/bone/netinet/in.h:49,
> <[Be]rnd>                   from
> /boot/home/Entwicklung/Sourcecodes/freeCIV_SDL/freeciv-test/common/netintf.h:38,
> <[Be]rnd>                   from
> /boot/home/Entwicklung/Sourcecodes/freeCIV_SDL/freeciv-test/common/connection.c:43:
> <[Be]rnd>  /boot/develop/headers/posix/be_prim.h:73: error: conflicting
> types for `bool'
> <[Be]rnd> 
> /boot/home/Entwicklung/Sourcecodes/freeCIV_SDL/freeciv-test/common/shared.h:44:
>  error: previous declaration of `bool'
> <[Be]rnd>  make[2]: *** [connection.o] Error 1
> <[Be]rnd>  make[2]: Leaving directory
> `/boot/home/Entwicklung/Sourcecodes/freeCIV_SDL/freeciv-test/common'
> <[Be]rnd>  make[1]: *** [all-recursive] Error 1
> <[Be]rnd>  make[1]: Leaving directory
> `/boot/home/Entwicklung/Sourcecodes/freeCIV_SDL/freeciv-test'
> <[Be]rnd>  make: *** [all] Error 2
> <[Be]rnd>  $ 
> 
> Indicating that 'bool' was already defined in the system headers.  It is
> typedefed as unsigned char.
> 
> I see two choices:
> 
> - Use fc_bool instead of bool.  That way we don't interfere with anyone
> else.  But people will forget to use it.  And IMO it is less readable.
> 
> - Check for the 'bool' type in configure, and define HAVE_BOOL based on
> this.  The downside here is that the check may not be trivial, since we
> don't know what header it might be in.
> 
> I much prefer the second solution.
> 
> There may be a problem with TRUE and FALSE as well (although not in this
> case, apparently).  It might be productive to use
> 
>   #define TRUE ((bool)1)
>   #define FALSE ((bool)0)
> 
> to help in type checking.  Or, perhaps this will just give spurious
> problems...

Please try the attached patch.

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  Microsoft does have a year 2000 problem. I'm part of it. I'm running Linux.

Index: configure.in
===================================================================
RCS file: /home/freeciv/CVS/freeciv/configure.in,v
retrieving revision 1.205
diff -u -r1.205 configure.in
--- configure.in        2002/11/30 20:42:01     1.205
+++ configure.in        2002/12/01 18:32:17
@@ -547,7 +547,8 @@
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h sys/time.h sys/types.h unistd.h sys/utsname.h)
+AC_CHECK_HEADERS(fcntl.h sys/time.h sys/types.h unistd.h sys/utsname.h \
+                 stdbool.h)
 dnl Avoid including the unix emulation layer if we build mingw executables
 dnl There would be type conflicts between winsock and bsd/unix includes
 if test "x$MINGW32" != "xyes"; then
Index: common/shared.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/shared.h,v
retrieving revision 1.106
diff -u -r1.106 shared.h
--- common/shared.h     2002/11/21 13:35:31     1.106
+++ common/shared.h     2002/12/01 18:32:32
@@ -15,6 +15,19 @@
 
 #include <stdlib.h>            /* size_t */
 
+#ifdef HAVE_STDBOOL_H
+#include <stdbool.h>
+#else /* Implement <stdbool.h> ourselves */
+#undef bool
+#undef true
+#undef false
+#undef__bool_true_false_are_defined
+#define bool fc_bool
+#define true  1
+#define false 0
+#define __bool_true_false_are_defined 1
+typedef unsigned int fc_bool;
+#endif /* ! HAVE_STDBOOL_H */
 
 /* Want to use GCC's __attribute__ keyword to check variadic
  * parameters to printf-like functions, without upsetting other
@@ -46,15 +58,9 @@
 /* Use FC_INFINITY to denote that a certain event will never occur or
    another unreachable condition. */
 #define FC_INFINITY            (1000 * 1000 * 1000)
-
-#ifndef TRUE
-#define TRUE (1)
-#endif
-#ifndef FALSE
-#define FALSE (0)
-#endif
 
-typedef int bool;
+#define TRUE true
+#define FALSE false
 
 #ifndef MAX
 #define MAX(x,y) (((x)>(y))?(x):(y))

[Prev in Thread] Current Thread [Next in Thread]