Symbian3/SDK/Source/GUID-8675AC01-E2D8-425C-899F-12BE99345AA9.dita
changeset 8 ae94777fff8f
parent 7 51a74ef9ed63
child 13 48780e181b38
equal deleted inserted replaced
7:51a74ef9ed63 8:ae94777fff8f
    81     TInt iInt; // offset 0, 4 bytes
    81     TInt iInt; // offset 0, 4 bytes
    82     TText8 iText; // offset 4, 1 byte
    82     TText8 iText; // offset 4, 1 byte
    83         // 3 wasted bytes
    83         // 3 wasted bytes
    84     TReal iReal; // offset 8, 8 bytes
    84     TReal iReal; // offset 8, 8 bytes
    85     } // total length = 16 bytes</codeblock><fig id="GUID-70477651-EC14-4321-ACA5-79CEE4AEC69E">
    85     } // total length = 16 bytes</codeblock><fig id="GUID-70477651-EC14-4321-ACA5-79CEE4AEC69E">
    86 <image href="GUID-7E801A44-4509-5AC0-88D5-7DEA1AF7969D_d0e5815_href.png" placement="inline"/>
    86 <image href="GUID-7E801A44-4509-5AC0-88D5-7DEA1AF7969D_d0e7090_href.png" placement="inline"/>
    87 </fig><p>Structures are regarded as <codeph>T</codeph> types: that is they
    87 </fig><p>Structures are regarded as <codeph>T</codeph> types: that is they
    88 may not own heap-allocated resources such as <codeph>C</codeph> type classes.
    88 may not own heap-allocated resources such as <codeph>C</codeph> type classes.
    89     </p><p>An array contains many built-ins or other types </p><codeblock xml:space="preserve">TInt a[32]; // 32 TInts, = 128 bytes  
    89     </p><p>An array contains many built-ins or other types </p><codeblock xml:space="preserve">TInt a[32]; // 32 TInts, = 128 bytes  
    90 S b[3]; // 3 Ss, = 48 bytes </codeblock><p>The main disadvantage of using
    90 S b[3]; // 3 Ss, = 48 bytes </codeblock><p>The main disadvantage of using
    91 C++ arrays is that there is no automatic checking of index values. For this
    91 C++ arrays is that there is no automatic checking of index values. For this
    96 Arrays</xref>. </p></section>
    96 Arrays</xref>. </p></section>
    97 <section id="GUID-F925F040-C1A3-420A-A9A9-BDFBCDA212B2"><title>Pointers</title><p>A pointer is a memory address. If you can
    97 <section id="GUID-F925F040-C1A3-420A-A9A9-BDFBCDA212B2"><title>Pointers</title><p>A pointer is a memory address. If you can
    98 take the address of an object, then you can refer to it by pointer:</p><codeblock xml:space="preserve">S* ps; // pointer to an S
    98 take the address of an object, then you can refer to it by pointer:</p><codeblock xml:space="preserve">S* ps; // pointer to an S
    99 ps=&amp;s // take address of existing S
    99 ps=&amp;s // take address of existing S
   100 </codeblock><p>A pointer is a 32-bit machine word, and could point to anything.</p><fig id="GUID-D33AB198-0B62-4391-B86D-088595AE6B8B">
   100 </codeblock><p>A pointer is a 32-bit machine word, and could point to anything.</p><fig id="GUID-D33AB198-0B62-4391-B86D-088595AE6B8B">
   101 <image href="GUID-045F3455-2B5A-5B20-ABCE-ED202DC5078A_d0e5846_href.png" placement="inline"/>
   101 <image href="GUID-045F3455-2B5A-5B20-ABCE-ED202DC5078A_d0e7121_href.png" placement="inline"/>
   102 </fig><p>The specifier is placed next to the type rather than the name.   </p><p>There
   102 </fig><p>The specifier is placed next to the type rather than the name.   </p><p>There
   103 is often a need to refer to memory as anything: for this, a <codeph>void*</codeph> pointer
   103 is often a need to refer to memory as anything: for this, a <codeph>void*</codeph> pointer
   104 is used in C++. In Symbian, a <codeph>TAny*</codeph> may be referred to instead.
   104 is used in C++. In Symbian, a <codeph>TAny*</codeph> may be referred to instead.
   105 A <codeph>TAny*</codeph> is a pointer to anything. </p></section>
   105 A <codeph>TAny*</codeph> is a pointer to anything. </p></section>
   106 <section id="GUID-51EBCCA6-8E19-43CC-819E-8A7F0560DE4C"><title>Strings</title><p>In C++, the basic string is an array of
   106 <section id="GUID-51EBCCA6-8E19-43CC-819E-8A7F0560DE4C"><title>Strings</title><p>In C++, the basic string is an array of
   107 characters:</p><codeblock xml:space="preserve">char* hello="hello";</codeblock><p>This statement
   107 characters:</p><codeblock xml:space="preserve">char* hello="hello";</codeblock><p>This statement
   108 does two things: firstly, it sets aside six bytes of memory containing the
   108 does two things: firstly, it sets aside six bytes of memory containing the
   109 characters 'h', 'e', 'l', 'l', 'o', '\0'. Secondly, it sets the pointer hello
   109 characters 'h', 'e', 'l', 'l', 'o', '\0'. Secondly, it sets the pointer hello
   110 to contain the address of the first of those bytes. </p><fig id="GUID-08C1AF40-8D93-414E-B103-1E57AB17480F">
   110 to contain the address of the first of those bytes. </p><fig id="GUID-08C1AF40-8D93-414E-B103-1E57AB17480F">
   111 <image href="GUID-512D0DA7-0BC2-534F-9233-11F46D285CA6_d0e5873_href.png" placement="inline"/>
   111 <image href="GUID-512D0DA7-0BC2-534F-9233-11F46D285CA6_d0e7148_href.png" placement="inline"/>
   112 </fig><p>Functions accessing the string rely on this address as its starting
   112 </fig><p>Functions accessing the string rely on this address as its starting
   113 point, and the terminating <codeph>\0</codeph> to indicate its end. Functions
   113 point, and the terminating <codeph>\0</codeph> to indicate its end. Functions
   114 which manipulate the string must either deliberately not extend it, or must
   114 which manipulate the string must either deliberately not extend it, or must
   115 have some cue as to the amount of memory reserved for the string (beyond the
   115 have some cue as to the amount of memory reserved for the string (beyond the
   116 trailing<codeph>\0</codeph>) so they know how much it can be extended. This
   116 trailing<codeph>\0</codeph>) so they know how much it can be extended. This