<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>enum type mixed with another type</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/19966/enum-type-mixed-with-another-type</link><description> 
I&amp;#39;m getting a warning &amp;quot;enumeration type mixed with another type&amp;quot;
with the following line of code. 

 
typedef enum { FALSE = 0, TRUE = !FALSE } bool;

bool bResult;
bool bAAA;
bool bBBB;

bResult = bAAA &amp;amp;&amp;amp; bBBB; // &amp;lt;-- warning

bResult = (bAAA == TRUE</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: enum type mixed with another type</title><link>https://community.arm.com/thread/88085?ContentTypeID=1</link><pubDate>Sun, 24 Dec 2006 03:37:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dcd80d19-083b-41d8-aa35-198bda0f3b26</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;&amp;quot;The &lt;b&gt;&amp;amp;&amp;amp;&lt;/b&gt; operator ... returns 1 if both its
operands compare unequal to zero, 0 otherwise.&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
That&amp;#39;s the point - it takes arguments of type &lt;b&gt;int&lt;/b&gt;, and
returns a result of type &lt;b&gt;int&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;
The code you showed is using your &amp;quot;bool&amp;quot; &lt;b&gt;enum&lt;/b&gt; type; not
&lt;b&gt;int&lt;/b&gt; - hence the compiler warns you,&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;enumeration type mixed with another type&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
The &amp;quot;other type&amp;quot; in this case is, of course, &lt;b&gt;int&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;
You missed section A4.2 in K&amp;amp;R:&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;Enumerations behave like integers, but it is common for a
compiler to issue a warning when an object of a particular
enumeration type is assigned something other than one of its
constants, or an expression of its type&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
The way to get around such warnings is always to use an
appropriate explicit cast.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;&amp;quot;code should now be safer with this convension&amp;quot;&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Not really.&lt;br /&gt;
I don&amp;#39;t think it makes any difference at all to the safety here, but
it does have the disadvantage that the compiler can no longer produce
symbolic debug information for the &lt;b&gt;enum&lt;/b&gt; type.&lt;/p&gt;

&lt;p&gt;
For safety, I think the explicit cast is probably the way to go -
as it makes your intention fully clear.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: enum type mixed with another type</title><link>https://community.arm.com/thread/47465?ContentTypeID=1</link><pubDate>Sun, 24 Dec 2006 01:08:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:737faf58-a121-414d-bae2-ea2136792064</guid><dc:creator>barry gordon</dc:creator><description>&lt;p&gt;&lt;p&gt;
I just reviewed ritchie &amp;amp; kernie. Section A7.14: &amp;quot;The
&amp;amp;&amp;amp; operator groups left-to-right. It returns 1 if both its
operands compare unequal to zero, 0 otherwise.&amp;quot;&lt;/p&gt;

&lt;p&gt;
The logic operation is returning a 1 or 0 and its being assigned
to a bool (defined by the enum). If I perform the following, the
warning is removed:&lt;/p&gt;

&lt;pre&gt;
bResult = (bAAA &amp;amp;&amp;amp; bBBB) ? TRUE : FALSE;
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
Since I&amp;#39;m including STR 73x_type.h in my code (located in my common
project space), I made the following changes.&lt;/p&gt;

&lt;pre&gt;
#ifdef __PROJECT__
typedef u16 bool;
#define FALSE 0
#define TRUE 1
#else
typedef enum { FALSE = 0, TRUE != FALSE } bool;
#endif
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
Compiles without the warning and my code should now be safer with
this convension. __PROJECT__ is defined in the project file.&lt;/p&gt;

&lt;p&gt;
Thanks&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: enum type mixed with another type</title><link>https://community.arm.com/thread/98765?ContentTypeID=1</link><pubDate>Sat, 23 Dec 2006 04:25:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fd2331f4-7420-42b3-a748-42f11fad1ad1</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;a href="http://c-faq.com/bool/index.html"&gt;c-faq.com/.../index.html&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: enum type mixed with another type</title><link>https://community.arm.com/thread/88084?ContentTypeID=1</link><pubDate>Sat, 23 Dec 2006 03:34:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e42cbba5-c2d5-434b-a6d0-d03cd5f3b4ae</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;pre&gt;
typedef enum
{
   FALSE = 0,      // Fine
   TRUE  = !FALSE  // Risky
} bool;
&lt;/pre&gt;

&lt;p&gt;
The &amp;#39;C&amp;#39; language treats 0 as &amp;quot;false&amp;quot;, but &lt;b&gt;&lt;i&gt;any&lt;/i&gt;&lt;/b&gt;
non-zero value as &amp;quot;true&amp;quot;&lt;/p&gt;

&lt;p&gt;
Therefore beware of making any direct comparison to &amp;#39;TRUE&amp;#39;...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: enum type mixed with another type</title><link>https://community.arm.com/thread/47464?ContentTypeID=1</link><pubDate>Sat, 23 Dec 2006 03:31:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cc1a459f-6adf-4ea6-9ef7-c7671839de20</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
The is standard &amp;#39;C&amp;#39; - nothing to do with Keil nor ARM.&lt;/p&gt;

&lt;p&gt;
Look up the &lt;b&gt;&amp;amp;&amp;amp;&lt;/b&gt; operator in your &amp;#39;C&amp;#39; text book -
what does it tell you about the types of the arguments that it
expects and returns...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>