stdbool.h

J. Johnston jjohnstn@redhat.com
Thu Jul 3 17:14:00 GMT 2003


Shaun,

   In the future, it would be helpful if you sent patches against /dev/null.
I have modified your version below to:

   1. handle compilers that don't have _Bool
   2. handle cases whereby some application may already have defined true or false

A patch is attached which I can apply if there are no additional comments.

-- Jeff J.

Shaun Jackman wrote:
> I got my hands on a copy of the C99 standard. Section 7.16 is relevant,
> and for one enforces that bool, false, and true have to be defines. Too
> bad; an enum would have been nice.
> 
> Cheers,
> Shaun
> 
> 
> #ifndef _STDBOOL_H_
> #define _STDBOOL_H_
> 
> #ifndef __cplusplus
> #define bool _Bool
> #define false 0
> #define true 1
> #define __bool_true_false_are_defined 1
> #endif
> 
> #endif
> 
> 
> [Excerpt from the C99 standard]
> 7.16  Boolean type and values <stdbool.h>
> 
>        [#1] The header <stdbool.h> defines four macros.
> 
>        [#2] The macro
> 
>                bool
> 
>        expands to _Bool.
> 
>        [#3]  The remaining three macros are suitable for use in #if
>        preprocessing directives.  They are
> 
>                true
> 
>        which expands to the integer constant 1,                     |
> 
>                false
> 
>        which expands to the integer constant 0, and                 |
> 
>                __bool_true_false_are_defined
> 
>        which expands to the decimal constant 1.
> 
>        [#4] Notwithstanding the provisions of 7.1.3, a  program  is
>        permitted  to  undefine and perhaps then redefine the macros
>        bool, true, and false.200)
> 
> 
> On Wed, 2003-07-02 at 13:52, Shaun Jackman wrote:
> 
>>Here's a stdbool.h implementation. I haven't read the C99 standard. So
>>if this misses something, please point it out.
>>
>>Cheers,
>>Shaun
>>
>>
>>#ifndef _STDBOOL_H_
>>#define _STDBOOL_H_
>>
>>typedef enum { false, true } bool;
>>
>>#endif
> 
> 
> 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: stdbool.patch
URL: <http://sourceware.org/pipermail/newlib/attachments/20030703/269cbf57/attachment.ksh>


More information about the Newlib mailing list