<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: how to assign a union to an array element in CodeWarrior for MCU</title>
    <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209072#M8166</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Ahh, I see now.&amp;nbsp; I've updated all my instances of memory[x] to memory.data[x].&amp;nbsp; That does indeed work.&lt;BR /&gt;&lt;BR /&gt;However, it seems that all my instances of VCONFIG will&amp;nbsp; have to change to something like memory.vconfig.&amp;nbsp; In the debugger, I'm seeing two entries for vconfig, both with separate segments in RAM.&amp;nbsp; The second is an element of the memory structure.&lt;BR /&gt;&lt;BR /&gt;Is there a way I should be restructuring my #define's so that my labels -- like VCONFIG -- call out the memory. vconfig structure elements?&amp;nbsp; The #define obviously makes it more manageable.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 26 Apr 2008 01:35:16 GMT</pubDate>
    <dc:creator>irob</dc:creator>
    <dc:date>2008-04-26T01:35:16Z</dc:date>
    <item>
      <title>how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209060#M8154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey everyone.&amp;nbsp; Does anyone know how I can assign a union to a particular element of array?&amp;nbsp; For instance, I have the following union defined:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;typedef union{&amp;nbsp; Byte bits;&amp;nbsp; struct&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte VIDEO0&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp; // video mode bits&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte VIDEO1&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte ORIENT0&amp;nbsp; :1;&amp;nbsp;&amp;nbsp; // orientation bits&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte ORIENT1&amp;nbsp; :1;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte FREQ0&amp;nbsp;&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp; // frequency bits&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte FREQ1&amp;nbsp;&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte LED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp; // LED enable bit&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp; // unused&amp;nbsp; } bit;&amp;nbsp; struct&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte mrgVIDEO&amp;nbsp;&amp;nbsp; :2;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte mrgORIENT&amp;nbsp; :2;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte mrgFREQ&amp;nbsp;&amp;nbsp;&amp;nbsp; :2;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :1;&amp;nbsp;&amp;nbsp;&amp;nbsp; Byte&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; :1;&amp;nbsp; } mergedbits;} vconfig_union;extern volatile vconfig_union vconfig;#define VCONFIG&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vconfig.bits#define VCONFIG_VIDEO0&amp;nbsp; vconfig.bit.VIDEO0#define VCONFIG_VIDEO1&amp;nbsp; vconfig.bit.VIDEO1#define VCONFIG_ORIENT0 vconfig.bit.ORIENT0#define VCONFIG_ORIENT1 vconfig.bit.ORIENT1#define VCONFIG_FREQ0&amp;nbsp;&amp;nbsp; vconfig.bit.FREQ0#define VCONFIG_FREQ1&amp;nbsp;&amp;nbsp; vconfig.bit.FREQ1#define VCONFIG_LED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; vconfig.bit.LED#define VCONFIG_VIDEO&amp;nbsp;&amp;nbsp; vconfig.mergedbits.mrgVIDEO#define VCONFIG_ORIENT&amp;nbsp; vconfig.mergedbits.mrgORIENT#define VCONFIG_FREQ&amp;nbsp;&amp;nbsp;&amp;nbsp; vconfig.mergedbits.mrgFREQ&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;SPAN&gt;And I also have an array of bytes defined:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;Byte memory[8];&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;I want to assign the above union to the 8th element in the memory[] array.&amp;nbsp; I've tried the address operator in various ways but can't seem to make this work.&lt;BR /&gt;&lt;BR /&gt;The reason is so that the last byte of that array can be easier to work with and test other control loops against.&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 07:30:03 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209060#M8154</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-02T07:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209061#M8155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Without having it tried out, but does&lt;BR /&gt;&lt;PRE&gt;memory[7]= VCONFIG;

not work?

Also I'm not completely understand why
you want to do this assignment,
not sure how memory[7] could be simpler than using the VCONFIG,
but there are certainly good reasons for copying a byte :smileyhappy:.

Daniel

