Symbian3/SDK/Source/GUID-37057FD5-7ED0-5B18-9C28-39F6816D7627.dita
changeset 13 48780e181b38
parent 12 80ef3a206772
child 14 578be2adaf3e
equal deleted inserted replaced
12:80ef3a206772 13:48780e181b38
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept id="GUID-37057FD5-7ED0-5B18-9C28-39F6816D7627" xml:lang="en"><title>Arrays
       
    13 within structs</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p>A declaration of a struct member may either be a simple <varname>type-name</varname>  <varname>member-name</varname>,
       
    15 or it may be an array of values of identical type.</p>
       
    16 <p>Arrays are always indicated by square brackets:</p>
       
    17 <codeblock id="GUID-4F6A2882-FDF8-5DBA-A01D-6772D5BDF70F" xml:space="preserve">STRUCT HAS_ARRAY
       
    18  {
       
    19  STRUCT elements[];
       
    20  }</codeblock>
       
    21 <p>In the example above, the <codeph>HAS_ARRAY</codeph> struct has one array
       
    22 member, <codeph>elements</codeph>. Each member of <codeph>elements</codeph> is
       
    23 of <codeph>STRUCT</codeph> type.</p>
       
    24 <p><b>Array size</b> </p>
       
    25 <p>If you specify the array size, inside the square brackets, then the generated
       
    26 resource will contain no count of the number of elements. So this resource:</p>
       
    27 <codeblock id="GUID-F50D2117-7554-5D80-ABF1-2393E65B54CB" xml:space="preserve">STRUCT FIXED_ARRAY
       
    28  {
       
    29  WORD elements[3];
       
    30  }
       
    31 
       
    32 RESOURCE FIXED_ARRAY example1
       
    33  {
       
    34  elements={9,8,7};
       
    35  }</codeblock>
       
    36 <p>will generate the output</p>
       
    37 <codeblock id="GUID-880DF2CB-D042-59CD-AF28-89D971CC6466" xml:space="preserve">0x09 0x00 0x08 0x00 0x07 0x00</codeblock>
       
    38 <p>For variable length arrays, a count of the number of elements precedes
       
    39 the resource. The default for this is a word, but by prefixing the struct
       
    40 definition with <codeph>LEN BYTE</codeph> it will be a byte count. So the
       
    41 following resource:</p>
       
    42 <codeblock id="GUID-FEAD195C-8C3F-529F-AE2A-AC42F2ACA66F" xml:space="preserve">STRUCT VAR_ARRAY
       
    43  {
       
    44  WORD elements [];
       
    45  }
       
    46 
       
    47 RESOURCE VAR_ARRAY example2
       
    48  {
       
    49  elements={9,8,7};
       
    50  }</codeblock>
       
    51 <p>will generate the output</p>
       
    52 <codeblock id="GUID-D21EA8C8-876D-5DD8-9F0C-256288A2B6B1" xml:space="preserve">0x03 0x00 0x09 0x00 0x08 0x00 0x07 0x00 </codeblock>
       
    53 <p>whereas this resource:</p>
       
    54 <codeblock id="GUID-14A52C15-5D28-5716-AED4-22F02AF23AAE" xml:space="preserve">STRUCT VAR_ARRAY2
       
    55  {
       
    56  LEN BYTE WORD elements[];
       
    57  }
       
    58 
       
    59 RESOURCE VAR_ARRAY2 example3
       
    60  {
       
    61  elements={9,8,7};
       
    62  }</codeblock>
       
    63 <p>will generate this output</p>
       
    64 <codeblock id="GUID-3909C1FE-84B3-50D1-9519-417B84DD93B0" xml:space="preserve">0x03 0x09 0x00 0x08 0x00 0x07 0x00</codeblock>
       
    65 <p>The compiler allows you to prefix <codeph>LEN BYTE</codeph> or <codeph>LEN
       
    66 WORD</codeph> even for fixed length arrays, but it has no effect. Fixed length
       
    67 arrays do not generate an element count.</p>
       
    68 </conbody><related-links>
       
    69 <link href="GUID-0142B290-DA6C-5574-83D7-7555D804D9B5.dita"><linktext>How to initialise
       
    70 array RESOURCE members</linktext></link>
       
    71 </related-links></concept>