[Freeciv-Dev] Re: PATCH change_specialist
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Hi,
Gregor Zeitlinger wrote:
On Mon, 17 Dec 2001, Stewart Adcock wrote:
Maybe:
#if _USE_C99_SOURCE
typedef _Bool boolean;
#else
typedef short boolean;
#endif
great. That's what I was looking for. But int should be more suitable as
it's faster, AFAIK
I doubt that it's faster with any sensible compiler. Of course you can allow the
compiler to make the choice about integer type using "typedef enum {false, true}
boolean;". gcc typically chooses unsigned short for that, I believe.
Adam Olsen wrote:
> On Mon, Dec 17, 2001 at 01:24:17PM -0800, Stewart Adcock wrote:
>
>>Why not use the C99 boolean type when available (i.e. in gcc), which can
>>be checked in the configure script, and default to int, or short, or
>>something otherwise?
>>
>>Maybe:
>>#if _USE_C99_SOURCE
>>typedef _Bool boolean;
>>#else
>>typedef short boolean;
>>#endif
>>
>>Then the compiler will check it, when the feature is available.
>>
>
> I think it's better to use typedef enum {false, true} boolean; since
> then gdb can handle it.
What exactly can't gdb handle about _Bool? Everyone know that false is
0 and true is 1, right? ;)
Of course, the best approach, IMHO, would be to use sdtbool.h, and
create our own stuff if that isn't available. Something like this would
probably do the trick:
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
/* Some platforms already define true and false. To the
* best of my knowledge, it is always safe to zap these.
*/
# ifdef false
# undef false
# undef true
# endif
# ifndef __cplusplus
/* By defining _Bool as an enum type we get to see symbolic
* names in gdb.
*/
typedef enum { false, true } _Bool;
# else
typedef bool _Bool;
# endif
# define bool _Bool
/* According to ISO C99, the boolean stuff must be available
* in preprocessor directives and __bool_true_false_are_defined
* should be true.
*/
# define false 0
# define true 1
# define __bool_true_false_are_defined 1
#endif
Obviously, the check for stdbool.h needs to be added to the configure
script.
Stewart.
--
____________________________________________________________________
Stewart Adcock stewart@xxxxxxxxxxxxxxxx www.stewart-adcock.co.uk
Dept. Chemistry & Biochemistry, University of California, San Diego
4234 Urey Hall, 9500 Gilman Drive, La Jolla, CA 92093-0365 USA
lab: +1 858 534 0956 home: +1 858 453 2577
- [Freeciv-Dev] PATCH change_specialist, Gregor Zeitlinger, 2001/12/16
- [Freeciv-Dev] Re: PATCH change_specialist, Raimar Falke, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist, Gregor Zeitlinger, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist, Raimar Falke, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist, Gregor Zeitlinger, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist, Stewart Adcock, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist, Adam Olsen, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist, Gregor Zeitlinger, 2001/12/17
- [Freeciv-Dev] Re: PATCH change_specialist,
Stewart Adcock <=
- [Freeciv-Dev] Re: PATCH change_specialist, Raimar Falke, 2001/12/18
- [Freeciv-Dev] Re: PATCH change_specialist, Gregor Zeitlinger, 2001/12/18
- [Freeciv-Dev] Re: PATCH change_specialist, Raimar Falke, 2001/12/18
- [Freeciv-Dev] Re: PATCH change_specialist, Reinier Post, 2001/12/17
|
|