This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: stdbool.h


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]