Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#600 Patch for problems with _Bool

open
nobody
None
5
2013-02-10
2012-08-28
Mojca Miklavec
No

I'm attaching a tentative patch for problems with _Bool as reported at various places:
* http://lists.macosforge.org/pipermail/macports-users/2012-August/030311.html
* http://sourceforge.net/tracker/?func=detail&atid=102055&aid=3538084&group_id=2055
* http://sourceforge.net/tracker/?func=detail&atid=102055&aid=3129839&group_id=2055
* http://sourceforge.net/tracker/?func=detail&atid=102055&aid=2995024&group_id=2055
* http://sourceforge.net/tracker/?func=detail&atid=102055&aid=2915835&group_id=2055

I believe that it should solve problems for all platforms involved, but it definitely needs testing as I'm not 100% confident in its correctness.

The problem with current approach is that it relies on _Bool being present in C++ when it is actually only present in C, and then uses nonexistent "_Bool" instead of existing "bool" when in C++.

So here's my suggestion for the code that deals with boolean values:

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

On Sparc Solaris it worked as expected.

Please keep in mind that until recently there would be (were?) bug reports as a consequence of a bug in autotools.

Currently gnuplot really behaves wrong in respect to _Bool, but the buggy behaviour only manifests itself when stdbool.h doesn't comply with C99 standard.

Discussion

  • Mojca Miklavec
    Mojca Miklavec
    2012-08-28

    Actually, true & false should only be defined for C, so a slight correction:

    #if HAVE_STDBOOL_H
    # include <stdbool.h>
    #else
    # ifndef __cplusplus
    # if ! HAVE__BOOL
    typedef unsigned char _Bool;
    # endif
    # define bool _Bool
    # define false 0
    # define true 1
    # endif
    // the line below is probably not needed
    # define __bool_true_false_are_defined 1
    #endif

    For comparison, this is what one of Apple's recent stdbool.h does (but gnuplot doesn't really have to define _Bool in C++, does it?):

    /* Don't define bool, true, and false in C++, except as a GNU extension. */
    #ifndef __cplusplus
    #define bool _Bool
    #define true 1
    #define false 0
    #elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
    /* Define _Bool, bool, false, true as a GNU extension. */
    #define _Bool bool
    #define bool bool
    #define false false
    #define true true
    #endif

    #define __bool_true_false_are_defined 1

     
  • Mojca Miklavec
    Mojca Miklavec
    2012-08-28

    Patch for problems with _Bool in C++

     
    Attachments