|
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-97C0A5B1-99AE-5F71-9092-A6976E54AEA7" xml:lang="en"><title>How |
|
13 to initialise STRUCT RESOURCE members</title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p><i><codeph><struct-initialiser></codeph></i> |
|
15 </p> |
|
16 <p><b>struct-initialiser ::=</b> |
|
17 </p> |
|
18 <p><i><codeph><struct-name></codeph></i><b> {</b> <i><codeph><struct-initialiser-item-list></codeph></i> <b>}</b> <i><codeph><struct-initialiser-item></codeph></i> |
|
19 </p> |
|
20 <p><b>struct-initialiser-item ::=</b> |
|
21 </p> |
|
22 <p><i><codeph><member-name> = <initialiser> ;</codeph></i></p> |
|
23 <p>To initialise a member of <codeph>STRUCT</codeph> type, give the <varname>struct-name</varname> with |
|
24 which you wish to initialise it, and then specify each member of that struct |
|
25 which you wish to initialise.</p> |
|
26 <p>The <varname>member-name</varname>s listed must be members of the <varname>struct-name</varname> struct. |
|
27 Each <varname>initialise</varname> must be of a type compatible with the member |
|
28 it is initialising.</p> |
|
29 <p><b>Example</b> </p> |
|
30 <p>Given the previously defined struct types,</p> |
|
31 <codeblock id="GUID-B7A47237-F871-5A07-B97B-11034F7019D1" xml:space="preserve">STRUCT STRINGCOUNT |
|
32 { |
|
33 BUF message; |
|
34 WORD num; |
|
35 }</codeblock> |
|
36 <codeblock id="GUID-562D9436-F734-5E07-B452-08BD40F08959" xml:space="preserve">STRUCT SAMPLE |
|
37 { |
|
38 WORD anynumber; |
|
39 STRUCT text; // should be a STRINGCOUNT |
|
40 }</codeblock> |
|
41 <p>the following example shows how to define the struct within a resource:</p> |
|
42 <codeblock id="GUID-425AD6B0-750B-56C2-8643-2726904C7DB7" xml:space="preserve">RESOURCE SAMPLE show_how |
|
43 { |
|
44 anynumber=10; |
|
45 text=STRINGCOUNT |
|
46 { |
|
47 message="Hello" |
|
48 num=5; |
|
49 }; |
|
50 }</codeblock> |
|
51 <p><b>Type safety</b> </p> |
|
52 <p>The compiler does not enforce type safety. Any struct can be used to initialise |
|
53 a member declared to be of struct type. Usually, however, the designer of |
|
54 the struct will have intended only one or a limited number of structs ever |
|
55 be used to initialise a member. You should ensure that you initialise struct |
|
56 members with the intended struct type.</p> |
|
57 </conbody></concept> |