Symbian3/SDK/Source/GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita
changeset 2 ebc84c812384
parent 0 89d6a7a84779
equal deleted inserted replaced
1:25a17d01db0c 2:ebc84c812384
     8 Contributors: 
     8 Contributors: 
     9 -->
     9 -->
    10 <!DOCTYPE concept
    10 <!DOCTYPE concept
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
    12 <concept id="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2" xml:lang="en"><title>Standard
    12 <concept id="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2" xml:lang="en"><title>Standard
    13 C++ Support on Symbian Platform</title><prolog><metadata><keywords/></metadata></prolog><conbody>
    13 C++ Support on the Symbian Platform</title><prolog><metadata><keywords/></metadata></prolog><conbody>
    14 <p>This topic describes the Standard C++ runtime features supported on Symbian^3. </p>
    14 <p>This topic describes the Standard C++ runtime features supported on Symbian^3. </p>
    15 <ul>
    15 <ul>
    16 <li id="GUID-F620B47D-35A9-54DF-89FC-031C3B3A50D4"><p><xref href="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita#GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2/GUID-B44FDC08-487F-589B-8355-CF6EAB3F25BC">Global operator new</xref>  </p> </li>
    16 <li id="GUID-F620B47D-35A9-54DF-89FC-031C3B3A50D4"><p><xref href="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita#GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2/GUID-B44FDC08-487F-589B-8355-CF6EAB3F25BC">Global operator new</xref>  </p> </li>
    17 <li id="GUID-2BF296E4-1204-599D-889B-46CD0FEFCC52"><p><xref href="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita#GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2/GUID-ED64EEBA-A52D-5008-8F5F-11019BC5B1E2">new_handler</xref>  </p> </li>
    17 <li id="GUID-2BF296E4-1204-599D-889B-46CD0FEFCC52"><p><xref href="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita#GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2/GUID-ED64EEBA-A52D-5008-8F5F-11019BC5B1E2">new_handler</xref>  </p> </li>
    18 <li id="GUID-E53A2527-BF8A-5578-AF29-B4E1862E958E"><p><xref href="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita#GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2/GUID-FEC1BFE6-0219-5EE8-93D1-C0D5BCFA8A26">Global object destruction</xref>  </p> </li>
    18 <li id="GUID-E53A2527-BF8A-5578-AF29-B4E1862E958E"><p><xref href="GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2.dita#GUID-2CCD1748-9EDE-5383-9941-A3051E06F3E2/GUID-FEC1BFE6-0219-5EE8-93D1-C0D5BCFA8A26">Global object destruction</xref>  </p> </li>
    24 code throws an exception (<codeph>std::bad_alloc</codeph>). But in Symbian
    24 code throws an exception (<codeph>std::bad_alloc</codeph>). But in Symbian
    25 C++, when dynamic memory allocation fails, the code returns <b>NULL</b>. </p> <p>When
    25 C++, when dynamic memory allocation fails, the code returns <b>NULL</b>. </p> <p>When
    26 you write Standard C++ code on Symbian C++ ensure that you either use Symbian
    26 you write Standard C++ code on Symbian C++ ensure that you either use Symbian
    27 C++ semantics of operator new or Standard C++ semantics of operator new in
    27 C++ semantics of operator new or Standard C++ semantics of operator new in
    28 your code. You can use the global <codeph>operator new</codeph> as per the
    28 your code. You can use the global <codeph>operator new</codeph> as per the
    29 Standard C++ specification on Symbian platform by either: </p> <ul>
    29 Standard C++ specification on the Symbian platform by either: </p> <ul>
    30 <li id="GUID-3E72A8F5-F68B-5454-8F20-67CC53FDC37F"><p>Building your application
    30 <li id="GUID-3E72A8F5-F68B-5454-8F20-67CC53FDC37F"><p>Building your application
    31 or library using the STD target type. </p> </li>
    31 or library using the STD target type. </p> </li>
    32 <li id="GUID-40D77F25-4EE4-578A-B51E-451F7655CBA6"><p>Using the <codeph>MMP</codeph> keyword, <codeph>STDCPP</codeph>. </p> </li>
    32 <li id="GUID-40D77F25-4EE4-578A-B51E-451F7655CBA6"><p>Using the <codeph>MMP</codeph> keyword, <codeph>STDCPP</codeph>. </p> </li>
    33 </ul> <p> <b>Note:</b> For detailed information about problems that can occur
    33 </ul> <p> <b>Note:</b> For detailed information about problems that can occur
    34 while using the global <codeph>operator new</codeph>, see <xref href="GUID-AF2CE612-F12E-5A18-81A5-C303992D2D46.dita#GUID-AF2CE612-F12E-5A18-81A5-C303992D2D46/GUID-39350E32-26C2-5440-B221-10EE693CCF18">Use of operator new</xref>. </p> <p> <b>Warning:</b> The Symbian build system
    34 while using the global <codeph>operator new</codeph>, see <xref href="GUID-AF2CE612-F12E-5A18-81A5-C303992D2D46.dita#GUID-AF2CE612-F12E-5A18-81A5-C303992D2D46/GUID-39350E32-26C2-5440-B221-10EE693CCF18">Use of operator new</xref>. </p> <p> <b>Warning:</b> The Symbian build system
    35 does not permit you to mix the Standard C++ <codeph>operator new</codeph> and
    35 does not permit you to mix the Standard C++ <codeph>operator new</codeph> and
    36 the Symbian C++ <codeph>operator new</codeph>. </p> <p><b>Example</b> </p> <p>The
    36 the Symbian C++ <codeph>operator new</codeph>. </p> <p><b>Example</b> </p> <p>The
    37 following example code illustrates how to use the global <codeph>operator
    37 following example code illustrates how to use the global <codeph>operator
    38 new</codeph> when you write Standard C++ code on Symbian platform and your
    38 new</codeph> when you write Standard C++ code on the Symbian platform and
    39 target type is a non-STD target type, for example, <codeph>exe</codeph>. </p> <p>You
    39 your target type is a non-STD target type, for example, <codeph>exe</codeph>. </p> <p>You
    40 must add the <codeph>MMP</codeph> keyword, <codeph>STDCPP</codeph> in the <filepath>.mmp</filepath> file
    40 must add the <codeph>MMP</codeph> keyword, <codeph>STDCPP</codeph> in the <filepath>.mmp</filepath> file
    41 as shown in the following code: </p> <codeblock id="GUID-400432AB-79A2-5F17-9F96-22209524BC84" xml:space="preserve">//operator_new_example.mmp
    41 as shown in the following code: </p> <codeblock id="GUID-400432AB-79A2-5F17-9F96-22209524BC84" xml:space="preserve">//operator_new_example.mmp
    42 Target             operator_new_example.exe
    42 Target             operator_new_example.exe
    43 Targettype        exe
    43 Targettype        exe
    44 //The STDCPP keyword specifies Standard C++ 
    44 //The STDCPP keyword specifies Standard C++ 
    61         return 1;
    61         return 1;
    62         }
    62         }
    63     delete ptr;
    63     delete ptr;
    64     return 0;
    64     return 0;
    65     }</codeblock> </section>
    65     }</codeblock> </section>
    66 <section id="GUID-ED64EEBA-A52D-5008-8F5F-11019BC5B1E2"><title>new_handler</title> <p>The
    66 <section id="GUID-ED64EEBA-A52D-5008-8F5F-11019BC5B1E2"><title>new_handler</title> <p>The <codeph>new_handler()</codeph> function
    67 new_handler() function of Standard C++ is fully supported on Symbian platform
    67 of Standard C++ is fully supported on the Symbian platform (the global <codeph>operator
    68 (the global <codeph>operator new</codeph> restrictions are applicable). You
    68 new</codeph> restrictions are applicable). You can use the new_handler function
    69 can use the new_handler function to handle an out of memory scenario caused
    69 to handle an out of memory scenario caused by the global <codeph>operator
    70 by the global <codeph>operator new</codeph> when dynamic memory allocation
    70 new</codeph> when dynamic memory allocation fails. </p> <p>The following code
    71 fails. </p> <p>The following code illustrates how to set and invoke a <codeph>new_handler</codeph>: </p> <codeblock id="GUID-E1CD4479-99AF-5547-B350-00699CD2788D" xml:space="preserve">#include &lt;new&gt;
    71 illustrates how to set and invoke a <codeph>new_handler</codeph>: </p> <codeblock id="GUID-E1CD4479-99AF-5547-B350-00699CD2788D" xml:space="preserve">#include &lt;new&gt;
    72 int one_huge_chunk = 0xa000;
    72 int one_huge_chunk = 0xa000;
    73 int *last_huge_chunk=NULL;
    73 int *last_huge_chunk=NULL;
    74 void foo()
    74 void foo()
    75     {
    75     {
    76     /*
    76     /*
   144     std::cout &lt;&lt; “main()” &lt;&lt; std::endl;
   144     std::cout &lt;&lt; “main()” &lt;&lt; std::endl;
   145     }</codeblock> <p>The output of this example must be: </p> <codeblock id="GUID-0AB81D7E-B310-5CEA-86DD-65E697F4D2C2" xml:space="preserve">ctor
   145     }</codeblock> <p>The output of this example must be: </p> <codeblock id="GUID-0AB81D7E-B310-5CEA-86DD-65E697F4D2C2" xml:space="preserve">ctor
   146 main
   146 main
   147 dtor</codeblock> </section>
   147 dtor</codeblock> </section>
   148 <section id="GUID-1D9D2701-FD3E-57D1-952B-FB8C057FE055"><title>STL</title> <p>Here
   148 <section id="GUID-1D9D2701-FD3E-57D1-952B-FB8C057FE055"><title>STL</title> <p>Here
   149 are some key facts about STL support on Symbian platform: </p> <ul>
   149 are some key facts about STL support on the Symbian platform: </p> <ul>
   150 <li id="GUID-F0FCA9CA-7417-5D07-A6AA-F679B3A3A41A"><p>The Standard C++ implementation
   150 <li id="GUID-F0FCA9CA-7417-5D07-A6AA-F679B3A3A41A"><p>The Standard C++ implementation
   151 on Symbian platform is based on STLPort version 5.1.4. </p> </li>
   151 on the Symbian platform is based on STLPort version 5.1.4. </p> </li>
   152 <li id="GUID-FB97F095-533F-582D-BD28-667D1BD6863A"><p>The Standard C++ header
   152 <li id="GUID-FB97F095-533F-582D-BD28-667D1BD6863A"><p>The Standard C++ header
   153 files are available in the <filepath>${EPOCROOT}/epoc32/include/stdapis/stlportv5</filepath> directory. </p> </li>
   153 files are available in the <filepath>${EPOCROOT}/epoc32/include/stdapis/stlportv5</filepath> directory. </p> </li>
   154 <li id="GUID-F6381C75-4C30-5627-8AAA-7D8F1FF53565"><p>The Standard C++ library
   154 <li id="GUID-F6381C75-4C30-5627-8AAA-7D8F1FF53565"><p>The Standard C++ library
   155 name that you must use is <filepath>libstdcppv5.lib</filepath>. The value
   155 name that you must use is <filepath>libstdcppv5.lib</filepath>. The value
   156 5 (in the library name) being based on the STL Port version number, which
   156 5 (in the library name) being based on the STL Port version number, which