&lt;/PRE&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 Apr 2008 09:06:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209061#M8155</guid>
      <dc:creator>CompilerGuru</dc:creator>
      <dc:date>2008-04-02T09:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209062#M8156</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks for your help, Mr. Guru.&amp;nbsp; &lt;SPAN&gt;&lt;IMG alt=":manhappy:" class="emoticon emoticon-manhappy" id="manhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_man-happy.gif" title="Man Happy" /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;I should have been more clear.&amp;nbsp; It's not simply byte copying that I wanted to do.&amp;nbsp; The memory array is stored to and retrieved from EEPROM.&amp;nbsp; It's easy to work with inside an array.&amp;nbsp; Each element of my array happens to be 8 bits in length, except for the last byte.&amp;nbsp; That one is broken into three pairs of bits, and one final bit (7 total bits).&amp;nbsp; The arrangement matches the breakdown listed in my union.&lt;BR /&gt;&lt;BR /&gt;The union is obviously the easiest to work with in my code for its bit fields.&amp;nbsp; But how to then pack that back into the 8th element of the memory array when it's time to write or read from EEPROM?&lt;BR /&gt;&lt;BR /&gt;You are correct, simply copying the full union to memory[7] during the EEPROM storage/retrieval will work just fine.&amp;nbsp; I was merely hoping for a clever way to maybe have the two entities mirror each other, avoiding the need to read and write each time.&amp;nbsp; Maybe I'm just making this too difficult.&lt;BR /&gt;&lt;BR /&gt;Does that make any sense?&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Apr 2008 00:30:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209062#M8156</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-03T00:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209063#M8157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello irob,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Not sure&amp;nbsp;whether the following is what you require -&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;typedef struct {&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; Byte data[7];&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&amp;nbsp; vconfig_union vconfig;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;} mem_array;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;extern vconfig_union vconfig;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;extern mem_array memory;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;VCONFIG = memory.VCONFIG;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;dataval = memory.data[x];&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Apr 2008 04:15:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209063#M8157</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-04-03T04:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209064#M8158</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Bigmac, thanks for your suggestion.&amp;nbsp; Though I couldn't quite follow it completely, or make it compile without error in my source.&amp;nbsp; For instance, I wasn't sure what dataval was doing.&lt;BR /&gt;&lt;BR /&gt;It occurred to me that maybe I could just add memory[7] inside my existing union, like this:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;extern Byte memory[];  // Flash EEPROM memory
