clang++ and C _Bool

641 views
Skip to first unread message

r0ller

unread,
Oct 17, 2014, 10:38:57 AM10/17/14
to min...@googlegroups.com
Hi All,

Just for the record and if anyone cares. This is not a minix issue at all but due to the fact that previously I had some discussion about it here, someone may be interested in it since gcc is currently not available on 3.3.0. One important thing I missed with the example C code: it was pure C while I had problems when using C lib header in C++ source. So the key was to compile it with clang++. The small test provided back then complies fine with clang but when compiled with clang++ adding on top the -ansi option (which I also used when compiling my project), the error "error: unknown type name '_Bool' " appears. If the -ansi option is not specified, it compiles fine with clang++ as well.

There are two interesting links I found about it:


which contains a commented section:

3// Test stdbool.h's _Bool
4
5// Prior to C99, stdbool.h uses this typedef, but even in ANSI C mode, _Bool
6// appears to be defined.
7
8// #if __STDC_VERSION__ < 199901L
9// typedef int _Bool;
10

// #endif

The other one:

http://clang-developers.42468.n3.nabble.com/How-to-use-Bool-td3925833.html

I haven't gone any deeper into these after finding the solution (i.e. omit -ansi) so don't ask me what they imply:) A last remark: on 3.2.1 clang++ produces the same problem while interestingly enough g++ doesn't have any issues with _Bool even when the -ansi option is specified.

Regards,

r0ller

Antoine LECA

unread,
Oct 20, 2014, 8:57:15 AM10/20/14
to min...@googlegroups.com
On 2014-10-17 14:38Z, r0ller wrote:
> was to compile it with clang++. The small test provided back then
> complies fine with clang but when compiled with clang++ adding on top
> the -ansi option (which I also used when compiling my project), the
> error "error: unknown type name '_Bool' " appears. If the -ansi option
> is not specified, it compiles fine with clang++ as well.

Seems somehow logical, if you consider that -ansi is supposed to be an
alias to --std=c89 (for the C compiler at least.)
And _Bool is a C99 thing, it was absent from the C89/C90 Standard.

Also, I am not sure how well _Bool plays with the C++ Standard.
I believe you are supposed to use bool in C++ code; and if you need
compatibility with C here, then #include <stdbool.h>, perhaps protected
with #ifndef __bool_true_false_are_defined, this is its very purpose.


Antoine

r0ller

unread,
Oct 20, 2014, 10:21:53 AM10/20/14
to min...@googlegroups.com
Hi Antoine,

Yepp, that's what I'm doing (I mean including stdbool.h) in my project due to the C lib header I'm using and within my own C++ source I stick to the C++ bool. But it's still surprising that clang++ and g++ react differently on the -ansi option concerning _Bool:)

Regards,
r0ller
Reply all
Reply to author
Forward
0 new messages