<?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>Problem with size of structers</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/15158/problem-with-size-of-structers</link><description> Hi anybody 
 
I declare the folowing stuctures: 
 
 
typedef struct {
 ubyte	bLength;
 ubyte	bDescriptorType;
 ubyte	bInterfaceNumber;
 ubyte	bAlternateSetting;
 ubyte	bNumEndpoints;
 ubyte	bInterfaceClass;
 ubyte	bInterfaceSubClass;
 ubyte	bInterfaceProtocol;</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/110134?ContentTypeID=1</link><pubDate>Tue, 24 May 2011 20:58:53 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:9e2e4fa6-774c-43fa-8e5e-f11f5e86dda1</guid><dc:creator>raji k</dc:creator><description>&lt;p&gt;&lt;p&gt;
2000&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/95219?ContentTypeID=1</link><pubDate>Wed, 06 Nov 2002 10:32:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:57a86b25-9216-4dc8-8af2-16ac0c488f12</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;&lt;br /&gt;
While we&amp;#39;re on the topic, I notice there are some bitfield declarations in the structure.  Bitfield endianess (that is, whether they are allocated from the LSB first or MSB first) is implementation-specific, and is independent of multi-byte word endianness.  Given the fragment&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
struct
   {
   ubyte myBits:4;
   ubyte myOtherBits:4;
   } nibble;

   nibble.myBits = 0xF;
   nibble.myOtherBits = 0;
&lt;/pre&gt;
&lt;br /&gt;
nibble might wind up looking like either 0xF0 or 0x0F.  So check the manuals or write a little test.  &lt;br /&gt;
&lt;br /&gt;
ANSI also says that bitfields are always part of an &amp;#39;int&amp;#39;, so there&amp;#39;s a potential portability issue for bitfields in other sizes like bytes.  Most embedded compilers will let you specify other sizes for bitfields, but it&amp;#39;s non-standard behavior.&lt;br /&gt;
&lt;br /&gt;
Oddly enough, even though ANSI-standard bitfields are &amp;quot;ints&amp;quot;, whether or not they are signed is also left up to the implementation.  int myBit:1 may take on the values 0 and 1, or 0 and -1, depending on your compiler.  Plain &amp;quot;int&amp;quot; doesn&amp;#39;t necessarily mean &amp;quot;signed int&amp;quot; in the context of bitfields (unlike its normal meaning), and if you have a concern for portability or even just clarity, you might want to always specify &amp;quot;signed int&amp;quot; or &amp;quot;unsigned int&amp;quot; to be sure.&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/54775?ContentTypeID=1</link><pubDate>Wed, 06 Nov 2002 07:27:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b58bfeb4-38f4-4e9b-9d07-61e175a271d6</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot;...controllers that &amp;quot;prefer&amp;quot; word alignments...&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Don&amp;#39;t forget that the PC is a 32-bit architecture these days, so there are alignment issues with both 16- &lt;i&gt;&lt;b&gt;and&lt;/b&gt;&lt;/i&gt; 32-bit &amp;quot;objects!&amp;quot;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/39345?ContentTypeID=1</link><pubDate>Wed, 06 Nov 2002 06:58:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b36630f5-bb24-42e6-9af9-62212a35ef18</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;When I work with controllers that &amp;quot;prefer&amp;quot; word alignments, I always make the length of structures even (insert a dummy char at the end if required) &amp;lt;b&amp;lt;and make sure all ints start after an even number of bytes.  Even if this were to be transferred to a controller that did not care about alignment, no harm would be done.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;
 7* ubyte
    ubyte	bInterfaceProtocol;
    ubyte	&lt;b&gt;i&lt;/b&gt;Interface;
    ubyte       bdummy
} USB_interface_desc_t;

