473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

stdbool.h and backward compatibility

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
1 3233
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vyacheslav Lanovets | last post by:
Hello, All! Installed VS 2005... What is annoying is that project files are not backward compatible. For instance, EVC4 vcp files are backward compatible with EVC3 and can be used...
2
by: Neal Becker | last post by:
How can I write code to take advantage of new decorator syntax, while allowing backward compatibility? I almost want a preprocessor. #if PYTHON_VERSION >= 2.4 @staticmethod ....
1
by: Dev | last post by:
Dear Friends, I have created VC++.NET dll by VS.NET2003.Is it possible to use this dll(vs.net2003) into C# version (Vs.net2002)? Is there backward compatibility? If so ..How do to this?..If...
2
by: Dominic | last post by:
Hi everybody, I'm planning to use serialization to persist an object (and possibly its child objects) in my application. However, I'm concerned about the backward compatibility issue. I'm...
1
by: MLibby | last post by:
I'm a Netscape newbie and am using it for backward compatibility testing. How do I debug javascript in Netscape? I set Netscape as the default debugger (design mode | file | Browse With) and I am...
3
by: Madhu | last post by:
We are having a dll backward compatibility issue since we migrated to .NET 2005. As part of our product, we build a dll which is used by other products. Everything was fine when we were build it...
0
by: bhargav mandlem | last post by:
hi friends i have created VC++.NET dll by VS.NET2003.Is it possible to use this dll(vs.net2003) into C# version (Vs.net2002)? Is there backward compatibility? If so ..How do to this?..If anyone...
2
by: Ernesto Bascón | last post by:
Hi: I've read some about the pimpl idiom and I know that it provides safe ABI backward compatibility on shared libraries. Let's consider the following definitions: template <class T> class...
7
by: Ernesto Bascón | last post by:
Hi everybody: I want to develop a library that uses heavily templates. Is there an idiom or some tips about things that I should care of in order to provide backward compatibility with my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.