stdbool.h and backward compatibility

Discussion in 'C Programming' started by Tristan Miller, Dec 11, 2003.

  1. 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
     
    Tristan Miller, Dec 11, 2003
    #1
    1. Advertising

  2. In article <>,
    Tristan Miller <> 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/
     
    Goran Larsson, Dec 13, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TUxpYmJ5?=

    Netscape - Backward compatibility testing

    =?Utf-8?B?TUxpYmJ5?=, Sep 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    638
    [MSFT]
    Sep 6, 2004
  2. Ben Hinkle

    rationale for #define true 1 in stdbool.h

    Ben Hinkle, Jan 10, 2006, in forum: C Programming
    Replies:
    15
    Views:
    944
    Old Wolf
    Jan 12, 2006
  3. v4vijayakumar

    HTML and Backward compatibility

    v4vijayakumar, Jul 24, 2007, in forum: HTML
    Replies:
    1
    Views:
    372
    David Dorward
    Jul 24, 2007
  4. Philippe DAVID
    Replies:
    0
    Views:
    236
    Philippe DAVID
    Dec 19, 2007
  5. Jorgen Grahn

    stdbool.h

    Jorgen Grahn, Mar 1, 2014, in forum: C Programming
    Replies:
    110
    Views:
    829
    David Brown
    Jun 12, 2014
Loading...

Share This Page