[ECOS] Definition of 'bool'

Nick Garnett nickg@ecoscentric.com
Fri Sep 17 10:33:00 GMT 2004


Matt Jerdonek <MJerdonek@hypercom.com> writes:

> We recently added some C++ code and encountered a problem with the definition of 'bool'.  In
> infra/include/cyg_type.h, bool is typedef'd as an int, while in C++ a bool is an 8-bit value.  This
> difference causes us problems as when sharing a boolean between C and C++ code because the variable
> is accessed differently.
> 
> I'm wondering if anyone else has seen this problem and how they got around it.  Also, does it make
> sense to change the definition of bool in cyg_type.h to be an 8-bit value?

You cannot share "bool" between C and C++. C does not define a "bool"
type so there is no possible translation. This is why we have defined
"cyg_bool", which should be sharable between languages and is defined
to be an "int".

Note C99 defines "_Bool" and <stdbool.h> defined "bool" to equal
"_Bool". This was standardized well after eCos was written, and found
its way into compilers even later. There is still no requirement for C
and C++ to represent their versions of bool similarly. The only
sensible approach is to pass boolean values via a type that has a
shared representation.

-- 
Nick Garnett                    eCos Kernel Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss



More information about the Ecos-discuss mailing list