Don wrote:
I am using some C code in my CPP code, like:
extern "C" {
#include "myC_Code.h"
}
CPP Code....
...............
............
My trouble is that some of my C function uses "bool" types. Therefore I
need, in the C files, to include "stdbool.h". But then my compiler reports
an error :-(. Strangely it reports a parsing error.......
Any ideas on how to resolve this issue?
...
Since in C99 language name 'bool' is a typedef-name for built-in type
'_Bool', your C++ compiler will complain when it encounters the 'typedef
_Bool bool' definition in 'stdbool.h'. 'bool' is a keyword in C++.
Maybe in your case the problem can be solved by selectively eliminating
the '#include <stdbool.h>' directive in C++ translation units. Instead
of including 'stdbool.h' unconditionally try doing this
#ifndef __cplusplus
#include <stdbool.h>
#endif /* __cplusplus */
However, I still think that using C99's type 'bool' in dual-language
header files is a bad idea. For example, a the following declaraion
void foo(bool);
when compiled as C99 code will be interpreted as
void foo(_Bool); /* C99's '_Bool' */
and when compiled as C++ it will be interpreted as
void foo(bool); /* C++'s 'bool' */
These are two different function signatures. Strictly speaking, I don't
know what in C++ and C99 standards guarantees that such C++ declaration
will be properly matched with corresponding C definition. As far as I
know, there's no such guarantee (correct me if I'm wrong).
--
Best regards,
Andrey Tarasevich