bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with stdbool.h redefining true/false even in C++


From: Daniel J Sebald
Subject: Re: Problem with stdbool.h redefining true/false even in C++
Date: Wed, 29 Aug 2012 13:59:03 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 08/29/2012 01:27 PM, John W. Eaton wrote:
On 29-Aug-2012, Bastien ROUCARIES wrote:

| n Wed, Aug 29, 2012 at 7:36 PM, John W. Eaton<address@hidden>  wrote:
|>  On 29-Aug-2012, Paul Eggert wrote:
|>
|>  | On 08/29/2012 10:00 AM, John W. Eaton wrote:
|>  |>  Why define true, false, and bool to anything when using C++?
|>  |
|>  | Maybe it's for '#ifdef bool' but to be honest I'm just doing what
|>  | GCC does.  Perhaps you can ask the GCC developers why they do did
|>  | it that way....
|>  |
|>  | Anyway, I'd be surprised if Octave cares whether true, false, and bool
|>  | are macros.  If it does, then it's broken on GNUish hosts anyway,
|>  | right?  And if it doesn't, the gnulib patch should work as-is.
|>
|>  No, I don't think Octave currently has any checks like this.
|>
|>  For C++ code, I think '#ifdef bool' will be false.  So
|>  '#define bool bool' switches the meaning.  Should that happen if
|>  stdbool.h has been included?  I don't know.
|
| echo -e "#include<stdbool.h>  \n #ifdef bool \n echo \n#endif" | g++ -E -
|
| # 1 "<stdin>"
| # 1 "<built-in>"
| # 1 "<command-line>"
| # 1 "<stdin>"
| # 1 "/usr/lib/gcc/x86_64-linux-gnu/4.6/include/stdbool.h" 1 3 4
| # 2 "<stdin>" 2
|
|  echo

I understand that this is what currently happens.  I'm just wondering
if that is really the right thing.

g++ -E, nice...

This bool conundrum came up in gnuplot discussions as well. With the wxt/qt gnuplot terminal being in C++ there's now a mix of code where it used to be solely C. When someone inquired about _Bool/bool, I too thought "It's C++, just use 'bool'".

I'm none the wiser at this point, but I see some statements on the topic in this wiki:

http://en.wikipedia.org/wiki/Compatibility_of_C_and_C%2B%2B

From what I'm reading, my conclusion too would be that under the condition of compiling C++ code:

1) _Bool should be defined for C99 compatibility
2) bool, true, and false should only be defined if <stdbool.h> is included

Note that on my system.

address@hidden ~]$ echo -e "#include <stdbool.h> \n #ifdef bool \n echo \n#endif" | g++ -E -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
# 1 "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stdbool.h" 1 3 4
# 2 "<stdin>" 2

 echo
address@hidden ~]$ echo -e "#include <stdbool.h> \n #ifdef _Bool \n echo \n#endif" | g++ -E -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
# 1 "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stdbool.h" 1 3 4
# 2 "<stdin>" 2
address@hidden ~]$ echo -e "#include <stdbool.h> \n #ifdef __bool_true_false_are_defined \n echo \n#endif" | g++ -E -
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "<stdin>"
# 1 "/usr/lib/gcc/x86_64-redhat-linux/4.5.1/include/stdbool.h" 1 3 4
# 2 "<stdin>" 2

 echo

I'm wondering why I'm not seeing the test for _Bool defined as true (i.e., the second command above). The contents of "stdbool.h" above is:

#else /* __cplusplus */

/* Supporting <stdbool.h> in C++ is a GCC extension.  */
#define _Bool   bool
#define bool    bool
#define false   false
#define true    true

Dan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]