⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c-wfc3.html

📁 this about vxworks operations systems
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><link rel="STYLESHEET" type="text/css" href="wrs.css"><title>    C++ Development   </title></head><body bgcolor="FFFFFF"><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-wfc.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-wfc2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-wfc4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p><font face="Helvetica, sans-serif" class="sans"><h3 class="H2"><i><a name="84595">5.3  &nbsp;&nbsp;C++ Language and Library Support</a></i></h3></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84596"> </a>In this section we describe some of the VxWorks-specific aspects of our C++ implementation. To learn more about the C++ language and the Standard libraries consult any standard C++ reference (a good one is Stroustrup, <i class="title">The C++ Programming Language</i>, Third Edition). For documentation on the GNU implementation of the Iostream library see </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84597">5.3.1  &nbsp;&nbsp;Language Features</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84598"> </a>We support many but not all of the new language features contained in the recently approved ANSI C++ Standard. Tornado 2.0 has support for exception handling and run-time type information, as well as improved template support. We do not yet support the namespace feature although the compiler will accept (and ignore) references to the <b class="symbol_lc">std</b> namespace.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84599">Exception Handling</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84600"> </a>Our C++ compiler supports multithread safe exception handling by default. To turn off exception handling support use the <b class="symbol_lc">-fno-exceptions</b> compiler flag.</p></dl></dl><dl class="margin"><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="84601">Using Exceptions</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="84602"> </a>You may have code which was designed around the pre-exception model of C++ compilation. Your calls to <b class="symbol_lc">new</b> may check the returned pointer for a failure value of zero, for example. If you are worried that the exception handling enhancements in this release will not compile your code correctly, you could adhere to the following simple rules:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84603"> </a>Use new (nothrow). </li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84604"> </a>Do not explicitly turn on exceptions in your Iostream objects. </li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84605"> </a>Do not use string objects or wrap them in "try {&nbsp;} catch (...) {&nbsp;}" blocks.</li></ul></p></dl><dl class="margin"><dd><p class="Body"><a name="84606"> </a>These rules derive from the following observations:</p></dl><dl class="margin"><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84607"> </a>The GNU Iostream does not throw unless <b class="symbol_UC">IO_THROW</b> is defined when the library is built and exceptions are explicitly enabled for the particular Iostream object in use. The default is no exceptions. Exceptions have to be explicitly turned on for each iostate flag that wants to throw.</li></ul></p><p class="listspace"><ul class="Bullet" type="disc"><li><a name="84608"> </a>The STL does not throw except in some methods in the <b class="symbol_lc">basic_string</b> class (of which string is a specialization).</li></ul></p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="84609">Exception Handling Overhead</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="84610"> </a>To support destruction of automatic objects during stack-unwinding the compiler must insert house-keeping code into any function that creates an automatic (stack based) object with a destructor. </p><dd><p class="Body"><a name="84611"> </a>Below are some of the costs of exception handling as measured on a PowerPC 604 target (BSP mv2604); counts are in executed instructions. 1,235 instructions are executed to execute a "throw 1" and the associated "catch (...)". There are 14 "extra" instructions to register and deregister automatic variables and temporary objects with destructors and 29 "extra" instructions per non-inlined function for exception-handling setup if any exception handling is used in the function. Finally, the implementation executes 947 "extra" instructions upon encountering the first exception-handling construct (try, catch, throw, or registration of an auto variable or temporary).</p><dl class="margin"><dd><pre class="Code2"><b><a name="84612">                            first time&nbsp;&nbsp;&nbsp;normal case void test()&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 3+29&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3+29     throw 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 1235&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1235&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;total time to printf }  void doit()&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 3+29+947&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3+29     try {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 22&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;22         test();         // 1            1     } catch (...) {         printf("Hi\n");     } }  struct A { ~A(&nbsp;) { } };  void local_var (&nbsp;) {&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3+29     A a;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14 }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4</a></b></pre></dl><dd><p class="Body"><a name="84613"> </a><b class="command">-fno-exceptions</b> can be used to turn exception handling off. Doing so will reduce the overheads back to classical C++.</p></dl><dd><font face="Helvetica, sans-serif" size="-1" class="sans"><h5 class="HU"><i><a name="84614">Unhandled Exceptions</a></i></h5></font><dl class="margin"><dd><p class="Body"><a name="84615"> </a>As required by the Standard, an uncaught exception will eventually lead to a call to <b class="routine"><i class="routine">terminate</i></b><b>(&nbsp;)</b>. The default behavior of this function is to suspend the offending task and log a warning message to the console. You may install your own termination handler by calling <b class="routine"><i class="routine">set_terminate</i></b><b>(&nbsp;)</b> (defined in the header file <b class="file">exception</b>).</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84616">Run-Time Type Information (RTTI)</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84617"> </a>This feature is turned on by default and adds a small overhead to any C++ program containing classes with virtual functions. If you do not need this feature you may turn it off using <b class="command">-fno-rtti</b>.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H3"><i><a name="84618">5.3.2  &nbsp;&nbsp;Standard Template Library (STL)</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84619"> </a>The Standard Template library consists of a small run-time component (which may be configured into your kernel by selecting <b class="symbol_UC">INCLUDE_CPLUS_STL</b> for inclusion in the project facility VxWorks view) and a set of header files.</p><dd><p class="Body"><a name="84620"> </a>Our STL port is VxWorks thread safe at the class level. This means that the client has to provide explicit locking if two tasks want to use the same container object. (For example, this could be done by using a semaphore; for details, see <i class="title"><a href="c-basic4.html#84992">2.4.3&nbsp;Semaphores</i><i class="title"></a>.</i>) However two different objects of the same STL container class may be accessed concurrently.</p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84624">Iostream Library</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="86148"> </a>This library is configured into VxWorks by selecting <b class="symbol_UC">INCLUDE_CPLUS_IOSTREAMS</b> for inclusion in the project facility VxWorks view; see <a href="c-wfc2.html#84436"><i class="title">5.2.4&nbsp;Configuration Constants</i></a>. </p><dd><p class="Body"><a name="84631"> </a>The Iostream library header files reside in the standard VxWorks header file directory, <i class="textVariable">installDir</i><b class="file">/target/h</b>. To use this library, include one or more of the header files after the <b class="file">vxWorks.h</b> header in the appropriate modules of your application. The most frequently used header file is <b class="file">iostream.h</b>, but others are available; see a C++ reference such as Stroustrup for information.</p><dd><p class="Body"><a name="84632"> </a>The standard Iostream objects (<b class="keyword">cin</b>, <b class="keyword">cout</b>, <b class="keyword">cerr</b>, and <b class="keyword">clog</b>) are global: that is, they are not private to any given task. They are correctly initialized regardless of the number of tasks or modules that reference them and they may safely be used across multiple tasks that have the same definitions of stdin, stdout, and stderr. However they cannot safely be used in the case that different tasks have different standard i/o file-descriptors; in this case, the responsibility for mutual exclusion rests with the application.</p><dd><p class="Body"><a name="84633"> </a>The effect of private standard Iostream objects can be simulated by creating a new Iostream object of the same class as the standard Iostream object (for example, <b class="keyword">cin</b> is an <b class="keyword">istream_withassign</b>), and assigning to it a new <b class="keyword">filebuf</b> object tied to the appropriate file descriptor. The new <b class="keyword">filebuf</b> and Iostream<b class="library"> </b>objects are private to the calling task, ensuring that no other task can accidentally corrupt them.</p><dl class="margin"><dd><pre class="Code2"><b><a name="84634">ostream my_out (new filebuf (1));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/* 1 == STDOUT */  istream my_in (new filebuf (0), &amp;my_out);&nbsp;&nbsp;&nbsp;&nbsp;/* 0 == STDIN;                                              &nbsp;&nbsp;&nbsp;* TIE to my_out */</a></b></pre></dl><dd><p class="Body"><a name="85974"> </a>For complete details on the Iostreams library, see the online manual <i class="title">The GNU C++ Iostream Library</i>. </p></dl></dl><font face="Helvetica, sans-serif" class="sans"><h4 class="H4"><i><a name="84636">String and Complex Number Classes</a></i></h4></font><dl class="margin"><dl class="margin"><dd><p class="Body"><a name="84637"> </a>These classes are part of the new Standard C++ library. They may be configured into the kernel by selecting <b class="symbol_UC">INCLUDE_CPLUS_STRING</b> and <b class="symbol_UC">INCLUDE_CPLUS_COMPLEX</b> for inclusion in the project facility VxWorks view. You may optionally include I/O facilities for these classes by selecting <b class="symbol_UC">INCLUDE_CPLUS_STRING_IO</b> and <b class="symbol_UC">INCLUDE_CPLUS_COMPLEX_IO</b>.</p></dl></dl><dl class="margin"><dd><p class="table" callout><table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td valign="top" width="40"><br><img border="0" alt="*" src="icons/note.gif"></td><td><hr><div class="CalloutCell"><a name="85497"><b class="symbol_UC"><font face="Helvetica, sans-serif" size="-1" class="sans">NOTE:  </font></b></a>Tornado 2.0 C++ support does not include support for multi-byte strings. This includes certain classes which are part of the tools.h++ portion of the Wind Foundation Classes. </div></td></tr><tr valign="top"><td></td><td><hr></td></tr><tr valign="middle"><td colspan="20"></td></tr></table></p callout></dl><a name="foot"><hr></a><p class="navbar" align="right"><a href="index.html"><img border="0" alt="[Contents]" src="icons/contents.gif"></a><a href="GuideIX.html"><img border="0" alt="[Index]" src="icons/index.gif"></a><a href="c-wfc.html"><img border="0" alt="[Top]" src="icons/top.gif"></a><a href="c-wfc2.html"><img border="0" alt="[Prev]" src="icons/prev.gif"></a><a href="c-wfc4.html"><img border="0" alt="[Next]" src="icons/next.gif"></a></p></body></html><!---by WRS Documentation (), Wind River Systems, Inc.    conversion tool:  Quadralay WebWorks Publisher 4.0.11    template:         CSS Template, Jan 1998 - Jefro --->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -