<?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>C51: Word Alignment in Keil C51</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/25149/c51-word-alignment-in-keil-c51</link><description> 
How I can turn-on word alignment in Keil C51? 
I have such definition of USB-descriptors for Cypress EZ-USB chip
CY7C68013: 

 
const DEVICEDSCR code TestSyncSlave_DeviceDescriptor =
{ // Device descriptor
 sizeof(DEVICEDSCR), // 0x00 Length of this</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/144580?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 07:26:02 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:72d3c919-3446-4b86-976f-dfc44522c20d</guid><dc:creator>Nick Gerasimenko</dc:creator><description>&lt;p&gt;&lt;p&gt;
Than how put to even-aligned address first descriptor in chain?
:)&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/142247?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 07:18:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:eeb75ee0-9222-44db-b558-4948b6370522</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
In a similar vein to your assembler, how about something
like:&lt;/p&gt;

&lt;pre&gt;
#if (offsetof(x)/2)*2 != offsetof(x)
// Offset is odd - packing needed
#endif
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/139091?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 06:42:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b2e85af8-244b-4455-ba80-05965423ff67</guid><dc:creator>Nick Gerasimenko</dc:creator><description>&lt;p&gt;&lt;p&gt;
I not see the way, how offsetof construction can help me...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/135707?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 06:28:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:138dd85c-ca18-426c-b1ff-dee3707a42ba</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
One more time, In an &lt;b&gt;8-bit&lt;/b&gt; processor, the &lt;b&gt;word&lt;/b&gt; size
is &lt;b&gt;8 bits&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;
You need to stop using &amp;quot;word&amp;quot; as if it has some definite,
universal size - it does &lt;i&gt;&lt;b&gt;not&lt;/b&gt;&lt;/i&gt;!&lt;/p&gt;

&lt;p&gt;
If you mean &amp;quot;16-bit alignment&amp;quot; or &amp;quot;even-address&amp;quot; alignment, you
need to say that explicitly - otherwise you are going to cause
confusion and, probably, end up in trouble.&lt;/p&gt;

&lt;p&gt;
Have you looked into using sizeof and/or offsetof to do it in
&amp;#39;C&amp;#39;...?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/125343?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 05:32:17 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fe80304e-62bb-4eb5-ac74-b621d93db4bf</guid><dc:creator>Nick Gerasimenko</dc:creator><description>&lt;p&gt;&lt;p&gt;
Yes this more safer, than manualy setup code segments.&lt;br /&gt;
Especially as after every change of code segment need check, that no
overlap.&lt;/p&gt;

&lt;p&gt;
In cypress examples, i find interest way to align on word, but
only in asm:&lt;/p&gt;

&lt;pre&gt;
;;-----------------------------------------------------------------------------
;; Global Variables
;;-----------------------------------------------------------------------------
;      rseg DSCR     ;; locate the descriptor table in on-part memory.

CSEG   AT 100H


DeviceDscr:
      db   DSCR_DEVICE_LEN      ;; Descriptor length
      db   DSCR_DEVICE   ;; Decriptor type
      dw   0002H      ;; Specification Version (BCD)
      db   00H        ;; Device class
      db   00H         ;; Device sub-class
      db   00H         ;; Device sub-sub-class
      db   64         ;; Maximum packet size
      dw   0B404H      ;; Vendor ID
      dw   0310H      ;; Product ID (Sample Device)
      dw   0000H      ;; Product version ID
      db   1         ;; Manufacturer string index
      db   2         ;; Product string index
      db   0         ;; Serial number string index
      db   1         ;; Number of configurations

&lt;b&gt; org (($ / 2) +1) * 2 &lt;/b&gt;

DeviceQualDscr:
      db   DSCR_DEVQUAL_LEN   ;; Descriptor length
      db   DSCR_DEVQUAL   ;; Decriptor type
      dw   0002H      ;; Specification Version (BCD)
      db   00H        ;; Device class
      db   00H         ;; Device sub-class
      db   00H         ;; Device sub-sub-class
      db   64         ;; Maximum packet size
      db   1         ;; Number of configurations
      db   0         ;; Reserved

&lt;/pre&gt;

&lt;p&gt;
.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/114775?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 05:12:13 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:b9d161f7-34ec-43be-8e80-833645002746</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think doing it in the &amp;#39;C&amp;#39; source code with some suitable
preprocessor checking would be safer...?&lt;/p&gt;

&lt;p&gt;
Maybe this could help: &lt;a href="http://www.keil.com/support/man/docs/c51/c51_offsetof.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_offsetof.htm&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/101734?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 05:03:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:23f401ed-2345-4f56-9a33-3144197c616c</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
I&amp;#39;ll remind of the link I gave earlier:&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_ap_linkerloc.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_ap_linkerloc.htm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;
Basically, you put each descriptor variable definition into its
own source file. This way the compiler puts each variable into its
own section. Then you have the freedom to locate each section as you
like, e.g. placing each section at a specific address. Specifying
start address for each section manually isn&amp;#39;t perfect, but at least
you&amp;#39;ll get a linker warning if sections clash due to changed variable
size...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/103007?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 04:16:24 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:cc50fbfd-0660-44fb-aac4-4dcec2c80ab4</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
No, there aren&amp;#39;t.&lt;/p&gt;

&lt;p&gt;
Note that &amp;quot;word&amp;quot; and &amp;quot;long&amp;quot; have no generic size - it depends upon
the implementation!&lt;/p&gt;

&lt;p&gt;
Again, In an &lt;b&gt;8-bit&lt;/b&gt; processor, the &lt;b&gt;word&lt;/b&gt; size is &lt;b&gt;8
bits&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;
There is no reason &lt;i&gt;&lt;b&gt;on an 8-bit processor&lt;/b&gt;&lt;/i&gt; to have
anything other than byte alignment - so C51 has no directives to
enforce it!&lt;/p&gt;

&lt;p&gt;
The only reason to add padding would be specific to the
application - so the application (ie, you) must do it!&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/77285?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 03:39:50 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a3c58011-8960-459e-81aa-c7b0c0d3e398</guid><dc:creator>Nick Gerasimenko</dc:creator><description>&lt;p&gt;&lt;p&gt;
I think must be any directive that align stuctures by word,long
etc ?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/77284?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 03:38:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e7fd0c43-3c49-4bc8-b972-5c40694a0470</guid><dc:creator>Nick Gerasimenko</dc:creator><description>&lt;p&gt;&lt;p&gt;
I also try this, i define char variables bethween structures.&lt;br /&gt;
But this method uncomfortabe, because we may want to change
descriptor, so changed length of
HighSpeedConfigDscr,FullSpeedConfigDscr. In this case may appear
situation that structures were alignment, but char variabes insert
missalignment )))&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/55669?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 03:27:58 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:533fbeda-0de8-4733-940a-bf73d103ea89</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;p&gt;
The 8051 is an &lt;b&gt;8-bit&lt;/b&gt; processor; that is, its &lt;b&gt;Word
Size&lt;/b&gt; is &lt;b&gt;8 bits&lt;/b&gt; and, hence, &amp;quot;word alignment&amp;quot; is &amp;quot;byte
alignment&amp;quot; in C51.&lt;/p&gt;

&lt;p&gt;
As Mike Kleshov says, if you want padding, you must add it
yourself...&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/89635?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 03:27:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:d22f8837-c314-4c76-83af-2c0577e47ca5</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sorry, I misunderstood the question. It&amp;#39;s not about structure
padding, it&amp;#39;s about placing variables in memory.&lt;br /&gt;
It does appear that Keil 8051 tools don&amp;#39;t have settings for word
alignment of data. But you can always place your sections manually. I
believe this is how it&amp;#39;s done:&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_ap_linkerloc.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_ap_linkerloc.htm&lt;/a&gt;&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C51: Word Alignment in Keil C51</title><link>https://community.arm.com/thread/55671?ContentTypeID=1</link><pubDate>Thu, 19 Mar 2009 03:10:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:038d9bd9-e2fe-41a5-8d38-0b3b0b3ec597</guid><dc:creator>Mike Kleshov</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I have such definition of USB-descriptors for Cypress EZ-USB
chip CY7C68013:&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
These are not definitions, they are initializers. Structure
definitions must be elsewhere.&lt;br /&gt;
Anyway, it wouldn&amp;#39;t be too difficult to add padding fields to the
structures manually.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>