public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Definition of 'bool'
@ 2004-09-16 23:07 Matt Jerdonek
  2004-09-16 23:28 ` Gary Thomas
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Matt Jerdonek @ 2004-09-16 23:07 UTC (permalink / raw)
  To: ecos-discuss





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?

Thanks,
-- Matt


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Definition of 'bool'
  2004-09-16 23:07 [ECOS] Definition of 'bool' Matt Jerdonek
@ 2004-09-16 23:28 ` Gary Thomas
  2004-09-17  8:39 ` Lars Viklund
  2004-09-17 10:33 ` Nick Garnett
  2 siblings, 0 replies; 6+ messages in thread
From: Gary Thomas @ 2004-09-16 23:28 UTC (permalink / raw)
  To: Matt Jerdonek; +Cc: ecos-discuss

On Thu, 2004-09-16 at 17:07, Matt Jerdonek wrote:
> 
> 
> 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?

We've been around this bush before, but I don't recall the details.
Have you searched the archives to see if there are any relevant posts?

-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Definition of 'bool'
  2004-09-16 23:07 [ECOS] Definition of 'bool' Matt Jerdonek
  2004-09-16 23:28 ` Gary Thomas
@ 2004-09-17  8:39 ` Lars Viklund
  2004-09-17 10:33 ` Nick Garnett
  2 siblings, 0 replies; 6+ messages in thread
From: Lars Viklund @ 2004-09-17  8:39 UTC (permalink / raw)
  To: Matt Jerdonek; +Cc: ecos-discuss

On Fri, 2004-09-17 at 01:07, Matt Jerdonek wrote:
> 
> 
> 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.

The size of a C++ bool depends on the ABI. It may be one byte or it may
be the same size as an int.

>   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?

If the size of a C++ bool is not the same as the size of an int (the
default in infra/current/include/cyg_type.h) the HAL should #define
cyg_halbool to an appropriate type.

For the Axis CRIS (where sizeof(bool) == 1) we do the following in
basetype.h:

#ifdef __cplusplus
#define cyg_halbool bool
#else
#define cyg_halbool char
#endif

You don't mention which platform you are using, but it sounds like your
HAL should do the same thing.


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Definition of 'bool'
  2004-09-16 23:07 [ECOS] Definition of 'bool' Matt Jerdonek
  2004-09-16 23:28 ` Gary Thomas
  2004-09-17  8:39 ` Lars Viklund
@ 2004-09-17 10:33 ` Nick Garnett
  2 siblings, 0 replies; 6+ messages in thread
From: Nick Garnett @ 2004-09-17 10:33 UTC (permalink / raw)
  To: Matt Jerdonek; +Cc: ecos-discuss

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Definition of 'bool'
  2004-09-16 23:33 Matt Jerdonek
@ 2004-09-16 23:41 ` Gary Thomas
  0 siblings, 0 replies; 6+ messages in thread
From: Gary Thomas @ 2004-09-16 23:41 UTC (permalink / raw)
  To: Matt Jerdonek; +Cc: ecos-discuss

On Thu, 2004-09-16 at 17:33, Matt Jerdonek wrote:
> 
> 
> >>We've been around this bush before, but I don't recall the details.
> >> Have you searched the archives to see if there are any relevant posts?
> 
> I searched on 'boolean' and 'cyg_type.h' in the discussion group, but maybe I missed something?

I gave it a look myself and didn't find anything.  Maybe it was an 
internal discussion (long, long ago).  In any case, I don't recall
the details, sorry - maybe one of my colleagues can help.

-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates


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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ECOS] Definition of 'bool'
@ 2004-09-16 23:33 Matt Jerdonek
  2004-09-16 23:41 ` Gary Thomas
  0 siblings, 1 reply; 6+ messages in thread
From: Matt Jerdonek @ 2004-09-16 23:33 UTC (permalink / raw)
  To: gary; +Cc: ecos-discuss





>>We've been around this bush before, but I don't recall the details.
>> Have you searched the archives to see if there are any relevant posts?

I searched on 'boolean' and 'cyg_type.h' in the discussion group, but maybe I missed something?





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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-09-17 10:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-16 23:07 [ECOS] Definition of 'bool' Matt Jerdonek
2004-09-16 23:28 ` Gary Thomas
2004-09-17  8:39 ` Lars Viklund
2004-09-17 10:33 ` Nick Garnett
2004-09-16 23:33 Matt Jerdonek
2004-09-16 23:41 ` Gary Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).