By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,214 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

stdbool.h and backward compatibility

P: n/a
Greetings.

I have a program written in C99 which uses the bool, true, and false
definitions from <stdbool.h>. Without rewriting the code, I'd like to
make this program compatible with C89. I'm using GNU Autoconf, whose
configure script will automatically do a #define HAVE_STDBOOL_H 1 if
the user's compiler has a C99-conformant <stdbool.h> and a #define
HAVE__BOOL 1 if the user's compiler provides a type _Bool. The
Autoconf manual seems to suggest that the following code be used in
one's program instead of #include <stdbool.h>:

#if HAVE_STDBOOL_H
# include <stdbool.h>
#else
# if ! HAVE__BOOL
# ifdef __cplusplus
typedef bool _Bool;
# else
typedef unsigned char _Bool;
# endif
# endif
# define bool _Bool
# define false 0
# define true 1
# define __bool_true_false_are_defined 1
#endif

Is this good advice? Specifically, how wise is it to be #defining a
preprocessor macro with two leading underscores? I thought such macros
were reserved for the implementation. What's the purpose of this
macro, anyway? It's not referred to anywhere else in the Autoconf
documentation, so am I correct in thinking it's required by the quirk
of some specific implementation that ought to be compensated for?

Regards,
Tristan

--
_
_V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
/ |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
(7_\\ http://www.nothingisreal.com/ >< To finish what you
Nov 14 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
In article <58****************@ID-187157.news.dfncis.de>,
Tristan Miller <ps********@nothingisreal.com> wrote:
# define bool _Bool
# define false 0
# define true 1
# define __bool_true_false_are_defined 1 Is this good advice? Specifically, how wise is it to be #defining a
preprocessor macro with two leading underscores? I thought such macros
were reserved for the implementation. What's the purpose of this
macro, anyway?


The purpose of the __bool_true_false_are_defined macro is to
mimic the ISO/IEC 9899:1999 standard.

From ISO/IEC 9899:1999, 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 integer constant 1.

--
Göran Larsson http://www.mitt-eget.com/
Nov 14 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.