<?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>Is this a C51 bug?</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/28284/is-this-a-c51-bug</link><description> 
struct tag
{
 char a:7;
 char b:1;
};

unsigned char foo(void)
{
 struct tag test;

 test.b = 1;

 return test.b;
}

void main(void)
{
 char dat;

 if(foo() == 1)// ***foo return 0x80 not 0x01
 {
 dat = 2;
 }
 while(1);
}
 

 
17: void main(void) 18</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Is this a C51 bug?</title><link>https://community.arm.com/thread/80067?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2012 23:31:11 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d3e01577-24e8-4903-8e9c-4f32542ce270</guid><dc:creator>H Mackie</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;... I tend to think that something isn&amp;#39;t right here.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
I thought the same as you. When I first tried it with the signed
char, things were obviously wrong and I thought I understood. When I
converted to unsigned char, it looked right. I then tried it later
and it didn&amp;#39;t work. Must have done something different, but don&amp;#39;t
know what. This was all determined by looking at the disassembly.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is this a C51 bug?</title><link>https://community.arm.com/thread/60484?ContentTypeID=1</link><pubDate>Fri, 09 Mar 2012 13:17:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:2601bb2f-f040-44ae-ad23-91e2c201f981</guid><dc:creator>Ashley Madison</dc:creator><description>&lt;p&gt;&lt;p&gt;
As written, the code worked for me: dat is assigned a value of 2
and its branch is executed.&lt;/p&gt;

&lt;p&gt;
however, if you change&lt;/p&gt;

&lt;pre&gt;
char dat;
&lt;/pre&gt;

&lt;p&gt;
by giving dat a value, like&lt;/p&gt;

&lt;pre&gt;
char dat=1;
&lt;/pre&gt;

&lt;p&gt;
the branch isn&amp;#39;t executed.&lt;/p&gt;

&lt;p&gt;
I didn&amp;#39;t take a look at the disassembly but I tend to think that
something isn&amp;#39;t right here.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is this a C51 bug?</title><link>https://community.arm.com/thread/105807?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2012 03:00:16 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4ec07402-1946-4597-aec3-eea6d586134e</guid><dc:creator>H Mackie</dc:creator><description>&lt;p&gt;&lt;p&gt;
Keil support should be interested in this. Contact them.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is this a C51 bug?</title><link>https://community.arm.com/thread/80068?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2012 02:43:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a8d2355e-d9a7-4ab2-b687-c00831dd2678</guid><dc:creator>huang faqian</dc:creator><description>&lt;p&gt;&lt;pre&gt;
struct tag
{
    unsigned char a:7;
    unsigned char b:1;
};

unsigned char foo(void)
{
    struct tag test;

    test.b = 1;

    return test.b;
}

void main(void)
{
    unsigned char dat;

    if(foo() == 1)// ***foo return 0x80 not 0x01
    {
        dat = 2;
    }
    while(1);
}
&lt;/pre&gt;

&lt;p&gt;
17: void main(void) 18: { 19: unsigned char dat; 20: 21: if(foo()
== 1)// ***foo return 0x80 not 0x01&lt;br /&gt;
C:0x000F 12001A LCALL foo(C:001A)&lt;br /&gt;
C:0x0012 BF0103 CJNE R7,#0x01,C:0018 22: { 23: dat = 2;&lt;br /&gt;
C:0x0015 750802 MOV 0x08,#0x02 24: }&lt;br /&gt;
C:0x0018 80FE SJMP C:0018 8: unsigned char foo(void) 9: { 10: struct
tag test; 11: 12: test.b = 1; 13:&lt;br /&gt;
C:0x001A 430980 ORL 0x09,#P0(0x80) 14: return test.b;&lt;br /&gt;
C:0x001D E509 MOV A,0x09&lt;br /&gt;
C:0x001F 5480 ANL A,#P0(0x80)&lt;br /&gt;
C:0x0021 FF MOV R7,A 15: }&lt;/p&gt;

&lt;p&gt;
THE RESULT IS THE SAME!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Is this a C51 bug?</title><link>https://community.arm.com/thread/60488?ContentTypeID=1</link><pubDate>Wed, 07 Mar 2012 02:16:51 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f8ac04cd-d35f-4956-9bad-9bf37eac6aba</guid><dc:creator>H Mackie</dc:creator><description>&lt;p&gt;&lt;p&gt;
What is the sign-ness of char for your build?&lt;/p&gt;

&lt;p&gt;
Assuming a char is signed then:&lt;/p&gt;

&lt;p&gt;
You have an element with a width of 1 bit as a signed char.&lt;br /&gt;
Does a 1 bit twos complement value make any sense?&lt;/p&gt;

&lt;p&gt;
When you return the value it is being converted to an unsigned
char.&lt;br /&gt;
What conversion will occur?&lt;/p&gt;

&lt;p&gt;
Likely that you intended your 1 bit variable to be unsigned.&lt;br /&gt;
Try it.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>