typedef union
{
  Byte bits;
  struct
  {
    Byte LEDS       :1;   // LED enable bit, 0
    Byte SSVR       :1;   // screensaver bit, 1
    Byte FREQ0      :1;   // frequency bits, 2-3
    Byte FREQ1      :1;
    Byte ORIENT0    :1;   // orientation bits, 4-5
    Byte ORIENT1    :1;
    Byte VIDEO0     :1;   // video mode bits, 6-7
    Byte VIDEO1     :1;
  } bit;
  struct
  {
    Byte            :1;
    Byte            :1;
    Byte mrgFREQ    :2;
    Byte mrgORIENT  :2;
    Byte mrgVIDEO   :2;
  } mergedbits;
 &lt;B&gt;struct
  {
    Byte memory[7]  :8;
  } eeprombits;&lt;/B&gt;
} config_union;
extern volatile config_union config;
&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;My hope was that the 8th byte of the memory[] array will also reside in the same memory as config.bits&lt;BR /&gt;&lt;BR /&gt;This compiles, but alas, it treats the two "memory"s as unique names .&amp;nbsp; One is part of the memory[] array, the other is simply all 8 bits (config.bits).&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 01:13:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209064#M8158</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-25T01:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209065#M8159</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;I think bigmac's suggestion should work, I made the following file:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;typedef union{  Byte bits;  struct  {    Byte VIDEO0   :1;   // video mode bits    Byte VIDEO1   :1;    Byte ORIENT0  :1;   // orientation bits    Byte ORIENT1  :1;    Byte FREQ0    :1;   // frequency bits    Byte FREQ1    :1;    Byte LED      :1;   // LED enable bit    Byte          :1;   // unused  } bit;  struct  {    Byte mrgVIDEO   :2;    Byte mrgORIENT  :2;    Byte mrgFREQ    :2;    Byte            :1;    Byte            :1;  } mergedbits;} vconfig_union;#define VCONFIG         vconfig.bits#define VCONFIG_VIDEO0  vconfig.bit.VIDEO0#define VCONFIG_VIDEO1  vconfig.bit.VIDEO1#define VCONFIG_ORIENT0 vconfig.bit.ORIENT0#define VCONFIG_ORIENT1 vconfig.bit.ORIENT1#define VCONFIG_FREQ0   vconfig.bit.FREQ0#define VCONFIG_FREQ1   vconfig.bit.FREQ1#define VCONFIG_LED     vconfig.bit.LED#define VCONFIG_VIDEO   vconfig.mergedbits.mrgVIDEO#define VCONFIG_ORIENT  vconfig.mergedbits.mrgORIENT#define VCONFIG_FREQ    vconfig.mergedbits.mrgFREQtypedef struct {   Byte data[7];   vconfig_union vconfig;   } mem_array;mem_array memory;unsigned char test;void main(void) {  /* put your own code here */  memory.VCONFIG_VIDEO0 = 1;  test = memory.data[7];  for(;;) {} /* wait forever */  /* please make sure that you never leave this function */}&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;For which the disassembly is:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;   52:    memory.VCONFIG = 0x12;  0000 c612         [1]     LDAB  #18  0002 7b0000       [3]     STAB  memory:7   53:    test = memory.data[7];  0005 b60000       [3]     LDAA  memory:7  0008 7a0000       [3]     STAA  test&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;Becareful with the array as it doesn't seem to be checking the bounds.&lt;/P&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 03:23:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209065#M8159</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-04-25T03:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209066#M8160</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Thanks, allawtterb, but yours will not compile for me.&amp;nbsp; I'm getting C1019, incompatible type, found 'mem_array', expected "unsigned char[8]").&lt;BR /&gt;&lt;BR /&gt;I presume it's because memory for me is already defined in main.c as unsigned character array, 8 bytes wide.&amp;nbsp; Hmm.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 04:08:32 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209066#M8160</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-25T04:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209067#M8161</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello iRob,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I wonder if your compile problem has anything to do with the visibility (or lack thereof) of the typedef &lt;STRONG&gt;Byte&lt;/STRONG&gt; within&amp;nbsp;one of the&amp;nbsp;files.&amp;nbsp; I am not sure in which header file this is defined.&amp;nbsp; I would usually make use of the alternate typedef &lt;STRONG&gt;byte&lt;/STRONG&gt; as I know this is defined within the MCU header file, and is accessible through derivative.h.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 22:41:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209067#M8161</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-04-25T22:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209068#M8162</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;Hmm, good thought.&amp;nbsp; "Byte" is defined in stdtypes.h (&amp;lt;install dir&amp;gt;\lib\hc08c\include\).&lt;BR /&gt;&lt;BR /&gt;On a whim, I change all instances of Byte and Word over to byte and word.&amp;nbsp; Alas, I get the same error at the "mem_array memory;" line in main.h&lt;BR /&gt;&lt;BR /&gt;To be clear, all the structure definitions are in my main.h file.&amp;nbsp; In my main.c, I have memory first initialized:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;byte memory[8];      // flash config bytes&lt;/PRE&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;Message Edited by irob on &lt;SPAN class="date_text"&gt;2008-04-25&lt;/SPAN&gt; &lt;SPAN class="time_text"&gt;10:03 AM&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2008 22:56:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209068#M8162</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-25T22:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209069#M8163</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;You need to remove this definition for the above code to work properly, you can't define two variables with the same name.&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Apr 2008 00:01:12 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209069#M8163</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-04-26T00:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209070#M8164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;But without the first declaration (memory[8]), I get C1827 errors.&amp;nbsp; memory is an array of 8 elements.&lt;BR /&gt;&lt;BR /&gt;I'm starting to think this isn't worth the effort.&amp;nbsp; &lt;IMG alt=":smileyhappy:" class="emoticon emoticon-smileyhappy" id="smileyhappy" src="http://freescale.i.lithium.com/i/smilies/16x16_smiley-happy.gif" title="Smiley Happy" /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Apr 2008 00:14:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209070#M8164</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-26T00:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209071#M8165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello iRob,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Now I think that I understand.&amp;nbsp; If you are attempting to use the code posted by Brett, there is already the global variable definition -&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;mem_array memory;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;So you cannot also have the global definition -&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;byte memory[8];&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This would appear to give the conflict.&amp;nbsp; You can only have a single definition for &lt;STRONG&gt;memory&lt;/STRONG&gt;.&amp;nbsp; If you need to access one of the data byte locations within the array, it would need to occur via the structure, as with&amp;nbsp;-&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;test = memory.data[0];&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Apr 2008 00:15:53 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209071#M8165</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-04-26T00:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209072#M8166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;Ahh, I see now.&amp;nbsp; I've updated all my instances of memory[x] to memory.data[x].&amp;nbsp; That does indeed work.&lt;BR /&gt;&lt;BR /&gt;However, it seems that all my instances of VCONFIG will&amp;nbsp; have to change to something like memory.vconfig.&amp;nbsp; In the debugger, I'm seeing two entries for vconfig, both with separate segments in RAM.&amp;nbsp; The second is an element of the memory structure.&lt;BR /&gt;&lt;BR /&gt;Is there a way I should be restructuring my #define's so that my labels -- like VCONFIG -- call out the memory. vconfig structure elements?&amp;nbsp; The #define obviously makes it more manageable.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Apr 2008 01:35:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209072#M8166</guid>
      <dc:creator>irob</dc:creator>
      <dc:date>2008-04-26T01:35:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209073#M8167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;irob wrote:&lt;BR /&gt;However, it seems that all my instances of VCONFIG will&amp;nbsp; have to change to something like memory.vconfig.&amp;nbsp; In the debugger, I'm seeing two entries for vconfig, both with separate segments in RAM.&amp;nbsp; The second is an element of the memory structure.&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;Make sure that you don't have another vconfig defined somewhere else, in your original post you had:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;extern volatile vconfig_union vconfig;&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;This declaration and any definition of vconfig outside of the&amp;nbsp;struct should not exist.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;irob wrote:&lt;BR /&gt;Is there a way I should be restructuring my #define's so that my labels -- like VCONFIG -- call out the memory. vconfig structure elements?&amp;nbsp; The #define obviously makes it more manageable.&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;If you want to access memory.vconfig with one define, change the defines to:&lt;/DIV&gt;&lt;DIV class="msg_source_code"&gt;&lt;DIV class="text_smallest"&gt;Code:&lt;/DIV&gt;&lt;PRE&gt;#define VCONFIG         memory.vconfig.bits#define VCONFIG_VIDEO0  memory.vconfig.bit.VIDEO0#define VCONFIG_VIDEO1  memory.vconfig.bit.VIDEO1#define VCONFIG_ORIENT0 memory.vconfig.bit.ORIENT0#define VCONFIG_ORIENT1 memory.vconfig.bit.ORIENT1#define VCONFIG_FREQ0   memory.vconfig.bit.FREQ0#define VCONFIG_FREQ1   memory.vconfig.bit.FREQ1#define VCONFIG_LED     memory.vconfig.bit.LED#define VCONFIG_VIDEO   memory.vconfig.mergedbits.mrgVIDEO#define VCONFIG_ORIENT  memory.vconfig.mergedbits.mrgORIENT#define VCONFIG_FREQ    memory.vconfig.mergedbits.mrgFREQ&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;That being said, I don't like the implementation very much.&amp;nbsp; The overlaying of memory.data[7] and memory.vconfig is only because the compiler is letting you access an array out of it's bounds.&amp;nbsp;&lt;BR /&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Apr 2008 02:31:25 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209073#M8167</guid>
      <dc:creator>allawtterb</dc:creator>
      <dc:date>2008-04-26T02:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign a union to an array element</title>
      <link>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209074#M8168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;DIV&gt;Hello,&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;allawtterb wrote:&lt;BR /&gt;&lt;DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;BR /&gt;&lt;/DIV&gt;&lt;BLOCKQUOTE&gt;That being said, I don't like the implementation very much.&amp;nbsp; The overlaying of memory.data[7] and memory.vconfig is only because the compiler is letting you access an array out of it's bounds.&amp;nbsp;&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;&lt;HR /&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;DIV&gt;When I posted my original suggestion in message 4, I had intended that the &lt;FONT face="Courier New"&gt;vconfig&lt;/FONT&gt; element of the &lt;FONT face="Courier New"&gt;memory&lt;/FONT&gt; structure would be accessed as &lt;FONT face="Courier New"&gt;memory.vconfig.bits&lt;/FONT&gt;&amp;nbsp;and &lt;U&gt;not&lt;/U&gt; as &lt;FONT face="Courier New"&gt;memory.data[7]&lt;/FONT&gt;.&amp;nbsp; So there would be no array bounds issue.&amp;nbsp; My understanding was that this element was to be handled differently than the other elements of the structure because of&amp;nbsp;its union with a bit field.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;For demonstration purposes, I had also assumed the creation of a separate variable of type &lt;FONT face="Courier New"&gt;vconfig_union&lt;/FONT&gt; outside of the &lt;FONT face="Courier New"&gt;memory&lt;/FONT&gt; structure.&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;extern vconfig_union vconfig;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;It would then be possible to have the following statement to read the contents of the&amp;nbsp;whole structure element -&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;vconfig.bits = memory.vconfig.bits;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Then applying&amp;nbsp;a macro that had previously been defined, the result was -&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT face="Courier New"&gt;VCONFIG = memory.VCONFIG;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;But it seems this may have confused the issue.&amp;nbsp; This is what I thought the OP required, but I may have been wrong.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Regards,&lt;/DIV&gt;&lt;DIV&gt;Mac&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 26 Apr 2008 11:27:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/CodeWarrior-for-MCU/how-to-assign-a-union-to-an-array-element/m-p/209074#M8168</guid>
      <dc:creator>bigmac</dc:creator>
      <dc:date>2008-04-26T11:27:31Z</dc:date>
    </item>
  </channel>
</rss>

