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


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




--- /dev/null	Thu Apr 11 10:25:15 2002
+++ stdbool.h	Thu Jul  3 11:47:14 2003
@@ -0,0 +1,22 @@
+#ifndef _STDBOOL_H_
+#define _STDBOOL_H_
+ 
+#ifndef __cplusplus
+
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#define bool _Bool
+#else
+#define bool char
+#endif
+
+#undef false
+#define false 0
+#undef true
+#define true 1
+
+#define __bool_true_false_are_defined 1
+
+#endif /* !__cplusplus */
+ 
+#endif /* _STDBOOL_H_ */
+

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