Symbian3/SDK/Source/GUID-0142B290-DA6C-5574-83D7-7555D804D9B5.dita
changeset 7 51a74ef9ed63
parent 0 89d6a7a84779
equal deleted inserted replaced
6:43e37759235e 7:51a74ef9ed63
       
     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-0142B290-DA6C-5574-83D7-7555D804D9B5" xml:lang="en"><title>How
       
    13 to initialise array RESOURCE members</title><prolog><metadata><keywords/></metadata></prolog><conbody>
       
    14 <p><i><codeph>&lt;array-initialiser&gt;</codeph></i> </p>
       
    15 <p><b>array-initialiser ::=</b>     </p>
       
    16 <p><b> {</b> <i><codeph>&lt;array-initialiser-item-comma-list&gt;</codeph></i><b> }</b> <i><codeph>&lt;array-initialiser-item&gt;</codeph></i> </p>
       
    17 <p><b>array-initialiser-item ::=</b>     </p>
       
    18 <p><codeph><i>&lt;initialiser&gt;</i></codeph></p>
       
    19 <p><b>Fixed-length arrays</b> </p>
       
    20 <p>If a member is declared as a fixed-length array in the <codeph>STRUCT</codeph> or <codeph>RESOURCE</codeph> definition,
       
    21 for example,</p>
       
    22 <codeblock id="GUID-B2D4E3E1-2F01-53A4-92AE-AB99E3D2A680" xml:space="preserve">WORD elements[10]</codeblock>
       
    23 <p>then you must not specify any more items than were given in the length. </p>
       
    24 <p>If fewer items are specified in the default initialisation (i.e. in the <codeph>STRUCT</codeph> definition),
       
    25 then an error also results. </p>
       
    26 <p>Note that no values will be given to unspecified elements at the end of
       
    27 the array, even if they have been default initialised in the <codeph>STRUCT</codeph> definition.
       
    28 Take the following example:</p>
       
    29 <codeblock id="GUID-02A51707-F693-588B-9B84-35D5F04E26EB" xml:space="preserve">STRUCT SAMPLE
       
    30  {
       
    31  BYTE bts[3]={1,2,3};
       
    32  }</codeblock>
       
    33 <p>In the following resource:</p>
       
    34 <codeblock id="GUID-D1C8604D-6877-54EA-A880-14316BC11008" xml:space="preserve">RESOURCE SAMPLE default
       
    35  {}</codeblock>
       
    36 <p>the output will be the whole default array</p>
       
    37 <codeblock id="GUID-6CA06CBD-03A3-5CA9-8E66-69E8F703470D" xml:space="preserve">0x01 0x02 0x03</codeblock>
       
    38 <p>but in this resource:</p>
       
    39 <codeblock id="GUID-4B3D2892-C408-547F-9D83-40963CF68D19" xml:space="preserve">RESOURCE SAMPLE first_specified
       
    40  {
       
    41  bts={5};
       
    42  }</codeblock>
       
    43 <p>the output is:</p>
       
    44 <codeblock id="GUID-DE3C3486-1084-5A69-8BAE-0DDC0975D8B6" xml:space="preserve">0x05</codeblock>
       
    45 <p>with the second and third elements lost. </p>
       
    46 <p>If you specify only the second element in the <codeph>RESOURCE</codeph> definition,
       
    47 then the first element is taken from the default initialisation, the second
       
    48 from the explicit initialisation and the third element is lost. The following
       
    49 resource:</p>
       
    50 <codeblock id="GUID-0A8BB7DF-64BC-5399-921C-82E304B0F58D" xml:space="preserve">RESOURCE SAMPLE  second_specified
       
    51  {
       
    52  bts[1]=5;
       
    53  }</codeblock>
       
    54 <p>results in the 2-byte output:</p>
       
    55 <codeblock id="GUID-90DEAE7C-41E3-5D14-B074-A9BDC3862363" xml:space="preserve">0x01 0x05</codeblock>
       
    56 <p>If, however, you explicitly initialise an element in the middle of an array
       
    57 without having supplied default values for array members before it, then an
       
    58 error will result.</p>
       
    59 <section><title>Using expressions to initialise array elements</title> <p>You
       
    60 may initialise array elements with expressions. You must explicitly initialise
       
    61 each member component of the array otherwise the expressions will be evaluated
       
    62 incorrectly. The following resource:</p> <codeblock id="GUID-59A9B709-7E44-51BE-A690-7E126EBF4483" xml:space="preserve">RESOURCE SAMPLE correct_expression
       
    63  {
       
    64  bts[0]=3+1;
       
    65  bts[1]=2;
       
    66  bts[2]=3;
       
    67  }</codeblock> <p>will generate the correct output <codeph>0x04  0x02 0x03</codeph>.
       
    68 However, if you use the following syntax:</p> <codeblock id="GUID-943761CA-D4ED-5B8E-9997-17785E1881FB" xml:space="preserve">RESOURCE SAMPLE incorrect_expression
       
    69  {
       
    70  bts={3+1,2,3};
       
    71  }</codeblock> <p>the output will be <codeph>0x03 0x02 0x03</codeph>. This
       
    72 is because the pre-processor treats <codeph>3+1</codeph> as a literal string
       
    73 that is then interpreted by the compiler as 3. In the resource <codeph>correct_expression</codeph> above
       
    74 the ‘=‘ sign forces the pre-processor to evaluate the expression.</p> </section>
       
    75 </conbody></concept>