6*  ubyte
    ubyte	MaxPower;
    ubyte       bdummy
} USB_config_desc_t;
&lt;/pre&gt;
&lt;br /&gt;
etc&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Erik&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/110133?ContentTypeID=1</link><pubDate>Tue, 05 Nov 2002 17:10:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:375c8c09-d16c-4316-a09d-b50564a8a866</guid><dc:creator>Andrew Neil</dc:creator><description>&lt;p&gt;Rather than try to force your system(s) to work with mis-aligned data - which could well be &lt;i&gt;&lt;b&gt;grossly&lt;/b&gt;&lt;/i&gt; inefficient - it might be better to have your driver(s) parse the communication packets into sutiable target-friendly structures?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/95218?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2002 15:51:26 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:77177465-68ef-469f-ab2c-9e035bf39cd4</guid><dc:creator>Andrew Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot; I am trying to establish communication with PC (Windows 98)&amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Welcome to the world of cross-platform interworking!&lt;br /&gt;
&lt;br /&gt;
If you&amp;#39;re going to try to use &amp;#39;C&amp;#39; structures to map language types onto the communications frame/packet format, you are going to have to study the &lt;b&gt;manuals&lt;/b&gt; for &lt;i&gt;&lt;b&gt;both&lt;/b&gt;&lt;/i&gt; platforms &lt;b&gt;&lt;i&gt;very&lt;/i&gt;&lt;/b&gt; carefully - playing particular attention to data sizes, endianness, packing, alignments, and all the other &lt;i&gt;&lt;b&gt;implementation-specific&lt;/b&gt;&lt;/i&gt; details.&lt;br /&gt;
&lt;br /&gt;
Don&amp;#39;t forget that Win98 runs on 32-bit Intel x86 architecture, and there is no guarantee that the data representation will match Keil&amp;#39;s implementation on the 16-bit(?) C16x/ST10 - in fact, it&amp;#39;s more likely that they &lt;i&gt;&lt;b&gt;won&amp;#39;t&lt;/b&gt;&lt;/i&gt; match!  :-(&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/110143?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2002 13:42:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c92e8a74-145c-4231-921a-a067b7d3d7d5</guid><dc:creator>Aram Semerjyan</dc:creator><description>&lt;p&gt;Thanks guys&lt;br /&gt;
&lt;br /&gt;
The directive&lt;br /&gt;
 #pragma pack(1)     /* byte alignment */&lt;br /&gt;
 #pragma BYTEALIGN&lt;br /&gt;
&lt;br /&gt;
works fine even on C166 version 4.05, witch I have.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/95216?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2002 12:24:55 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:44f24000-1e42-4c04-8474-df3c81e6c46d</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;Take a look at the following knowledgebase articles:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://www.keil.com/support/docs/1689.htm"&gt;http://www.keil.com/support/docs/1689.htm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="http://www.keil.com/support/docs/1688.htm"&gt;http://www.keil.com/support/docs/1688.htm&lt;/a&gt;&lt;/li&gt;
&lt;/ul&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: Problem with size of structers</title><link>https://community.arm.com/thread/95220?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2002 12:24:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:637be1ab-579e-4e01-9781-ab0527dbc7a0</guid><dc:creator>Dan Henry</dc:creator><description>&lt;p&gt;I am not familiar with Keil&amp;#39;s C166 product, but usually if a compiler adds padding within a structure, it also provides a mechanism for controlling the padding.  The control is usually in the form of a #pragma.  Check the manual for #pragma support.  Search the manual for &amp;quot;padding&amp;quot; or &amp;quot;packing&amp;quot;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/54781?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2002 12:15:15 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ea5bf113-6fc2-4ab5-aea8-9a1ee8f836c0</guid><dc:creator>Aram Semerjyan</dc:creator><description>&lt;p&gt;If I understood it correctly, there are pad bytes in structures.&lt;br /&gt;
But still there is a problem. I am trying to establish communication with&lt;br /&gt;
 PC (Windows 98) via USB port, and with this pad bytes I need to know &lt;br /&gt;
how to do that if the first sizeof(USB_interface_desc_t) returns 0x09,&lt;br /&gt;
but actually 10 bytes were sent and second sizeof(USB_endpoint_desc_t)&lt;br /&gt;
in C166 returns 0x08, while on PC side this structure has size of 7 bytes,&lt;br /&gt;
and standard Windows DDK function for USB can&amp;#39;t properly receive &lt;br /&gt;
Endpoints information. &lt;br /&gt;
&lt;br /&gt;
I need help ASAP!!!!!&lt;br /&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Problem with size of structers</title><link>https://community.arm.com/thread/39344?ContentTypeID=1</link><pubDate>Mon, 04 Nov 2002 11:08:23 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:4df6e83c-81ee-41df-92ba-75c8c935e97c</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;Does C166 insert &amp;quot;padding&amp;quot; bytes? - check the &lt;b&gt;manual&lt;/b&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>