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
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#2461) bool type already exists
From: "Raimar Falke via RT" <rt@xxxxxxxxxxxxxx>
Date: Mon, 2 Dec 2002 12:44:13 -0800
Reply-to: rt@xxxxxxxxxxxxxx

On Sun, Dec 01, 2002 at 11:04:44AM -0800, Raimar Falke via RT wrote:
>        7.1.7  Boolean type and values <stdbool.h>
> 
>        [#1] The header  <stdbool.h>  defines  one  type  and  three
>        macros.
> 
>        [#2] The type is
> 
>                bool
> 
>        which is an integer type that promotes to  int  or  unsigned
>        int,  and  that is suitable to be used as the type of a bit-
>        field.  A bit-field of any width  and  type  bool  shall  be
>        capable for representing the value 1.138
> 
> 
>        __________
> 
>        138. The  traditional choice for type bool has been int, but
>            this  is  not  a  requirement  of   this   International
>            Standard.   Other available choices include, but are not
>            limited to, char, unsigned int, and an enumeration type.
> 
>            If an enumeration type is chosen, the names of its  true
>            and  false  members  are "masked" by the macros true and
>            false, but the member names might be  available  to  the
>            debugger:
> 
>            typedef enum { false=0, true=1 } bool;
>            #define false 0
>            #define true 1
> 
>            The type is  suitable  for  bit-fields  if  it  is  int,
>            unsigned  int,  signed  int,  or some type allowed by an
> 
>        [#3] The macros are
> 
>                true
> 
>        which expands to the decimal constant 1,
> 
>                false
> 
>        which expands to the decimal constant 0, and
> 
>                __bool_true_false_are_defined
> 
>        which expands to the decimal constant  1.   The  macros  are
>        suitable for use in #if preprocessing directives.

In addition to the above (I only had a working draft from 97 and now I
have one from 98 but still not the final one) it looks like the final
C99 also contains the following:

       [#2] An object declared as type _Bool  is  large  enough  to
       store the values 0 and 1.
...
       6.3.1.2  Boolean type

       [#1] When any scalar value is converted to _Bool, the result
       is 0 if the value compares equal to 0; otherwise, the result
       is 1.

This basically means that the bool type (_Bool) is a first level type
(it is for example a reserved keyword like for example "char", "auto",
"inline" or "if").

The second point above means that if you run this code:

#include <stdio.h>

int main()
{
  _Bool a, b = 23;
  int i = 45;

  a = i;

  printf("%d %d %d\n", b, i, a);
  return 0;
}

You get 
1 45 1
and not
23 45 45
which you would get if you use a simple typedef.

We shouldn't rely on this behavior (this isn't hard).

        Raimar

-- 
 email: rf13@xxxxxxxxxxxxxxxxx
  "Windows is the one true OS. MS invented the GUI. MS invented 
   the 32 bit OS. MS is open and standard. MS loves you. We have 
   always been at war with Oceana."



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