T
Tristan Miller
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
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