<?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>Use of C&amp;#39;s enum command with C166 compiler</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/13935/use-of-c-s-enum-command-with-c166-compiler</link><description> I&amp;#39;m currently attempting to modify an automatic code generation 
package (designed to run with MSVC/C++, WATCOM C/C++ and 
Borland C) to autogenerate software compilable with the Keil 
CA166 package. Of the standard files which have to be included 
into</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/53543?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2001 17:55:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:883c8db7-c992-4595-a3f8-f2f76fe203a0</guid><dc:creator>Andrew Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;For instance if it is used in array subscripting, the negative value would be an error.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
A slight side-track here, as Jon has alrady pointed out that negative indices are not wrong &lt;i&gt;per se&lt;/i&gt;.&lt;br /&gt;
&lt;br /&gt;
With C51, I have found that it will report errors on &lt;b&gt;all&lt;/b&gt; lines containing any array reference if there is any error in any preceding line.&lt;br /&gt;
Maybe Keil&amp;#39;s handling of the subscript operator, [], is just particularly fragile?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/109787?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2001 16:20:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f2354745-3127-4bc5-a7da-abc471109a4c</guid><dc:creator>Barry Shonbeck</dc:creator><description>&lt;p&gt;The solution with my compiler (C166 v4.06) seems to be to explicitly equate the value which should be zero to zero.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/94733?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2001 15:58:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c1583cac-f0cb-4c54-aef1-39bae0f2c03c</guid><dc:creator>Barry Shonbeck</dc:creator><description>&lt;p&gt;You got me Jon.  I started shooting my keyboard off and got called on it.&lt;br /&gt;
&lt;br /&gt;
As for the problem described though, I can not get the following to compile without generating the warning &amp;quot;C118 enum constant: signed value out of range&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
enum&lt;br /&gt;
	{&lt;br /&gt;
	TEST_A1 = -1,&lt;br /&gt;
	TEST_A2&lt;br /&gt;
	};&lt;br /&gt;
&lt;br /&gt;
If you change the initial value to -2, it compiles.  &lt;br /&gt;
&lt;br /&gt;
If you add member TEST_A3 after TEST_A2 and leave the initial value at -2, now it won&amp;#39;t compile.&lt;br /&gt;
&lt;br /&gt;
If the only member is TEST_A1 and it is initialized to -1, it compiles.&lt;br /&gt;
&lt;br /&gt;
It appears the problem is experienced when the enum list crosses from a negative number to zero.&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/53544?ContentTypeID=1</link><pubDate>Thu, 22 Feb 2001 13:24:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5971492a-e930-4091-bf8a-899e6a1a088d</guid><dc:creator>Keil Support</dc:creator><description>&lt;p&gt;&lt;i&gt;For instance if it is used in array subscripting, the negative value would be an error.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Just curious, but why would negative array subscripts be an error?  For example:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;char stack [100]; /* Create a stack */
char *p;          /* Create a stack pointer */

p = &amp;amp;stack [50];  /* Initialize the stack pointer */

p [0]  = 12;      /* Put stuff onto the stack */
p [-1] = 13;
p [-2] = 14;&lt;/pre&gt;
&lt;br /&gt;
This is legal C code and should work just fine with the Keil tools.  Is there a problem we should know about here?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/37275?ContentTypeID=1</link><pubDate>Wed, 21 Feb 2001 17:55:31 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:bcd90640-90f6-4a45-9933-ed7b6f5f8a5b</guid><dc:creator>Barry Shonbeck</dc:creator><description>&lt;p&gt;I also have bumped into this behavior but found like Mark stated that it was how I was using the enum that was the cause.  For instance if it is used in array subscripting, the negative value would be an error.  However the compiler does not always give an error that relates to the actual problem.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/37266?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2001 06:47:27 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0cd1cdea-6f2e-433f-9000-3709ac9dfdd1</guid><dc:creator>Mark Odell</dc:creator><description>&lt;p&gt;Of course C has no &amp;#39;commands&amp;#39; but your example works fine in C51. If you place this enum in a simple foo.c within main(), does C166 still have problems? You are correct, enum&amp;#39;s have type int so -1 is valid. I suspect code that preceded the enum is giving you problems.&lt;br /&gt;
&lt;br /&gt;
- Mark&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Use of C's enum command with C166 compiler</title><link>https://community.arm.com/thread/37265?ContentTypeID=1</link><pubDate>Mon, 19 Feb 2001 06:11:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cfcb1caa-644f-4f7a-8827-c33c3b5600a7</guid><dc:creator>Andrew Neil</dc:creator><description>&lt;p&gt;Be &lt;i&gt;&lt;b&gt;very&lt;/b&gt;&lt;/i&gt; careful - here be cross-platform compatibility dragons!&lt;br /&gt;
It&amp;#39;s one thing to get it to &lt;i&gt;compile;&lt;/i&gt; possibly as much again to get the compiled code to &lt;i&gt;work!&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Byte ordering and data sizes are two of the fiercest dragons.&lt;br /&gt;
&lt;br /&gt;
Anyway, back at your question, does the C166 compiler have an option which forces &lt;b&gt;int&lt;/b&gt; to default to &lt;b&gt;unsigned&lt;/b&gt;?&lt;br /&gt;
&lt;br /&gt;
My Borland manual specifically includes an example like yours, and the Keil C51 manual specifically mentions negative values in enums.&lt;br /&gt;
Your example gives no error in C51 v6.03, but the Keil compilers are not all equal!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>