home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / help / cpplng.inf (.txt) < prev    next >
Encoding:
OS/2 Help File  |  1996-02-19  |  654.6 KB  |  25,294 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. How to Use the VisualAge for C++ Language Reference ΓòÉΓòÉΓòÉ
  3.  
  4. The VisualAge for C++ Language Reference is a language reference guide for C 
  5. and C++ programmers. It provides information about the VisualAge for C++ 
  6. implementation of both the C and C++ languages, including code examples, to 
  7. enable you to write C and C++ programs. 
  8.  
  9. This document is a reference rather than a tutorial. It assumes you are already 
  10. familiar with C and C++ programming concepts. 
  11.  
  12. With the exception of the separate introductory sections for each language and 
  13. the additional C++-specific topics (such as templates and exception handling), 
  14. information applies to both the C and C++ languages. Differences between the 
  15. two languages in the implementation of a construct or concept are indicated. 
  16.  
  17. Before you begin to use this information, it would be helpful to understand how 
  18. to navigate through it. You can use the Table of Contents and Index facility to 
  19. locate topics and the Search facility to search the text of this document. You 
  20. can use hypertext links to acquire related information on the current topic. 
  21. Hypertext links appear in a different color. For example, here is a link to 
  22. another panel: Communicating Your Comments to IBM. By double-clicking on the 
  23. text of the link or by pressing Enter on a highlighted link, you will open a 
  24. panel of related information. When you open a panel, the first link has the 
  25. focus; to shift the focus to other links, use the Tab key. 
  26.  
  27. You should also understand: 
  28.  
  29.      How to Use the Contents 
  30.      How to Get More Information on a Topic 
  31.      How to Use Menu Bar Choices 
  32.      How to Cut and Paste Examples 
  33.  
  34.  
  35. ΓòÉΓòÉΓòÉ 1.1. How to Use the Contents ΓòÉΓòÉΓòÉ
  36.  
  37. When the Contents window first appears, some topics have a plus (+) sign beside 
  38. them. The plus sign indicates that additional topics are available. 
  39.  
  40. To expand the Contents if you are using a mouse, click on the plus sign. If you 
  41. are using the keyboard, use the Up or Down Arrow key to highlight the topic, 
  42. and press the plus (+) key. For example, Preprocessor Directives has a plus 
  43. sign beside it. To see additional topics for that heading, click on the plus 
  44. sign or highlight that topic and press the plus (+) key. 
  45.  
  46. To view a topic, double-click on the topic (or press the Up or Down Arrow key 
  47. to highlight the topic, and then press the Enter key). 
  48.  
  49.  
  50. ΓòÉΓòÉΓòÉ 1.2. How to Get More Information on a Topic ΓòÉΓòÉΓòÉ
  51.  
  52. After you select a topic, the information for that topic appears in a window. 
  53. Highlighted words or phrases indicate that additional information is available. 
  54. Words and phrases highlighted in a different color from the surrounding text 
  55. are called hypertext terms. 
  56.  
  57. If you are using a mouse, double-click on the highlighted word. If you are 
  58. using a keyboard, press the Tab key to move to the highlighted word, and then 
  59. press the Enter key. Additional information then appears in a window. 
  60.  
  61.  
  62. ΓòÉΓòÉΓòÉ 1.3. How to Use Menu Bar Choices ΓòÉΓòÉΓòÉ
  63.  
  64. Several choices are available for managing information presented in this 
  65. document. There are three choices on the menu bar: the Services menu, the 
  66. Options menu, and the Help menu. 
  67.  
  68. Use the Services menu to operate the active window currently displayed on the 
  69. screen. Available actions include the following: 
  70.  
  71.  Bookmark 
  72.    You can set a placeholder so you can retrieve information of interest to 
  73.    you. 
  74.  
  75.  Search 
  76.    You can find occurrences of a word or phrase in the current topic, selected 
  77.    topics, or all topics. 
  78.  
  79.  Print 
  80.    You can print one or more topics. You can also print a set of topics by 
  81.    first marking the topics in the Contents list. 
  82.  
  83.  Copy 
  84.    You can copy a topic that you are viewing to the System Clipboard or to a 
  85.    file that you can edit. This method is particularly useful for copying 
  86.    syntax definitions and program samples into the application that you are 
  87.    developing. 
  88.  
  89.  Select actions from the Options menu, to change the way your Contents list is 
  90.  displayed. To expand the Contents and show all levels for all topics, choose 
  91.  Expand all from the Options pull-down. You can also press the Ctrl, Shift, and 
  92.  * keys together. 
  93.  
  94.  You can select various types of help information from the Help menu. 
  95.  
  96.  For information about any of the menu choices, highlight the choice in the 
  97.  menu and press F1. 
  98.  
  99.  
  100. ΓòÉΓòÉΓòÉ <hidden> Placing Bookmarks ΓòÉΓòÉΓòÉ
  101.  
  102. When you place a bookmark on a topic, it is added to a list of bookmarks you 
  103. have previously set. You can view the list, and you can remove one or all 
  104. bookmarks from the list. If you have not set any bookmarks, the list is empty. 
  105.  
  106. To set a bookmark, do the following: 
  107.  
  108.    1. Select a topic from the Contents. 
  109.    2. When that topic appears, select the Bookmark option from the Services 
  110.       menu. 
  111.    3. If you want to change the name used for the bookmark, type the new name 
  112.       in the field. 
  113.    4. Click on the Place radio button (or press the Up or Down Arrow key to 
  114.       select it). 
  115.    5. Click on OK (or select it and press Enter). The bookmark is then added to 
  116.       the bookmark list. 
  117.  
  118.  
  119. ΓòÉΓòÉΓòÉ <hidden> Searching for Information ΓòÉΓòÉΓòÉ
  120.  
  121. You can specify a word or phrase to be searched. You can also limit the search 
  122. to a set of topics by first marking the topics in the Contents list. 
  123.  
  124. To search for a word or phrase in all topics, do the following: 
  125.  
  126.    1. Select the Search option from the Services menu. 
  127.    2. Type the word or words to be searched for. 
  128.    3. Click on All sections (or press the Up or Down Arrow keys to select it). 
  129.    4. Click on Search (or select it and press Enter) to begin the search. 
  130.    5. The list of topics where the word or phrase appears is displayed. 
  131.  
  132.  
  133. ΓòÉΓòÉΓòÉ <hidden> Printing Information ΓòÉΓòÉΓòÉ
  134.  
  135. You can print one or more topics, the index, or the table of contents. Make 
  136. sure that your printer is connected to the serial port, configured correctly, 
  137. and ready for input. To print: 
  138.  
  139.    1. Select Print from the Services pull-down. 
  140.    2. Select what you want to print. Note that the This section and Marked 
  141.       sections choices are only available if you are viewing a topic or if you 
  142.       have marked topics, respectively. To mark topics in the table of 
  143.       contents, press the Ctrl key and click on the topics, or use the arrow 
  144.       keys. 
  145.    3. Select Print to print what you've chosen on your printer. 
  146.  
  147.  
  148. ΓòÉΓòÉΓòÉ <hidden> Copying Information to a File ΓòÉΓòÉΓòÉ
  149.  
  150. You can copy a topic that you are viewing in two ways: 
  151.  
  152.      Copy copies the topic that you are viewing into the System Clipboard. 
  153.  
  154.      Copy to file copies the topic that you are viewing into a temporary file 
  155.       named text.tmp. You can later edit that file by using any editor. 
  156.       text.tmp is placed in the directory where your viewable document resides. 
  157.       This copy function does not apply if you are viewing the document from 
  158.       the CD-ROM. 
  159.  
  160.  To copy a topic, do the following: 
  161.  
  162.    1. Expand the Contents list and select a topic. 
  163.    2. When the topic appears, select Copy to file from the Services menu. 
  164.    3. The system puts the text pertaining to that topic into the temporary file 
  165.       text.tmp. 
  166.  
  167.  
  168. ΓòÉΓòÉΓòÉ 1.4. How to Cut and Paste Examples ΓòÉΓòÉΓòÉ
  169.  
  170. You can copy examples (or information) from this document to compile, link, and 
  171. run them, or to paste them into your own code. 
  172.  
  173. To copy an example or information: 
  174.  
  175.    1. Make the topic you want to copy the active window. 
  176.  
  177.    2. From the Services menu, select Copy to file. The text in that topic is 
  178.       placed in the temporary file text.tmp, in the same directory as this 
  179.       reference. This copy function does not apply if you are viewing the 
  180.       document from the CD-ROM. 
  181.  
  182.    3. You can then modify or use text.tmp as you want. 
  183.  
  184.  Note:  Because the system copies the entire contents of the topic to the file, 
  185.  you may need to edit it to remove additional text. Most examples in this 
  186.  reference are ready to compile, link, and run as they appear, and do not 
  187.  require any editing. 
  188.  
  189.  
  190. ΓòÉΓòÉΓòÉ 1.5. Other Information You Might Find Helpful ΓòÉΓòÉΓòÉ
  191.  
  192. This product provides a number of online guides and references that we hope 
  193. you'll find helpful as you develop applications. This information includes 
  194. User's Guides, References, and How Do I help that gives you specific 
  195. instructions for performing common tasks. You can get to this online 
  196. information from the Information folder inside the main product folder. You can 
  197. also get to it from the Help menu in any of the components of the product. 
  198.  
  199.  
  200. ΓòÉΓòÉΓòÉ 1.6. Communicating Your Comments to IBM ΓòÉΓòÉΓòÉ
  201.  
  202. If there is something you like, or dislike, about this book, please let us 
  203. know. You can use one of the methods listed below to send your comments to IBM. 
  204. Please be sure to include the complete title of the publication that you are 
  205. commenting on. 
  206.  
  207. The comments you send should only pertain to the information in this document 
  208. and its presentation. To request additional publications or to ask questions or 
  209. make comments about the functions of IBM products or systems, you should talk 
  210. to your IBM representative or your authorized IBM remarketer. 
  211.  
  212. When you send comments to IBM, you grant IBM a nonexclusive right to use or 
  213. distribute your comments in any way it believes appropriate without incurring 
  214. any obligation to you. 
  215.  
  216. You can send your comments to IBM in the following ways: 
  217.  
  218.      By mail to the following address: 
  219.  
  220.             IBM Canada Ltd. Laboratory
  221.             Information Development
  222.             2G/345/1150/TOR
  223.             1150 EGLINTON AVENUE EAST
  224.             NORTH YORK, ONTARIO
  225.             CANADA M3C 1H7
  226.  
  227.      By FAX to the following number: 
  228.  
  229.         -  United States and Canada: (416) 448-6161 
  230.         -  Other countries (+1) 416-448-6161 
  231.  
  232.      By electronic mail to one of the following IDs. Be sure to include your 
  233.       entire network address if you wish to get a reply. 
  234.  
  235.         -  Internet: torrcf@vnet.ibm.com 
  236.         -  IBMLink: toribm(torrcf) 
  237.         -  IBM/PROFS: torolab4(torrcf) 
  238.         -  IBMMAIL: ibmmail(caibmwt9) 
  239.  
  240.  
  241. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  242.  
  243.      Copyright 
  244.      Edition Notice 
  245.      Notices 
  246.      Trademarks and Service Marks 
  247.  
  248.  
  249. ΓòÉΓòÉΓòÉ 1.7. Copyright ΓòÉΓòÉΓòÉ
  250.  
  251. Copyright International Business Machines Corporation, 1996. All rights 
  252. reserved. 
  253.  
  254. Note to U.S. Government Users - Documentation related to restricted rights - 
  255. Use, duplication, or disclosure is subject to restrictions set forth in GSA ADP 
  256. Schedule Contract with IBM Corp. 
  257.  
  258.  
  259. ΓòÉΓòÉΓòÉ 1.8. Edition Notice ΓòÉΓòÉΓòÉ
  260.  
  261. First Edition (February 1996) 
  262.  
  263. This edition applies to Version 3.5 of IBM VisualAge for C++ for Windows 
  264. (33H4979, 33H4980) and to all subsequent releases and modifications until 
  265. otherwise indicated in new editions. Make sure you are using the correct 
  266. edition for the level of the product. 
  267.  
  268. This publication could include technical inaccuracies or typographical errors. 
  269. Changes are periodically made to the information herein; any such changes will 
  270. be reported in subsequent revisions. 
  271.  
  272. Requests for publications and for technical information about IBM products 
  273. should be made to your IBM Authorized Dealer or your IBM Marketing 
  274. Representative. 
  275.  
  276. When you send information to IBM, you grant IBM a nonexclusive right to use or 
  277. distribute the information in any ways it believes appropriate without 
  278. incurring any obligation to you. 
  279.  
  280.  
  281. ΓòÉΓòÉΓòÉ 1.9. Notices ΓòÉΓòÉΓòÉ
  282.  
  283. Any reference to an IBM licensed program in this publication is not intended to 
  284. state or imply that only IBM's licensed program may be used. Any functionally 
  285. equivalent product, program, or service that does not infringe any of IBM's 
  286. intellectual property rights may be used instead of the IBM product, program, 
  287. or service. Evaluation and verification of operation in conjunction with other 
  288. products, except those expressly designated by IBM, is the user's 
  289. responsibility. 
  290.  
  291. IBM may have patents or pending patent applications covering subject matter in 
  292. this document. The furnishing of this document does not give you any license to 
  293. these patents. You can send license inquiries, in writing, to the 
  294.  
  295. IBM Director of Licensing,
  296. IBM Corporation,
  297. 500 Columbus Avenue,
  298. Thornwood, NY, 10594,
  299. USA.
  300.  
  301. Licensees of this program who wish to have information about it for the purpose 
  302. of enabling: (i) the exchange of information between independent created 
  303. programs and other programs (including this one) and (ii) the mutual use of the 
  304. information which has been exchanged, should contact IBM Canada Ltd., 
  305. Department 071, 1150 Eglinton Avenue East, North York, Ontario M3C 1H7, Canada. 
  306. Such information may be available, subject to appropriate terms and conditions, 
  307. including in some cases payment of a fee. 
  308.  
  309. This publication contains examples of data and reports used in daily business 
  310. operations. To illustrate them as completely as possible, the examples include 
  311. the names of individuals, companies, brands, and products. All of these names 
  312. are fictitious and any similarity to the names and addresses used by an actual 
  313. business enterprise is entirely coincidental. 
  314.  
  315.  
  316. ΓòÉΓòÉΓòÉ 1.10. Trademarks and Service Marks ΓòÉΓòÉΓòÉ
  317.  
  318. The following terms used in this publication are trademarks or service marks of 
  319. IBM Corporation in the United States or other countries: 
  320.  
  321.       IBM 
  322.       IBMLink 
  323.       Personal System/2 
  324.       PS/2 
  325.       VisualAge 
  326.       WorkFrame 
  327.  
  328.  Windows is a trademark of Microsoft Corporation. 
  329.  
  330.  Other company, product, and service names, which may be denoted by a double 
  331.  asterisk(**), may be trademarks or service marks of others. 
  332.  
  333.  IBM's VisualAge products and services are not associated with or sponsored by 
  334.  Visual Edge Software, Ltd.. 
  335.  
  336.  
  337. ΓòÉΓòÉΓòÉ <hidden> signed/unsigned types ΓòÉΓòÉΓòÉ
  338.  
  339. The signed and unsigned types can be used with either a character (char) or an 
  340. integer (int, short, long). The unsigned prefix indicates that the value of the 
  341. object is to be a nonnegative value. 
  342.  
  343. For more information on conversions between signed and unsigned types, see 
  344. Implicit Type Conversions. 
  345.  
  346.  
  347. ΓòÉΓòÉΓòÉ <hidden> \ Character ΓòÉΓòÉΓòÉ
  348.  
  349. The backslash can appear in string literals or comments as a punctuator.  A 
  350. backslash followed by a single character in C code indicates an escape 
  351. sequence. A backslash by itself at the end of a line of C code is a 
  352. continuation character. 
  353.  
  354. Escape Sequences provides help on escape sequences and the continuation 
  355. character. 
  356.  
  357.  
  358. ΓòÉΓòÉΓòÉ <hidden> ( ) ΓòÉΓòÉΓòÉ
  359.  
  360. Parentheses are used to group expressions to force a particular order of 
  361. evaluation. A parenthesized expression usually contains one or more operators 
  362. and operands (variables or constants), and is often part of an assignment 
  363. expression. For example, ((x + y) * g) is a parenthesized expression. 
  364.  
  365. Parentheses are also used in function calls to group the argument list for the 
  366. function. The opening parenthesis appears directly after the function name, and 
  367. may be followed by any number of arguments (or no arguments), followed by the 
  368. closing parenthesis and a semicolon. For example, fgets(line, 100, stream); is 
  369. a function call. 
  370.  
  371. For help on parenthesized expressions, see Parenthesized Expressions ( ). 
  372.  
  373. For help on function calls, see Function Calls ( ). 
  374.  
  375.  
  376. ΓòÉΓòÉΓòÉ <hidden> + ΓòÉΓòÉΓòÉ
  377.  
  378. The plus (+) sign can be used as a unary operator to maintain the value of an 
  379. operand, for example, +quality. The unary plus sign is the opposite of the 
  380. unary minus (-) sign, which negates the value of an operand, for example, 
  381. -quality. 
  382.  
  383. The plus sign can also be used as a binary operator in an arithmetic expression 
  384. to represent the addition operation. For example, x + y indicates that the 
  385. variables x and y are to be added together. 
  386.  
  387. For more information on the unary plus operator, see Unary Plus  +. 
  388.  
  389. For more information on the addition operator, see Addition  +. 
  390.  
  391.  
  392. ΓòÉΓòÉΓòÉ <hidden> - ΓòÉΓòÉΓòÉ
  393.  
  394. The minus (-) sign can be used as a unary operator to negate the value of an 
  395. operand, for example -quality. 
  396.  
  397. It can also be used as a binary operator in an arithmetic expression to 
  398. represent the subtraction operation. For example, x - y indicates that the 
  399. variable y is to be subtracted from the variable x. 
  400.  
  401. For more information on the unary minus operator, see Unary Minus  -. 
  402.  
  403. For more information on the subtraction operator, see Subtraction  -. 
  404.  
  405.  
  406. ΓòÉΓòÉΓòÉ <hidden> & ΓòÉΓòÉΓòÉ
  407.  
  408. The ampersand (&) sign can be used as a unary operator to indicate the address 
  409. of its operand. For example, &anyvar represents the address of the variable 
  410. anyvar. 
  411.  
  412. The ampersand can also be used as a binary operator to represent the bitwise 
  413. AND operation. For example, in the expression x & y, the corresponding bits of 
  414. the x and y values are compared to see if the bits are both 1. 
  415.  
  416. A double ampersand (&&) is the logical AND operator. which indicate For 
  417. example, in the expression x && y, the values of x and y are checked to see if 
  418. both are nonzero values. 
  419.  
  420. For more information on the address operator, see Address  &. 
  421.  
  422. For more information on the bitwise AND operator, see Bitwise AND  &. 
  423.  
  424. For more information on the logical AND operator, see Logical AND  &&. 
  425.  
  426.  
  427. ΓòÉΓòÉΓòÉ <hidden> * ΓòÉΓòÉΓòÉ
  428.  
  429. The asterisk (*) can be used as a unary operator to indicate indirection. For 
  430. example, int *anyvar; declares anyvar as a pointer to int, that points to the 
  431. value of *anyvar. 
  432.  
  433. The asterisk can also be used as a binary operator in an arithmetic expression 
  434. to represent the multiplication operation. For example, x * y indicates that 
  435. the variable x is to be multiplied by y. 
  436.  
  437. For more information on the indirection operator, see Indirection  *. 
  438.  
  439. For more information on the multiplication operator, see Multiplication  *. 
  440.  
  441.  
  442. ΓòÉΓòÉΓòÉ <hidden> % ΓòÉΓòÉΓòÉ
  443.  
  444. The percent (%) sign can be used simply to indicate percentage in a string 
  445. literal.  For example, "More than 50% agree". 
  446.  
  447. The percent sign is also used as part of the format specifier for the printf 
  448. and scanf functions.  For example, in the statement printf("The value is %d", 
  449. anyint); the integer value of anyint is printed in the place of the %d 
  450. specifier. 
  451.  
  452. The percent sign can also be used as a binary operator to represent the modulus 
  453. (or remainder) operation. For example, the expression x % y indicates that x is 
  454. divided by y, and the result of the expression is the remainder of the 
  455. division. 
  456.  
  457. For more information on string literals, see String Literals. 
  458.  
  459. For more information on format specifiers, see the printf function or the scanf 
  460. function in the IBM VisualAge for C++ for Windows C Library Reference. 
  461.  
  462. For more information on the remainder operator, see Remainder  %. 
  463.  
  464.  
  465. ΓòÉΓòÉΓòÉ <hidden> : ΓòÉΓòÉΓòÉ
  466.  
  467. The colon (:) is used to indicate the end of a label and separate it from the 
  468. following statement. For example, in the expression anylabl: x = y;, anylabl is 
  469. a label that could be part of a switch statement or the target of a goto 
  470. statement. 
  471.  
  472. The colon is also used in bit-field declarations to separate the identifier of 
  473. the bit field and the storage it is given. For example, in the structure 
  474.  
  475. struct {
  476.     unsigned x : 4
  477.     unsigned y : 1
  478.     }
  479.  
  480. the bit fields x and y are assigned 4 bits and 1 bit of storage, respectively. 
  481.  
  482. The colon can also be used as part of the compound conditional expression (?:) 
  483. to separate the two action expressions. For example, in the expression x = (y < 
  484. z) ? y : z;, if y is less than z, the value of y is assigned to x; if y is not 
  485. less than z, the value of z is assigned to x. 
  486.  
  487. For more information on labels, see Labels. 
  488.  
  489. For more information on bit fields, see the section Declaring and Using Bit 
  490. Fields under Structures. 
  491.  
  492. For more information on the compound conditional expression, see Conditional 
  493. Expressions. 
  494.  
  495.  
  496. ΓòÉΓòÉΓòÉ <hidden> ? ΓòÉΓòÉΓòÉ
  497.  
  498. The question mark (?) is used for both trigraphs (three characters starting 
  499. with ??) and as the first part of the operator for the conditional expression. 
  500.  
  501. For more information on the compound conditional expression, see Conditional 
  502. Expressions. 
  503.  
  504.  
  505. ΓòÉΓòÉΓòÉ <hidden> , ΓòÉΓòÉΓòÉ
  506.  
  507. The comma (,) can be used to separate items such as parameters in a function 
  508. call. 
  509.  
  510. The comma is also used in the comma expression to separate two operands.  For 
  511. example, in the expression x = (y++, z * 4);, the left operand is evaluated 
  512. then discarded, and the value of the right operand is assigned to x. 
  513.  
  514. For more information on the comma expression, see Comma Expression  ,. 
  515.  
  516.  
  517. ΓòÉΓòÉΓòÉ <hidden> ; ΓòÉΓòÉΓòÉ
  518.  
  519. The semicolon (;) is used to indicate the end of a C expression, for example, 
  520. int x = 4;. 
  521.  
  522. The semicolon can also be used by itself as a null statement to show a 
  523. nonexistent action. 
  524.  
  525. For more information on expressions, see Expression. 
  526.  
  527. For more information on null statements, see Null Statement. 
  528.  
  529.  
  530. ΓòÉΓòÉΓòÉ <hidden> # ΓòÉΓòÉΓòÉ
  531.  
  532. The number sign (#) is used to begin preprocessor directives. The # token must 
  533. appear as the first character that is not white space on a line. The # is not 
  534. part of the directive name and can be separated from the name with white 
  535. spaces. 
  536.  
  537. It can also be used by itself as a null preprocessing directive The null 
  538. directive performs no action. It consists of a single # on a line of its own. 
  539.  
  540. The null directive should not be confused with the # operator, which converts a 
  541. parameter of a function-like macro into a character string literal. 
  542.  
  543. For more information on the # preprocessor operator, see # Operator. 
  544.  
  545. For more information on the null directive, see Null Directive (#). 
  546.  
  547. For more information on preprocessor directives, see Preprocessor Directive 
  548. Format. 
  549.  
  550.  
  551. ΓòÉΓòÉΓòÉ 2. Introduction to C and C++ ΓòÉΓòÉΓòÉ
  552.  
  553. This chapter describes the C and C++ programming languages implemented by 
  554. VisualAge for C++ and shows you how to structure C and C++ source programs. It 
  555. also briefly summarizes the differences between C and C++, and discusses the 
  556. principles of object-oriented programming. 
  557.  
  558. Refer to the IBM VisualAge for C++ for Windows Programming Guide for 
  559. information about implementation-defined behavior in the VisualAge for C++ 
  560. environment. 
  561.  
  562. This section discusses: 
  563.  
  564.      Overview of the C Language 
  565.      C Source Programs 
  566.      C Source Files 
  567.      Program Execution 
  568.      Scope in C 
  569.      Program Linkage 
  570.      Storage Duration 
  571.      Name Spaces 
  572.  
  573.  Related Information 
  574.  
  575.      Overview of the C++ Language 
  576.  
  577.  
  578. ΓòÉΓòÉΓòÉ 2.1. Overview of the C Language ΓòÉΓòÉΓòÉ
  579.  
  580. C is a programming language designed for a wide variety of programming tasks. 
  581. It is used for system-level code, text processing, graphics, and in many other 
  582. application areas. 
  583.  
  584. The C language described here is consistent with the Systems Application 
  585. Architecture Common Programming Interface (also known as the SAA C Level 2 
  586. interface), and with the International Standard C (ANSI/ISO-IEC 
  587. 9899-1990[1992]). This standard has officially replaced American National 
  588. Standard for Information Systems-Programming Language C (X3.159-1989) 
  589. (X3.159-1989) and is technically equivalent to the ANSI** C standard. 
  590.  
  591. VisualAge for C++ supports most, but not all, of the changes adopted into the C 
  592. Standard by ISO/IEC 9899:1990/Amendment 1:1994. 
  593.  
  594. C supports several data types, including characters, integers, floating-point 
  595. numbers and pointers - each in a variety of forms. In addition, C also supports 
  596. arrays, structures (records), unions, and enumerations. 
  597.  
  598. The C language contains a concise set of statements, with functionality added 
  599. through its library. This division enables C to be both flexible and efficient. 
  600. An additional benefit is that the language is highly consistent across 
  601. different systems. 
  602.  
  603. The C library contains functions for input and output, mathematics, exception 
  604. handling, string and character manipulation, dynamic memory management, as well 
  605. as date and time manipulation. Use of this library helps to maintain program 
  606. portability, because the underlying implementation details for the various 
  607. operations need not concern the programmer. 
  608.  
  609. The IBM VisualAge for C++ for Windows C Library Reference describes all of the 
  610. C library functions supported by the VisualAge for C++ compiler. 
  611.  
  612. Related Information 
  613.  
  614.      Lexical Elements of C and C++ 
  615.      Functions 
  616.      Type Specifiers 
  617.      Overview of the C++ Language 
  618.  
  619.  
  620. ΓòÉΓòÉΓòÉ 2.2. C Source Programs ΓòÉΓòÉΓòÉ
  621.  
  622. A C source program is a collection of one or more directives, declarations, and 
  623. statements contained in one or more source files. The resulting collection of 
  624. files constitutes a compilation unit. 
  625.  
  626.  Statements      Specify the action to be performed. 
  627.  
  628.  Directives      Instruct the preprocessor to act on the text of the program. 
  629.                  Pragma directives affect compiler behavior. 
  630.  
  631.  Declarations    Establish names and define characteristics such as scope, data 
  632.                  type and linkage. 
  633.  
  634.  Definitions     Are declarations that allocate storage for data objects or 
  635.                  define a body for functions. An object definition allocates 
  636.                  storage and may optionally initialize the object. 
  637.  
  638.  A function declaration precedes the function body. The function body is a 
  639.  compound statement that can contain declarations and statements that define 
  640.  what the function does. The function declaration declares the function name, 
  641.  its parameters, and the data type of the value it returns. 
  642.  
  643.  A program must contain one, and only one, function called main. The main 
  644.  function is the first function called when a program is run. 
  645.  
  646.  C++ Note:  This is not the case for C++ programs. If a C++ program 
  647.  instantiates an object in file scope, the constructor for that object is 
  648.  executed first. 
  649.  
  650.  By convention, main is the starting point for running a program. It typically 
  651.  calls other functions. A program usually stops running at 
  652.  
  653.      the end of the main function 
  654.      a return statement in the main function 
  655.      an exit function call. 
  656.  
  657.  Source for a Simple C Program 
  658.  
  659.  Related Information 
  660.  
  661.      C Source Files 
  662.      Overview of the C Language 
  663.      C++ Programs 
  664.  
  665.  
  666. ΓòÉΓòÉΓòÉ <hidden> Source for a Simple C Program ΓòÉΓòÉΓòÉ
  667.  
  668. /************************************************************************
  669. *
  670.  
  671. This is the source code of a simple C program: 
  672.  
  673.                                      *
  674. ************************************************************************/
  675.  
  676. /**
  677.  ** This is an example of a simple C program
  678.  **/
  679. #include <stdio.h>        /* standard I/O library header that
  680.                   contains macros and function declarations
  681.                   such as printf used below      */
  682.  
  683. #include <math.h>        /* standard math library header that
  684.                   contains macros and function declarations
  685.                   such as cos used below       */
  686.  
  687. #define NUM 46.0         /* Preprocessor directive       */
  688.  
  689. double x = 45.0;         /* External variable definitions    */
  690.  
  691. double y = NUM;
  692.  
  693.  
  694. int main(void)          /* Function definition
  695.                   for main function          */
  696. {
  697.   double z;           /* Local variable definitions     */
  698.   double w;
  699.  
  700.   z = cos(x);          /* cos is declared in math.h as
  701.                      double cos(double arg)    */
  702.   w = cos(y);
  703.   printf ("cosine of x is %f\n", z);  /* Print cosine of x      */
  704.   printf ("cosine of y is %f\n", w);  /* Print cosine of y      */
  705.  
  706.   return 0;
  707. }
  708.  
  709. /************************************************************************
  710. *
  711.  
  712. This source program defines main and declares a reference to the functions cos 
  713. and printf. The program defines the global variables x and y, initializes them, 
  714. and declares two local variables z and w. 
  715.  
  716.                                     *
  717. ************************************************************************/
  718.  
  719.  
  720. ΓòÉΓòÉΓòÉ 2.3. C Source Files ΓòÉΓòÉΓòÉ
  721.  
  722. A C source file is a text file that contains all or part of a C source program. 
  723. It can include any of the functions that the program needs. To create an 
  724. executable module, you compile the separate source files individually and then 
  725. link them as one program. With the #include directive, you can combine source 
  726. files into larger source files. The resulting collection of files constitutes a 
  727. compilation unit. 
  728.  
  729. A source file contains any combination of directives, declarations, and 
  730. definitions. You can split items such as function definitions and large data 
  731. structures between source files, but you cannot split them between compiled 
  732. files. Before the source file is compiled, the preprocessor alters the source 
  733. file in a predictable way. The preprocessor directives determine what changes 
  734. are made to the source text. As a result of the preprocessing stage, 
  735. preprocessor directives are completed, macros are expanded, and a source file 
  736. is created containing C statements, completed directives, declarations, and 
  737. definitions. 
  738.  
  739. It is sometimes useful to gather variable definitions into one source file and 
  740. declare references to those variables in any source files that use them. This 
  741. procedure makes definitions easy to find and change, if necessary. You can also 
  742. organize constants and macros into separate files and include them into source 
  743. files as required. 
  744.  
  745. Directives in a source file apply to that source file and its included files 
  746. only. Each directive applies only to the part of the file following the 
  747. directive. 
  748.  
  749. Example of C Source Files 
  750.  
  751. Related Information 
  752.  
  753.      C Source Programs 
  754.      Overview of the C Language 
  755.      Declarations 
  756.      Statements 
  757.      Functions 
  758.      Preprocessor Directives 
  759.      C++ Programs 
  760.  
  761.  
  762. ΓòÉΓòÉΓòÉ <hidden> Example of C Source Files ΓòÉΓòÉΓòÉ
  763.  
  764. /************************************************************************
  765. *
  766.  
  767. The following example is a C program in two source files. The main and max 
  768. functions are in separate files. The program starts running with the main 
  769. function. 
  770.  
  771. Source file 1 
  772.  
  773.                                     *
  774. ************************************************************************/
  775.  
  776. /************************************************************************
  777. *  Source file 1 - main function                     *
  778. ************************************************************************/
  779.  
  780. #define ONE   1
  781. #define TWO   2
  782. #define THREE  3
  783.  
  784. extern int max(int, int);        /* Function declaration */
  785.  
  786. int main(int argc, char * argv[])    /* Function definition  */
  787. {
  788.   int u, w, x, y, z;
  789.  
  790.   u = 5;
  791.   z = 2;
  792.   w = max(u, ONE);
  793.   x = max(w,TWO);
  794.   y = max(x,THREE);
  795.   z = max(y,z);
  796. return z;
  797. }
  798.  
  799. /************************************************************************
  800. *
  801.  
  802. Source file 2 
  803.  
  804.                                     *
  805. ************************************************************************/
  806.  
  807. /************************************************************************
  808. *  Source file 2 - max function                     *
  809. ************************************************************************/
  810. int max (int a,int b)         /* Function  definition      */
  811.  
  812. {
  813.   if ( a > b )
  814.     return (a);
  815.   else
  816.     return (b);
  817. }
  818.  
  819. /************************************************************************
  820. *
  821.  
  822. The first source file declares the function max, but does not define it. This 
  823. is an external declaration, a declaration of a function defined in source file 
  824. 2. Four statements in main are function calls of max. 
  825.  
  826. The lines beginning with a number sign (#) are preprocessor directives that 
  827. direct the preprocessor to replace the identifiers ONE, TWO, and THREE with the 
  828. digits 1, 2, and 3. The directives do not apply to the second source file. 
  829.  
  830. The second source file contains the function definition for max, which is 
  831. called four times in main. After you compile the source files, you can link and 
  832. run them as a single program. 
  833.  
  834. /************************************************************************
  835. *
  836.  
  837.  
  838. ΓòÉΓòÉΓòÉ 2.4. Program Execution ΓòÉΓòÉΓòÉ
  839.  
  840. Every program must have a function called main and usually contains other 
  841. functions. 
  842.  
  843. The main function is the starting point for running a program. The statements 
  844. within the main function are executed sequentially. There may be calls to other 
  845. functions. A program usually stops running at the end of the main function, 
  846. although it can stop at other points in the program. 
  847.  
  848. You can make your program more modular by creating separate functions to 
  849. perform a specific task or set of tasks. The main function calls these 
  850. functions to perform the tasks. Whenever a function call is made, the 
  851. statements are executed sequentially starting with the first statement in the 
  852. function. The function returns control to the calling function at the return 
  853. statement or at the end of the function. 
  854.  
  855. You can declare any function to have parameters. When functions are called, 
  856. they receive values for their parameters from the arguments passed by the 
  857. calling functions. You can declare parameters for the main function so you can 
  858. pass values to main from the command line. The command line processor that 
  859. starts the program can pass such values as described in The main() Function. 
  860.  
  861. Related Information 
  862.  
  863.      Functions 
  864.      The main() Function 
  865.      Calling Functions and Passing Arguments 
  866.      C Source Files 
  867.      Overview of the C Language 
  868.      C++ Programs 
  869.  
  870.  
  871. ΓòÉΓòÉΓòÉ 2.5. Scope in C ΓòÉΓòÉΓòÉ
  872.  
  873. An identifier becomes visible with its declaration. The region where an 
  874. identifier is visible is referred to as the identifier's scope. The four kinds 
  875. of scope are: 
  876.  
  877.      Block 
  878.      Function 
  879.      File 
  880.      Function prototype 
  881.  
  882.  The scope of an identifier is determined by where the identifier is declared. 
  883.  See Identifiers for more information on identifiers. 
  884.  
  885.  In the following example, the variable x, which is declared on line 1, is 
  886.  different from the x declared on line 2. The variable declared on line 2 has 
  887.  function prototype scope and is visible only up to the closing parenthesis of 
  888.  the prototype declaration. Visibility of the variable x declared on line 2 
  889.  resumes after the end of the prototype declaration. 
  890.  
  891.   1  int x = 4;       /* variable x defined with file scope */
  892.   2  long myfunc(int x, long y); /* variable x has function    */
  893.   3                /* prototype scope        */
  894.   4  int main(void)
  895.   5  {
  896.   6    /* . . . */
  897.   7  }
  898.  
  899.  Functions with static storage class are visible only in the source file they 
  900.  are defined in. All other functions can be globally visible. 
  901.  
  902.  Example of Scope 
  903.  
  904.  Related Information 
  905.  
  906.      Block 
  907.      Labels 
  908.      goto 
  909.      Functions 
  910.      static Storage Class Specifier 
  911.      C Source Files 
  912.      Scope in C++ 
  913.  
  914.  
  915. ΓòÉΓòÉΓòÉ <hidden> Block Scope ΓòÉΓòÉΓòÉ
  916.  
  917. The identifier's declaration is located inside a statement block. A block 
  918. starts with an opening brace ({) and ends with a closing brace (}). An 
  919. identifier with block scope is visible from the point where it is declared to 
  920. the closing brace that ends the block. Block scope is sometimes referred to as 
  921. local scope. 
  922.  
  923. You can nest block visibility. A block nested inside a block can contain 
  924. declarations that redeclare variables declared in the outer block. The new 
  925. declaration of the variable applies to the inner block. The original 
  926. declaration is restored when program control returns to the outer block. A 
  927. variable from the outer block is visible inside inner blocks that do not 
  928. redefine the variable. 
  929.  
  930.  
  931. ΓòÉΓòÉΓòÉ <hidden> Function Scope ΓòÉΓòÉΓòÉ
  932.  
  933. The only type of identifier with function scope is a label name. A label is 
  934. implicitly declared by its appearance in the program text and is visible 
  935. throughout the function that declares it. 
  936.  
  937.  
  938. ΓòÉΓòÉΓòÉ <hidden> File Scope ΓòÉΓòÉΓòÉ
  939.  
  940. The identifier's declaration appears outside of any block. It is visible from 
  941. the point where it is declared to the end of the source file. If source files 
  942. are included by #include preprocessor directives, those files are considered to 
  943. be part of the source and the identifier will be visible to all included files 
  944. that appear after the declaration of the identifier. The identifier can be 
  945. declared again as a block scope variable. The new declaration replaces the 
  946. file-scope declaration until the end of the block. 
  947.  
  948.  
  949. ΓòÉΓòÉΓòÉ <hidden> Function Prototype Scope ΓòÉΓòÉΓòÉ
  950.  
  951. The identifier's declaration appears within the list of parameters in a 
  952. function prototype. It is visible from the point where it is declared to the 
  953. closing parenthesis of the prototype declaration. 
  954.  
  955.  
  956. ΓòÉΓòÉΓòÉ <hidden> Example of Scope ΓòÉΓòÉΓòÉ
  957.  
  958. /************************************************************************
  959. *
  960.  
  961. The following program illustrates blocks, nesting, and scope. The example shows 
  962. two kinds of scope: file and block. The main function prints the values 1, 2, 
  963. 3, 0, 3, 2, 1 on separate lines. Each instance of i represents a different 
  964. variable. 
  965.  
  966.                                     *
  967. ************************************************************************/
  968.  
  969.      #include <stdio.h>
  970.      int i = 1;             /* i defined at file scope */
  971.  
  972.      int main(int argc, char * argv[])
  973.  ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ  {
  974.  Γöé
  975.  Γöé      printf("%d\n", i);        /* Prints 1 */
  976.  Γöé
  977.  Γöé ΓöîΓöÇΓöÇΓöÇΓöÇ   {
  978.  Γöé Γöé       int i = 2, j = 3;       /* i and j defined at
  979.  Γöé Γöé                       block scope */
  980.  Γöé Γöé       printf("%d\n%d\n", i, j);   /* Prints 2, 3 */
  981.  Γöé Γöé
  982.  Γöé Γöé ΓöîΓöÇΓöÇ     {
  983.  Γöé Γöé Γöé       int i = 0;         /* i is redefined in a nested block   */
  984.  Γöé Γöé Γöé                    /* previous definitions of i are hidden */
  985.  Γöé Γöé Γöé       printf("%d\n%d\n", i, j); /* Prints 0, 3 */
  986.  Γöé Γöé ΓööΓöÇΓöÇ     }
  987.  Γöé Γöé
  988.  Γöé Γöé       printf("%d\n", i);      /* Prints 2 */
  989.  Γöé Γöé
  990.  Γöé ΓööΓöÇΓöÇΓöÇΓöÇ   }
  991.  Γöé
  992.  Γöé      printf("%d\n", i);        /* Prints 1 */
  993.  Γöé
  994.  Γöé      return 0;
  995.  Γöé
  996.  ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ  }
  997.  
  998.  
  999. ΓòÉΓòÉΓòÉ 2.6. Program Linkage ΓòÉΓòÉΓòÉ
  1000.  
  1001. The association, or lack of association, between two identical identifiers is 
  1002. known as linkage. The kind of linkage that an identifier has depends on the way 
  1003. that it is declared. 
  1004.  
  1005. A file scope identifier has one of the following kinds of linkage: 
  1006.  
  1007.  Internal        Identical identifiers within a single source file refer to the 
  1008.                  same data object or function. 
  1009.  
  1010.  External        Identical identifiers in separately compiled files refer to 
  1011.                  the same data object or function. 
  1012.  
  1013.  No linkage      Each identical identifier refers to a unique object. 
  1014.  
  1015.  Note:  Program linkage is not the same as a function calling convention, which 
  1016.  is also commonly referred to as linkage. While it is related to program 
  1017.  linkage, a calling convention concerns itself with C++ linkage specifications 
  1018.  and the use of certain keywords. This section discusses only program linkage. 
  1019.  
  1020.  C++ Notes: 
  1021.  
  1022.      Linkage specifications are used to link to non-C++ declarations. 
  1023.  
  1024.      During compilation, the compiler encodes all function names and certain 
  1025.       other identifiers to include type and scope information. This encoding 
  1026.       process is called mangling, and the mangled names are used in the object 
  1027.       files and final executable file. Tools that use these files must use the 
  1028.       mangled names and not the original names used in the source code. 
  1029.  
  1030.       VisualAge for C++ provides two methods of converting mangled names to the 
  1031.       original source code names, demangling functions and the CPPFILT utility. 
  1032.       The demangling functions are described in the appendix on Mapping in the 
  1033.       IBM VisualAge for C++ for Windows User's Guide and in the <demangle.h> 
  1034.       header file. The CPPFILT utility is described in the IBM VisualAge for 
  1035.       C++ for Windows User's Guide. 
  1036.  
  1037.  Related Information 
  1038.  
  1039.      Internal Linkage 
  1040.      External Linkage 
  1041.      No Linkage 
  1042.      Scope in C 
  1043.      Declarations 
  1044.  
  1045.  
  1046. ΓòÉΓòÉΓòÉ <hidden> Internal Linkage ΓòÉΓòÉΓòÉ
  1047.  
  1048. The following kinds of identifiers have internal linkage: 
  1049.  
  1050.      All identifiers with file or block scope that have the keyword static in 
  1051.       their declarations. Functions with static storage class are visible only 
  1052.       in the source file in which you define them. 
  1053.      Functions qualified with _Inline and C++ inline functions. 
  1054.      C++ identifiers declared at file scope with the specifier const and not 
  1055.       explicitly declared extern. In C, const objects have external linkage by 
  1056.       default 
  1057.  
  1058.  A variable that has static storage class can be defined within a block or 
  1059.  outside a function. If the definition occurs within a block, the variable has 
  1060.  internal linkage and is only visible within the block after its declaration is 
  1061.  seen. If the definition occurs outside a function, the variable has internal 
  1062.  linkage and is available from the point where it is defined to the end of the 
  1063.  current source file. 
  1064.  
  1065.  A class that has no static members or noninline member functions, and that has 
  1066.  not been used in the declaration of an object or function or class is local to 
  1067.  its compilation unit. 
  1068.  
  1069.  If the declaration of an identifier has the keyword extern and if a previous 
  1070.  declaration of the identifier is visible at file scope, the identifier has the 
  1071.  same linkage as the first declaration. 
  1072.  
  1073.  
  1074. ΓòÉΓòÉΓòÉ <hidden> External Linkage ΓòÉΓòÉΓòÉ
  1075.  
  1076. The following kinds of identifiers have external linkage: 
  1077.  
  1078.      Identifiers with file or block scope that have the keyword extern in 
  1079.       their declarations. 
  1080.  
  1081.       If a previous declaration of the identifier is visible at file scope, the 
  1082.       identifier has the same linkage as the first declaration. For example, a 
  1083.       variable or function that is first declared with the keyword static and 
  1084.       later declared with the keyword extern has internal linkage. 
  1085.      Function identifiers declared without storage-class specifiers. 
  1086.      Object identifiers that have file scope declarations without a 
  1087.       storage-class specified.  Storage is allocated for such object 
  1088.       identifiers. 
  1089.      Static class members and noninline member functions. 
  1090.  
  1091.  Identifiers declared with the keyword extern can be defined in other 
  1092.  compilation units. 
  1093.  
  1094.  Related Information 
  1095.  
  1096.      Program Linkage 
  1097.      Internal Linkage 
  1098.      No Linkage 
  1099.      Storage Class Specifiers 
  1100.  
  1101.  
  1102. ΓòÉΓòÉΓòÉ <hidden> No Linkage ΓòÉΓòÉΓòÉ
  1103.  
  1104. The following kinds of identifiers have no linkage: 
  1105.  
  1106.      Identifiers that do not represent an object or a function, including 
  1107.       labels, enumerators, typedef names, type names, and template names 
  1108.      Identifiers that represent a function argument 
  1109.      Identifiers declared inside a block without the keyword extern 
  1110.  
  1111.  Related Information 
  1112.  
  1113.      Program Linkage 
  1114.      Internal Linkage 
  1115.      External Linkage 
  1116.      extern Storage Class Specifier 
  1117.      Identifiers 
  1118.  
  1119.  
  1120. ΓòÉΓòÉΓòÉ 2.7. Storage Duration ΓòÉΓòÉΓòÉ
  1121.  
  1122. Storage duration determines how long storage for an object exists. An object 
  1123. has either static storage duration or automatic storage duration depending on 
  1124. its declaration. 
  1125.  
  1126.  Static storage      Is allocated at initialization and remains available until 
  1127.                      the program ends. Objects have static storage duration if 
  1128.                      they: 
  1129.  
  1130.                          Have file scope 
  1131.                          Have external or internal linkage 
  1132.  
  1133.                           OR 
  1134.                          Contain the static storage class specifier. 
  1135.  
  1136.  Automatic storage   Is allocated and removed according to the scope of the 
  1137.                      identifier. Objects have automatic storage duration if 
  1138.                      they are: 
  1139.  
  1140.                          Parameters in a function definition. 
  1141.                          Declared at block scope and do not have any storage 
  1142.                           class specifier. 
  1143.  
  1144.                           OR 
  1145.                          Declared at block scope and have the register or auto 
  1146.                           storage class specifier. 
  1147.  
  1148.                      For example, storage for an object declared at block scope 
  1149.                      is allocated when the identifier is declared and removed 
  1150.                      when the closing brace (}) is reached. 
  1151.  
  1152.  Note:  Objects can also have heap storage duration. Heap objects are created 
  1153.  at runtime and storage is allocated for them by calling a function such as 
  1154.  malloc(). 
  1155.  
  1156.  Related Information 
  1157.  
  1158.      Storage Class Specifiers 
  1159.      Scope in C 
  1160.      Program Linkage 
  1161.  
  1162.  
  1163. ΓòÉΓòÉΓòÉ 2.8. Name Spaces ΓòÉΓòÉΓòÉ
  1164.  
  1165. The compiler sets up name spaces to distinguish among identifiers referring to 
  1166. different kinds of entities. Identical identifiers in different name spaces do 
  1167. not interfere with each other, even if they are in the same scope. 
  1168.  
  1169. You must assign unique names within each name space to avoid conflict. The same 
  1170. identifier can be used to declare different objects as long as each identifier 
  1171. is unique within its name space. The syntactic context of an identifier within 
  1172. a program lets the compiler resolve its name space without ambiguity. 
  1173.  
  1174. Identifiers in the same name space can be redefined within enclosed program 
  1175. blocks as described in Scope in C. 
  1176.  
  1177. Within each of the following four name spaces, the identifiers must be unique. 
  1178.  
  1179.      Tags of these types must be unique within a single scope: 
  1180.  
  1181.         -  Enumerations 
  1182.         -  Structures and unions 
  1183.  
  1184.      Members of structures, unions, and classes must be unique within a single 
  1185.       structure, union or class type. 
  1186.  
  1187.      Statement labels have function scope and must be unique within a 
  1188.       function. 
  1189.  
  1190.      All other ordinary identifiers must be unique within a single scope: 
  1191.  
  1192.         -  Function names 
  1193.         -  Variable names 
  1194.         -  Names of function parameters 
  1195.         -  Enumeration constants 
  1196.         -  typedef names. 
  1197.  
  1198.  Structure tags, structure members, variable names, and statement labels are in 
  1199.  four different name spaces; no conflict occurs among the four items named 
  1200.  student in the following example: 
  1201.  
  1202.   int get_item()
  1203.   {
  1204.     struct student     /*  structure tag     */
  1205.     {
  1206.      char student[20];  /*  structure member   */
  1207.      int section;
  1208.      int id;
  1209.     } student;       /*  structure variable  */
  1210.  
  1211.     goto student;
  1212.     student: ;       /*  null statement label */
  1213.     return (0);
  1214.   }
  1215.  
  1216.  Each occurrence of student is interpreted by its context in the program. For 
  1217.  example, when student appears after the keyword struct, it is a structure tag. 
  1218.  When student appears after either of the member selection operators . or ->, 
  1219.  the name refers to the structure member. When student appears after the goto 
  1220.  statement, control is passed to the null statement label. In other contexts, 
  1221.  the identifier student refers to the structure variable. 
  1222.  
  1223.  Related Information 
  1224.  
  1225.      Scope in C 
  1226.      Identifiers 
  1227.      Type Specifiers 
  1228.      Expressions and Operators 
  1229.  
  1230.  
  1231. ΓòÉΓòÉΓòÉ 2.9. Overview of the C++ Language ΓòÉΓòÉΓòÉ
  1232.  
  1233. C++ is an object-oriented language based on the C programming language. It can 
  1234. be viewed as a superset of C. Almost all of the features and constructs 
  1235. available in C are also available in C++. However, C++ is more than just an 
  1236. extension of C. Its additional features support the programming style known as 
  1237. object-oriented programming. Several features that are already available in C, 
  1238. such as input and output may be implemented differently in C++. In C++ you may 
  1239. use the conventional C input and output routines or you may use object oriented 
  1240. input and output by using the I/O Stream class library. 
  1241.  
  1242. C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories. It was 
  1243. originally based on the definition of the C language stated in The C 
  1244. Programming Language by Brian W. Kernighan and Dennis M. Ritchie. This C 
  1245. language definition is commonly called K&R C. Since then, the International 
  1246. Standards Organization C language definition (referred to here as ANSI/ISO C) 
  1247. has been approved. It specifies many of the features that K&R left unspecified. 
  1248. Some features of ANSI/ISO C have been incorporated into the current definition 
  1249. of C++, and some parts of the ANSI/ISO C definition have been motivated by C++. 
  1250.  
  1251. While there is currently no C++ standard comparable to the ANSI/ISO C 
  1252. definition, an ISO committee is working on such a definition. The draft of the 
  1253. Working Paper for Draft Proposed American National Standard for Information 
  1254. Systems-Programming Language C++, X3J16/95-0087, is the base document for the 
  1255. ongoing standardization of C++. The VisualAge for C++ compiler adheres to most 
  1256. aspects of the language specified in the ANSI/ISO working paper dated April 28, 
  1257. 1995. 
  1258.  
  1259.  
  1260. ΓòÉΓòÉΓòÉ 2.10. C++ Support for Object-Oriented Programming ΓòÉΓòÉΓòÉ
  1261.  
  1262. Object-oriented programming is based on the concepts of data abstraction, 
  1263. inheritance, and polymorphism. Unlike procedural programming, it concentrates 
  1264. on the data objects that are involved in a problem and how they are 
  1265. manipulated, not on how something is accomplished. Based on the foundation of 
  1266. data abstraction, object-oriented programming allows you to reuse existing code 
  1267. more efficiently and increase your productivity. 
  1268.  
  1269.      Data Abstraction 
  1270.      Encapsulation 
  1271.      Inheritance 
  1272.      Dynamic Binding and Polymorphism 
  1273.      Other Features of C++ 
  1274.  
  1275.  Related Information 
  1276.  
  1277.      C++ Classes 
  1278.      Member Access 
  1279.      Inheritance Overview 
  1280.      Derivation 
  1281.      Overview of the C++ Language 
  1282.  
  1283.  
  1284. ΓòÉΓòÉΓòÉ <hidden> Data Abstraction ΓòÉΓòÉΓòÉ
  1285.  
  1286. Data abstraction provides the foundation for object-oriented programming. In 
  1287. addition to providing fundamental data types, object-oriented programming 
  1288. languages allow you to define your own data types, called user-defined or 
  1289. abstract data types. In the C programming language, related data items can be 
  1290. organized into structures. These structures can then be manipulated as units of 
  1291. data. In addition to providing this type of data structure, object-oriented 
  1292. programming languages allow you to implement a set of operations that can be 
  1293. applied to the data elements. The data elements and the set of operations 
  1294. applicable to the data elements together form the abstract data type. 
  1295.  
  1296. To support data abstraction, a programming language must provide a construct 
  1297. that can be used to encapsulate the data elements and operations that make up 
  1298. an abstract data type. In C++, this construct is called a class. An instance of 
  1299. a class is called an object. Classes are composed of data elements called data 
  1300. members and member functions that define the operations that can be carried out 
  1301. on the data members. 
  1302.  
  1303.  
  1304. ΓòÉΓòÉΓòÉ <hidden> Encapsulation ΓòÉΓòÉΓòÉ
  1305.  
  1306. Another key feature of object-oriented programming is encapsulation. 
  1307. Encapsulation means a class can hide the details of: 
  1308.  
  1309.      The representation of its data members 
  1310.      The implementation of the operations that can be performed on these data 
  1311.       members 
  1312.  
  1313.  Application programs manipulate objects of a class using a clearly defined 
  1314.  interface. As long as this interface does not change, you can change the 
  1315.  implementation of a class without having to change the application programs 
  1316.  that use the class. Encapsulation provides the following advantages: 
  1317.  
  1318.      Users of a class do not have to deal with unnecessary implementation 
  1319.       details. 
  1320.      Programs are easier to debug and maintain. 
  1321.      Permitted alterations are clearly specified. 
  1322.  
  1323.  In C++, encapsulation is accomplished by specifying the level of access for 
  1324.  each member of a class. Both the data members and member functions of a class 
  1325.  can be declared public, protected, or private depending on the kind of access 
  1326.  required. 
  1327.  
  1328.  Note:  C++ encapsulation is not a true security mechanism. It is possible to 
  1329.  circumvent the class access controls that make encapsulation possible. The 
  1330.  language is not designed to prevent such misuse. 
  1331.  
  1332.  
  1333. ΓòÉΓòÉΓòÉ <hidden> Inheritance ΓòÉΓòÉΓòÉ
  1334.  
  1335. Inheritance lets you reuse existing code and data structures in new 
  1336. applications. In C++, inheritance is implemented through class derivation. You 
  1337. can extend a library of existing classes by adding data elements and operations 
  1338. to existing classes to form derived classes. A derived class has all the 
  1339. members of its parent or base class, as well as extensions that can provide 
  1340. additional features. When you create a new derived class, you only have to 
  1341. write the code for the additional features. The existing features of the base 
  1342. class are already available. 
  1343.  
  1344. A base class can have more than one class derived from it. In addition, a 
  1345. derived class can serve as a base class for other derived classes in a 
  1346. hierarchy. Typically, a derived class is more specialized than its base class. 
  1347.  
  1348. A derived class can inherit data members and member functions from more than 
  1349. one base class. Inheritance from more than one base class is called multiple 
  1350. inheritance. 
  1351.  
  1352.  
  1353. ΓòÉΓòÉΓòÉ <hidden> Dynamic Binding and Polymorphism ΓòÉΓòÉΓòÉ
  1354.  
  1355. Another key concept that allows you to write generic programs is dynamic or 
  1356. late binding. Dynamic binding allows a member function call to be resolved at 
  1357. run time, according to the run-time type of an object reference. This permits 
  1358. each user-defined class in an inheritance hierarchy to have a different 
  1359. implementation of a particular function. Application programs can then apply 
  1360. that function to an object without needing to know the specifics of the class 
  1361. that the object belongs to. 
  1362.  
  1363. In C++, dynamic binding hides the differences between a group of classes in an 
  1364. inheritance hierarchy from the application program. At run time, the system 
  1365. determines the specific class of the object and invokes the appropriate 
  1366. function implementation for that class. 
  1367.  
  1368. Dynamic binding is distinguished from static or compile-time binding, which 
  1369. involves compile-time member function resolution according to the static type 
  1370. of an object reference. 
  1371.  
  1372.  
  1373. ΓòÉΓòÉΓòÉ <hidden> Other Features of C++ ΓòÉΓòÉΓòÉ
  1374.  
  1375. C++ provides several other powerful extensions to the C programming language. 
  1376. Among these are: 
  1377.  
  1378.      Constructors and destructors, which are used to create, initialize and 
  1379.       destroy class objects 
  1380.      Overloaded functions and operators, which let you extend the operations a 
  1381.       function or operator can perform on different data types 
  1382.      Inline functions, which make programs more efficient 
  1383.      References, which allow a function to modify its arguments in the calling 
  1384.       function 
  1385.      Template functions and classes, which allow the definition of generic 
  1386.       classes and functions 
  1387.      Object-Oriented Exception handling, which provides transfer of control 
  1388.       and recovery from errors and other exceptional circumstances 
  1389.  
  1390.  
  1391. ΓòÉΓòÉΓòÉ 2.11. C++ Programs ΓòÉΓòÉΓòÉ
  1392.  
  1393. C++ programs contain many of the same programming statements and constructs as 
  1394. C programs: 
  1395.  
  1396.      C++ has the same fundamental types (built-in) data types as C, as well as 
  1397.       some types that are not built-in to C. 
  1398.      Like ANSI/ISO C, C++ allows you to declare new type names by using the 
  1399.       typedef construct. These new type names are not new types. 
  1400.      In general, the scope and storage class rules for C also apply in C++. 
  1401.      C and C++ have the same set of arithmetic and logical operators. 
  1402.  
  1403.  A C++ name can identify any of the following: 
  1404.  
  1405.      an object 
  1406.      a function 
  1407.      a set of functions 
  1408.      an enumerator 
  1409.      a type 
  1410.      a class member 
  1411.      a template 
  1412.      a value 
  1413.      a label 
  1414.  
  1415.  A declaration introduces a name into a program and can define an area of 
  1416.  storage associated with that name. 
  1417.  
  1418.  An expression can be evaluated and is composed of operations and operands. An 
  1419.  expression ending with a ; (semicolon) is called a statement. A statement is 
  1420.  the smallest independent computational unit. Functions are composed of groups 
  1421.  of one or more statements. 
  1422.  
  1423.  A C++ program is composed of one or more functions. These functions can all 
  1424.  reside in a single file or can be placed in different files that are linked to 
  1425.  each other. In C++, a program must have one and only one non-member function 
  1426.  called main(). 
  1427.  
  1428.  Source for a Simple C++ Program 
  1429.  
  1430.  Related Information 
  1431.  
  1432.      C++ Support for Object-Oriented Programming 
  1433.      Overview of the C Language 
  1434.      C Source Files 
  1435.      C Source Programs 
  1436.  
  1437.  
  1438. ΓòÉΓòÉΓòÉ <hidden> Source for a Simple C++ Program ΓòÉΓòÉΓòÉ
  1439.  
  1440. /************************************************************************
  1441. *
  1442.  
  1443. The following is a simple C++ program containing declarations, expressions, 
  1444. statements, and two functions: 
  1445.  
  1446.                                     *
  1447. ************************************************************************/
  1448.  
  1449. /**
  1450.  ** A simple C++ program containing declarations,
  1451.  ** expressions, statements, and two functions:
  1452.  **/
  1453.  
  1454. #include <math.h>             // contains definition of abs()
  1455. double multiplier, common_ratio;      // variable declarations
  1456. double geo_series(double a, double r)   // function definition
  1457. {
  1458.    if (r == 1)             // if statement
  1459.       return -1.0;          // return statement
  1460.    else if (abs(r) < 1.0)        // else if statement
  1461.       return (a / (1 - r));     // statement containing
  1462.                      // expression
  1463.    else return -2.0;
  1464. }
  1465. int main()         // program execution begins here
  1466. {
  1467.    double sum;      // variable declaration
  1468.    multiplier = 2.2;   // initialization of external variable
  1469.    common_ratio = 3.1;  // initialization of external variable
  1470.    sum = geo_series(multiplier, common_ratio); // function call
  1471.    // ..
  1472.    return 0;
  1473. }
  1474.  
  1475.  
  1476. ΓòÉΓòÉΓòÉ 2.12. Scope in C++ ΓòÉΓòÉΓòÉ
  1477.  
  1478. The area of the code where an identifier is visible is referred to as the scope 
  1479. of the identifier. The four kinds of scope are: 
  1480.  
  1481.      Local 
  1482.      Function 
  1483.      File 
  1484.      Class 
  1485.  
  1486.  The scope of a name is determined by the location of the name's declaration. 
  1487.  
  1488.  A type name first declared in a function return type has file scope. A type 
  1489.  name first declared in a function argument list has local scope. 
  1490.  
  1491.  A function name that is first declared as a friend of a class is in the first 
  1492.  nonclass scope that encloses the class. 
  1493.  
  1494.  If the friend function is a member of another class, it has the scope of that 
  1495.  class. The scope of a class name first declared as a friend of a class is the 
  1496.  first nonclass enclosing scope. 
  1497.  
  1498.  Related Information 
  1499.  
  1500.      Scope in C 
  1501.      Friend Scope 
  1502.      Scope of Class Names 
  1503.      Member Scope 
  1504.  
  1505.  
  1506. ΓòÉΓòÉΓòÉ <hidden> Local Scope ΓòÉΓòÉΓòÉ
  1507.  
  1508. A name has local scope if it is declared in a block. A name with local scope 
  1509. can be used in that block and in blocks enclosed within that block, but the 
  1510. name must be declared before it is used. When the block is exited, the names 
  1511. declared in the block are no longer available. 
  1512.  
  1513. Formal argument names for a function have the scope of the outermost block of 
  1514. that function. 
  1515.  
  1516. If a local variable is a class object with a destructor, the destructor is 
  1517. called when control passes out of the block in which the class object was 
  1518. constructed. 
  1519.  
  1520. When one block is nested inside another, the variables from the outer block are 
  1521. usually visible in the nested block. However, if an outer block variable is 
  1522. redefined in a nested block, the new declaration is in effect in the inner 
  1523. block. The original declaration is restored when program control returns to the 
  1524. outer block. This is called block visibility. 
  1525.  
  1526.  
  1527. ΓòÉΓòÉΓòÉ <hidden> Function Scope ΓòÉΓòÉΓòÉ
  1528.  
  1529. The only type of identifier with function scope is a label name. A label is 
  1530. implicitly declared by its appearance in the program text and is visible 
  1531. throughout the function that declares it. 
  1532.  
  1533.  
  1534. ΓòÉΓòÉΓòÉ <hidden> File Scope ΓòÉΓòÉΓòÉ
  1535.  
  1536. A name has file scope if its declaration appears outside of all blocks and 
  1537. classes. A name with file scope is visible from the point where it is declared 
  1538. to the end of the source file. The name is also made accessible for the 
  1539. initialization of global variables. If a name is declared extern, it is also 
  1540. visible, at link time, in all object files being linked. Global names are names 
  1541. declared with file scope. 
  1542.  
  1543.  
  1544. ΓòÉΓòÉΓòÉ <hidden> Class Scope ΓòÉΓòÉΓòÉ
  1545.  
  1546. The name of a class member has class scope and can only be used in the 
  1547. following cases: 
  1548.  
  1549.      In a  member function of that class 
  1550.      In a member function of a class derived from that class 
  1551.      After the . (dot) operator applied to an instance of that class 
  1552.      After the . (dot) operator applied to an instance of a class derived from 
  1553.       that class 
  1554.      After the -> (arrow) operator applied to a pointer to an instance of that 
  1555.       class 
  1556.      After the -> (arrow) operator applied to a pointer to an instance of a 
  1557.       class derived from that class 
  1558.      After the :: (scope resolution) operator applied to the name of a class 
  1559.      After the :: (scope resolution) operator applied to a class derived from 
  1560.       that class. 
  1561.  
  1562.  For more information on class scope, see Scope of Class Names. 
  1563.  
  1564.  
  1565. ΓòÉΓòÉΓòÉ 2.13. Simple C++ Input and Output ΓòÉΓòÉΓòÉ
  1566.  
  1567. Like C, the C++ language has no built-in input and output facilities. Instead, 
  1568. input and output facilities for C++ are provided by the I/O Stream Library. For 
  1569. compatibility with C, C++ also supports the standard I/O functions of C. The 
  1570. I/O Stream Library supports a set of I/O operations, written in the C++ 
  1571. language, for the built-in types. You can extend these facilities to provide 
  1572. input and output functions for user-defined data types. For a complete 
  1573. description of the I/O Stream Library, see the Standard Class Library Guide. 
  1574.  
  1575. There are four predefined I/O stream objects that you can use to perform 
  1576. standard I/O: 
  1577.  
  1578.      cout 
  1579.      cin 
  1580.      cerr 
  1581.      clog 
  1582.  
  1583.  You can use these in conjunction with the overloaded << (insertion or output) 
  1584.  and >> (extraction or input) operators. To use these streams and operators, 
  1585.  you must include the header file iostream.h. The following example prints 
  1586.  Hello World! to standard output: 
  1587.  
  1588.   /**
  1589.    ** Hello World
  1590.    **/
  1591.  
  1592.   #include <iostream.h>
  1593.   void main()
  1594.   {
  1595.      cout << "Hello World!" << endl;
  1596.   }
  1597.  
  1598.  The manipulator endl acts as a newline character, causing any output following 
  1599.  it to be directed to the next line. Because it also causes any buffered output 
  1600.  to be flushed, endl is preferred over \n to end lines. 
  1601.  
  1602.  Related Information 
  1603.  
  1604.      Overview of the C++ Language 
  1605.      Overview of the C Language 
  1606.      Overloading Operators 
  1607.  
  1608.  
  1609. ΓòÉΓòÉΓòÉ <hidden> cout ΓòÉΓòÉΓòÉ
  1610.  
  1611. The cout stream is associated with standard output. You can use the output 
  1612. operator in conjunction with cout to direct a value to standard output. 
  1613. Successive output operators are concatenated when applied to cout. The 
  1614. following example prints out three strings in a row and produces the same 
  1615. result as the previous example, printing Hello World! to standard output. 
  1616.  
  1617. /**
  1618.  ** Another Hello World, illustrating concatenation with cout
  1619.  **/
  1620.  
  1621. #include <iostream.h>
  1622. void main()
  1623. {
  1624.    cout << "Hello "
  1625.       << "World"
  1626.       << "!"
  1627.       << endl;
  1628. }
  1629.  
  1630. Output operators are defined to accept arguments of any of the fundamental data 
  1631. types, as well as pointers, references, and array types. You can also overload 
  1632. the output operator to define output for your own class types. 
  1633.  
  1634.  
  1635. ΓòÉΓòÉΓòÉ <hidden> cerr and clog ΓòÉΓòÉΓòÉ
  1636.  
  1637. The cerr and clog streams direct output to standard error. cerr provides 
  1638. unbuffered output, while clog provides buffered output. The following example 
  1639. checks for a division by zero condition. If one occurs, a message is sent to 
  1640. standard error. 
  1641.  
  1642. /**
  1643.  ** Check for a division by zero condition.
  1644.  ** If one occurs, a message is sent to standard error.
  1645.  **/
  1646.  
  1647. #include <iostream.h>
  1648. void main()
  1649. {
  1650.    double val1, val2;
  1651.    cout << "Divide Two Values" << endl;
  1652.    cout << "Enter two numeric values: " << endl;
  1653.    cin >> val1 >> val2;
  1654.    if (val2 == 0 )
  1655.    {
  1656.        cerr << "The second value must be non-zero" << endl;
  1657.    } else
  1658.        cout << "The answer is " << val1 / val2 << endl;
  1659. }
  1660.  
  1661.  
  1662. ΓòÉΓòÉΓòÉ <hidden> cin ΓòÉΓòÉΓòÉ
  1663.  
  1664. The cin class object is associated with standard input. You can use the input 
  1665. operator in conjunction with cin to read a value from standard input. By 
  1666. default, white space (including blanks, tabs, and new lines) is disregarded by 
  1667. the input operator. For example: 
  1668.  
  1669. /**
  1670.  ** This example illustrates the cin operator
  1671.  **/
  1672.  
  1673. #include <iostream.h>
  1674. main()
  1675. {
  1676.    double val1, val2;
  1677.    cout << "Enter two numeric values:" << endl;
  1678.    cin >> val1 >> val2;
  1679.    cout  << "The first value entered is " << val1
  1680.        << " and the second value is "
  1681.        << val2 << "." << endl;
  1682. }
  1683.  
  1684. If the values 1.2 and 3.4 are entered through standard input, the above program 
  1685. prints the following to standard output: 
  1686.  
  1687. Enter two numeric values:
  1688. 1.2
  1689. 3.4
  1690. The first value entered is 1.2 and the second value is 3.4.
  1691.  
  1692. Any white space entered between the two numeric values is disregarded by the 
  1693. input operator. 
  1694.  
  1695. The input operator is defined to accept arguments of any of the fundamental 
  1696. data types, as well as pointers, references and array types. You can also 
  1697. overload the input operator to define input for your own class types. 
  1698.  
  1699.  
  1700. ΓòÉΓòÉΓòÉ 2.14. Linkage Specifications - Linking to non-C++ Programs ΓòÉΓòÉΓòÉ
  1701.  
  1702. You can link C++ object modules to object modules produced using other source 
  1703. languages such as C and Fortran by using a linkage specification. 
  1704.  
  1705. The syntax is: 
  1706.  
  1707. >>ΓöÇΓöÇexternΓöÇΓöÇstring-literalΓöÇΓöÇΓö¼ΓöÇdeclarationΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  1708.               Γöé   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé
  1709.               Γöé           Γöé   Γöé
  1710.               ΓööΓöÇ{ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ}ΓöÇΓöÿ
  1711.                  ΓööΓöÇdeclarationΓöÇΓöÿ
  1712.  
  1713. The string-literal is used to specify the linkage associated with a particular 
  1714. function. For example: 
  1715.  
  1716. /**
  1717.  ** This example illustrates linkage specifications
  1718.  **/
  1719.  
  1720. extern "C" int printf(const char*,...);
  1721. void main()
  1722. {
  1723.    printf("hello\n");
  1724. }
  1725.  
  1726. Here the string-literal, "C", tells the compiler that the routine printf(const 
  1727. char*,...) has C linkage. Note that string literals used in linkage 
  1728. specifications are not case sensitive. 
  1729.  
  1730. Some valid values for string-literal are: 
  1731.  
  1732.  "C++"                      Default 
  1733.  
  1734.  "C"                        C type linkage 
  1735.  
  1736.  If the value of string-literal is not recognized, C type linkage is used. For 
  1737.  more information on linkage specifications, see the description of calling 
  1738.  conventions in the IBM VisualAge for C++ for Windows Programming Guide. 
  1739.  
  1740.  Related Information 
  1741.  
  1742.      Overview of the C++ Language 
  1743.      Overview of the C Language 
  1744.  
  1745.  
  1746. ΓòÉΓòÉΓòÉ 3. Lexical Elements of C and C++ ΓòÉΓòÉΓòÉ
  1747.  
  1748. This section describes the following lexical elements of C and C++: 
  1749.  
  1750.      Tokens 
  1751.      Source Program Character Set 
  1752.      Trigraph Sequences 
  1753.      Escape Sequences 
  1754.      Comments 
  1755.      Identifiers 
  1756.      Keywords 
  1757.      Constants 
  1758.  
  1759.  
  1760. ΓòÉΓòÉΓòÉ 3.1. Tokens ΓòÉΓòÉΓòÉ
  1761.  
  1762. Source code is treated during preprocessing and compilation as a sequence of 
  1763. tokens. There are five different types of tokens: 
  1764.  
  1765.      Identifiers 
  1766.      Keywords 
  1767.      Literals 
  1768.      Operators 
  1769.      Other separators 
  1770.  
  1771.  Adjacent identifiers, keywords and literals must be separated with white 
  1772.  space. Other tokens should be separated by white space to make the source code 
  1773.  more readable. White space includes blanks, horizontal and vertical tabs, new 
  1774.  lines, form feeds and comments. 
  1775.  
  1776.  
  1777. ΓòÉΓòÉΓòÉ 3.2. Source Program Character Set ΓòÉΓòÉΓòÉ
  1778.  
  1779. The following lists the basic character set that must be available at both 
  1780. compile and run time: 
  1781.  
  1782.      The uppercase and lowercase letters of the English alphabet 
  1783.      The decimal digits 0 through 9 
  1784.      The following graphic characters: 
  1785.  
  1786.               ! " # % & ' ( ) * + , - . / :
  1787.               ; < = > ? [ \ ] _ { } ~
  1788.  
  1789.      The caret (^) character 
  1790.      The split vertical bar (Γûî) character 
  1791.      The space character 
  1792.      The control characters representing new-line, horizontal tab, vertical 
  1793.       tab, and form feed, and end of string (NULL character). 
  1794.  
  1795.  The # (number sign) character is used for preprocessing only, and the _ 
  1796.  (underscore) character is treated as a normal letter. 
  1797.  
  1798.  In extended and compatible language levels, the compiler allows the $ (dollar 
  1799.  sign) character in C++ identifiers to facilitate calls between different 
  1800.  languages and porting code. In ansi language level, the $ (dollar sign) 
  1801.  character is not permitted in C++ identifiers. The default language level for 
  1802.  the compiler is extended. Language level is set with the #pragma langlvl or 
  1803.  the /S option. 
  1804.  
  1805.  Related Information 
  1806.  
  1807.      Trigraph Sequences 
  1808.      /Ss option 
  1809.  
  1810.  
  1811. ΓòÉΓòÉΓòÉ <hidden> Trigraph Sequences ΓòÉΓòÉΓòÉ
  1812.  
  1813. Some characters from the C character set are not available in all environments. 
  1814. You can enter these characters into a C source program using a sequence of 
  1815. three characters called a trigraph. The trigraph sequences are: 
  1816.  
  1817. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1818. Γöé "??="   Γöé "#"      Γöé pound sign      Γöé
  1819. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1820. Γöé "??("   Γöé "["      Γöé left bracket     Γöé
  1821. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1822. Γöé "??)"   Γöé "]"      Γöé right bracket     Γöé
  1823. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1824. Γöé "??<"   Γöé "{"      Γöé left brace      Γöé
  1825. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1826. Γöé "??>"   Γöé "}"      Γöé right brace      Γöé
  1827. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1828. Γöé "??/"   Γöé "\"      Γöé backslash       Γöé
  1829. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1830. Γöé "??'"   Γöé "^"      Γöé caret         Γöé
  1831. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1832. Γöé "??!"   Γöé "|"      Γöé vertical bar     Γöé
  1833. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1834. Γöé "??-"   Γöé "~"      Γöé tilde         Γöé
  1835. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1836.  
  1837. The preprocessor replaces trigraph sequences with the corresponding 
  1838. single-character representation. 
  1839.  
  1840. Related Information 
  1841.  
  1842.      Source Program Character Set 
  1843.  
  1844.  
  1845. ΓòÉΓòÉΓòÉ 3.2.1. Digraph Sequences ΓòÉΓòÉΓòÉ
  1846.  
  1847. You can represent unavailable characters in a source program by using a 
  1848. combination of two keystrokes called a digraph sequence. Digraphs are read as 
  1849. tokens during the preprocessor phase. Digraphs can be created using macro 
  1850. concatenation. They are not replaced in string literals or in character 
  1851. literals. For example: 
  1852.  
  1853. char *s = "<%%>"; // stays "<%%>"
  1854.  
  1855. switch (c)
  1856. {
  1857.    case '<%' : { /* ... */ } // stays '<%'
  1858.    case '%>' : { /* ... */ } // stays '%>'
  1859. }
  1860.  
  1861. The digraph sequences are: 
  1862.  
  1863. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1864. Γöé "%%"  Γöé "#"  Γöé pound sign                          Γöé
  1865. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1866. Γöé "<:"  Γöé "["  Γöé left bracket                         Γöé
  1867. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1868. Γöé ":>"  Γöé "]"  Γöé right bracket                         Γöé
  1869. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1870. Γöé "<%"  Γöé "{"  Γöé left brace                          Γöé
  1871. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1872. Γöé "%>"  Γöé "}"  Γöé right brace                          Γöé
  1873. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1874. Γöé "%:%:" Γöé "##" Γöé preprocessor macro concatenation operator           Γöé
  1875. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1876.  
  1877. The nodigraph option disables processing of digraphs. The digraph option is on 
  1878. by default. 
  1879.  
  1880. The digraph option is described in the IBM VisualAge for C++ for Windows User's 
  1881. Guide. 
  1882.  
  1883.  
  1884. ΓòÉΓòÉΓòÉ 3.3. Comments ΓòÉΓòÉΓòÉ
  1885.  
  1886. Comments begin with the /* characters, end with the */ characters, and can span 
  1887. more than one line. You can put comments anywhere the language allows white 
  1888. space. 
  1889.  
  1890. Comments are replaced during preprocessing by a single space character. 
  1891.  
  1892. Multibyte characters can also be included within a comment. 
  1893.  
  1894. Note:  The /* or */ characters found in a character constant or string literal 
  1895. do not start or end comments. 
  1896.  
  1897. In the following program, line 6 is a comment: 
  1898.  
  1899.  1  #include <stdio.h>
  1900.  2
  1901.  3  int main(void)
  1902.  4  {
  1903.  5    printf("This program has a comment.\n");
  1904.  6    /* printf("This is a comment line and will not print.\n"); */
  1905.  7  return 0;
  1906.  8  }
  1907.  
  1908. Because the comment on line 6 is equivalent to a space, the output of this 
  1909. program is: 
  1910.  
  1911. This program has a comment.
  1912.  
  1913. Because the comment delimiters are inside a string literal, line 5 in the 
  1914. following program is not a comment. 
  1915.  
  1916.  1  #include <stdio.h>
  1917.  2
  1918.  3  int main(void)
  1919.  4  {
  1920.  5    printf("This program does not have \
  1921.  6  /* NOT A COMMENT */ a comment.\n");
  1922.  7  return 0;
  1923.  8  }
  1924.  
  1925. The output of the program is: 
  1926.  
  1927. This program does not have /* NOT A COMMENT */ a comment.
  1928.  
  1929. You cannot nest comments. Each comment ends at the first occurrence of */. 
  1930.  
  1931. Related Information 
  1932.  
  1933.      C++ Comments 
  1934.      /Ss option 
  1935.  
  1936.  
  1937. ΓòÉΓòÉΓòÉ <hidden> C++ Comments ΓòÉΓòÉΓòÉ
  1938.  
  1939. If the /Ss compiler option is in effect when you compile a C program, double 
  1940. slashes (//) also specify the beginning of a comment. 
  1941.  
  1942. This is the default for VisualAge for C++. C++ permits double-slash comments as 
  1943. part of the language definition. 
  1944.  
  1945. A C++ comment can span more than one physical source line if it is joined into 
  1946. one logical source line with line-continuation (\) characters. The backslash 
  1947. character can also be represented by a trigraph. 
  1948.  
  1949.  
  1950. ΓòÉΓòÉΓòÉ 3.4. Identifiers ΓòÉΓòÉΓòÉ
  1951.  
  1952. Identifiers consist of an arbitrary number of letters or digits. They provide 
  1953. names for the following language elements: 
  1954.  
  1955.      Functions 
  1956.      Data objects 
  1957.      Labels 
  1958.      Tags 
  1959.      Parameters 
  1960.      Macros 
  1961.      Typedefs 
  1962.      Structure and union members. 
  1963.  
  1964.  
  1965. ΓòÉΓòÉΓòÉ 3.4.1. Significant Characters in Identifiers ΓòÉΓòÉΓòÉ
  1966.  
  1967. There is no limit for the number of characters in an identifier. However, only 
  1968. the first several characters of identifiers may be significant. The following 
  1969. table shows the number of significant characters for several kinds of 
  1970. identifiers. 
  1971.  
  1972.  Identifier                  Maximum Number of Significant Characters 
  1973.  Static data objects         255 characters 
  1974.  Static function names       255 characters 
  1975.  External data objects       255 after name decoration for linkage conventions 
  1976.                              (254 characters before name decoration for linkage 
  1977.                              conventions) 
  1978.  External function names     255 after name decoration for linkage conventions 
  1979.                              (243 characters before name decoration for 
  1980.                              __stdcall linkage convention, and 254 characters 
  1981.                              before name decoration for other linkage 
  1982.                              conventions) 
  1983.  
  1984.  
  1985. ΓòÉΓòÉΓòÉ 3.4.2. Case Sensitivity and Special Characters in Identifiers ΓòÉΓòÉΓòÉ
  1986.  
  1987. The compiler distinguishes between uppercase and lowercase letters in 
  1988. identifiers. For example, PROFIT and profit represent different data objects. 
  1989.  
  1990. Note:  By default, the VisualAge for C++ linker linkage editor is case 
  1991. sensitive. To force it to be case insensitive, use the /IGNORECASE linkage 
  1992. editor option, though you typically should not need to use this option. For 
  1993. complete portability, never use different case representations to refer to the 
  1994. same object. 
  1995.  
  1996. Avoid creating identifiers that begin with an underscore (_) for function names 
  1997. and variable names. 
  1998.  
  1999. The first character in an identifier must be a letter. The _ (underscore) 
  2000. character is considered a letter; however, identifiers beginning with an 
  2001. underscore are reserved by the compiler for identifiers at file scope. 
  2002.  
  2003. Identifiers that begin with two underscores or an underscore followed by a 
  2004. capital letter, are reserved in all contexts. 
  2005.  
  2006. Although the names of system calls and library functions are not reserved words 
  2007. if you do not include the appropriate headers, avoid using them as identifiers. 
  2008. Duplication of a predefined name can lead to confusion for the maintainers of 
  2009. your code and can cause errors at link time or run time. If you include a 
  2010. library in a program, be aware of the function names in that library to avoid 
  2011. name duplications. 
  2012.  
  2013. You should always include the appropriate headers when using standard library 
  2014. functions. At the extended and compatible language levels, C++ identifiers can 
  2015. contain the $ character. 
  2016.  
  2017. Related Information 
  2018.  
  2019.      Name Spaces 
  2020.      Overview of the C Language 
  2021.      File Inclusion (#include) 
  2022.  
  2023.  
  2024. ΓòÉΓòÉΓòÉ 3.4.3. Keywords ΓòÉΓòÉΓòÉ
  2025.  
  2026. Keywords are identifiers reserved by the language for special use. Although you 
  2027. can use them for preprocessor macro names, it is poor programming style. Only 
  2028. the exact spelling of keywords is reserved. For example, auto is reserved but 
  2029. AUTO is not. The following lists the keywords common to both the C and C++ 
  2030. languages. These keywords are also included in the ANSI/ISO C language 
  2031. definition: 
  2032.  
  2033. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2034. Γöé Table 1. Keywords Common to C and C++                     Γöé
  2035. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2036. Γöé auto        Γöé double       Γöé int        Γöé struct      Γöé
  2037. Γöé break       Γöé else        Γöé long        Γöé switch      Γöé
  2038. Γöé case        Γöé enum        Γöé register      Γöé typedef      Γöé
  2039. Γöé char        Γöé extern       Γöé return       Γöé union       Γöé
  2040. Γöé const       Γöé float       Γöé short       Γöé unsigned     Γöé
  2041. Γöé continue      Γöé for        Γöé signed       Γöé void       Γöé
  2042. Γöé default      Γöé goto        Γöé sizeof       Γöé volatile     Γöé
  2043. Γöé do         Γöé if         Γöé static       Γöé while       Γöé
  2044. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2045.  
  2046. The C++ language also reserves the following keywords: 
  2047.  
  2048. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2049. Γöé Table 2. C++ Keywords                             Γöé
  2050. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2051. Γöé asm        Γöé friend       Γöé protected     Γöé try        Γöé
  2052. Γöé catch       Γöé inline       Γöé public       Γöé typeid      Γöé
  2053. Γöé class       Γöé new        Γöé template      Γöé virtual      Γöé
  2054. Γöé delete       Γöé operator      Γöé this        Γöé wchar_t      Γöé
  2055. Γöé dynamic_cast    Γöé private      Γöé throw       Γöé          Γöé
  2056. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2057.  
  2058. Although they are documented in the ANSI/ISO C++ Working Paper, and are 
  2059. reserved by the compiler, the following keywords are not yet supported by 
  2060. VisualAge for C++: 
  2061.  
  2062. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2063. Γöé Table 3. C++ Language Keywords Not Supported by VisualAge for C++       Γöé
  2064. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2065. Γöé bool        Γöé false       Γöé reinterpret_cast  Γöé typename     Γöé
  2066. Γöé const_cast     Γöé mutable      Γöé static_cast    Γöé using       Γöé
  2067. Γöé explicit      Γöé namespace     Γöé true        Γöé          Γöé
  2068. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2069.  
  2070. The VisualAge for C++ compiler also reserves the following keywords. They are 
  2071. VisualAge for C++ extensions to the existing language standards. 
  2072.  
  2073. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2074. Γöé Table 4. Additional VisualAge for C++ Keywords                Γöé
  2075. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2076. Γöé _Builtin    Γöé _Far16     Γöé __import    Γöé _Optlink    Γöé __system   Γöé
  2077. Γöé __builtin   Γöé __far16    Γöé __int64    Γöé __optlink   Γöé __thread   Γöé
  2078. Γöé _Cdecl     Γöé _Far32     Γöé _Inline    Γöé _Pascal    Γöé __try     Γöé
  2079. Γöé __cdecl    Γöé __far32    Γöé __inline    Γöé __pascal    Γöé __unaligned  Γöé
  2080. Γöé __declspec   Γöé _Fastcall   Γöé __int8     Γöé _Packed    Γöé        Γöé
  2081. Γöé _Export    Γöé __fastcall   Γöé __int16    Γöé __packed    Γöé        Γöé
  2082. Γöé __export    Γöé __finally   Γöé __int32    Γöé __stdcall   Γöé        Γöé
  2083. Γöé __except    Γöé _Import    Γöé __leave    Γöé _System    Γöé        Γöé
  2084. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2085.  
  2086. The following keywords are reserved only for C programs: 
  2087.  
  2088. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2089. Γöé Table 5. Keywords for C Only                         Γöé
  2090. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2091. Γöé _FAR32       Γöé _PACKED      Γöé __FINALLY     Γöé          Γöé
  2092. Γöé __FAR32      Γöé __PACKED      Γöé __LEAVE      Γöé          Γöé
  2093. Γöé _INLINE      Γöé __EXCEPT      Γöé __TRY       Γöé          Γöé
  2094. Γöé __INLINE      Γöé          Γöé          Γöé          Γöé
  2095. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2096.  
  2097. The keywords used in the following function calling conventions are reserved by 
  2098. the compiler, but the calling conventions themselves are not supported by IBM 
  2099. VisualAge for C++ for Windows: 
  2100.  
  2101.      _Pascal 
  2102.      _Far32 _Pascal 
  2103.      _Far16 _Cdecl 
  2104.      _Far16 _Pascal 
  2105.      _Far16 _Fastcall 
  2106.  Using the keywords as calling conventions causes a warning to be issued. 
  2107.  
  2108.  See Linkage Keywords for more information about linkage keywords for calling 
  2109.  conventions. 
  2110.  
  2111.  For compatibility with Microsoft Visual C++, the VisualAge for C++ compiler 
  2112.  also reserves the following keywords in extended mode only: 
  2113.  
  2114.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2115.   Γöé Table 6. Additional VisualAge for C++ Keywords for Microsoft Compatibility  Γöé
  2116.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2117.   Γöé _asm        Γöé _except      Γöé _int16       Γöé _stdcall     Γöé
  2118.   Γöé __asm       Γöé _finally      Γöé _int32       Γöé _try       Γöé
  2119.   Γöé _cdecl       Γöé _inline      Γöé _int64       Γöé          Γöé
  2120.   Γöé _declspec     Γöé _int8       Γöé _leave       Γöé          Γöé
  2121.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2122.  
  2123.  The following keywords are reserved only for C programs: 
  2124.  
  2125.      _except 
  2126.      _finally 
  2127.      _inline 
  2128.      _leave 
  2129.      _try 
  2130.  
  2131.  If you include the <iso646.h> header, you can represent unavailable characters 
  2132.  in a source program using the following keywords: 
  2133.  
  2134.  Keyword     Symbol 
  2135.  bitand      & 
  2136.  and         && 
  2137.  bitor       | 
  2138.  or          || 
  2139.  xor         ^ 
  2140.  compl       ~ 
  2141.  and_eq      &= 
  2142.  or_eq       |= 
  2143.  xor_eq      ^= 
  2144.  not         ! 
  2145.  not_eq      != 
  2146.  
  2147.  
  2148. ΓòÉΓòÉΓòÉ 3.4.3.1. _asm and __asm Keywords ΓòÉΓòÉΓòÉ
  2149.  
  2150. Some compilers permit assembler code to be inlined using the keywords asm, 
  2151. _asm, and __asm. Declarations with asm are described in Assembler Declarations 
  2152. (asm Keyword). 
  2153.  
  2154. The _asm and __asm keywords can appear anywhere a C statement is permitted. 
  2155.  
  2156. The _asm and __asm keywords are recognized by VisualAge for C++ in extended 
  2157. mode only. However, no code is generated for the inlined assembler instructions 
  2158. and a warning is issued. They must be followed by: 
  2159.  
  2160.      An assembler instruction followed by a new-line character 
  2161.      An assembler instruction followed by another _asm or __asm statement. 
  2162.      A block of assembler instructions enclosed in braces ({ }) 
  2163.      An empty pair of braces. 
  2164.  
  2165.  Any preprocessor directives within a statement using the _asm or __asm 
  2166.  keywords are interpreted and macros are expanded. 
  2167.  
  2168.  Related Information 
  2169.  
  2170.      _Packed Qualifier 
  2171.      __unaligned Type Qualifier 
  2172.      Linkage Keywords 
  2173.      _Export Keyword 
  2174.      Inline Specifiers 
  2175.      Inline Functions 
  2176.  
  2177.  
  2178. ΓòÉΓòÉΓòÉ 3.5. Constants ΓòÉΓòÉΓòÉ
  2179.  
  2180. A constant does not change its value while the program is running. The value of 
  2181. any constant must be in the range of representable values for its type. 
  2182.  
  2183. The C language contains the following types of constants (also called 
  2184. literals): 
  2185.  
  2186.      Integer Constants 
  2187.      Floating-Point Constants 
  2188.      Character Constants 
  2189.      String Literals 
  2190.  
  2191.  Enumeration constants, which belong to the lexical class of identifiers, are 
  2192.  discussed in Enumerations. For more information on data types, see Type 
  2193.  Specifiers. 
  2194.  
  2195.  
  2196. ΓòÉΓòÉΓòÉ 3.5.1. Integer Constants ΓòÉΓòÉΓòÉ
  2197.  
  2198. Integer constants can represent decimal, octal, or hexadecimal values. The data 
  2199. type of an integer constant is determined by the form, value, and suffix of the 
  2200. constant. The following lists the integer constants and shows the possible data 
  2201. types for each constant. The smallest data type that can represent the constant 
  2202. value is used to store the constant. 
  2203.  
  2204.  Constant                              Data Type 
  2205.  unsuffixed decimal                    int, long int, unsigned long int 
  2206.  unsuffixed octal                      int, unsigned int, long int, unsigned 
  2207.                                        long int 
  2208.  unsuffixed hexadecimal                int, unsigned int, long int, unsigned 
  2209.                                        long int 
  2210.  suffixed by u or U                    unsigned int, unsigned long int 
  2211.  suffixed by l or L                    long int, unsigned long int 
  2212.  suffixed by both u or U, and l or L   unsigned long int 
  2213.  
  2214.  A plus (+) or minus (-) symbol can precede the constant. It is treated as a 
  2215.  unary operator rather than as part of the constant value. 
  2216.  
  2217.  Related Information 
  2218.  
  2219.      Decimal Constants 
  2220.      Octal Constants 
  2221.      Hexadecimal Constants 
  2222.      Integer Variables 
  2223.  
  2224.  
  2225. ΓòÉΓòÉΓòÉ 3.5.1.1. Decimal Constants ΓòÉΓòÉΓòÉ
  2226.  
  2227. A decimal constant contains any of the digits 0 through 9. The first digit 
  2228. cannot be 0. Integer constants beginning with the digit 0 are interpreted as an 
  2229. octal constant, rather than as a decimal constant. 
  2230.  
  2231. Related Information 
  2232.  
  2233.      Integer Constants 
  2234.      Octal Constants 
  2235.      Hexadecimal Constants 
  2236.      Integer Variables 
  2237.  
  2238.  
  2239. ΓòÉΓòÉΓòÉ 3.5.1.2. Hexadecimal Constants ΓòÉΓòÉΓòÉ
  2240.  
  2241. A hexadecimal constant begins with the 0 digit followed by either an x or X, 
  2242. followed by any combination of the digits 0 through 9 and the letters a through 
  2243. f or A through F. The letters A (or a) through F (or f) represent the values 10 
  2244. through 15, respectively. 
  2245.  
  2246. The following are examples of hexadecimal constants: 
  2247.  
  2248. 0x3b24
  2249. 0XF96
  2250. 0x21
  2251. 0x3AA
  2252. 0X29b
  2253. 0X4bD
  2254.  
  2255. Related Information 
  2256.  
  2257.      Integer Constants 
  2258.      Decimal Constants 
  2259.      Octal Constants 
  2260.      Integer Variables 
  2261.  
  2262.  
  2263. ΓòÉΓòÉΓòÉ 3.5.1.3. Octal Constants ΓòÉΓòÉΓòÉ
  2264.  
  2265. An octal constant begins with the digit 0 and contains any of the digits 0 
  2266. through 7. 
  2267.  
  2268. The following are examples of octal constants: 
  2269.  
  2270. 0
  2271. 0125
  2272. 034673
  2273. 03245
  2274.  
  2275. Related Information 
  2276.  
  2277.      Integer Constants 
  2278.      Decimal Constants 
  2279.      Hexadecimal Constants 
  2280.      Integer Variables 
  2281.  
  2282.  
  2283. ΓòÉΓòÉΓòÉ 3.5.2. Floating-Point Constants ΓòÉΓòÉΓòÉ
  2284.  
  2285. A floating-point constant consists of: 
  2286.  
  2287.      An integral part 
  2288.      A decimal point 
  2289.      A fractional part 
  2290.      An exponent part 
  2291.      An optional suffix. 
  2292.  
  2293.  Both the integral and fractional parts are made up of decimal digits. You can 
  2294.  omit either the integral part or the fractional part, but not both. You can 
  2295.  omit either the decimal point or the exponent part, but not both. 
  2296.  
  2297.  The representation of a floating-point number on a system is unspecified. If a 
  2298.  floating-point constant is too large or too small, the result is undefined by 
  2299.  the language. VisualAge for C++, represents floating-point numbers according 
  2300.  to IEEE rules. For C, if a floating-point constant is too large, it is set to 
  2301.  the largest value representable by the type. If it is too small, it is set to 
  2302.  zero. For C++, constant values that are too large or too small cause a 
  2303.  compile-time error. 
  2304.  
  2305.  The suffix f or F indicates a type of float, and the suffix l or L indicates a 
  2306.  type of long double. If a suffix is not specified, the floating-point constant 
  2307.  has a type double. 
  2308.  
  2309.  A plus (+) or minus (-) symbol can precede a floating-point constant. However, 
  2310.  it is not part of the constant; it is interpreted as a unary operator. 
  2311.  
  2312.  The following are examples of floating-point constants: 
  2313.  
  2314.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2315.   Γöé FLOATING-POINT CON-   Γöé VALUE          Γöé
  2316.   Γöé STANT          Γöé             Γöé
  2317.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2318.   Γöé "5.3876e4"       Γöé "53,876"        Γöé
  2319.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2320.   Γöé "4e-11"         Γöé "0.00000000004"     Γöé
  2321.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2322.   Γöé "1e+5"         Γöé "100000"        Γöé
  2323.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2324.   Γöé "7.321E-3"       Γöé "0.007321"       Γöé
  2325.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2326.   Γöé "3.2E+4"        Γöé "32000"         Γöé
  2327.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2328.   Γöé "0.5e-6"        Γöé "0.0000005"       Γöé
  2329.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2330.   Γöé "0.45"         Γöé "0.45"         Γöé
  2331.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2332.   Γöé "6.e10"         Γöé "60000000000"      Γöé
  2333.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2334.  
  2335.  Related Information 
  2336.  
  2337.      Floating-Point Variables 
  2338.  
  2339.  
  2340. ΓòÉΓòÉΓòÉ 3.5.3. Character Constants ΓòÉΓòÉΓòÉ
  2341.  
  2342. A character constant contains a sequence of characters or escape sequences 
  2343. enclosed in single quotation mark symbols. 
  2344.  
  2345. At least one character or escape sequence must appear in the character 
  2346. constant. The characters can be any from the source program character set, 
  2347. excluding the single quotation mark, backslash and new-line symbols. The prefix 
  2348. L indicates a wide character constant. A character constant must appear on a 
  2349. single logical source line. 
  2350.  
  2351. The value of a character constant containing a single character is the numeric 
  2352. representation of the character in the character set used at run time. The 
  2353. value of a wide character constant containing a single multibyte character is 
  2354. the code for that character, as defined by the mbtowc function. If the 
  2355. character constant contains more than one character, the last 4 bytes represent 
  2356. the character constant. In C++, a character constant can contain only one 
  2357. character. 
  2358.  
  2359. In C, a character constant has type int. In C++, a character constant has type 
  2360. char. 
  2361.  
  2362. A wide character constant is represented by a double-byte character of type 
  2363. wchar_t. Multibyte characters represent character sets that use more than one 
  2364. byte in their representation. In Windows, each multibyte character can contain 
  2365. up to 2 bytes. 
  2366.  
  2367. Restrictions 
  2368.  
  2369. To represent the single quotation symbol, backslash, and new-line characters, 
  2370. you must use the corresponding escape sequence. For more information on escape 
  2371. sequences, see Escape Sequences. 
  2372.  
  2373. The following are examples of character constants: 
  2374.  
  2375.  'a'    '\'' 
  2376.  '0'    '(' 
  2377.  'x'    '\n' 
  2378.  '7'    '\117' 
  2379.  'C' 
  2380.  
  2381.  Related Information 
  2382.  
  2383.      String Literals 
  2384.      Escape Sequences 
  2385.      Integer Variables 
  2386.  
  2387.  
  2388. ΓòÉΓòÉΓòÉ 3.5.4. String Literals ΓòÉΓòÉΓòÉ
  2389.  
  2390. A string constant or literal contains a sequence of characters or escape 
  2391. sequences enclosed in double quotation mark symbols. 
  2392.  
  2393. The prefix L indicates a wide-character string literal. 
  2394.  
  2395. A null ('\0') character is appended to each string. For a wide character string 
  2396. (a string prefixed by the letter L), the value '\0' of type wchar_t is 
  2397. appended. By convention, programs recognize the end of a string by finding the 
  2398. null character. 
  2399.  
  2400. Multiple spaces contained within a string constant are retained. 
  2401.  
  2402. To continue a string on the next line, use the line continuation sequence (\ 
  2403. symbol immediately followed by a new-line character). A carriage return must 
  2404. immediately follow the backslash. In the following example, the string literal 
  2405. second causes a compile-time error. 
  2406.  
  2407. char *first = "This string continues onto the next\
  2408.  line, where it ends.";         /* compiles successfully.  */
  2409. char *second = "The comment makes the \ /* continuation symbol    */
  2410.  invisible to the compiler.";      /* compilation error.    */
  2411.  
  2412. Another way to continue a string is to have two or more consecutive strings. 
  2413. Adjacent string literals are concatenated to produce a single string. You 
  2414. cannot concatenate a wide string constant with a character string constant. For 
  2415. example: 
  2416.  
  2417. "hello " "there"   /* is equivalent to "hello there"  */
  2418. "hello " L"there"   /* is not valid           */
  2419. "hello" "there"    /* is equivalent to "hellothere"   */
  2420.  
  2421. Characters in concatenated strings remain distinct. For example, the strings 
  2422. "\xab" and "3" are concatenated to form "\xab3". However, the characters \xab 
  2423. and 3 remain distinct and are not merged to form the hexadecimal character 
  2424. \xab3. 
  2425.  
  2426. Following any concatenation, '\0' of type char is appended at the end of each 
  2427. string. C++ programs find the end of a string by scanning for this value. For a 
  2428. wide-character string literal, '\0' of type wchar_t is appended. For example: 
  2429.  
  2430. char *first = "Hello ";       /* stored as "Hello \0"    */
  2431. char *second = "there";       /* stored as "there\0"     */
  2432. char *third = "Hello " "there";   /* stored as "Hello there\0"  */
  2433.  
  2434. A character string constant has type array of char and static storage duration. 
  2435. A wide character constant has type array of wchar_t and static storage 
  2436. duration. 
  2437.  
  2438. Use the escape sequence \n to represent a new-line character as part of the 
  2439. string. Use the escape sequence \\ to represent a backslash character as part 
  2440. of the string. You can represent the single quotation mark symbol by itself ', 
  2441. but you use the escape sequence \" to represent the double quotation mark 
  2442. symbol. 
  2443.  
  2444. For example: 
  2445.  
  2446. /**
  2447.  ** This example illustrates escape sequences in string literals
  2448.  **/
  2449.  
  2450. #include <iostream.h>
  2451. void main ()
  2452. {
  2453.    char *s ="Hi there! \n";
  2454.    cout << s;
  2455.    char *p = "The backslash character \\.";
  2456.    cout << p << endl;
  2457.    char *q = "The double quotation mark \".\n";
  2458.    cout << q ;
  2459. }
  2460.  
  2461. This program produces the following output: 
  2462.  
  2463. Hi there!
  2464. The backslash character \.
  2465. The double quotation mark ".
  2466.  
  2467. You should be careful when modifying string literals because the resulting 
  2468. behavior depends on whether your strings are stored in read/write static 
  2469. memory. Strings are readonly by default. 
  2470.  
  2471. Use the #pragma strings preprocessor directive to change the default storage 
  2472. for string literals. 
  2473.  
  2474. The following are examples of string literals: 
  2475.  
  2476. char titles[ ] = "Handel's \"Water Music\"";
  2477. char *mail_addr = "Last Name   First Name   MI  Street Address  \
  2478.   City   Province  Postal code ";
  2479. char *temp_string = "abc" "def" "ghi";  /* *temp_string = "abcdefghi\0" */
  2480. wchar_t *wide_string = L"longstring";
  2481.  
  2482. Related Information 
  2483.  
  2484.      Character Constants 
  2485.      Escape Sequences 
  2486.      Characters 
  2487.      Arrays 
  2488.      Pragma Directives (#pragma) 
  2489.      #pragma strings 
  2490.  
  2491.  
  2492. ΓòÉΓòÉΓòÉ 3.5.5. Escape Sequences ΓòÉΓòÉΓòÉ
  2493.  
  2494. An escape sequence contains a backslash (\) symbol followed by one of the 
  2495. escape sequence characters or an octal or hexadecimal number. A hexadecimal 
  2496. escape sequence contains an x followed by one or more hexadecimal digits (0-9, 
  2497. A-F, a-f). An octal escape sequence uses up to three octal digits (0-7). 
  2498.  
  2499. Note:  The line continuation sequence (\ followed by a new-line character) is 
  2500. not an escape sequence. It is used in character strings to indicate that the 
  2501. current line continues on the next line. 
  2502.  
  2503. The escape sequences and the characters they represent are: 
  2504.  
  2505. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2506. Γöé ESCAPE   Γöé CHARACTER REPRES-   Γöé
  2507. Γöé SEQUENCE  Γöé ENTED         Γöé
  2508. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2509. Γöé "\a"    Γöé Alert (bell, alarm)  Γöé
  2510. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2511. Γöé "\b"    Γöé Backspace       Γöé
  2512. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2513. Γöé "\f"    Γöé Form feed (new page) Γöé
  2514. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2515. Γöé "\n"    Γöé New-line       Γöé
  2516. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2517. Γöé "\r"    Γöé Carriage return    Γöé
  2518. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2519. Γöé "\t"    Γöé Horizontal tab    Γöé
  2520. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2521. Γöé "\v"    Γöé Vertical tab     Γöé
  2522. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2523. Γöé "\'"    Γöé Single quotation   Γöé
  2524. Γöé       Γöé mark         Γöé
  2525. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2526. Γöé "\""    Γöé Double quotation   Γöé
  2527. Γöé       Γöé mark         Γöé
  2528. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2529. Γöé "\?"    Γöé Question mark     Γöé
  2530. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2531. Γöé "\\"    Γöé Backslash       Γöé
  2532. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2533.  
  2534. The value of an escape sequence represents the member of the character set used 
  2535. at run time. Escape sequences are translated during preprocessing. For example, 
  2536. on a system using the ASCII character codes, the value of the escape sequence 
  2537. \x56 is the letter V. 
  2538.  
  2539. Use escape sequences only in character constants or in string literals. 
  2540.  
  2541. If an escape sequence is not recognized, the compiler uses the character 
  2542. following the backslash and a message is issued. Note that this behavior is 
  2543. implementation-defined. 
  2544.  
  2545. In string and character sequences, when you want the backslash to represent 
  2546. itself (rather than the beginning of an escape sequence), you must use a \\ 
  2547. backslash escape sequence. For example: 
  2548.  
  2549.    cout << "The escape sequence \\n." << endl;
  2550.  
  2551. This statement results in the following output: 
  2552.  
  2553.    The escape sequence \n.
  2554.  
  2555. The following program prints the character 'a' four times to standard output, 
  2556. and then prints a new line: 
  2557.  
  2558. #include <iostream.h>
  2559. void main()
  2560. {
  2561.    char a,b,c,d,e;
  2562.    a='a';
  2563.    b=97;    // ASCII integer value
  2564.    c='\141';  // ASCII octal value
  2565.    d='\x61';  // ASCII hexadecimal value
  2566.    e='\n';
  2567.    cout << a << b << c << d << e;
  2568. }
  2569.  
  2570. Related Information 
  2571.  
  2572.      Character Constants 
  2573.      String Literals 
  2574.  
  2575.  
  2576. ΓòÉΓòÉΓòÉ 4. Declarations ΓòÉΓòÉΓòÉ
  2577.  
  2578. A declaration establishes the names and characteristics of data objects and 
  2579. functions used in a program. A definition allocates storage for data objects or 
  2580. specifies the body for a function. When you define a type, no storage is 
  2581. allocated. 
  2582.  
  2583. Declarations determine the following properties of data objects and their 
  2584. identifiers: 
  2585.  
  2586.      Scope, which describes the visibility of an identifier in a block or 
  2587.       source file. For a complete description of scope, see Scope in C. 
  2588.      Linkage, which describes the association between two identical 
  2589.       identifiers. See Program Linkage for more information. 
  2590.      Storage duration, which describes when the system allocates and frees 
  2591.       storage for a data object. See Storage Duration for more information. 
  2592.      Type, which describes the kind of data the object is to represent. 
  2593.  
  2594.  The lexical order of elements of declaration for a data object is as follows: 
  2595.  
  2596.      Storage duration and linkage specification, described in Storage Class 
  2597.       Specifiers 
  2598.      Type specification, described in Type Specifiers 
  2599.      Declarators, which introduce identifiers and make use of type qualifiers 
  2600.       and storage qualifiers, described in Declarators 
  2601.      Initializers, which initialize storage with initial values, described in 
  2602.       Initializers. 
  2603.  
  2604.  Function declarations are described in Functions. 
  2605.  
  2606.  Syntax of a Data Declaration 
  2607.  
  2608.  Note: 
  2609.  
  2610.    1. One of the fundamental differences between C++ and C is the placement of 
  2611.       variable declarations. Although variables are declared in the same way, 
  2612.       in C++, variable declarations can be put anywhere in the program. In C, 
  2613.       declarations must come before any statements in a block. 
  2614.  
  2615.       In the following C++ example, the variable d is declared in the middle of 
  2616.       the main() function: 
  2617.  
  2618.             #include <iostream.h>
  2619.             void main()
  2620.             {
  2621.                int a, b;
  2622.                cout << "Please enter two integers" << endl;
  2623.                cin >> a >> b;
  2624.                int d = a + b;
  2625.                cout << "Here is the sum of your two integers:" << d << endl;
  2626.             }
  2627.  
  2628.    2. A given function, object, or type can have only one definition. It can 
  2629.       have more than one declaration as long as all of the declarations match. 
  2630.       If a function is never called and its address is never taken, then you do 
  2631.       not have to define it. If an object is declared but never used, or is 
  2632.       only used as the operand of sizeof, you do not have to define it. You can 
  2633.       declare a given class or enumerator more than once. 
  2634.  
  2635.  The following table shows examples of declarations and definitions. 
  2636.  
  2637.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2638.   Γöé Table 7. Examples of Declarations and Definitions               Γöé
  2639.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2640.   Γöé DECLARATIONS          Γöé DECLARATIONS AND DEFINITIONS         Γöé
  2641.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2642.   Γöé "extern double pi;"      Γöé "double pi = 3.14159265;"           Γöé
  2643.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2644.   Γöé "float square(float x);"    Γöé "float square(float x) { return x*x; }"    Γöé
  2645.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2646.   Γöé "struct payroll;"       Γöé  struct payroll {              Γöé
  2647.   Γöé                Γöé           char *name;        Γöé
  2648.   Γöé                Γöé           float salary;       Γöé
  2649.   Γöé                Γöé          } employee;         Γöé
  2650.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2651.  
  2652.  Related Information 
  2653.  
  2654.      Block Scope Data Declarations 
  2655.      File Scope Data Declarations 
  2656.      Declarators 
  2657.      Storage Class Specifiers 
  2658.      Initializers 
  2659.      Type Specifiers 
  2660.  
  2661.  
  2662. ΓòÉΓòÉΓòÉ <hidden> Data Declaration Syntax ΓòÉΓòÉΓòÉ
  2663.  
  2664.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2665.                 Γöé                 Γöé
  2666. >>ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓöÇdeclaratorΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ;ΓöÇΓöÇ><
  2667.    Γö£ΓöÇstorage_class_specifierΓöÇΓöñ         ΓööΓöÇinitializerΓöÇΓöÿ
  2668.    Γö£ΓöÇtype_specifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2669.    ΓööΓöÇtype_qualifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2670.  
  2671.  
  2672. ΓòÉΓòÉΓòÉ 4.1. Block Scope Data Declarations ΓòÉΓòÉΓòÉ
  2673.  
  2674. A block scope data declaration can only be put at the beginning of a block. It 
  2675. describes a variable and makes that variable accessible to the current block. 
  2676. All block scope declarations that do not have the extern storage class 
  2677. specifier are definitions and allocate storage for that object. 
  2678.  
  2679. You can declare a data object with block scope with any of the storage class 
  2680. specifiers described in Storage Class Specifiers. If you do not specify a 
  2681. storage class specifier in a block-scope data declaration, the default storage 
  2682. class specifier auto is used. If you specify a storage class specifier, you can 
  2683. omit the type specifier. If you omit the type specifier, all variables in that 
  2684. declaration receive type int. 
  2685.  
  2686. Initialization 
  2687. You cannot initialize a variable declared in a block scope data declaration 
  2688. that has the extern storage class specifier. 
  2689.  
  2690. The types of variables you can initialize and the values that uninitialized 
  2691. variables receive vary for that storage class specifier. See Storage Class 
  2692. Specifiers for details on the different storage classes. 
  2693.  
  2694. Storage 
  2695.  
  2696. The duration and type of storage varies for each storage class specifier. 
  2697.  
  2698. Declarations with the auto or register storage class specifier result in 
  2699. automatic storage duration. Declarations with the extern or static storage 
  2700. class specifier result in static storage duration. 
  2701.  
  2702. Related Information 
  2703.  
  2704.      Declarators 
  2705.      Storage Class Specifiers 
  2706.      auto Storage Class Specifier 
  2707.      extern Storage Class Specifier 
  2708.      register Storage Class Specifier 
  2709.      static Storage Class Specifier 
  2710.      Declarations 
  2711.      Initializers 
  2712.      Type Specifiers 
  2713.  
  2714.  
  2715. ΓòÉΓòÉΓòÉ 4.2. File Scope Data Declarations ΓòÉΓòÉΓòÉ
  2716.  
  2717. A file scope data declaration appears outside any function definition. It 
  2718. describes a variable and makes that variable accessible to all functions that 
  2719. are in the same file and whose definitions appear after the declaration. 
  2720.  
  2721. A file scope data definition is a data declaration at file scope that also 
  2722. causes storage to be allocated for that variable. All objects whose identifiers 
  2723. are declared at file scope have static storage duration. 
  2724.  
  2725. Use a file scope data declaration to declare variables that you want to have 
  2726. external linkage. 
  2727.  
  2728. The only storage class specifiers you can put in a file scope data declaration 
  2729. are static, extern, and typedef. If you specify static, all variables defined 
  2730. in it have internal linkage. If you do not specify static, all variables 
  2731. defined in it have external linkage. If you specify the storage class you can 
  2732. omit the type specifier. If you omit the type specifier, all variables defined 
  2733. in that declaration receive the type int. 
  2734.  
  2735. Initialization 
  2736. You can initialize any object with file scope. If you do not initialize a file 
  2737. scope variable, its initial value is zero of the appropriate type. If you do 
  2738. initialize it, the initializer must be described by a constant expression, or 
  2739. it must reduce to the address of a previously declared variable at file scope, 
  2740. possibly modified by a constant expression. Initialization of all variables at 
  2741. file scope takes place before the main function begins running. 
  2742.  
  2743. Storage 
  2744. All objects with file scope data declarations have static storage duration. 
  2745. Storage is allocated at runtime and freed when the program stops running. 
  2746.  
  2747. Related Information 
  2748.  
  2749.      extern Storage Class Specifier 
  2750.      static Storage Class Specifier 
  2751.      Declarations 
  2752.      Declarators 
  2753.      Initializers 
  2754.      Type Specifiers 
  2755.  
  2756.  
  2757. ΓòÉΓòÉΓòÉ 4.3. Objects ΓòÉΓòÉΓòÉ
  2758.  
  2759. An object is a region of storage that contains a value or group of values. Each 
  2760. value can be accessed using its identifier or a more complex expression that 
  2761. refers to the object. In addition, each object has a unique data type. Both the 
  2762. identifier and data type of an object are established in the object 
  2763. declaration. 
  2764.  
  2765. The data type of an object determines the initial storage allocation for that 
  2766. object and the interpretation of the values during subsequent access. It is 
  2767. also used in any type-checking operations. 
  2768.  
  2769. C++ has built-in, or standard, data types and user-defined data types. Standard 
  2770. data types include signed and unsigned integers, floating-point numbers, and 
  2771. characters. User-defined types include enumerations, structures, unions, and 
  2772. classes. 
  2773.  
  2774. In C++ code, objects are represented by variables. A variable also represents 
  2775. the location in storage that contains the value of an object. 
  2776.  
  2777. An instance of a class type is commonly called a class object. The individual 
  2778. class members are also called objects. The set of all member objects comprises 
  2779. a class object. 
  2780.  
  2781. Related Information 
  2782.  
  2783.      Type Specifiers 
  2784.      C++ Classes 
  2785.      Declarations 
  2786.  
  2787.  
  2788. ΓòÉΓòÉΓòÉ 4.4. Storage Class Specifiers ΓòÉΓòÉΓòÉ
  2789.  
  2790. The storage class specifier used within the declaration determines whether: 
  2791.  
  2792.      The object has internal, external, or no linkage. 
  2793.  
  2794.      The object is to be stored in memory or in a register, if available. 
  2795.  
  2796.      The object receives the default initial value 0 or an indeterminate 
  2797.       default initial value. 
  2798.  
  2799.      The object can be referenced throughout a program or only within the 
  2800.       function, block, or source file where the variable is defined. 
  2801.  
  2802.      The storage duration for the object is static (storage is maintained 
  2803.       throughout program run time) or automatic (storage is maintained only 
  2804.       during the execution of the block where the object is defined). 
  2805.  
  2806.  For a function, the storage class specifier determines the linkage of the 
  2807.  function. 
  2808.  
  2809.  Declarations with the auto or register storage-class specifier result in 
  2810.  automatic storage. Those with the extern or static storage-class specifier 
  2811.  result in static storage. 
  2812.  
  2813.  Most local declarations that do not include the extern storage-class specifier 
  2814.  allocate storage; however, function declarations and type declarations do not 
  2815.  allocate storage. 
  2816.  
  2817.  The only storage-class specifiers allowed in a global or file scope 
  2818.  declaration are static and extern. 
  2819.  
  2820.  The VisualAge for C++ compiler implements additional storage class specifiers 
  2821.  for inlining functions: 
  2822.  
  2823.      inline for C++ functions 
  2824.      _Inline, _inline, and __inline specifiers for C functions 
  2825.  The inlining specifiers determine whether the function code will be inlined or 
  2826.  called. Note that they are ignored if the /Oi- compiler option is specified. 
  2827.  
  2828.  The following sections describe the storage class specifiers: 
  2829.  
  2830.      auto Storage Class Specifier 
  2831.      extern Storage Class Specifier 
  2832.      register Storage Class Specifier 
  2833.      static Storage Class Specifier 
  2834.      typedef 
  2835.  
  2836.  Related Information 
  2837.  
  2838.      Program Linkage 
  2839.      Inline Functions 
  2840.      Declarations 
  2841.      Inline Specifiers 
  2842.      /Oi option 
  2843.  
  2844.  
  2845. ΓòÉΓòÉΓòÉ 4.4.1. auto Storage Class Specifier ΓòÉΓòÉΓòÉ
  2846.  
  2847. The auto storage class specifier lets you define a variable with automatic 
  2848. storage; its use and storage is restricted to the current block. The storage 
  2849. class keyword auto is optional in a data declaration. It is not permitted in a 
  2850. parameter declaration. A variable having the auto storage class specifier must 
  2851. be declared within a block. It cannot be used for file scope declarations. 
  2852.  
  2853. Because automatic variables require storage only while they are actually being 
  2854. used, defining variables with the auto storage class can decrease the amount of 
  2855. memory required to run a program. However, having many large automatic objects 
  2856. may cause you to run out of stack space. 
  2857.  
  2858. Declaring variables with the auto storage class can also make code easier to 
  2859. maintain, because a change to an auto variable in one function never affects 
  2860. another function (unless it is passed as an argument). 
  2861.  
  2862. You can initialize any auto variable except parameters. If you do not 
  2863. initialize an automatic object, its value is indeterminate. If you provide an 
  2864. initial value, the expression representing the initial value can be any valid C 
  2865. or C++ expression. For structure and union members, the initial value must be a 
  2866. valid constant expression if an initializer list is used. The object is then 
  2867. set to that initial value each time the program block that contains the 
  2868. object's definition is entered. 
  2869.  
  2870. Note:  If you use the goto statement to jump into the middle of a block, 
  2871. automatic variables within that block are not initialized. 
  2872.  
  2873. Objects with the auto storage class specifier have automatic storage duration. 
  2874. Each time a block is entered, storage for auto objects defined in that block is 
  2875. made available. When the block is exited, the objects are no longer available 
  2876. for use. 
  2877.  
  2878. If an auto object is defined within a function that is recursively invoked, 
  2879. memory is allocated for the object at each invocation of the block. 
  2880.  
  2881. Examples of auto Storage Class 
  2882.  
  2883. Related Information 
  2884.  
  2885.      Storage Class Specifiers 
  2886.      register Storage Class Specifier 
  2887.      Block Scope Data Declarations 
  2888.      Function Declarator 
  2889.      Address  & 
  2890.  
  2891.  
  2892. ΓòÉΓòÉΓòÉ <hidden> Examples of auto Storage Class ΓòÉΓòÉΓòÉ
  2893.  
  2894. /************************************************************************
  2895. *
  2896.  
  2897. The following program shows the scope and initialization of auto variables. The 
  2898. function main defines two variables, each named auto_var. The first definition 
  2899. occurs on line 10. The second definition occurs in a nested block on line 13. 
  2900. While the nested block is running, only the auto_var created by the second 
  2901. definition is available. During the rest of the program, only the auto_var 
  2902. created by the first definition is available. 
  2903.  
  2904.                                     *
  2905. ************************************************************************/
  2906.  
  2907.  1  /****************************************************
  2908.  2   ** Example illustrating the use of auto variables **
  2909.  3   ****************************************************/
  2910.  4
  2911.  5  #include <stdio.h>
  2912.  6
  2913.  7  int main(void)
  2914.  8  {
  2915.  9    void call_func(int passed_var);
  2916. 10    auto int auto_var = 1;  /* first definition of auto_var  */
  2917. 11
  2918. 12    {
  2919. 13     int auto_var = 2;   /* second definition of auto_var */
  2920. 14     printf("inner auto_var = %d\n", auto_var);
  2921. 15    }
  2922. 16    call_func(auto_var);
  2923. 17    printf("outer auto_var = %d\n", auto_var);
  2924. 18    return 0;
  2925. 19  }
  2926. 20
  2927. 21  void call_func(int passed_var)
  2928. 22  {
  2929. 23    printf("passed_var = %d\n", passed_var);
  2930. 24    passed_var = 3;
  2931. 25    printf("passed_var = %d\n", passed_var);
  2932. 26  }
  2933.  
  2934. /************************************************************************
  2935. *
  2936. This program produces the following output: 
  2937.  
  2938. inner auto_var = 2
  2939. passed_var = 1
  2940. passed_var = 3
  2941. outer auto_var = 1
  2942.  
  2943. The following example uses an array that has the storage class auto to pass a 
  2944. character string to the function sort. The function sort receives the address 
  2945. of the character string, rather than the contents of the array. The address 
  2946. enables sort to change the values of the elements in the array. 
  2947.  
  2948.                                     *
  2949. ************************************************************************/
  2950.  
  2951. /*****************************************************************
  2952.  ** Sorted string program -- this example passes an array name  **
  2953.  ** to a function                        **
  2954.  *****************************************************************/
  2955.  
  2956. #include <stdio.h>
  2957. #include <string.h>
  2958.  
  2959. int main(void)
  2960. {
  2961.   void sort(char *array, int n);
  2962.   char string[75];
  2963.   int length;
  2964.  
  2965.   printf("Enter letters:\n");
  2966.   scanf("%74s", string);
  2967.   length = strlen(string);
  2968.   sort(string,length);
  2969.   printf("The sorted string is: %s\n", string);
  2970.  
  2971.   return(0);
  2972. }
  2973.  
  2974. void sort(char *array, int n)
  2975. {
  2976.   int gap, i, j, temp;
  2977.  
  2978.   for (gap = n / 2; gap > 0; gap /= 2)
  2979.    for (i = gap; i < n; i++)
  2980.      for (j = i - gap; j >= 0 && array[j] > array[j + gap];
  2981.       j -= gap)
  2982.      {
  2983.       temp = array[j];
  2984.       array[j] = array[j + gap];
  2985.       array[j + gap] = temp;
  2986.      }
  2987. }
  2988.  
  2989. /**********************************************************************************
  2990. *
  2991.  
  2992. When the program is run, interaction with the program could produce: 
  2993.  
  2994.  Output    Enter letters: 
  2995.  
  2996.  Input     zyfab 
  2997.  
  2998.  Output    The sorted string is:  abfyz 
  2999.  
  3000.                                        *
  3001.   ************************************************************************/
  3002.  
  3003.  
  3004. ΓòÉΓòÉΓòÉ 4.4.2. extern Storage Class Specifier ΓòÉΓòÉΓòÉ
  3005.  
  3006. The extern storage class specifier lets you declare objects and functions that 
  3007. several source files can use. All object declarations that occur outside a 
  3008. function and that do not contain a storage class specifier declare identifiers 
  3009. with external linkage. All function definitions that do not specify a storage 
  3010. class define functions with external linkage. 
  3011.  
  3012. You can distinguish an extern declaration from an extern definition by the 
  3013. presence of the keyword extern and the absence of an initial value. If the 
  3014. keyword extern is absent or if there is an initial value, the declaration is 
  3015. also a definition; otherwise, it is just a declaration. An extern definition 
  3016. can appear only at file scope. 
  3017.  
  3018. An extern variable, function definition, or declaration also makes the 
  3019. described variable or function usable by the succeeding part of the current 
  3020. source file. This declaration does not replace the definition. The declaration 
  3021. is used to describe the variable that is externally defined. 
  3022.  
  3023. If a declaration for an identifier already exists at file scope, any extern 
  3024. declaration of the same identifier found within a block refers to that same 
  3025. object. If no other declaration for the identifier exists at file scope, the 
  3026. identifier has external linkage. 
  3027.  
  3028. An extern declaration can appear outside a function or at the beginning of a 
  3029. block. If the declaration describes a function or appears outside a function 
  3030. and describes an object with external linkage, the keyword extern is optional. 
  3031.  
  3032. C++ Note:  In C++, an extern declaration cannot appear in class scope. 
  3033.  
  3034. You can initialize any object with the extern storage class specifier at file 
  3035. scope. You can initialize an extern object with an initializer that must 
  3036. either: 
  3037.  
  3038.      Appear as part of the definition and the initial value must be described 
  3039.       by a constant expression. 
  3040.  
  3041.       OR 
  3042.      Reduce to the address of a previously declared object with static storage 
  3043.       duration. This object may be modified by adding or subtracting an 
  3044.       integral constant expression. 
  3045.  
  3046.  If you do not explicitly initialize an extern variable, its initial value is 
  3047.  zero of the appropriate type. Initialization of an extern object is completed 
  3048.  by the time the program starts running. 
  3049.  
  3050.  extern objects have static storage duration. Memory is allocated for extern 
  3051.  objects before the main function begins running. When the program finishes 
  3052.  running, the storage is freed. 
  3053.  
  3054.  Examples of extern Storage Class 
  3055.  
  3056.  Related Information 
  3057.  
  3058.      Storage Class Specifiers 
  3059.      File Scope Data Declarations 
  3060.      Function Definitions 
  3061.      Function Declarator 
  3062.      Constant Expressions 
  3063.  
  3064.  
  3065. ΓòÉΓòÉΓòÉ <hidden> Examples of extern Storage Class ΓòÉΓòÉΓòÉ
  3066.  
  3067. /************************************************************************
  3068. *
  3069.  
  3070. The following program shows the linkage of extern objects and functions. The 
  3071. extern object total is declared on line 12 of File 1 and on line 11 of File 2. 
  3072. The definition of the external object total appears in File 3. The extern 
  3073. function tally is defined in File 2. The function tally can be in the same file 
  3074. as main or in a different file. Because main precedes these definitions and 
  3075. main uses both total and tally, main declares tally on line 11 and total on 
  3076. line 12. 
  3077.  
  3078. File 1 
  3079.  
  3080.  
  3081. ************************************************************************/
  3082.  
  3083.  1  /**************************************************************
  3084.  2   ** The program receives the price of an item, adds the    **
  3085.  3   ** tax, and prints the total cost of the item.        **
  3086.  5   **************************************************************/
  3087.  6
  3088.  7  #include <stdio.h>
  3089.  8
  3090.  9  int main(void)
  3091. 10  {                /* begin main           */
  3092. 11    void tally(void);       /* declaration of function tally */
  3093. 12    extern float total;      /* first declaration of total   */
  3094. 13
  3095. 14    printf("Enter the purchase amount: \n");
  3096. 15    tally();
  3097. 16    printf("\nWith tax, the total is:  %.2f\n", total);
  3098. 17
  3099. 18    return(0);
  3100. 19  }                /* end main            */
  3101.  
  3102. /************************************************************************
  3103. *
  3104.  
  3105. File 2 
  3106.  
  3107.                                     *
  3108. ************************************************************************/
  3109.  
  3110.  1  /**************************************************************
  3111.  2   ** This file defines the function tally           **
  3112.  3   **************************************************************/
  3113.  4  #include <stdio.h>
  3114.  6  #define  tax_rate  0.05
  3115.  7
  3116.  8  void tally(void)
  3117.  9  {                      /* begin tally */
  3118. 10    float tax;
  3119. 11    extern float total;   /* second declaration of total  */
  3120. 12
  3121. 13    scanf("%f", &total);
  3122. 14    tax = tax_rate * total;
  3123. 15    total += tax;
  3124. 16  }                       /* end tally */
  3125.  
  3126. /************************************************************************
  3127. *
  3128.  
  3129. File 3 
  3130.  
  3131.                                     *
  3132. ************************************************************************/
  3133.  
  3134.  1  float total;
  3135.  
  3136. /************************************************************************
  3137. *
  3138.  
  3139. When this program is run, interaction with it could produce: 
  3140.  
  3141.  Output    Enter the purchase amount: 
  3142.  
  3143.  Input     99.95 
  3144.  
  3145.  Output    With tax, the total is:  104.95 
  3146.  
  3147.  The following program shows extern variables used by two functions. Because 
  3148.  both functions main and sort can access and change the values of the extern 
  3149.  variables string and length, main does not have to pass parameters to sort. 
  3150.  
  3151.                                       *
  3152.   ************************************************************************/
  3153.  
  3154.   /*****************************************************************
  3155.    ** Sorted string program -- this example shows extern      **
  3156.    ** used by two functions                    **
  3157.    *****************************************************************/
  3158.  
  3159.   #include <stdio.h>
  3160.   #include <string.h>
  3161.  
  3162.   char string[75];
  3163.   int length;
  3164.  
  3165.   int main(void)
  3166.   {
  3167.     void sort(void);
  3168.  
  3169.     printf("Enter letters:\n");
  3170.     scanf("%s", string);
  3171.     length = strlen(string);
  3172.     sort();
  3173.     printf("The sorted string is: %s\n", string);
  3174.  
  3175.     return(0);
  3176.   }
  3177.  
  3178.   void sort(void)
  3179.   {
  3180.     int gap, i, j, temp;
  3181.  
  3182.     for (gap = length / 2; gap > 0; gap /= 2)
  3183.      for (i = gap; i < length; i++)
  3184.        for (j = i - gap;
  3185.          j >= 0 && string[j] > string[j + gap];
  3186.          j -= gap)
  3187.        {
  3188.         temp = string[j];
  3189.         string[j] = string[j + gap];
  3190.         string[j + gap] = temp;
  3191.        }
  3192.   }
  3193.  
  3194.   /************************************************************************
  3195.   *
  3196.  
  3197.  When this program is run, interaction with it could produce: 
  3198.  
  3199.  Output    Enter letters: 
  3200.  
  3201.  Input     zyfab 
  3202.  
  3203.  Output    The sorted string is:  abfyz 
  3204.  
  3205.  The following program shows a static variable var1, which is defined at file 
  3206.  scope and then declared with the storage class specifier extern. The second 
  3207.  declaration refers to the first definition of var1 and so it has internal 
  3208.  linkage. 
  3209.  
  3210.   static int var1;
  3211.     .
  3212.     .
  3213.     .
  3214.   extern int var1;
  3215.  
  3216.                                        *
  3217.   ************************************************************************/
  3218.  
  3219.  
  3220. ΓòÉΓòÉΓòÉ 4.4.3. register Storage Class Specifier ΓòÉΓòÉΓòÉ
  3221.  
  3222. The register storage class specifier indicates to the compiler that a heavily 
  3223. used variable (such as a loop control variable) within a block scope data 
  3224. definition or a parameter declaration should be allocated a register to 
  3225. minimize access time. 
  3226.  
  3227. It is equivalent to the auto storage class except that the compiler places the 
  3228. object, if possible, into a machine register for faster access. 
  3229.  
  3230. Note:  Because the VisualAge for C++ compiler optimizes register use, it 
  3231. ignores the register keyword. 
  3232.  
  3233. Most heavily used entities are generated by the compiler itself; therefore, 
  3234. register variables are given no special priority for placement in machine 
  3235. registers. The register storage class keyword is required in a data definition 
  3236. and in a parameter declaration that describes an object having the register 
  3237. storage class. An object having the register storage class specifier must be 
  3238. defined within a block or declared as a parameter to a function. 
  3239.  
  3240. You can initialize any register object except parameters. If you do not 
  3241. initialize an automatic object, its value is indeterminate. If you provide an 
  3242. initial value, the expression representing the initial value can be any valid C 
  3243. or C++ expression. For structure and union members, the initial value must be a 
  3244. valid constant expression if an initializer list is used. The object is then 
  3245. set to that initial value each time the program block that contains the 
  3246. object's definition is entered. 
  3247.  
  3248. Objects with the register storage class specifier have automatic storage 
  3249. duration. Each time a block is entered, storage for register objects defined in 
  3250. that block are made available. When the block is exited, the objects are no 
  3251. longer available for use. 
  3252.  
  3253. If a register object is defined within a function that is recursively invoked, 
  3254. the memory is allocated for the variable at each invocation of the block. 
  3255.  
  3256. The register storage class specifier indicates that the object is heavily used 
  3257. and indicates to the compiler that the value of the object should reside in a 
  3258. machine register. Because of the limited size and number of registers available 
  3259. on most systems, few variables can actually be put in registers. 
  3260.  
  3261. If the compiler does not allocate a machine register for a register object, the 
  3262. object is treated as having the storage class specifier auto. 
  3263.  
  3264. Using register definitions for variables that are heavily used may make your 
  3265. object files smaller and make them run faster. In object code, a reference to a 
  3266. register can require less code and time than a reference to memory. 
  3267.  
  3268. Restrictions 
  3269.  
  3270. You cannot use the register storage class specifier in file scope data 
  3271. declarations. 
  3272.  
  3273. C++ Note: 
  3274.  
  3275. In C programs, you cannot apply the address (&) operator to register variables. 
  3276. However, C++ lets you take the address of an object with the register storage 
  3277. class. For example: 
  3278.  
  3279.   register i;
  3280.   int* b = &i;    // valid in C++, but not in C
  3281.  
  3282. Related Information 
  3283.  
  3284.      Storage Class Specifiers 
  3285.      Block Scope Data Declarations 
  3286.      auto Storage Class Specifier 
  3287.      Address  & 
  3288.  
  3289.  
  3290. ΓòÉΓòÉΓòÉ 4.4.4. static Storage Class Specifier ΓòÉΓòÉΓòÉ
  3291.  
  3292. The static storage class specifier lets you define objects with static storage 
  3293. duration and internal linkage, or to define functions with internal linkage. 
  3294.  
  3295. An object having the static storage class specifier can be defined within a 
  3296. block or at file scope. If the definition occurs within a block, the object has 
  3297. no linkage. If the definition occurs at file scope, the object has internal 
  3298. linkage. 
  3299.  
  3300. You can initialize any static object with a constant expression or an 
  3301. expression that reduces to the address of a previously declared extern or 
  3302. static object, possibly modified by a constant expression. If you do not 
  3303. provide an initial value, the object receives the value of zero of the 
  3304. appropriate type. Initializing a C static data pointer to the address of an 
  3305. imported data object causes a compilation error. Such an initialization is 
  3306. permitted in C++. 
  3307.  
  3308. Storage is allocated at compile time for static variables that are initialized. 
  3309. Uninitialized static variables are mapped at compile time and initialized to 0 
  3310. (zero) at load time. This storage is freed when the program finishes running. 
  3311. Beyond this, the language does not define the order of initialization of 
  3312. objects from different files. 
  3313.  
  3314. Use static variables to declare objects that retain their value from one 
  3315. execution of a block to the next execution of that block. The static storage 
  3316. class specifier keeps the variable from being reinitialized each time the block 
  3317. where the variable is defined runs. For example: 
  3318.  
  3319. static float rate = 10.5;
  3320.  
  3321. Initialization of a static array is performed only once at compile time. The 
  3322. following examples show the initialization of an array of characters and an 
  3323. array of integers: 
  3324.  
  3325. static char message[] = "startup completed";
  3326. static int integers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  3327.  
  3328. The static storage class specifier causes the variable to be visible only in 
  3329. the file where it is declared. Files, therefore, cannot access file scope 
  3330. static variables declared in other files. 
  3331.  
  3332. C++ Note: 
  3333.  
  3334. If a local static variable is a class object with constructors and destructors, 
  3335. the object is constructed when control passes through its definition for the 
  3336. first time. If a local class object is created by a constructor, its destructor 
  3337. is called immediately before or as part of the calls of the atexit function. 
  3338.  
  3339. You cannot declare a static function at block scope. 
  3340.  
  3341. Examples of static Storage Class 
  3342.  
  3343. Related Information 
  3344.  
  3345.      Storage Class Specifiers 
  3346.      Block Scope Data Declarations 
  3347.      File Scope Data Declarations 
  3348.      Function Definitions 
  3349.      Function Declarator 
  3350.  
  3351.  
  3352. ΓòÉΓòÉΓòÉ <hidden> Examples of static Storage Class ΓòÉΓòÉΓòÉ
  3353.  
  3354. /************************************************************************
  3355. *
  3356.  
  3357. The following program shows the linkage of static identifiers at file scope. 
  3358. This program uses two different external static identifiers named stat_var. The 
  3359. first definition occurs in file 1. The second definition occurs in file 2. The 
  3360. main function references the object defined in file 1. The var_print function 
  3361. references the object defined in file 2: 
  3362.  
  3363. File 1 
  3364.  
  3365.                                     *
  3366. ************************************************************************/
  3367.  
  3368. /************************************************************************
  3369. ** Program to illustrate file scope static variables          **
  3370. ************************************************************************/
  3371.  
  3372. #include <stdio.h>
  3373.  
  3374. extern void var_print(void);
  3375. static stat_var = 1;
  3376.  
  3377. int main(void)
  3378. {
  3379.   printf("file1 stat_var = %d\n", stat_var);
  3380.   var_print();
  3381.   printf("FILE1 stat_var = %d\n", stat_var);
  3382.  
  3383.   return(0);
  3384. }
  3385.  
  3386. /************************************************************************
  3387. *
  3388.  
  3389. File 2 
  3390.  
  3391.                                     *
  3392. ************************************************************************/
  3393.  
  3394. /************************************************************************
  3395. ** This file contains the second definition of stat_var       **
  3396. ************************************************************************/
  3397.  
  3398. #include <stdio.h>
  3399.  
  3400. static int stat_var = 2;
  3401.  
  3402. void var_print(void)
  3403. {
  3404.   printf("file2 stat_var = %d\n", stat_var);
  3405. }
  3406.  
  3407. /************************************************************************
  3408. *
  3409.  
  3410. This program produces the following output: 
  3411.  
  3412. file1 stat_var = 1
  3413. file2 stat_var = 2
  3414. FILE1 stat_var = 1
  3415.  
  3416. The following program shows the linkage of static identifiers with block scope. 
  3417. The function test defines the static variable stat_var, which retains its 
  3418. storage throughout the program, even though test is the only function that can 
  3419. refer to stat_var. 
  3420.  
  3421.                                     *
  3422. ************************************************************************/
  3423.  
  3424. /************************************************************************
  3425. ** Program to illustrate block scope static variables          **
  3426. ************************************************************************/
  3427.  
  3428. #include <stdio.h>
  3429.  
  3430. int main(void)
  3431. {
  3432.   void test(void);
  3433.   int counter;
  3434.   for (counter = 1; counter <= 4; ++counter)
  3435.    test();
  3436.  
  3437.   return(0);
  3438. }
  3439.  
  3440. void test(void)
  3441. {
  3442.   static int stat_var = 0;
  3443.   auto int auto_var = 0;
  3444.   stat_var++;
  3445.   auto_var++;
  3446.   printf("stat_var = %d auto_var = %d\n", stat_var, auto_var);
  3447. }
  3448.  
  3449. /************************************************************************
  3450. *
  3451.  
  3452. This program produces the following output: 
  3453.  
  3454. stat_var = 1 auto_var = 1
  3455. stat_var = 2 auto_var = 1
  3456. stat_var = 3 auto_var = 1
  3457. stat_var = 4 auto_var = 1
  3458.  
  3459.                                     *
  3460. ************************************************************************/
  3461.  
  3462.  
  3463. ΓòÉΓòÉΓòÉ 4.4.5. typedef ΓòÉΓòÉΓòÉ
  3464.  
  3465. A typedef declaration lets you define your own identifiers that can be used in 
  3466. place of type specifiers such as int, float, and double. A typedef declaration 
  3467. does not reserve storage. The names you define using typedef are not new data 
  3468. types. They are synonyms for the data types or combinations of data types they 
  3469. represent. 
  3470.  
  3471. Syntax of a typedef Declaration 
  3472.  
  3473. When an object is defined using a typedef identifier, the properties of the 
  3474. defined object are exactly the same as if the object were defined by explicitly 
  3475. listing the data type associated with the identifier. 
  3476.  
  3477. C++ Note: 
  3478.  
  3479. A C++ class defined in a typedef without being named is given a dummy name and 
  3480. the typedef name for linkage. Such a class cannot have constructors or 
  3481. destructors. For example: 
  3482.  
  3483. typedef class {
  3484.         Trees();
  3485.        } Trees;
  3486.  
  3487. Here the function Trees() is an ordinary member function of a class whose type 
  3488. name is unspecified. In the above example, Trees is an alias for the unnamed 
  3489. class, not the class type name itself, so Trees() cannot be a constructor for 
  3490. that class. 
  3491.  
  3492. Duplicate typedefs are permitted. For example, 
  3493.  
  3494. typedef int zip;
  3495. typedef int zip;
  3496. typedef zip zip;
  3497.  
  3498. are allowed within a given scope. 
  3499.  
  3500. The following statements declare LENGTH as a synonym for int and then use this 
  3501. typedef to declare length, width, and height as integral variables: 
  3502.  
  3503. typedef int LENGTH;
  3504. LENGTH length, width, height;
  3505.  
  3506. The following declarations are equivalent to the above declaration: 
  3507.  
  3508. int length, width, height;
  3509.  
  3510. Similarly, typedef can be used to define a class type (structure, union, or C++ 
  3511. class). For example: 
  3512.  
  3513. typedef struct {
  3514.         int scruples;
  3515.         int drams;
  3516.         int grains;
  3517.         } WEIGHT;
  3518.  
  3519. The structure WEIGHT can then be used in the following declarations: 
  3520.  
  3521. WEIGHT  chicken, cow, horse, whale;
  3522.  
  3523. Related Information 
  3524.  
  3525.      Characters 
  3526.      Floating-Point Variables 
  3527.      Integer Variables 
  3528.      Enumerations 
  3529.      Pointers 
  3530.      void Type 
  3531.      Arrays 
  3532.      Structures 
  3533.      Unions 
  3534.      C++ Classes 
  3535.      Constructors and Destructors Overview 
  3536.  
  3537.  
  3538. ΓòÉΓòÉΓòÉ <hidden> Syntax of a typedef Declaration ΓòÉΓòÉΓòÉ
  3539.  
  3540. The syntax of a typedef declaration is: 
  3541.  
  3542. >>ΓöÇΓöÇtypedefΓöÇΓöÇtype_specifierΓöÇΓöÇidentifierΓöÇΓöÇ;ΓöÇΓöÇ><
  3543.  
  3544.  
  3545. ΓòÉΓòÉΓòÉ 4.5. Type Specifiers ΓòÉΓòÉΓòÉ
  3546.  
  3547. Type specifiers indicate the type of the object or function being declared. The 
  3548. fundamental data types are: 
  3549.  
  3550.      Characters 
  3551.      Floating-Point Variables 
  3552.      Integer Variables 
  3553.      Enumerations 
  3554.      void Type 
  3555.  
  3556.  From these types, you can derive: 
  3557.  
  3558.      Pointers 
  3559.      Arrays 
  3560.      Structures 
  3561.      Unions 
  3562.      Functions 
  3563.  
  3564.  The integral types are char, wchar_t (C++ only), and int of all sizes. 
  3565.  Floating-point numbers can have types float, double, or long double. Integral 
  3566.  and floating-point types are collectively called arithmetic types. In C++ 
  3567.  only, you can also derive the following: 
  3568.  
  3569.      References 
  3570.      Classes 
  3571.      Pointers to Members 
  3572.  
  3573.  In C++, enumerations are not an integral type, but they can be subject to 
  3574.  integral promotion, as described in Integral Promotions. 
  3575.  
  3576.  You can give names to both fundamental and derived types by using the typedef 
  3577.  specifier. 
  3578.  
  3579.  
  3580. ΓòÉΓòÉΓòÉ 4.5.1. Characters ΓòÉΓòÉΓòÉ
  3581.  
  3582. There are three character data types: char, signed char, and unsigned char. 
  3583. These three data types are not compatible. 
  3584.  
  3585. The character data types provide enough storage to hold any member of the 
  3586. character set used at run time. The amount of storage allocated for a char is 
  3587. implementation-dependent. The VisualAge for C++ compiler represents a character 
  3588. by 8 bits, as defined in the CHAR_BIT macro in the <limits.h> header. 
  3589.  
  3590. The default character type behaves like an unsigned char. To change this 
  3591. default, use #pragma chars or the /J compiler option. 
  3592.  
  3593. If it does not matter whether a char data object is signed or unsigned, you can 
  3594. declare the object as having the data type char;  otherwise, explicitly declare 
  3595. signed char or unsigned char. When a char (signed or unsigned) is widened to an 
  3596. int, its value is preserved. 
  3597.  
  3598. To declare a data object having a character type, use a char type specifier. 
  3599.  
  3600. The declarator for a simple character declaration is an identifier. You can 
  3601. initialize a simple character with a character constant or with an expression 
  3602. that evaluates to an integer. 
  3603.  
  3604. Use the char specifier in variable definitions to define such variables as: 
  3605. arrays of characters, pointers to characters, and arrays of pointers to 
  3606. characters. Use signed char or unsigned char to declare numeric variables that 
  3607. occupy a single byte. 
  3608.  
  3609. C++ Note:  For the purposes of distinguishing overloaded functions, a C++ char 
  3610. is a distinct type from signed char and unsigned char. 
  3611.  
  3612. Examples of Character Data Types 
  3613.  
  3614. Related Information 
  3615.  
  3616.      Arrays 
  3617.      Pointers 
  3618.      Character Constants 
  3619.      Assignment Expressions 
  3620.      Declarators 
  3621.      Initializers 
  3622.  
  3623.  
  3624. ΓòÉΓòÉΓòÉ <hidden> Examples of Character Data Types ΓòÉΓòÉΓòÉ
  3625.  
  3626. The following example defines the identifier end_of_string as a constant object 
  3627. of type char having the initial value \0 (the null character): 
  3628.  
  3629. const char end_of_string = '\0';
  3630.  
  3631. The following example defines the unsigned char variable switches as having the 
  3632. initial value 3: 
  3633.  
  3634. unsigned char switches = 3;
  3635.  
  3636. The following example defines string_pointer as a pointer to a character: 
  3637.  
  3638. char *string_pointer;
  3639.  
  3640. The following example defines name as a pointer to a character.  After 
  3641. initialization, name points to the first letter in the character string 
  3642. "Johnny": 
  3643.  
  3644. char *name = "Johnny";
  3645.  
  3646. The following example defines a one-dimensional array of pointers to 
  3647. characters.  The array has three elements.  Initially they are a pointer to the 
  3648. string "Venus", a pointer to "Jupiter", and a pointer to "Saturn": 
  3649.  
  3650. static char *planets[ ] = { "Venus", "Jupiter", "Saturn" };
  3651.  
  3652.  
  3653. ΓòÉΓòÉΓòÉ 4.5.2. Floating-Point Variables ΓòÉΓòÉΓòÉ
  3654.  
  3655. There are three types of floating-point variables: float, double, and long 
  3656. double. 
  3657.  
  3658. The amount of storage allocated for a float, a double, or a long double is 
  3659. implementation-dependent. On all compilers, the storage size of a float 
  3660. variable is less than or equal to the storage size of a double variable. 
  3661.  
  3662. The VisualAge for C++ compiler allocates the following storage for 
  3663. floating-point types: 
  3664.  
  3665.      4 bytes for a float with 32 bits of precision 
  3666.      8 bytes for a double with 64 bits of precision 
  3667.      16 bytes for a long double, with 80 bits of precision 
  3668.  
  3669.  For more information about compiler options and the VisualAge for C++ 
  3670.  implementation of floating-point types, see the IBM VisualAge for C++ for 
  3671.  Windows User's Guide. 
  3672.  
  3673.  To declare a data object having a floating-point type, use the float 
  3674.  specifier. 
  3675.  
  3676.  The declarator for a simple floating-point declaration is an identifier. 
  3677.  Initialize a simple floating-point variable with a float constant or with a 
  3678.  variable or expression that evaluates to an integer or floating-point number. 
  3679.  The storage class of a variable determines how you initialize the variable. 
  3680.  
  3681.  Examples of Floating-Point Data Types 
  3682.  
  3683.  Related Information 
  3684.  
  3685.      Floating-Point Constants 
  3686.      <float.h> 
  3687.      Assignment Expressions 
  3688.      Integer Variables 
  3689.      Declarators 
  3690.      Initializers 
  3691.  
  3692.  
  3693. ΓòÉΓòÉΓòÉ <hidden> Examples of Floating-Point Data Types ΓòÉΓòÉΓòÉ
  3694.  
  3695. The following example defines the identifier pi as an object of type double: 
  3696.  
  3697. double pi;
  3698.  
  3699. The following example defines the float variable real_number with the initial 
  3700. value 100.55: 
  3701.  
  3702. static float real_number = 100.55f;
  3703.  
  3704. The following example defines the float variable float_var with the initial 
  3705. value 0.0143: 
  3706.  
  3707. float float_var = 1.43e-2f;
  3708.  
  3709. The following example declares the long double variable maximum: 
  3710.  
  3711. extern long double maximum;
  3712.  
  3713. The following example defines the array table with 20 elements of type double: 
  3714.  
  3715. double table[20];
  3716.  
  3717.  
  3718. ΓòÉΓòÉΓòÉ 4.5.3. Integer Variables ΓòÉΓòÉΓòÉ
  3719.  
  3720. Integer variables fall into the following categories: 
  3721.  
  3722.      short int or short or signed short int or signed short 
  3723.      signed int or int 
  3724.      long int or long or signed long int 
  3725.      long long int or  long long or signed long long int or signed long 
  3726.      unsigned short int or unsigned short 
  3727.      unsigned or unsigned int 
  3728.      unsigned long int or unsigned long 
  3729.      unsigned long long int or unsigned long long 
  3730.  
  3731.  The default integer type for a bit field is unsigned. 
  3732.  
  3733.  Use the bitfields=signed option to change this default. 
  3734.  
  3735.  The amount of storage allocated for integer data is implementation-dependent. 
  3736.  
  3737.  The VisualAge for C++ compiler allocates the following storage for integer 
  3738.  types: 
  3739.  
  3740.      2 bytes for a short 
  3741.      4 bytes for an int 
  3742.      4 bytes for a long 
  3743.      8 bytes for a long long 
  3744.  
  3745.  Note:  The long long integer is not a standard C or C++ data type. It might be 
  3746.  needed for some Windows system programming, but it may not be portable to 
  3747.  other systems. 
  3748.  
  3749.  For more information about the VisualAge for C++ implementation of integer 
  3750.  types, see the IBM VisualAge for C++ for Windows User's Guide. 
  3751.  
  3752.  The unsigned prefix indicates that the object is a nonnegative integer. Each 
  3753.  unsigned type provides the same size storage as its signed equivalent. For 
  3754.  example, int reserves the same storage as unsigned int. Because a signed type 
  3755.  reserves a sign bit, an unsigned type can hold a larger positive integer than 
  3756.  the equivalent signed type. 
  3757.  
  3758.  To declare a data object having an integer data type, use an int type 
  3759.  specifier. 
  3760.  
  3761.  The declarator for a simple integer definition or declaration is an 
  3762.  identifier. You can initialize a simple integer definition with an integer 
  3763.  constant or with an expression that evaluates to a value that can be assigned 
  3764.  to an integer. The storage class of a variable determines how you can 
  3765.  initialize the variable. 
  3766.  
  3767.  C++ Note:  When the arguments in overloaded functions and overloaded operators 
  3768.  are integer types, two integer types that both come from the same group are 
  3769.  not treated as distinct types. For example, you cannot overload an int 
  3770.  argument against a signed int argument. Overloading and argument matching is 
  3771.  described in C++ Overloading. 
  3772.  
  3773.  Examples of Integer Data Types 
  3774.  
  3775.  Related Information 
  3776.  
  3777.      Integer Constants 
  3778.      Decimal Constants 
  3779.      Octal Constants 
  3780.      Hexadecimal Constants 
  3781.      Declarators 
  3782.      Initializers 
  3783.  
  3784.  
  3785. ΓòÉΓòÉΓòÉ <hidden> Examples of Integer Data Types ΓòÉΓòÉΓòÉ
  3786.  
  3787. The following example defines the short int variable flag: 
  3788.  
  3789. short int flag;
  3790.  
  3791. The following example defines the int variable result: 
  3792.  
  3793. int result;
  3794.  
  3795. The following example defines the unsigned long int variable ss_number as 
  3796. having the initial value 438888834: 
  3797.  
  3798. unsigned long ss_number = 438888834ul;
  3799.  
  3800. The following example defines the identifier sum as an object of type int. The 
  3801. initial value of sum is the result of the expression a + b: 
  3802.  
  3803. extern int a, b;
  3804. auto sum  = a + b;
  3805.  
  3806.  
  3807. ΓòÉΓòÉΓòÉ 4.5.4. Enumerations ΓòÉΓòÉΓòÉ
  3808.  
  3809. An enumeration data type represents a set of values that you declare. You can 
  3810. define an enumeration data type and all variables that have that enumeration 
  3811. type in one statement, or you can declare an enumeration type separately from 
  3812. the definition of variables of that type. The identifier associated with the 
  3813. data type (not an object) is called an enumeration tag. 
  3814.  
  3815. C++ Note:  In C, an enumeration has an implementation-defined integral type. 
  3816. This restriction does not apply to C++. In C++, an enumeration has a distinct 
  3817. type that does not have to be integral. 
  3818.  
  3819. An enumeration type declaration contains the enum keyword followed by an 
  3820. optional identifier (the enumeration tag) and a brace-enclosed list of 
  3821. enumerators. Commas separate each enumerator in the enumerator list. In 
  3822. extended mode, a trailing comma is permitted at the end of the enumerator list. 
  3823.  
  3824. Syntax of an Enumeration 
  3825.  
  3826. The keyword enum, followed by the identifier, names the data type (like the tag 
  3827. on a struct data type). The list of enumerators provides the data type with a 
  3828. set of values. 
  3829.  
  3830. C++ Note:  In C, each enumerator represents an integer value. In C++, each 
  3831. enumerator represents a value that can be converted to an integral value. 
  3832.  
  3833. To conserve space, enumerations may be stored in spaces smaller than that of an 
  3834. int. By default, the type of the enum variable is the size of the smallest 
  3835. integral type that can contain all enumerator values. You can change the 
  3836. default using the /Su option, described in the IBM VisualAge for C++ for 
  3837. Windows User's Guide. 
  3838.  
  3839. When you define an enumeration data type, you specify a set of identifiers that 
  3840. the data type represents. Each identifier in this set is an enumeration 
  3841. constant. 
  3842.  
  3843. The value of the constant is determined in the following way: 
  3844.  
  3845.    1. An equal sign (=) and a constant expression after the enumeration 
  3846.       constant gives an explicit value to the constant. The identifier 
  3847.       represents the value of the constant expression. 
  3848.  
  3849.    2. If no explicit value is assigned, the leftmost constant in the list 
  3850.       receives the value zero (0). 
  3851.  
  3852.    3. Identifiers with no explicitly assigned values receive the integer value 
  3853.       that is one greater than the value represented by the previous 
  3854.       identifier. 
  3855.  
  3856.  In C, enumeration constants have type int. 
  3857.  
  3858.  In C++, each enumeration constant has a value that can be promoted to a signed 
  3859.  or unsigned integer value and a distinct type that does not have to be 
  3860.  integral. Use an enumeration constant anywhere an integer constant is allowed, 
  3861.  or for C++, anywhere a value of the enumeration type is allowed. 
  3862.  
  3863.  Each enumeration constant must be unique within the scope in which the 
  3864.  enumeration is defined. It is possible to associate the same integer with two 
  3865.  different enumeration constants. 
  3866.  
  3867.  Additional information is provided on: 
  3868.  
  3869.      Defining Enumeration Variables 
  3870.      Defining Enumeration Types and Objects 
  3871.      Example Program Using Enumeration Types 
  3872.  
  3873.  Examples of Enumeration Types and Constants 
  3874.  
  3875.  Related Information 
  3876.  
  3877.      Constant Expressions 
  3878.      Identifiers 
  3879.      Declarators 
  3880.      Initializers 
  3881.  
  3882.  
  3883. ΓòÉΓòÉΓòÉ <hidden> Enumeration Syntax ΓòÉΓòÉΓòÉ
  3884.  
  3885. An enumeration type declaration has the form: 
  3886.  
  3887.                ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  3888.                       Γöé
  3889. >>ΓöÇΓöÇenumΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇenumeratorΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ;ΓöÇΓöÇ><
  3890.      ΓööΓöÇidentifierΓöÇΓöÿ
  3891.  
  3892. An enumerator has the form: 
  3893.  
  3894. >>ΓöÇΓöÇidentifierΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  3895.         ΓööΓöÇ=ΓöÇΓöÇintegral_constant_expressionΓöÇΓöÿ
  3896.  
  3897.  
  3898. ΓòÉΓòÉΓòÉ <hidden> Examples of Enumeration Types and Constants ΓòÉΓòÉΓòÉ
  3899.  
  3900. In the following example, the declarations of average on line 4 and of poor on 
  3901. line 5 cause compiler error messages: 
  3902.  
  3903.  1  func()
  3904.  2  {
  3905.  3    enum score { poor, average, good };
  3906.  4    enum rating { below, average, above };
  3907.  5    int poor;
  3908.  6  }
  3909.  
  3910. The following data type declarations list oats, wheat, barley, corn, and rice 
  3911. as enumeration constants. The number under each constant shows the integer 
  3912. value. 
  3913.  
  3914. enum grain { oats, wheat, barley, corn, rice };
  3915.   /*     0    1    2    3   4     */
  3916.  
  3917. enum grain { oats=1, wheat, barley, corn, rice };
  3918.   /*     1     2    3    4   5    */
  3919.  
  3920. enum grain { oats, wheat=10, barley, corn=20, rice };
  3921.   /*      0   10     11   20    21  */
  3922.  
  3923. It is possible to associate the same integer with two different enumeration 
  3924. constants. For example, the following definition is valid. The identifiers 
  3925. suspend and hold have the same integer value. 
  3926.  
  3927. enum status { run, clear=5, suspend, resume, hold=6 };
  3928.   /*      0    5     6    7    6    */
  3929.  
  3930. The following example is a different declaration of the enumeration tag status: 
  3931.  
  3932. enum status { run, create, clear=5, suspend };
  3933.   /*      0   1     5    6       */
  3934.  
  3935.  
  3936. ΓòÉΓòÉΓòÉ 4.5.4.1. Defining Enumeration Variables ΓòÉΓòÉΓòÉ
  3937.  
  3938. An enumeration variable definition contains an optional storage class 
  3939. specifier, a type specifier, a declarator, and an optional initializer. The 
  3940. type specifier contains the keyword enum followed by the name of the 
  3941. enumeration data type. You must declare the enumeration data type before you 
  3942. can define a variable having that type. 
  3943.  
  3944. The initializer for an enumeration variable contains the = symbol followed by 
  3945. an expression. 
  3946.  
  3947. In C, the initializer expression must evaluate to an int value. In C++, the 
  3948. initializer must be have the same type as the associated enumeration type. 
  3949.  
  3950. The first line of the following example declares the enumeration tag grain. The 
  3951. second line defines the variable g_food and gives g_food the initial value of 
  3952. barley (2). 
  3953.  
  3954. enum grain { oats, wheat, barley, corn, rice };
  3955. enum grain g_food = barley;
  3956.  
  3957. In C, the type specifier enum grain indicates that the value of g_food is a 
  3958. member of the enumerated data type grain. In C++, the value of g_food has the 
  3959. enumerated data type grain. 
  3960.  
  3961. C++ also makes the enum keyword optional in an initialization expression like 
  3962. the one in the second line of the preceding example. For example, both of the 
  3963. following statements are valid C++ code: 
  3964.  
  3965. enum grain g_food = barley;
  3966.    grain cob_food = corn;
  3967.  
  3968.  
  3969. ΓòÉΓòÉΓòÉ 4.5.4.2. Defining Enumeration Types and Objects ΓòÉΓòÉΓòÉ
  3970.  
  3971. You can define a type and a variable in one statement by using a declarator and 
  3972. an optional initializer after the type definition. To specify a storage class 
  3973. specifier for the variable, you must put the storage class specifier at the 
  3974. beginning of the declaration. For example: 
  3975.  
  3976. register enum score { poor=1, average, good } rating = good;
  3977.  
  3978. C++ also lets you put the storage class immediately before the declarator. For 
  3979. example: 
  3980.  
  3981. enum score { poor=1, average, good } register rating = good;
  3982.  
  3983. Either of these examples is equivalent to the following two declarations: 
  3984.  
  3985. enum score { poor=1, average, good };
  3986. register enum score rating = good;
  3987.  
  3988. Both examples define the enumeration data type score and the variable rating. 
  3989. rating has the storage class specifier register, the data type enum score, and 
  3990. the initial value good. 
  3991.  
  3992. Combining a data type definition with the definitions of all variables having 
  3993. that data type lets you leave the data type unnamed. For example: 
  3994.  
  3995. enum { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
  3996.    Saturday } weekday;
  3997.  
  3998. defines the variable weekday, which can be assigned any of the specified 
  3999. enumeration constants. 
  4000.  
  4001.  
  4002. ΓòÉΓòÉΓòÉ 4.5.4.3. Example Program Using Enumerations ΓòÉΓòÉΓòÉ
  4003.  
  4004. /**********************************************************************************
  4005. *
  4006. The following program receives an integer as input. The output is a sentence 
  4007. that gives the French name for the weekday that is associated with the integer. 
  4008. If the integer is not associated with a weekday, the program prints "C'est le 
  4009. mauvais jour." 
  4010.  
  4011.                                     *
  4012. ************************************************************************/
  4013.  
  4014. /**
  4015.  ** Example program using enumerations
  4016.  **/
  4017.  
  4018. #include <stdio.h>
  4019.  
  4020. enum days {
  4021.       Monday=1, Tuesday, Wednesday,
  4022.       Thursday, Friday, Saturday, Sunday
  4023.      } weekday;
  4024.  
  4025. void french(enum days);
  4026.  
  4027. int main(void)
  4028. {
  4029.   int num;
  4030.  
  4031.   printf("Enter an integer for the day of the week.  "
  4032.      "Mon=1,...,Sun=7\n");
  4033.   scanf("%d", &num);
  4034.   weekday=num;
  4035.   french(weekday);
  4036.   return(0);
  4037. }
  4038. void french(enum days weekday)
  4039. {
  4040.   switch (weekday)
  4041.   {
  4042.    case Monday:
  4043.      printf("Le jour de la semaine est lundi.\n");
  4044.      break;
  4045.    case Tuesday:
  4046.      printf("Le jour de la semaine est mardi.\n");
  4047.      break;
  4048.    case Wednesday:
  4049.      printf("Le jour de la semaine est mercredi.\n");
  4050.      break;
  4051.    case Thursday:
  4052.      printf("Le jour de la semaine est jeudi.\n");
  4053.      break;
  4054.    case Friday:
  4055.      printf("Le jour de la semaine est vendredi.\n");
  4056.      break;
  4057.    case Saturday:
  4058.      printf("Le jour de la semaine est samedi.\n");
  4059.      break;
  4060.    case Sunday:
  4061.      printf("Le jour de la semaine est dimanche.\n");
  4062.      break;
  4063.    default:
  4064.      printf("C'est le mauvais jour.\n");
  4065.   }
  4066. }
  4067.  
  4068.  
  4069. ΓòÉΓòÉΓòÉ 4.5.5. Pointers ΓòÉΓòÉΓòÉ
  4070.  
  4071. A pointer type variable holds the address of a data object or a function. A 
  4072. pointer can refer to an object of any one data type except to a bit field or a 
  4073. reference. Additionally, in C, a pointer cannot point to an object with the 
  4074. register storage class. Some common uses for pointers are: 
  4075.  
  4076.      To access dynamic data structures such as linked lists, trees, and 
  4077.       queues. 
  4078.      To access elements of an array or members of a structure or C++ class. 
  4079.      To access an array of characters as a string. 
  4080.      To pass the address of a variable to a function. (In C++, you can also 
  4081.       use a reference to do this.) By referencing a variable through its 
  4082.       address, a function can change the contents of that variable. Calling 
  4083.       Functions and Passing Arguments describes passing arguments by reference. 
  4084.  
  4085.  The following example declares pcoat as a pointer to an object having type 
  4086.  long: 
  4087.  
  4088.   extern long *pcoat;
  4089.  
  4090.  If the keyword volatile appears before the *, the declarator describes a 
  4091.  pointer to a volatile object. If the keyword volatile comes between the * and 
  4092.  the identifier, the declarator describes a volatile pointer. The keyword const 
  4093.  operates in the same manner as the volatile keyword. 
  4094.  
  4095.  Examples of Pointer Declarations 
  4096.  
  4097.  Additional information is provided on: 
  4098.  
  4099.      Assigning Pointers 
  4100.      Initializing Pointers 
  4101.      Restrictions on Pointers 
  4102.      Using Pointers 
  4103.      Pointer Arithmetic 
  4104.      Example Program Using Pointers 
  4105.  
  4106.  Related Information 
  4107.  
  4108.      Address  & 
  4109.      Indirection  * 
  4110.      __unaligned Type Qualifier 
  4111.      References 
  4112.      Declarators 
  4113.      volatile and const Qualifiers 
  4114.      Initializers 
  4115.  
  4116.  
  4117. ΓòÉΓòÉΓòÉ <hidden> Examples of Pointer Declarations ΓòÉΓòÉΓòÉ
  4118.  
  4119. In the following example, pvolt is a constant pointer to an object having type 
  4120. short: 
  4121.  
  4122. short * const pvolt;
  4123.  
  4124. The following example declares pnut as a pointer to an int object having the 
  4125. volatile qualifier: 
  4126.  
  4127. extern int volatile *pnut;
  4128.  
  4129. The following example defines psoup as a volatile pointer to an object having 
  4130. type float: 
  4131.  
  4132. float * volatile psoup;
  4133.  
  4134. The following example defines pfowl as a pointer to an enumeration object of 
  4135. type bird: 
  4136.  
  4137. enum bird *pfowl;
  4138.  
  4139. The next example declares pvish as a pointer to a function that takes no 
  4140. parameters and returns a char object: 
  4141.  
  4142. char (*pvish)(void);
  4143.  
  4144.  
  4145. ΓòÉΓòÉΓòÉ 4.5.5.1. Assigning Pointers ΓòÉΓòÉΓòÉ
  4146.  
  4147. When you use pointers in an assignment operation, you must ensure that the 
  4148. types of the pointers in the operation are compatible. 
  4149.  
  4150. The following example shows compatible declarations for the assignment 
  4151. operation: 
  4152.  
  4153.   float subtotal;
  4154.   float * sub_ptr;
  4155.      .
  4156.      .
  4157.      .
  4158.   sub_ptr = &subtotal;
  4159.   printf("The subtotal is %f\n", *sub_ptr);
  4160.  
  4161. The next example shows incompatible declarations for the assignment operation: 
  4162.  
  4163.   double league;
  4164.   int * minor;
  4165.      .
  4166.      .
  4167.      .
  4168.   minor = &league;   /* error */
  4169.  
  4170.  
  4171. ΓòÉΓòÉΓòÉ 4.5.5.2. Initializing Pointers ΓòÉΓòÉΓòÉ
  4172.  
  4173. The initializer is an = (equal sign) followed by the expression that represents 
  4174. the address that the pointer is to contain. The following example defines the 
  4175. variables time and speed as having type double and amount as having type 
  4176. pointer to a double. The pointer amount is initialized to point to total: 
  4177.  
  4178. double total, speed, *amount = &total;
  4179.  
  4180. The compiler converts an unsubscripted array name to a pointer to the first 
  4181. element in the array. You can assign the address of the first element of an 
  4182. array to a pointer by specifying the name of the array. The following two sets 
  4183. of definitions are equivalent. Both define the pointer student and initialize 
  4184. student to the address of the first element in section: 
  4185.  
  4186. int section[80];
  4187. int *student = section;
  4188.  
  4189. is equivalent to: 
  4190.  
  4191. int section[80];
  4192. int *student = §ion[0];
  4193.  
  4194. You can assign the address of the first character in a string constant to a 
  4195. pointer by specifying the string constant in the initializer. 
  4196.  
  4197. The following example defines the pointer variable string and the string 
  4198. constant "abcd". The pointer string is initialized to point to the character a 
  4199. in the string "abcd". 
  4200.  
  4201. char *string = "abcd";
  4202.  
  4203. The following example defines weekdays as an array of pointers to string 
  4204. constants. Each element points to a different string. The pointer weekdays[2], 
  4205. for example, points to the string "Tuesday". 
  4206.  
  4207. static char *weekdays[ ] =
  4208.       {
  4209.        "Sunday", "Monday", "Tuesday", "Wednesday",
  4210.        "Thursday", "Friday", "Saturday"
  4211.       };
  4212.  
  4213. A pointer can also be initialized to NULL using any integer constant expression 
  4214. that evaluates to 0, for example char * a=0;. Such a pointer is a NULL pointer. 
  4215. It does not point to any object. 
  4216.  
  4217.  
  4218. ΓòÉΓòÉΓòÉ 4.5.5.3. Restrictions on Pointers ΓòÉΓòÉΓòÉ
  4219.  
  4220. You cannot use pointers to reference bit fields or objects having the register 
  4221. storage class specifier. Initializing a C static data pointer to the address of 
  4222. an imported data object causes a compilation error. Such an initialization is 
  4223. permitted in C++. 
  4224.  
  4225. A pointer to a packed structure or union is incompatible with a pointer to a 
  4226. corresponding nonpacked structure or union because packed and nonpacked objects 
  4227. have different memory layouts. As a result, comparisons and assignments between 
  4228. pointers to packed and nonpacked objects are not valid. 
  4229.  
  4230. You can, however, perform these assignments and comparisons with type casts. In 
  4231. the following example: 
  4232.  
  4233. int main(void)
  4234. {
  4235.   _Packed struct ss *ps1;
  4236.   struct ss     *ps2;
  4237.    .
  4238.    .
  4239.    .
  4240.   ps1 = (_Packed struct ss *)ps2;
  4241.    .
  4242.    .
  4243.    .
  4244. }
  4245.  
  4246. the cast operation lets you compare the two pointers, but you must be aware 
  4247. that ps1 still points to a nonpacked object. 
  4248.  
  4249.  
  4250. ΓòÉΓòÉΓòÉ 4.5.5.4. Using Pointers ΓòÉΓòÉΓòÉ
  4251.  
  4252. Two operators are commonly used in working with pointers, the address (&) 
  4253. operator and the indirection (*) operator. You can use the & operator to refer 
  4254. to the address of an object. For example, the following statement assigns the 
  4255. address of x to the variable p_to_x. The variable p_to_x has been defined as a 
  4256. pointer. 
  4257.  
  4258. int x, *p_to_x;
  4259.  
  4260. p_to_x = &x;
  4261.  
  4262. The * (indirection) operator lets you access the value of the object a pointer 
  4263. refers to. The following statement assigns to y the value of the object that 
  4264. p_to_x points to: 
  4265.  
  4266. float y, *p_to_x;
  4267.  .
  4268.  .
  4269.  .
  4270. y = *p_to_x;
  4271.  
  4272. The following statement assigns the value of y to the variable that *p_to_x 
  4273. references: 
  4274.  
  4275. char y ,
  4276.    *p_to_x,
  4277.  .
  4278.  .
  4279.  .
  4280. *p_to_x = y;
  4281.  
  4282.  
  4283. ΓòÉΓòÉΓòÉ 4.5.5.5. Pointer Arithmetic ΓòÉΓòÉΓòÉ
  4284.  
  4285. You can perform a limited number of arithmetic operations on pointers. These 
  4286. operations are: 
  4287.  
  4288.      Increment and decrement 
  4289.      Addition and subtraction 
  4290.      Comparison 
  4291.      Assignment 
  4292.  
  4293.  The increment (++) operator increases the value of a pointer by the size of 
  4294.  the data object the pointer refers to. For example, if the pointer refers to 
  4295.  the second element in an array, the ++ makes the pointer refer to the third 
  4296.  element in the array. 
  4297.  
  4298.  The decrement (--) operator decreases the value of a pointer by the size of 
  4299.  the data object the pointer refers to. For example, if the pointer refers to 
  4300.  the second element in an array, the -- makes the pointer refer to the first 
  4301.  element in the array. 
  4302.  
  4303.  You can add a pointer to an integer, but you cannot add a pointer to a 
  4304.  pointer. 
  4305.  
  4306.  If the pointer p points to the first element in an array, the following 
  4307.  expression causes the pointer to point to the third element in the same array: 
  4308.  
  4309.   p = p + 2;
  4310.  
  4311.  If you have two pointers that point to the same array, you can subtract one 
  4312.  pointer from the other. This operation yields the number of elements in the 
  4313.  array that separate the two addresses that the pointers refer to. 
  4314.  
  4315.  You can compare two pointers with the following operators:  ==, !=, <, >, <=, 
  4316.  and >=. See Expressions and Operators for more information on these operators. 
  4317.  
  4318.  Pointer comparisons are defined only when the pointers point to elements of 
  4319.  the same array. Pointer comparisons using the == and != operators can be 
  4320.  performed even when the pointers point to elements of different arrays. 
  4321.  
  4322.  You can assign to a pointer the address of a data object, the value of another 
  4323.  compatible pointer or the NULL pointer. 
  4324.  
  4325.  
  4326. ΓòÉΓòÉΓòÉ 4.5.5.6. Example Program Using Pointers ΓòÉΓòÉΓòÉ
  4327.  
  4328. /************************************************************************
  4329. *
  4330.  
  4331. The following program contains pointer arrays: 
  4332.  
  4333.                                     *
  4334. ************************************************************************/
  4335.  
  4336. /********************************************************************
  4337. **  Program to search for the first occurrence of a specified   **
  4338. **  character string in an array of character strings.       **
  4339. ********************************************************************/
  4340.  
  4341. #include <stdio.h>
  4342. #include <stdlib.h>
  4343. #include <string.h>
  4344.  
  4345. #define  SIZE  20
  4346. #define  EXIT_FAILURE 999
  4347.  
  4348. int main(void)
  4349. {
  4350.   static char *names[ ] = { "Jim", "Amy", "Mark", "Sue", NULL };
  4351.   char * find_name(char **, char *);
  4352.   char new_name[SIZE], *name_pointer;
  4353.  
  4354.   printf("Enter name to be searched.\n");
  4355.   scanf("%s", new_name);
  4356.   name_pointer = find_name(names, new_name);
  4357.   printf("name %s%sfound\n", new_name,
  4358.      (name_pointer == NULL) ? " not " : " ");
  4359.   exit(EXIT_FAILURE);
  4360. } /* End of main */
  4361. /********************************************************************
  4362. **   Function find_name.  This function searches an array of   **
  4363. **   names to see if a given name already exists in the array.  **
  4364. **   It returns a pointer to the name or NULL if the name is   **
  4365. **   not found.                          **
  4366. **                                 **
  4367. ** char **arry is a pointer to arrays of pointers (existing names) **
  4368. ** char *strng is a pointer to character array entered (new name)  **
  4369. ********************************************************************/
  4370.  
  4371. char * find_name(char **arry, char *strng)
  4372. {
  4373.   for (; *arry != NULL; arry++)     /* for each name      */
  4374.   {
  4375.    if (strcmp(*arry, strng) == 0)   /* if strings match    */
  4376.      return(*arry);          /* found it!        */
  4377.   }
  4378.   return(*arry);             /* return the pointer   */
  4379. } /* End of find_name */
  4380.  
  4381. /************************************************************************
  4382. *
  4383.  
  4384. Interaction with this program could produce the following sessions: 
  4385.  
  4386.  Output    Enter name to be searched. 
  4387.  
  4388.  Input     Mark 
  4389.  
  4390.  Output    name Mark found 
  4391.  
  4392.  OR: 
  4393.  
  4394.  Output    Enter name to be searched. 
  4395.  
  4396.  Input     Deborah 
  4397.  
  4398.  Output    name Deborah not found 
  4399.  
  4400.                                        *
  4401.   ************************************************************************/
  4402.  
  4403.  
  4404. ΓòÉΓòÉΓòÉ 4.5.6. void Type ΓòÉΓòÉΓòÉ
  4405.  
  4406. The void data type always represents an empty set of values. The only object 
  4407. that can be declared with the type specifier void is a pointer. 
  4408.  
  4409. When a function does not return a value, you should use void as the type 
  4410. specifier in the function definition and declaration. An argument list for a 
  4411. function taking no arguments is void. 
  4412.  
  4413. You cannot declare a variable of type void, but you can explicitly convert any 
  4414. expression to type void, but the resulting expression can only be used as one 
  4415. of the following: 
  4416.  
  4417.      An expression statement 
  4418.      The left operand of a comma expression 
  4419.      The second or third operand in a conditional expression. 
  4420.  
  4421.  Example of void Type 
  4422.  
  4423.  Related Information 
  4424.  
  4425.      Cast Expressions 
  4426.      Type Specifiers 
  4427.      Expressions and Operators 
  4428.  
  4429.  
  4430. ΓòÉΓòÉΓòÉ <hidden> Example of void Type ΓòÉΓòÉΓòÉ
  4431.  
  4432. /************************************************************************
  4433. *
  4434.  
  4435. On line 7 of the following example, the function find_max is declared as having 
  4436. type void. Lines 15 through 26 contain the complete definition of find_max. 
  4437.  
  4438. Note:  The use of the sizeof operator in line 13 is a standard method of 
  4439. determining the number of elements in an array. 
  4440.  
  4441.                                     *
  4442. ************************************************************************/
  4443.  
  4444.  1  /**
  4445.  2  ** Example of void type
  4446.  3  **/
  4447.  4  #include <stdio.h>
  4448.  5
  4449.  6  /* declaration of function find_max */
  4450.  7  extern void find_max(int x[ ], int j);
  4451.  8
  4452.  9  int main(void)
  4453. 10  {
  4454. 11    static int numbers[ ] = { 99, 54, -102, 89 };
  4455. 12
  4456. 13    find_max(numbers, (sizeof(numbers) / sizeof(numbers[0])));
  4457. 14
  4458. 15    return(0);
  4459. 16  }
  4460. 17
  4461. 18  void find_max(int x[ ], int j)
  4462. 19  { /* begin definition of function find_max */
  4463. 20    int i, temp = x[0];
  4464. 21
  4465. 22    for (i = 1; i < j; i++)
  4466. 23    {
  4467. 24      if (x[i] > temp)
  4468. 25       temp = x[i];
  4469. 26    }
  4470. 27    printf("max number = %d\n", temp);
  4471. 28  } /* end definition of function find_max  */
  4472.  
  4473.  
  4474. ΓòÉΓòÉΓòÉ 4.5.7. Arrays ΓòÉΓòÉΓòÉ
  4475.  
  4476. An array is an ordered group of data objects. Each object is called an element. 
  4477. All elements within an array have the same data type. 
  4478.  
  4479. Use any type specifier in an array definition or declaration. Array elements 
  4480. can be of any data type, except function or, in C++, a reference. You can, 
  4481. however, declare an array of pointers to functions. 
  4482.  
  4483. The array declarator contains an identifier followed by an optional subscript 
  4484. declarator. An identifier preceded by an * (asterisk) is an array of pointers. 
  4485.  
  4486. Syntax of a Subscript Declarator 
  4487.  
  4488. The subscript declarator describes the number of dimensions in the array and 
  4489. the number of elements in each dimension. Each bracketed expression, or 
  4490. subscript, describes a different dimension and must be a constant expression. 
  4491.  
  4492. The following example defines a one-dimensional array that contains four 
  4493. elements having type char: 
  4494.  
  4495. char list[4];
  4496.  
  4497. The first subscript of each dimension is 0. The array list contains the 
  4498. elements: 
  4499.  
  4500. list[0]
  4501. list[1]
  4502. list[2]
  4503. list[3]
  4504.  
  4505. The following example defines a two-dimensional array that contains six 
  4506. elements of type int: 
  4507.  
  4508. int roster[3][2];
  4509.  
  4510. Multidimensional arrays are stored in row-major order. When elements are 
  4511. referred to in order of increasing storage location, the last subscript varies 
  4512. the fastest. For example, the elements of array roster are stored in the order: 
  4513.  
  4514. roster[0][0]
  4515. roster[0][1]
  4516. roster[1][0]
  4517. roster[1][1]
  4518. roster[2][0]
  4519. roster[2][1]
  4520.  
  4521. In storage, the elements of roster would be stored as: 
  4522.  
  4523.  
  4524.  Γöé        Γöé        Γöé
  4525.  ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  4526.                  
  4527.  Γöé        Γöé        Γöé
  4528.  roster[0][0]   roster[0][1]   roster[1][0]
  4529.  
  4530. You can leave the first (and only the first) set of subscript brackets empty in 
  4531.  
  4532.      Array definitions that contain initializations 
  4533.      extern declarations 
  4534.      Parameter declarations. 
  4535.  
  4536.  In array definitions that leave the first set of subscript brackets empty, the 
  4537.  initializer determines the number of elements in the first dimension. In a 
  4538.  one-dimensional array, the number of initialized elements becomes the total 
  4539.  number of elements. In a multidimensional array, the initializer is compared 
  4540.  to the subscript declarator to determine the number of elements in the first 
  4541.  dimension. 
  4542.  
  4543.  An unsubscripted array name (for example, region instead of region[4]) 
  4544.  represents a pointer whose value is the address of the first element of the 
  4545.  array, provided the array has previously been declared. An unsubscripted array 
  4546.  name with square brackets (for example, region[]) is allowed in the following 
  4547.  contexts: 
  4548.  
  4549.      In arrays declared at file scope 
  4550.      In the argument list of a function declaration 
  4551.  
  4552.  In declarations, only the first dimension can be left empty; you must specify 
  4553.  the sizes of additional dimensions. 
  4554.  
  4555.  In extended modes, they are also permitted in the following contexts: 
  4556.  
  4557.      In union members 
  4558.      As the last member of a structure 
  4559.  
  4560.  See Zero-Extent Arrays in Structures and Unions for more information about 
  4561.  using unsubscripted arrays in these contexts. 
  4562.  
  4563.  Whenever an array is used in a context (such as a parameter) where it cannot 
  4564.  be used as an array, the identifier is treated as a pointer. The two 
  4565.  exceptions are when an array is used as an operand of the sizeof or the 
  4566.  address (&) operator. 
  4567.  
  4568.  Additional information is provided on: 
  4569.  
  4570.      Initializing Arrays 
  4571.      Example Programs Using Arrays 
  4572.  
  4573.  Related Information 
  4574.  
  4575.      Pointers 
  4576.      Array Subscript [ ] (Array Element Specification) 
  4577.      String Literals 
  4578.      Declarators 
  4579.      Initializers 
  4580.      Implicit Type Conversions 
  4581.      Implicit Type Conversions 
  4582.  
  4583.  
  4584. ΓòÉΓòÉΓòÉ <hidden> Subscript Declarator Syntax ΓòÉΓòÉΓòÉ
  4585.  
  4586. A subscript declarator has the form: 
  4587.  
  4588. >>ΓöÇΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  4589.     ΓööΓöÇconstant_expressionΓöÇΓöÿ   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  4590.                   Γöé               Γöé Γöé
  4591.                   ΓööΓöÇΓöÇΓöÇ[ΓöÇΓöÇconstant_expressionΓöÇΓöÇ]ΓöÇΓö┤ΓöÇΓöÿ
  4592.  
  4593.  
  4594. ΓòÉΓòÉΓòÉ 4.5.7.1. Initializing Arrays ΓòÉΓòÉΓòÉ
  4595.  
  4596. The initializer for an array contains the = symbol followed by a 
  4597. comma-separated list of constant expressions enclosed in braces ({ }). You do 
  4598. not need to initialize all elements in an array. Elements that are not 
  4599. initialized (in extern and static definitions only) receive the value 0 of the 
  4600. appropriate type. 
  4601.  
  4602. Note:  Array initializations can be either fully braced (with braces around 
  4603. each dimension) or unbraced (with only one set of braces enclosing the entire 
  4604. set of initializers). Avoid placing braces around some dimensions and not 
  4605. around others. 
  4606. Initializing a one-dimensional character array 
  4607.  
  4608. Initialize a one-dimensional character array by specifying: 
  4609.  
  4610.      A brace-enclosed comma-separated list of constants, each of which can be 
  4611.       contained in a character 
  4612.      A string constant. (Braces surrounding the constant are optional.) 
  4613.  
  4614.  Initializing a string constant places the null character (\0) at the end of 
  4615.  the string if there is room or if the array dimensions are not specified. 
  4616.  
  4617.  Examples of Initialized Arrays 
  4618.  
  4619.  The following show four different character array initializations: 
  4620.  
  4621.   static char name1[] = { 'J', 'a', 'n' };
  4622.   static char name2[] = { "Jan" };
  4623.   static char name3[3] = "Jan";
  4624.   static char name4[4] = "Jan";
  4625.  
  4626.  These initializations create the following elements: 
  4627.  
  4628.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  4629.   Γöé  ELEMENT  Γöé VALUEΓöé  ELEMENT  Γöé VALUEΓöé  ELEMENT  Γöé VALUEΓöé  ELEMENT  Γöé VALUΓöé
  4630.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4631.   Γöé "name1[0]" Γöé  "J" Γöé "name2[0]" Γöé  "J" Γöé "name3[0]" Γöé  "J" Γöé "name4[0]" Γöé "J" Γöé
  4632.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4633.   Γöé "name1[1]" Γöé  "a" Γöé "name2[1]" Γöé  "a" Γöé "name3[1]" Γöé  "a" Γöé "name4[1]" Γöé "a" Γöé
  4634.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4635.   Γöé "name1[2]" Γöé  "n" Γöé "name2[2]" Γöé  "n" Γöé "name3[2]" Γöé  "n" Γöé "name4[2]" Γöé "n" Γöé
  4636.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4637.   Γöé       Γöé    Γöé "name2[3]" Γöé "\0" Γöé       Γöé    Γöé "name4[3]" Γöé "\0"Γöé
  4638.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  4639.  
  4640.  Note that the NULL character is lost for name1[] and name3[3]. In C, a 
  4641.  compiler warning is issued for name3[3]. In C++, the compiler issues a severe 
  4642.  error for name3[3]. 
  4643.  Initializing a multidimensional array 
  4644.  
  4645.  Initialize a multidimensional array by: 
  4646.  
  4647.      Listing the values of all elements you want to initialize, in the order 
  4648.       that the compiler assigns the values.  The compiler assigns values by 
  4649.       increasing the subscript of the last dimension fastest.  This form of a 
  4650.       multidimensional array initialization looks like a one-dimensional array 
  4651.       initialization.  The following definition completely initializes the 
  4652.       array month_days: 
  4653.  
  4654.               static month_days[2][12] =
  4655.               {
  4656.               31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  4657.               31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  4658.               };
  4659.  
  4660.      Using braces to group the values of the elements you want initialized. 
  4661.       You can put braces around each element, or around any nesting level of 
  4662.       elements. The following definition contains two elements in the first 
  4663.       dimension. (You can consider these elements as rows.) The initialization 
  4664.       contains braces around each of these two elements: 
  4665.  
  4666.               static int month_days[2][12] =
  4667.               {
  4668.               { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  4669.               { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  4670.               };
  4671.  
  4672.      Using use nested braces to initialize dimensions and elements in a 
  4673.       dimension selectively. 
  4674.  
  4675.  You cannot have more initializers than the number of elements in the array. 
  4676.  
  4677.  
  4678. ΓòÉΓòÉΓòÉ <hidden> Examples of Initialized Arrays ΓòÉΓòÉΓòÉ
  4679.  
  4680. The following definition shows a completely initialized one-dimensional array: 
  4681.  
  4682. static int number[3] = { 5, 7, 2 };
  4683.  
  4684. The array number contains the following values: 
  4685.  
  4686.  Element        Value 
  4687.  number[0]      5 
  4688.  number[1]      7 
  4689.  number[2]      2 
  4690.  
  4691.  The following definition shows a partially initialized one-dimensional array: 
  4692.  
  4693.   static int number1[3] = { 5, 7 };
  4694.  
  4695.  The values of number1 are: 
  4696.  
  4697.  Element        Value 
  4698.  number1[0]     5 
  4699.  number1[1]     7 
  4700.  number1[2]     0 
  4701.  
  4702.  Instead of an expression in the subscript declarator defining the number of 
  4703.  elements, the following one-dimensional array definition defines one element 
  4704.  for each initializer specified: 
  4705.  
  4706.   static int item[ ] = { 1, 2, 3, 4, 5 };
  4707.  
  4708.  The compiler gives item the five initialized elements: 
  4709.  
  4710.  Element        Value 
  4711.  item[0]        1 
  4712.  item[1]        2 
  4713.  item[2]        3 
  4714.  item[3]        4 
  4715.  item[4]        5 
  4716.  
  4717.  The following definitions show character array initializations: 
  4718.  
  4719.     static char name1[ ] = { 'J', 'a', 'n' };
  4720.     static char name2[ ] = { "Jan" };
  4721.     static char name3[4] = "Jan";
  4722.  
  4723.  These definitions create the following elements: 
  4724.  
  4725.  Element             Value 
  4726.  name1[0]            J 
  4727.  name1[1]            a 
  4728.  name1[2]            n 
  4729.  name2[0]            J 
  4730.  name2[1]            a 
  4731.  name2[2]            n 
  4732.  name2[3]            \0 
  4733.  name3[0]            J 
  4734.  name3[1]            a 
  4735.  name3[2]            n 
  4736.  
  4737.  The following definition explicitly initializes six elements in a 12-element 
  4738.  array: 
  4739.  
  4740.   static int matrix[3][4] =
  4741.     {
  4742.      {1, 2},
  4743.      {3, 4},
  4744.      {5, 6}
  4745.     };
  4746.  
  4747.  The initial values of matrix are: 
  4748.  
  4749.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  4750.   Γöé ELEMENT      Γöé VALUE       Γöé ELEMENT      Γöé VALUE       Γöé
  4751.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4752.   Γöé "matrix[0][0]"   Γöé "1"        Γöé "matrix[1][2]"   Γöé "0"        Γöé
  4753.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4754.   Γöé "matrix[0][1]"   Γöé "2"        Γöé "matrix[1][3]"   Γöé "0"        Γöé
  4755.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4756.   Γöé "matrix[0][2]"   Γöé "0"        Γöé "matrix[2][0]"   Γöé "5"        Γöé
  4757.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4758.   Γöé "matrix[0][3]"   Γöé "0"        Γöé "matrix[2][1]"   Γöé "6"        Γöé
  4759.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4760.   Γöé "matrix[1][0]"   Γöé "3"        Γöé "matrix[2][2]"   Γöé "0"        Γöé
  4761.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4762.   Γöé "matrix[1][1]"   Γöé "4"        Γöé "matrix[2][3]"   Γöé "0"        Γöé
  4763.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  4764.  
  4765.  
  4766. ΓòÉΓòÉΓòÉ 4.5.7.2. Zero-Extent Arrays in Structures and Unions ΓòÉΓòÉΓòÉ
  4767.  
  4768. Zero-extent arrays are permitted in structures and unions under extended mode. 
  4769.  
  4770. For example, Struct_A contains the zero-extent array char arr_a[0], and 
  4771. Struct_B contains the zero-extent array char arr_b[]. 
  4772.  
  4773. struct Struct_A {
  4774.   int i;
  4775.   char arr_a[0];
  4776. } a;
  4777.  
  4778. struct Struct_B {
  4779.   int k;
  4780.   char arr_b[];
  4781. } a;
  4782.  
  4783. Both char arr_a[0]; and char arr_b[]; are implicitly viewed by the compiler as 
  4784. if declared as arrays with one element: 
  4785.  
  4786. struct Struct_A {
  4787.   int i;
  4788.   char arr_a[1];
  4789. } a;
  4790.  
  4791. struct Struct_B {
  4792.   int k;
  4793.   char arr_b[1];
  4794. } b;
  4795.  
  4796. The zero-sized array can be any member of a union. Zero-sized arrays are only 
  4797. allowed as the last member of a structure. 
  4798.  
  4799. The sizeof operator assumes 1 for the zero-sized array. 
  4800.  
  4801. Structures containing zero-sized arrays can be nested within other structures 
  4802. as long as no additional members are subsequently declared in any enclosing 
  4803. structures. For example, the following declaration causes an error: 
  4804.  
  4805. struct Struct_S {
  4806.   int i;
  4807.   char arr_s[];
  4808. };
  4809.  
  4810. struct Struct_T {
  4811.   float f;
  4812.   struct Struct_S;
  4813.   int k;   // Error - addtional structure member following a
  4814.        // struct containing a zero-sized array
  4815. } t;
  4816.  
  4817. Note: 
  4818.  
  4819.    1. In C++, the zero-sized array must be non-static. 
  4820.  
  4821.    2. In a class definition, the zero-sized array must be the last non-static 
  4822.       data member. Members such as functions, static data members, and typedefs 
  4823.       are allowed after the zero-sized array. 
  4824.  
  4825.    3. A class containing a zero-sized array cannot be used as a base class. 
  4826.  
  4827.  
  4828. ΓòÉΓòÉΓòÉ 4.5.7.3. Example Programs Using Arrays ΓòÉΓòÉΓòÉ
  4829.  
  4830. /************************************************************************
  4831. *
  4832.  
  4833. The following program defines a floating-point array called prices. 
  4834.  
  4835. The first for statement prints the values of the elements of prices. The second 
  4836. for statement adds five percent to the value of each element of prices, and 
  4837. assigns the result to total, and prints the value of total. 
  4838.  
  4839.                                     *
  4840. ************************************************************************/
  4841.  
  4842. /**
  4843.  ** Example of one-dimensional arrays
  4844.  **/
  4845.  
  4846. #include <stdio.h>
  4847. #define  ARR_SIZE  5
  4848.  
  4849. int main(void)
  4850. {
  4851.  static float const prices[ARR_SIZE] = { 1.41, 1.50, 3.75, 5.00, .86 };
  4852.  auto float total;
  4853.  int i;
  4854.  
  4855.  for (i = 0; i < ARR_SIZE; i++)
  4856.  {
  4857.   printf("price = $%.2f\n", prices[i]);
  4858.  }
  4859.  
  4860.  printf("\n");
  4861.  
  4862.  for (i = 0; i < ARR_SIZE; i++)
  4863.  {
  4864.   total = prices[i] * 1.05;
  4865.  
  4866.   printf("total = $%.2f\n", total);
  4867.  }
  4868.  
  4869.  return(0);
  4870. }
  4871.  
  4872. /************************************************************************
  4873. *
  4874.  
  4875. This program produces the following output: 
  4876.  
  4877. price = $1.41
  4878. price = $1.50
  4879. price = $3.75
  4880. price = $5.00
  4881. price = $0.86
  4882.  
  4883. total = $1.48
  4884. total = $1.57
  4885. total = $3.94
  4886. total = $5.25
  4887. total = $0.90
  4888.  
  4889. The following program defines the multidimensional array salary_tbl. A for loop 
  4890. prints the values of salary_tbl. 
  4891.  
  4892.                                     *
  4893. ************************************************************************/
  4894.  
  4895. /**
  4896.  ** Example of a multidimensional array
  4897.  **/
  4898.  
  4899. #include <stdio.h>
  4900. #define  ROW_SIZE   3
  4901. #define  COLUMN_SIZE  5
  4902.  
  4903. int main(void)
  4904. {
  4905.  static int salary_tbl[ROW_SIZE][COLUMN_SIZE] =
  4906.  {
  4907.   {  500,  550,  600,  650,  700  },
  4908.   {  600,  670,  740,  810,  880  },
  4909.   {  740,  840,  940, 1040, 1140  }
  4910.  };
  4911.  int grade , step;
  4912.  
  4913.  for (grade = 0; grade < ROW_SIZE; ++grade)
  4914.   for (step = 0; step < COLUMN_SIZE; ++step)
  4915.   {
  4916.    printf("salary_tbl[%d] [%d] = %d\n", grade, step,
  4917.        salary_tbl[grade] [step]);
  4918.   }
  4919.  
  4920.   return(0);
  4921. }
  4922.  
  4923. /************************************************************************
  4924. *
  4925.  
  4926. This program produces the following output: 
  4927.  
  4928. salary_tbl[0] [0] = 500
  4929. salary_tbl[0] [1] = 550
  4930. salary_tbl[0] [2] = 600
  4931. salary_tbl[0] [3] = 650
  4932. salary_tbl[0] [4] = 700
  4933. salary_tbl[1] [0] = 600
  4934. salary_tbl[1] [1] = 670
  4935. salary_tbl[1] [2] = 740
  4936. salary_tbl[1] [3] = 810
  4937. salary_tbl[1] [4] = 880
  4938. salary_tbl[2] [0] = 740
  4939. salary_tbl[2] [1] = 840
  4940. salary_tbl[2] [2] = 940
  4941. salary_tbl[2] [3] = 1040
  4942. salary_tbl[2] [4] = 1140
  4943.  
  4944.                                     *
  4945. ************************************************************************/
  4946.  
  4947.  
  4948. ΓòÉΓòÉΓòÉ 4.5.8. Structures ΓòÉΓòÉΓòÉ
  4949.  
  4950. A structure contains an ordered group of data objects. Unlike the elements of 
  4951. an array, the data objects within a structure can have varied data types. Each 
  4952. data object in a structure is a member or field. 
  4953.  
  4954. Use structures to group logically related objects. For example, to allocate 
  4955. storage for the components of one address, define a number of variables for the 
  4956. street name and number, the city, and so on. To allocate storage for more than 
  4957. one address, group the components of each address by defining a structure data 
  4958. type and as many variables as you need to have the structure data type. 
  4959.  
  4960. In the following example, lines 1 through 7 declare the structure tag address: 
  4961.  
  4962.   1  struct address {
  4963.   2           int street_no;
  4964.   3           char *street_name;
  4965.   4           char *city;
  4966.   5           char *prov;
  4967.   6           char *postal_code;
  4968.   7          };
  4969.   8  struct address perm_address;
  4970.   9  struct address temp_address;
  4971.   10  struct address *p_perm_address = &perm_address;
  4972.  
  4973. The variables perm_address and temp_address are instances of the structure data 
  4974. type address. Both contain the members described in the declaration of address. 
  4975. The pointer p_perm_address points to a structure of address and is initialized 
  4976. to point to perm_address. 
  4977.  
  4978. Refer to a member of a structure by specifying the structure variable name with 
  4979. the dot operator (.) or a pointer with the arrow operator (->) and the member 
  4980. name. For example, both of the following: 
  4981.  
  4982.  perm_address.prov = "Ontario";
  4983.  p_perm_address -> prov = "Ontario";
  4984.  
  4985. assign a pointer to the string "Ontario" to the pointer prov that is in the 
  4986. structure perm_address. 
  4987.  
  4988. All references to structures must be fully qualified. In the example, you 
  4989. cannot reference the fourth field by prov alone. You must reference this field 
  4990. by perm_address.prov. 
  4991.  
  4992. Structures with identical members but different names are not compatible and 
  4993. cannot be assigned to each other. 
  4994.  
  4995. Structures are not intended to conserve storage. If you need direct control of 
  4996. byte mapping, use pointers. 
  4997.  
  4998. Structure member references are described in Dot Operator . and Arrow 
  4999. Operator -> 
  5000.  
  5001. You cannot declare a structure with members of incomplete types. 
  5002.  
  5003. A structure type declaration describes the members that are part of the 
  5004. structure. It contains the struct keyword followed by an optional identifier 
  5005. (the structure tag) and a brace-enclosed list of members. 
  5006.  
  5007. Syntax of a Structure 
  5008.  
  5009. The keyword struct followed by the identifier (tag) names the data type. If you 
  5010. do not provide a tag name to the data type, you must put all variable 
  5011. definitions that refer to it within the declaration of the data type. 
  5012.  
  5013. The list of members provides the data type with a description of the values 
  5014. that can be stored in the structure. 
  5015.  
  5016. If a : (colon) and a constant expression follow the member declarator, the 
  5017. member represents a bit field. A member that does not represent a bit field can 
  5018. be of any data type and can have the volatile or const qualifier. 
  5019.  
  5020. Identifiers used as structure or member names can be redefined to represent 
  5021. different objects in the same scope without conflicting. You cannot use the 
  5022. name of a member more than once in a structure type, but you can use the same 
  5023. member name in another structure type that is defined within the same scope. 
  5024.  
  5025. You cannot declare a structure type that contains itself as a member, but you 
  5026. can declare a structure type that contains a pointer to itself as a member. 
  5027.  
  5028. A structure variable definition contains an optional storage class keyword, the 
  5029. struct keyword, a structure tag, a declarator, and an optional identifier. The 
  5030. structure tag indicates the data type of the structure variable. 
  5031.  
  5032. C++ Note:  The keyword struct is optional in C++. 
  5033.  
  5034. You can declare structures having any storage class. 
  5035.  
  5036. Additional information is provided on: 
  5037.  
  5038.      Initializing Structures 
  5039.      Declaring Structure Types and Variables 
  5040.      Declaring and Using Bit Fields in Structures 
  5041.      Declaring a Packed Structure 
  5042.      Example Program Using Structures 
  5043.  
  5044.  Related Information 
  5045.  
  5046.      Dot Operator . 
  5047.      Arrow Operator -> 
  5048.      _Packed Qualifier 
  5049.      Declarators 
  5050.      Initializers 
  5051.  
  5052.  
  5053. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Structure ΓòÉΓòÉΓòÉ
  5054.  
  5055. A structure declaration has the form: 
  5056.  
  5057.                 ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5058.                       Γöé
  5059. >>ΓöÇΓöÇstructΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇmemberΓöÇΓöÇ;ΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  5060.       ΓööΓöÇidentifierΓöÇΓöÿ
  5061.  
  5062. A structure member definition has the form: 
  5063.  
  5064.           ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5065.                                 Γöé
  5066. >>ΓöÇΓöÇtype_specifierΓöÇΓöÇΓöÇΓö¼ΓöÇdeclaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ><
  5067.            ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ:ΓöÇΓöÇconstant_expressionΓöÇΓöÿ
  5068.             ΓööΓöÇ.declaratorΓöÇΓöÿ
  5069.  
  5070.  
  5071. ΓòÉΓòÉΓòÉ 4.5.8.1. Initializing Structures ΓòÉΓòÉΓòÉ
  5072.  
  5073. The initializer contains an = (equal sign) followed by a brace-enclosed 
  5074. comma-separated list of values. You do not have to initialize all members of a 
  5075. structure. 
  5076.  
  5077. The following definition shows a completely initialized structure: 
  5078.  
  5079. struct address {
  5080.          int street_no;
  5081.          char *street_name;
  5082.          char *city;
  5083.          char *prov;
  5084.          char *postal_code;
  5085.         };
  5086. static struct address perm_address =
  5087.         { 3, "Savona Dr.", "Dundas", "Ontario", "L4B 2A1"};
  5088.  
  5089. The values of perm_address are: 
  5090.  
  5091.  Member              Value 
  5092.  perm_address.street_no 3 
  5093.  perm_address.street_name address of string "Savona Dr." 
  5094.  perm_address.city   address of string "Dundas" 
  5095.  perm_address.prov   address of string "Ontario" 
  5096.  perm_address.postal_code address of string "L4B 2A1" 
  5097.  
  5098.  The following definition shows a partially initialized structure: 
  5099.  
  5100.   struct address {
  5101.            int street_no;
  5102.            char *street_name;
  5103.            char *city;
  5104.            char *prov;
  5105.            char *postal_code;
  5106.           };
  5107.   struct address temp_address =
  5108.           { 44, "Knyvet Ave.", "Hamilton", "Ontario" };
  5109.  
  5110.  The values of temp_address are: 
  5111.  
  5112.  Member                                  Value 
  5113.  temp_address.street_no                  44 
  5114.  temp_address.street_name                address of string "Knyvet Ave." 
  5115.  temp_address.city                       address of string "Hamilton" 
  5116.  temp_address.prov                       address of string "Ontario" 
  5117.  temp_address.postal_code                value depends on the storage class. 
  5118.  
  5119.  Note:  The initial value of uninitialized structure members like 
  5120.  temp_address.postal_code depends on the storage class associated with the 
  5121.  member. See Storage Class Specifiers for details on the initialization of 
  5122.  different storage classes. 
  5123.  
  5124.  
  5125. ΓòÉΓòÉΓòÉ 4.5.8.2. Declaring Structure Types and Variables ΓòÉΓòÉΓòÉ
  5126.  
  5127. To define a structure type and a structure variable in one statement, put a 
  5128. declarator and an optional initializer after the type definition. To specify a 
  5129. storage class specifier for the variable, you must put the storage class 
  5130. specifier at the beginning of the statement. 
  5131.  
  5132. For example: 
  5133.  
  5134. static struct {
  5135.          int street_no;
  5136.          char *street_name;
  5137.          char *city;
  5138.          char *prov;
  5139.          char *postal_code;
  5140.        } perm_address, temp_address;
  5141.  
  5142. Because this example does not name the structure data type, perm_address and 
  5143. temp_address are the only structure variables that will have this data type. 
  5144. Putting an identifier after struct, lets you make additional variable 
  5145. definitions of this data type later in the program. 
  5146.  
  5147. The structure type (or tag) cannot have the volatile qualifier, but a member or 
  5148. a structure variable can be defined as having the volatile qualifier. 
  5149.  
  5150. For example: 
  5151.  
  5152. static struct class1 {
  5153.             char descript[20];
  5154.             volatile long code;
  5155.             short complete;
  5156.            } volatile file1, file2;
  5157. struct class1 subfile;
  5158.  
  5159. This example qualifies the structures file1 and file2, and the structure member 
  5160. subfile.code as volatile. 
  5161.  
  5162.  
  5163. ΓòÉΓòÉΓòÉ 4.5.8.3. Declaring and Using Bit Fields in Structures ΓòÉΓòÉΓòÉ
  5164.  
  5165. A structure or a C++ class can contain bit fields that allow you to access 
  5166. individual bits. You can use bit fields for data that requires just a few bits 
  5167. of storage. A bit field declaration contains a type specifier followed by an 
  5168. optional declarator, a colon, a constant expression, and a semicolon. The 
  5169. constant expression specifies how many bits the field reserves. 
  5170.  
  5171. Bit fields with a length of 0 must be unnamed. Unnamed bit fields cannot be 
  5172. referenced or initialized. A zero-width bit field causes the next field to be 
  5173. aligned on the next container boundary, where the container is the same size as 
  5174. the underlying type as the bit field. For a _Packed structure, a bit field of 
  5175. length 0 causes the next field to be aligned on the next byte boundary. The 
  5176. padding to the next container boundary only takes place if the zero-width bit 
  5177. field has the same underlying type as the preceding bit-field member. If the 
  5178. types are different, the zero-width bit field has no effect. 
  5179.  
  5180. The maximum bit-field length is implementation dependent. The maximum bit field 
  5181. length for the VisualAge for C++ compiler is 32 bits (4 bytes, or 1 word). 
  5182.  
  5183. For portability, do not use bit fields greater than 32 bits in size. 
  5184.  
  5185. The following restrictions apply to bit fields. You cannot: 
  5186.  
  5187.      Define an array of bit fields 
  5188.      Take the address of a bit field 
  5189.      Have a pointer to a bit field 
  5190.      Have a reference to a bit field (C++ only) 
  5191.  
  5192.  In C, you can declare a bit field as type int, signed int, or unsigned int. 
  5193.  Bit fields of the type int are equivalent to those of type unsigned int. 
  5194.  
  5195.  The default integer type for a bit field is unsigned. Use the bitfields=signed 
  5196.  option to change this default. 
  5197.  
  5198.  In extended mode C, bit fields can be any integral type. For example, 
  5199.  
  5200.   struct S {
  5201.     short x : 4;
  5202.     long  y : 10;
  5203.     char  z : 7;
  5204.   } s;
  5205.  
  5206.  Non-integral bit fields in extended mode C are converted to type unsigned int 
  5207.  and a warning is issued. In other modes, the use of non-integral bit fields 
  5208.  results in an error. 
  5209.  
  5210.  A bit field cannot have the const or volatile qualifier. 
  5211.  
  5212.  The following structure has three bit-field members kingdom, phylum, and 
  5213.  genus, occupying 12, 6, and 2 bits respectively: 
  5214.  
  5215.   struct taxonomy {
  5216.      int kingdom : 12;
  5217.      int phylum : 6;
  5218.      int genus : 2;
  5219.      };
  5220.  
  5221.  C++ Note:  Unlike ANSI/ISO C, C++ bit fields can be any integral type or 
  5222.  enumeration type. When you assign a value that is out of range to a bit field, 
  5223.  the low-order bit pattern is preserved and the appropriate bits are assigned. 
  5224.  
  5225.  If a series of bit fields does not add up to the size of an int, padding can 
  5226.  take place. The amount of padding is determined by the alignment 
  5227.  characteristics of the members of the structure. Bit fields cannot cross word 
  5228.  boundaries but are forced to start at the next word boundary. 
  5229.  
  5230.  The following example declares the identifier kitchen to be of type struct 
  5231.  on_off: 
  5232.  
  5233.   struct on_off {
  5234.            unsigned light : 1;
  5235.            unsigned toaster : 1;
  5236.            int count;       /* 4 bytes */
  5237.            unsigned ac : 4;
  5238.            unsigned : 4;
  5239.            unsigned clock : 1;
  5240.            unsigned : 0;
  5241.            unsigned flag : 1;
  5242.            } kitchen ;
  5243.  
  5244.  The structure kitchen contains eight members totalling 16 bytes. The following 
  5245.  table describes the storage that each member occupies: 
  5246.  
  5247.  Member Name              Storage Occupied 
  5248.  light                    1 bit 
  5249.  toaster                  1 bit 
  5250.  (padding - 30 bits)      To next int boundary 
  5251.  count                    The size of an int 
  5252.  ac                       4 bits 
  5253.  (unnamed field)          4 bits 
  5254.  clock                    1 bit 
  5255.  (padding - 23 bits)      To next int boundary (unnamed field) 
  5256.  flag                     1 bit 
  5257.  (padding - 31 bits)      To next int boundary 
  5258.  
  5259.  All references to structure fields must be fully qualified. For instance, you 
  5260.  cannot reference the second field by toaster. You must reference this field by 
  5261.  kitchen.toaster. 
  5262.  
  5263.  The following expression sets the light field to 1: 
  5264.  
  5265.    kitchen.light = 1;
  5266.  
  5267.  When you assign to a bit field a value that is out of its range, the bit 
  5268.  pattern is preserved and the appropriate bits are assigned. The following 
  5269.  expression sets the toaster field of the kitchen structure to 0 because only 
  5270.  the least significant bit is assigned to the toaster field: 
  5271.  
  5272.    kitchen.toaster = 2;
  5273.  
  5274.  
  5275. ΓòÉΓòÉΓòÉ 4.5.8.4. Declaring a Packed Structure ΓòÉΓòÉΓòÉ
  5276.  
  5277. Data elements of a structure are stored in memory on an address boundary 
  5278. specific for that data type. For example, a double value is stored in memory on 
  5279. a doubleword (8-byte) boundary. Gaps may be left in memory between elements of 
  5280. a structure to align elements on their natural boundaries. You can reduce the 
  5281. padding of bytes within a structure by using the _Packed qualifier on the 
  5282. structure declaration. 
  5283.  
  5284. C++ Note:  C++ does not support the _Packed qualifier. To change the alignment 
  5285. of structures, use the #pragma pack directive or the /Sp compiler option. Both 
  5286. of these methods are also supported by C. 
  5287.  
  5288.  
  5289. ΓòÉΓòÉΓòÉ 4.5.8.5. Anonymous Structures in C ΓòÉΓòÉΓòÉ
  5290.  
  5291. Structures can be declared without declarators if they are members of another 
  5292. structure or union. Structures without declarators are called anonymous 
  5293. structures. They are only permitted in extended mode. 
  5294.  
  5295. Members of an anonymous structure can be accessed as if they were declared 
  5296. directly in the containing structure or union. For example, given the following 
  5297. structure: 
  5298.  
  5299.   struct s {
  5300.    int a;
  5301.    struct {
  5302.     int b;
  5303.     float c;
  5304.    };     /* no declarator */
  5305.   } kim;
  5306.  
  5307. you can make the following statements: 
  5308.  
  5309.   kim.a = 5;
  5310.   kim.b = 36;
  5311.  
  5312. You can also declare an anonymous structure: 
  5313.  
  5314.    1. By creating a typedef and using the typedef name without a declarator: 
  5315.  
  5316.               typedef struct {
  5317.                int a;
  5318.                int b;
  5319.               }  Struct_T;
  5320.  
  5321.               struct s1 {
  5322.                Struct_T;
  5323.                int c;
  5324.               } dave;
  5325.  
  5326.    2. By using an existing structure tag without a declarator: 
  5327.  
  5328.               struct s1 {
  5329.                int a;
  5330.                int b;
  5331.               };
  5332.  
  5333.               struct s2 {
  5334.                struct s1;
  5335.                int c;
  5336.               } dave;
  5337.  
  5338.  In both of the examples, the members can be accessed as dave.a, dave.b, and 
  5339.  dave.c. 
  5340.  
  5341.  An anonymous structure must be a member of, or nested within another anonymous 
  5342.  structure that is a member of, a named structure or union. If a structure is 
  5343.  declared at file scope without a declarator, its members are not available to 
  5344.  the surrounding scope. For example, the following structure only declares the 
  5345.  tag tom: 
  5346.  
  5347.     struct tom {
  5348.      int b;
  5349.      float c;
  5350.     };
  5351.  
  5352.  The variables b and c from this structure cannot be used at file scope, and 
  5353.  the following statements generate errors: 
  5354.  
  5355.     b = 5;
  5356.     c = 2.5;
  5357.  
  5358.  C++ Note:  Anonymous structures are treated differently in C++. See Anonymous 
  5359.  Structures in C++ for more information. 
  5360.  
  5361.  
  5362. ΓòÉΓòÉΓòÉ 4.5.8.6. Anonymous Structures in C++ ΓòÉΓòÉΓòÉ
  5363.  
  5364. Anonymous structures are treated differently in the C++ language. Given these 
  5365. declarations: 
  5366.  
  5367.   struct don {
  5368.    int a;
  5369.    int b;
  5370.   };
  5371.  
  5372.   struct pete {
  5373.    struct don;
  5374.   };
  5375.  
  5376. In C, struct don; declares an anonymous structure as a member of pete. In C++, 
  5377. it is treated as a forward or incomplete declaration of a nested structure, not 
  5378. as an anonymous structure. 
  5379.  
  5380. A C++ anonymous structure is a structure without a class name. It cannot be 
  5381. followed by a declarator. An anonymous structure is not a type; it defines an 
  5382. unnamed object and it cannot have member functions. 
  5383.  
  5384. The member names of a C++ anonymous structure must be distinct from other names 
  5385. within the scope in which the structure is declared. You can use member names 
  5386. directly in the structure scope without any additional member access syntax. 
  5387.  
  5388. An anonymous structure cannot have protected or private members. A global 
  5389. anonymous structure must be declared with the keyword static. 
  5390.  
  5391.  
  5392. ΓòÉΓòÉΓòÉ 4.5.8.7. Example Program Using Structures ΓòÉΓòÉΓòÉ
  5393.  
  5394. /************************************************************************
  5395. *
  5396.  
  5397. The following program finds the sum of the integer numbers in a linked list: 
  5398.  
  5399.                                     *
  5400. ************************************************************************/
  5401.  
  5402. /**
  5403.  ** Example program illustrating structures using linked lists
  5404.  **/
  5405.  
  5406. #include <stdio.h>
  5407.  
  5408. struct record {
  5409.         int number;
  5410.         struct record *next_num;
  5411.        };
  5412.  
  5413. int main(void)
  5414. {
  5415.   struct  record name1, name2, name3;
  5416.   struct  record *recd_pointer = &name1;
  5417.   int sum = 0;
  5418.  
  5419.   name1.number = 144;
  5420.   name2.number = 203;
  5421.   name3.number = 488;
  5422.  
  5423.   name1.next_num = &name2;
  5424.   name2.next_num = &name3;
  5425.   name3.next_num = NULL;
  5426.  
  5427.   while (recd_pointer != NULL)
  5428.   {
  5429.    sum += recd_pointer->number;
  5430.    recd_pointer = recd_pointer->next_num;
  5431.   }
  5432.   printf("Sum = %d\n", sum);
  5433.  
  5434.   return(0);
  5435. }
  5436.  
  5437. /************************************************************************
  5438. *
  5439.  
  5440. The structure type record contains two members: the integer number and 
  5441. next_num, which is a pointer to a structure variable of type record. 
  5442.  
  5443. The record type variables name1, name2, and name3 are assigned the following 
  5444. values: 
  5445.  
  5446.  Member Name                   Value 
  5447.  name1.number                  144 
  5448.  name1.next_num                The address of name2 
  5449.  
  5450.  name2.number                  203 
  5451.  name2.next_num                The address of name3 
  5452.  
  5453.  name3.number                  488 
  5454.  name3.next_num                NULL (Indicating the end of the linked list.) 
  5455.  
  5456.  The variable recd_pointer is a pointer to a structure of type record. It is 
  5457.  initialized to the address of name1 (the beginning of the linked list). 
  5458.  
  5459.  The while loop causes the linked list to be scanned until recd_pointer equals 
  5460.  NULL. The statement: 
  5461.  
  5462.   recd_pointer = recd_pointer->next_num;
  5463.  
  5464.  advances the pointer to the next object in the list. 
  5465.  
  5466.                                            *
  5467.   ***********************************************************************************/
  5468.  
  5469.  
  5470. ΓòÉΓòÉΓòÉ 4.5.9. Unions ΓòÉΓòÉΓòÉ
  5471.  
  5472. A union is an object that can hold any one of a set of named members. The 
  5473. members of the named set can be of any data type. Members are overlaid in 
  5474. storage. 
  5475.  
  5476. The storage allocated for a union is the storage required for the largest 
  5477. member of the union (plus any padding that is required so that the union will 
  5478. end at a natural boundary of its strictest member). 
  5479.  
  5480. C++ Notes: 
  5481.  
  5482. In C++, a union can have member functions, including constructors and 
  5483. destructors, but not virtual member functions. A union cannot be used as a base 
  5484. class and cannot be derived from a base class. 
  5485.  
  5486. A C++ union member cannot be a class object that has a constructor, destructor, 
  5487. or overloaded copy assignment operator. In C++, a member of a union cannot be 
  5488. declared with the keyword static. 
  5489.  
  5490. A union type declaration contains the union keyword followed by an identifier 
  5491. (optional) and a brace-enclosed list of members. 
  5492.  
  5493. Syntax of a Union 
  5494.  
  5495. The identifier is a tag given to the union specified by the member list. If you 
  5496. specify a tag, any subsequent declaration of the union (in the same scope) can 
  5497. be made by declaring the tag and omitting the member list. If you do not 
  5498. specify a tag, you must put all variable definitions that refer to that union 
  5499. within the statement that defines the data type. 
  5500.  
  5501. The list of members provides the data type with a description of the objects 
  5502. that can be stored in the union. 
  5503.  
  5504. You can reference one of the possible members of a union the same way as 
  5505. referencing a member of a structure. 
  5506.  
  5507. For example: 
  5508.  
  5509. union {
  5510.    char birthday[9];
  5511.    int age;
  5512.    float weight;
  5513.    } people;
  5514.  
  5515. people.birthday[0] = '\n';
  5516.  
  5517. assigns '\n' to the first element in the character array birthday, a member of 
  5518. the union people. 
  5519.  
  5520. A union can represent only one of its members at a time. In the example, the 
  5521. union people contains either age, birthday, or weight but never more than one 
  5522. of these. The printf statement in the following example does not give the 
  5523. correct result because people.age replaces the value assigned to 
  5524. people.birthday in the first line: 
  5525.  
  5526. 1  people.birthday = "03/06/56";
  5527. 2  people.age = 38;
  5528. 3  printf("%s\n", people.birthday);
  5529.  
  5530. Examples of Unions 
  5531.  
  5532. Additional information is provided on: 
  5533.  
  5534.      Defining a Union Variable 
  5535.      Defining a Packed Union 
  5536.      Anonymous Unions in C 
  5537.      Anonymous Unions in C++ 
  5538.  
  5539.  Related Information 
  5540.  
  5541.      Dot Operator . 
  5542.      Arrow Operator -> 
  5543.      _Packed Qualifier 
  5544.      Declarators 
  5545.      Initializers 
  5546.  
  5547.  
  5548. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Union ΓòÉΓòÉΓòÉ
  5549.  
  5550. A union declaration has the form: 
  5551.  
  5552.                        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5553.                              Γöé
  5554. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇunionΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇmemberΓöÇΓöÇ;ΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  5555.   ΓööΓöÇqualifierΓöÇΓöÿ     ΓööΓöÇidentifierΓöÇΓöÿ
  5556.  
  5557. A union member definition has the form: 
  5558.  
  5559.           ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5560.                                 Γöé
  5561. >>ΓöÇΓöÇtype_specifierΓöÇΓöÇΓöÇΓö¼ΓöÇdeclaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ><
  5562.            ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇconstant_expressionΓöÇΓöÿ
  5563.             ΓööΓöÇdeclaratorΓöÇΓöÿ
  5564.  
  5565.  
  5566. ΓòÉΓòÉΓòÉ 4.5.9.1. Defining a Union Variable ΓòÉΓòÉΓòÉ
  5567.  
  5568. A union variable definition contains an optional storage class keyword, the 
  5569. union keyword, a union tag, and a declarator. The union tag indicates the data 
  5570. type of the union variable. 
  5571.  
  5572. The type specifier contains the keyword union followed by the name of the union 
  5573. type. You must declare the union data type before you can define a union having 
  5574. that type. 
  5575.  
  5576. You can define a union data type and a union of that type in the same statement 
  5577. by placing the variable declarator after the data type definition. 
  5578.  
  5579. The declarator is an identifier, possibly with the volatile or const qualifier. 
  5580.  
  5581. You can only initialize the first member of a union. 
  5582.  
  5583. The following example shows how you would initialize the first union member 
  5584. birthday of the union variable people: 
  5585.  
  5586. union {
  5587.    char birthday[9];
  5588.    int age;
  5589.    float weight;
  5590.    } people = {"23/07/57"};
  5591.  
  5592. To define union type and a union variable in one statement, put a declarator 
  5593. after the type definition. The storage class specifier for the variable must go 
  5594. at the beginning of the statement. 
  5595.  
  5596.  
  5597. ΓòÉΓòÉΓòÉ 4.5.9.2. Defining Packed Unions ΓòÉΓòÉΓòÉ
  5598.  
  5599. To qualify a C union as packed, use _Packed. The _Packed qualifier is only 
  5600. supported in C. 
  5601.  
  5602. Under the _Packed qualifier, the memory layout of the union members is not 
  5603. affected; Each member starts at offset zero. The _Packed qualifier does affect 
  5604. the total alignment restriction of the whole union. 
  5605.  
  5606. C++ Note:  C++ does not support the _Packed qualifier. To change the alignment 
  5607. of C++ unions, use the #pragma pack directive or the /Sp compiler option. Both 
  5608. of these methods are also supported by C. 
  5609.  
  5610. In the following example, each of the elements in the nonpacked n_array is of 
  5611. type union uu. 
  5612.  
  5613.      union uu {
  5614.       short   a;
  5615.       struct {
  5616.        char x;
  5617.        char y;
  5618.        char z;
  5619.       } b;
  5620.      };
  5621.  
  5622.      union uu      n_array[2];
  5623.      _Packed union uu  p_array[2];
  5624.  
  5625. Because it is not packed, each element in the nonpacked n_array has an 
  5626. alignment restriction of 2 bytes (the largest alignment requirement among the 
  5627. union members is that of short a), and there is 1 byte of padding at the end of 
  5628. each element to enforce this requirement. 
  5629.  
  5630. In the packed array p_array, each element is of type _Packed union uu. Because 
  5631. every element aligned on the byte boundary, each element has a length of only 3 
  5632. bytes, instead of the 4 bytes in the previous example. 
  5633.  
  5634.  
  5635. ΓòÉΓòÉΓòÉ 4.5.9.3. Anonymous Unions in C ΓòÉΓòÉΓòÉ
  5636.  
  5637. Unions can be declared without declarators if they are members of another 
  5638. structure or union. Unions without declarators are called anonymous unions. 
  5639.  
  5640. Members of an anonymous union can be accessed as if they were declared directly 
  5641. in the containing structure or union. For example, given the following 
  5642. structure: 
  5643.  
  5644.   struct s {
  5645.    int a;
  5646.    union {
  5647.     int b;
  5648.     float c;
  5649.    };     /* no declarator */
  5650.   } kurt;
  5651.  
  5652. you can make the following statements: 
  5653.  
  5654.   kurt.a = 5;
  5655.   kurt.b = 36;
  5656.  
  5657. You can also declare an anonymous union: 
  5658.  
  5659.    1. By creating a typedef and using the typedef name without a declarator: 
  5660.  
  5661.               typedef union {
  5662.                int a;
  5663.                int b;
  5664.               }  UNION_T;
  5665.  
  5666.               struct s1 {
  5667.                UNION_T;
  5668.                int c;
  5669.               } dave;
  5670.  
  5671.    2. By using an existing union tag without a declarator: 
  5672.  
  5673.               union u1 {
  5674.                int a;
  5675.                int b;
  5676.               };
  5677.  
  5678.               struct s1 {
  5679.                union u1;
  5680.                int c;
  5681.               } dave;
  5682.  
  5683.  In both of the examples, the members can be accessed as dave.a, dave.b, and 
  5684.  dave.c. 
  5685.  
  5686.  An anonymous union must be a member of, or nested within another anonymous 
  5687.  union that is a member of, a named structure or union. If a union is declared 
  5688.  at file scope without a declarator, its members are not available to the 
  5689.  surrounding scope. For example, the following union only declares the union 
  5690.  tag tom: 
  5691.  
  5692.     union tom {
  5693.      int b;
  5694.      float c;
  5695.     };
  5696.  
  5697.  The variables b and c from this union cannot be used at file scope, and the 
  5698.  following statements will generate errors: 
  5699.  
  5700.     b = 5;
  5701.     c = 2.5;
  5702.  
  5703.  C++ Note:  Anonymous unions are treated differently in C++. See Anonymous 
  5704.  Unions in C++ for more information. 
  5705.  
  5706.  
  5707. ΓòÉΓòÉΓòÉ 4.5.9.4. Anonymous Unions in C++ ΓòÉΓòÉΓòÉ
  5708.  
  5709. It cannot be followed by a declarator. An anonymous union is not a type; it 
  5710. defines an unnamed object and it cannot have member functions. 
  5711.  
  5712. The member names of an anonymous union must be distinct from other names within 
  5713. the scope in which the union is declared. You can use member names directly in 
  5714. the union scope without any additional member access syntax. 
  5715.  
  5716. For example, in the following code fragment, you can access the data members i 
  5717. and cptr directly because they are in the scope containing the anonymous union. 
  5718. Because i and cptr are union members and have the same address, you should only 
  5719. use one of them at a time. The assignment to the member cptr will change the 
  5720. value of the member i. 
  5721.  
  5722. void f()
  5723. {
  5724. union { int i; char* cptr ; };
  5725. //    .
  5726. //    .
  5727. //    .
  5728. i = 5;
  5729. cptr = "string_in_union"; // overrides i
  5730. }
  5731.  
  5732. An anonymous union cannot have protected or private members. A global anonymous 
  5733. union must be declared with the keyword static. 
  5734.  
  5735.  
  5736. ΓòÉΓòÉΓòÉ <hidden> Examples of Unions ΓòÉΓòÉΓòÉ
  5737.  
  5738. The following example defines a union data type (not named) and a union 
  5739. variable (named length). The member of length can be a long int, a float, or a 
  5740. double. 
  5741.  
  5742. union {
  5743.     float meters;
  5744.     double centimeters;
  5745.     long inches;
  5746.    } length;
  5747.  
  5748. The following example defines the union type data as containing one member. The 
  5749. member can be named charctr, whole, or real. The second statement defines two 
  5750. data type variables: input and output. 
  5751.  
  5752. union data {
  5753.        char charctr;
  5754.        int whole;
  5755.        float real;
  5756.       };
  5757. union data input, output;
  5758.  
  5759. The following statement assigns a character to input: 
  5760.  
  5761. input.charctr = 'h';
  5762.  
  5763. The following statement assigns a floating-point number to member output: 
  5764.  
  5765. output.real = 9.2;
  5766.  
  5767. The following example defines an array of structures named records. Each 
  5768. element of records contains three members: the integer id_num, the integer 
  5769. type_of_input, and the union variable input. input has the union data type 
  5770. defined in the previous example. 
  5771.  
  5772. struct {
  5773.      int id_num;
  5774.      int type_of_input;
  5775.      union data input;
  5776.     } records[10];
  5777.  
  5778. The following statement assigns a character to the structure member input of 
  5779. the first element of records: 
  5780.  
  5781. records[0].input.charctr = 'g';
  5782.  
  5783.  
  5784. ΓòÉΓòÉΓòÉ 4.6. Declarators ΓòÉΓòÉΓòÉ
  5785.  
  5786. A declarator designates a data object or function. Declarators appear in all 
  5787. data definitions and declarations and in some type definitions. 
  5788.  
  5789. In a declarator, you can specify the type of an object to be an array, a 
  5790. pointer, or a reference. You can specify that the return type of a function is 
  5791. a pointer or a reference. You can also perform initialization in a declarator. 
  5792.  
  5793. Syntax of a Declarator VisualAge for C++ also recognizes the following 
  5794. qualifiers: 
  5795.  
  5796.      _Packed, described on page _Packed Qualifier 
  5797.      __unaligned, described on page __unaligned Type Qualifier 
  5798.  
  5799.  You can also use the following specifiers at the beginning of a declarator: 
  5800.  
  5801.      _Export, described on page _Export Keyword 
  5802.      _Import, described on page _Import Keyword 
  5803.      __thread, described on page __thread Keyword 
  5804.      __declspec, described on page __declspec Keyword 
  5805.  
  5806.  In C, you cannot declare or define a volatile or const function. C++ class 
  5807.  member functions can be qualified with const or volatile. A subscript 
  5808.  declarator has the form: 
  5809.  
  5810.   >>ΓöÇΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  5811.       ΓööΓöÇconstant_expressionΓöÇΓöÿ   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  5812.                     Γöé               Γöé Γöé
  5813.                     ΓööΓöÇΓöÇΓöÇ[ΓöÇΓöÇconstant_expressionΓöÇΓöÇ]ΓöÇΓö┤ΓöÇΓöÿ
  5814.  
  5815.  A simple declarator consists of an identifier, which names a data object. For 
  5816.  example, the following block scope data declaration uses initial as the 
  5817.  declarator: 
  5818.  
  5819.   auto char initial;
  5820.  
  5821.  The data object initial has the storage class auto and the data type char. 
  5822.  
  5823.  You can define or declare a structure, union, or array. by using a declarator 
  5824.  that contains an identifier, which names the data object, and some combination 
  5825.  of symbols and identifiers, which describes the type of data that the object 
  5826.  represents. 
  5827.  
  5828.  The following declaration uses compute[5] as the declarator: 
  5829.  
  5830.   extern long int compute[5];
  5831.  
  5832.  Examples of Declarators 
  5833.  
  5834.  Related Information 
  5835.  
  5836.      volatile and const Qualifiers 
  5837.      _Packed Qualifier 
  5838.      _Export Keyword 
  5839.      __unaligned Type Qualifier 
  5840.      Declarations 
  5841.      Arrays 
  5842.      Enumerations 
  5843.      Pointers 
  5844.      Structures 
  5845.      Unions 
  5846.  
  5847.  
  5848. ΓòÉΓòÉΓòÉ <hidden> Declarator Syntax ΓòÉΓòÉΓòÉ
  5849.  
  5850. A declarator has the form: 
  5851.  
  5852.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5853.              Γöé
  5854. >>ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ>
  5855.    ΓööΓöÇ*ΓöÇΓöÿ  Γö£ΓöÇvolatileΓöÇΓöñ
  5856.        ΓööΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöÿ
  5857.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5858.                              Γöé
  5859. >ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ><
  5860.    ΓööΓöÇ(ΓöÇΓöÇdeclaratorΓöÇΓöÇ)ΓöÇΓöÿ  Γö£ΓöÇsubscript_declaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5861.               Γö£ΓöÇ(ΓöÇΓöÇparameter_type_listΓöÇΓöÇ)ΓöÇΓöñ
  5862.               ΓööΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  5863.                 ΓööΓöÇidentifierΓöÇΓöÿ
  5864.  
  5865. A qualifier is one of:  const, volatile or _Packed. The VisualAge for C++ 
  5866. compiler also implements the __unaligned qualifier. 
  5867.  
  5868. C++ Note:  C++ does not support the _Packed keyword. 
  5869.  
  5870. A declarator can contain a subdeclarator. A subdeclarator has the form: 
  5871.  
  5872. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>
  5873.   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé  ΓööΓöÇ(ΓöÇΓöÇsubdeclaratorΓöÇΓöÇ)ΓöÇΓöÿ
  5874.   Γöé          Γöé Γöé
  5875.   ΓööΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ*ΓöÇΓö┤ΓöÇΓöÿ
  5876.     Γö£ΓöÇvolatileΓöÇΓöñ
  5877.     ΓööΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöÿ
  5878. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  5879.   ΓööΓöÇsubscript_declaratorΓöÇΓöÿ
  5880.  
  5881. A subscript declarator describes the number of dimensions in an array and the 
  5882. number of elements in each dimension. A subscript declarator has the form: 
  5883.  
  5884. >>ΓöÇΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  5885.     ΓööΓöÇconstant_expressionΓöÇΓöÿ   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  5886.                   Γöé               Γöé Γöé
  5887.                   ΓööΓöÇΓöÇΓöÇ[ΓöÇΓöÇconstant_expressionΓöÇΓöÇ]ΓöÇΓö┤ΓöÇΓöÿ
  5888.  
  5889.  
  5890. ΓòÉΓòÉΓòÉ 4.6.1. volatile and const Qualifiers ΓòÉΓòÉΓòÉ
  5891.  
  5892. The volatile qualifier maintains consistency of memory access to data objects. 
  5893. It tells the compiler that the variable should always contain its current value 
  5894. even when optimized, so that the variable can be queried when an exception 
  5895. occurs. Volatile objects are read from memory each time their value is needed, 
  5896. and written back to memory each time they are changed. 
  5897.  
  5898. The volatile qualifier is useful for data objects having values that may be 
  5899. changed in ways unknown to your program (such as the system clock). Objects 
  5900. referenced by multiple threads or by signal handlers should also be qualified 
  5901. as volatile. Portions of an expression that reference volatile objects are not 
  5902. to be changed or removed. 
  5903.  
  5904. The const qualifier explicitly declares a data object as a data item that 
  5905. cannot be changed. Its value is set at initialization. You cannot use const 
  5906. data objects in expressions requiring a modifiable lvalue. For example, a const 
  5907. data object cannot appear on the left-hand side of an assignment statement. 
  5908.  
  5909. These type qualifiers are only meaningful in expressions that are lvalues. 
  5910.  
  5911. For a volatile or const pointer, you must put the keyword between the * and the 
  5912. identifier. For example: 
  5913.  
  5914. int * volatile x;     /* x is a volatile pointer to an int */
  5915. int * const y = &z;    /* y is a const pointer to the int variable z */
  5916.  
  5917. For a pointer to a volatile or const data object, the type specifier, 
  5918. qualifier, and storage class specifier can be in any order. For example: 
  5919.  
  5920. volatile int *x;     /* x is a pointer to a volatile int  */
  5921.  or
  5922. int volatile *x;     /* x is a pointer to a volatile int  */
  5923.  
  5924. const int *y;       /* y is a pointer to a const int  */
  5925.  or
  5926. int const *y;       /* y is a pointer to a const int  */
  5927.  
  5928. In the following example, the pointer to y is a constant. You can change the 
  5929. value that y points to, but you cannot change the value of y: 
  5930.  
  5931. int * const y
  5932.  
  5933. In the following example, the value that y points to is a constant integer and 
  5934. cannot be changed. However, you can change the value of y: 
  5935.  
  5936. const int * y
  5937.  
  5938. For other types of volatile and const variables, the position of the keyword 
  5939. within the definition (or declaration) is less important. For example: 
  5940.  
  5941. volatile struct omega {
  5942.              int limit;
  5943.              char code;
  5944.            } group;
  5945.  
  5946. provides the same storage as: 
  5947.  
  5948. struct omega {
  5949.         int limit;
  5950.         char code;
  5951.        } volatile group;
  5952.  
  5953. In both examples, only the structure variable group receives the volatile 
  5954. qualifier. Similarly, if you specified the const keyword instead of volatile, 
  5955. only the structure variable group receives the const qualifier. The const and 
  5956. volatile qualifiers when applied to a structure, union, or class also apply to 
  5957. the members of the structure, union, or class. 
  5958.  
  5959. Although enumeration, structure, and union variables can receive the volatile 
  5960. or const qualifier, enumeration, structure, and union tags do not carry the 
  5961. volatile or const qualifier. For example, the blue structure does not carry the 
  5962. volatile qualifier: 
  5963.  
  5964. volatile struct whale {
  5965.               int weight;
  5966.               char name[8];
  5967.            } beluga;
  5968. struct whale blue;
  5969.  
  5970. The keywords volatile and const cannot separate the keywords enum, struct, and 
  5971. union from their tags. 
  5972.  
  5973. You can declare or define a volatile or const function only if it is a C++ 
  5974. member function. You can define or declare any function to return a pointer to 
  5975. a volatile or const function. 
  5976.  
  5977. You can put more than one qualifier on a declaration but you cannot specify the 
  5978. same qualifier more than once on a declaration. 
  5979.  
  5980. Related Information 
  5981.  
  5982.      Declarators 
  5983.      _Packed Qualifier 
  5984.      __unaligned Type Qualifier 
  5985.      Type Specifiers 
  5986.      Structures 
  5987.      Unions 
  5988.      Enumerations 
  5989.      Pointers 
  5990.      lvalues 
  5991.  
  5992.  
  5993. ΓòÉΓòÉΓòÉ 4.6.2. _Packed Qualifier ΓòÉΓòÉΓòÉ
  5994.  
  5995. The _Packed qualifier removes padding between members of structures and affects 
  5996. the alignment of unions whenever possible. However, the storage saved using 
  5997. packed structures and unions may come at the expense of runtime performance. 
  5998. Most machines access data more efficiently if it is aligned on appropriate 
  5999. boundaries. With packed structures and unions, members are generally not 
  6000. aligned on natural boundaries, and the result is that member-accessing 
  6001. operations (using the . and -> operators) are slower. 
  6002.  
  6003. _Packed can only be used with structures or unions. If you use _Packed with 
  6004. other types, an error message is generated and the qualifier has no effect on 
  6005. the declarator it qualifies. Packed and nonpacked structures and unions have 
  6006. different storage layouts. Comparisons between packed and nonpacked structures 
  6007. or unions of the same type are prohibited. 
  6008.  
  6009. If you specify the _Packed qualifier on a structure or union that contains a 
  6010. structure or union as a member, the qualifier is not passed on to the contained 
  6011. structure or union. 
  6012.  
  6013. The VisualAge for C++ compiler also lets you pack structures using the #pragma 
  6014. pack directive or the /Sp option. 
  6015.  
  6016. C++ Note:  C++ does not support the _Packed keyword. Use the #pragma pack 
  6017. directive or the /Sp compiler option to control the alignment of structures and 
  6018. unions. 
  6019.  
  6020. Related Information 
  6021.  
  6022.      #pragma pack 
  6023.      /Sp option 
  6024.      Declarators 
  6025.      volatile and const Qualifiers 
  6026.      __unaligned Type Qualifier 
  6027.      _Export Keyword 
  6028.      _Import Keyword 
  6029.      Type Specifiers 
  6030.      Structures 
  6031.      Unions 
  6032.  
  6033.  
  6034. ΓòÉΓòÉΓòÉ <hidden> Examples of Declarators ΓòÉΓòÉΓòÉ
  6035.  
  6036. The following table describes some declarators: 
  6037.  
  6038.  Example         Description 
  6039.  
  6040.  int owner       owner is an int data object. 
  6041.  
  6042.  int *node       node is a pointer to an int data object. 
  6043.  
  6044.  int names[126]  names is an array of 126 int elements. 
  6045.  
  6046.  int *action( )  action is a function returning a pointer to an int. 
  6047.  
  6048.  volatile int min min is an int that has the volatile 
  6049.  
  6050.  int * volatile volume volume is a volatile pointer to an int. 
  6051.  
  6052.  volatile int * next next is a pointer to a volatile int 
  6053.  
  6054.  volatile int * sequence[5] sequence is an array of five pointers to volatile 
  6055.                  int objects. 
  6056.  
  6057.  extern const volatile int op_system_clock op_system_clock is an extern int 
  6058.                  that has the volatile attribute. 
  6059.  
  6060.  
  6061. ΓòÉΓòÉΓòÉ 4.6.3. __unaligned Type Qualifier ΓòÉΓòÉΓòÉ
  6062.  
  6063. In most cases, data is aligned along the natural boundaries of the machine 
  6064. word. On some architectures, when data is not natuarally aligned, the operating 
  6065. system generates an exception. In order to minimize unaligned data access 
  6066. exceptions for objects that you know will not be naturally aligned, use the 
  6067. __unaligned type qualifier. 
  6068.  
  6069. The __unaligned qualifier can only be used with pointers or typedefs. 
  6070.  
  6071. The following are valid declarations with the __unaligned qualifier: 
  6072.  
  6073. // These are just the declaration examples from the feature.
  6074. // A more extensive example would be nice.
  6075.  
  6076. __unaligned int *pegasus;
  6077. int * __unaligned *jupiter;
  6078. typedef unaligned float flt_type;
  6079. __unaligned struct *oscar;
  6080. __unaligned _Packed struct *oscar; //redundant, see note
  6081.  
  6082. Note:  You do not need to use the __unaligned qualifier for packed structures, 
  6083. unions, and classes, because the _Packed qualifier or #pragma pack specifies 
  6084. the alignment of aggregates and their members. 
  6085.  
  6086. In declarations that are not typedefs, the __unaligned qualifier is bound to 
  6087. the type that is pointed to, not the pointer. The following declarations with 
  6088. the __unaligned qualifier are not valid: 
  6089.  
  6090. __unaligned int othneilia;
  6091. int * __unaligned camptosaur;
  6092. __unaligned struct troodon { /* ... */ } baryonyx;
  6093.  
  6094. Related Information 
  6095.  
  6096.      Pointers 
  6097.      Declarators 
  6098.      volatile and const Qualifiers 
  6099.      _Packed Qualifier 
  6100.      Structures 
  6101.      Unions 
  6102.  
  6103.  
  6104. ΓòÉΓòÉΓòÉ 4.6.4. _Export Keyword ΓòÉΓòÉΓòÉ
  6105.  
  6106. Use the _Export keyword with a function name or external variable to declare 
  6107. that the function or variable is to be exported; that is, made available to 
  6108. other modules. For example: 
  6109.  
  6110.   int _Export anthony(float);
  6111.  
  6112. causes the function anthony to be exported if it is defined within the 
  6113. compilation unit. The function must be defined in the same compilation unit in 
  6114. which the _Export keyword is used. 
  6115.  
  6116. _Export is allowed only at file scope. It is not allowed in a declaration that 
  6117. already contains _Import, and it cannot be used in a typedef. The _Export 
  6118. keyword cannot be applied to the return type of a function. For example, the 
  6119. declaration 
  6120.  
  6121.   int _Export * a(); // error
  6122.  
  6123. causes an error. 
  6124.  
  6125. If the _Export keyword is repeated in a declaration, a warning is issued when 
  6126. the /Wgen option is specified. If a name is redeclared with conflicting _Export 
  6127. or _Import qualifiers, an error message is issued. 
  6128.  
  6129. Since _Export is part of the declarator, it affects only the closest 
  6130. identifier. In the declaration 
  6131.  
  6132.   int _Export a, b;
  6133.  
  6134. _Export only modifies a. 
  6135.  
  6136. You can use _Export at any language level. 
  6137.  
  6138. If you also use linkage keywords, you can place _Export either before or after 
  6139. a linkage keyword. For example, both of the following declarations are valid: 
  6140.  
  6141.   int _Export _Optlink brian(int);
  6142.   int _Optlink _Export brian(int);
  6143.  
  6144. You can also mark exports with the #pragma export directive or the 
  6145. __declspec(dllexport) construct. 
  6146.  
  6147. Thread-local data cannot be imported or exported. 
  6148.  
  6149. If you use _Export to export your function, you may still need to provide an 
  6150. EXPORTS entry for that function in your module definition (.DEF) file. If your 
  6151. function has any of the following default characteristics 
  6152.  
  6153.      Has shared data 
  6154.      Has no I/O privileges 
  6155.      Is not resident 
  6156.  
  6157.  it does not require an EXPORTS entry. If your function has characteristics 
  6158.  other than the defaults, the only way you can specify them is with an EXPORTS 
  6159.  entry in your .DEF file. 
  6160.  
  6161.  Note:  To create an import library for the DLL, and you are not passing 
  6162.  objects to ILIB, you must provide a .DEF file with an EXPORTS entry for every 
  6163.  function. You can create the .DEF file from the DLL itself. The description of 
  6164.  ILIB in the IBM VisualAge for C++ for Windows User's Guide describes how to do 
  6165.  this. 
  6166.  
  6167.  No .DEF file is needed if you use _Export on all exports and the object files 
  6168.  are passed to the ILIB program. 
  6169.  
  6170.  For more information on DLLs, .DEF files, and exporting functions, see the IBM 
  6171.  VisualAge for C++ for Windows Programming Guide. 
  6172.  
  6173.  Related Information 
  6174.  
  6175.      #pragma export 
  6176.      #pragma import 
  6177.      Declarators 
  6178.      volatile and const Qualifiers 
  6179.      _Packed Qualifier 
  6180.      __unaligned Type Qualifier 
  6181.      __thread Keyword 
  6182.      __declspec Keyword 
  6183.      Assembler Declarations (asm Keyword) 
  6184.      _asm and __asm Keywords 
  6185.  
  6186.  
  6187. ΓòÉΓòÉΓòÉ 4.6.5. _Import Keyword ΓòÉΓòÉΓòÉ
  6188.  
  6189. Use the _Import keyword with a function name or external variable to declare 
  6190. that the function or variable is to be imported from a DLL. For example: 
  6191.  
  6192.   int _Import anthony(float);
  6193.  
  6194. causes the function anthony to be imported. You must mark data imports by 
  6195. _Import or __declspec(dllimport). Code is generated more efficiently if you 
  6196. also mark function imports this way. 
  6197.  
  6198. Thread-local data cannot be imported or exported. 
  6199.  
  6200. _Import is allowed at file scope and at block scope with the extern storage 
  6201. class specifier. It is not allowed in a declaration that already contains 
  6202. _Export, and it cannot be used in a typedef. _Import is not allowed on a 
  6203. defined external. The following declaration gives an error: 
  6204.  
  6205.   int _Import jill = 0;
  6206.  
  6207. An external pointer cannot be initialized with the address of an imported C 
  6208. variable. This is allowed in C++. Both C and C++ allow a function pointer to be 
  6209. statically initialized to the address of an imported function. 
  6210.  
  6211. If the _Import keyword is repeated in a declaration, a warning is issued when 
  6212. the /Wgen option is specified. If a name is redeclared with conflicting _Import 
  6213. or _Export qualifiers, an error message is issued. If _Import is specified and 
  6214. the variable is defined later, _Export is assumed, and a warning is issued if 
  6215. the /Wdcl option is specified. For example: 
  6216.  
  6217.   extern int _Import joe;
  6218.   int joe; // Warning issued with /Wdcl and joe is exported
  6219.  
  6220. Since _Import is part of the declarator, it affects only the closest 
  6221. identifier. In the declaration 
  6222.  
  6223.   int _Import a, b;
  6224.  
  6225. _Import only modifies a. 
  6226.  
  6227. You can use _Import at any language level. 
  6228.  
  6229. If you also use linkage keywords, you can place _Import either before or after 
  6230. a linkage keyword. For example, both of the following declarations are valid: 
  6231.  
  6232.   int _Import _Optlink brian(int);
  6233.   int _Optlink _Import brian(int);
  6234.  
  6235. For more information on DLLs and importing functions see the IBM VisualAge for 
  6236. C++ for Windows Programming Guide. 
  6237.  
  6238. Related Information 
  6239.  
  6240.      #pragma export 
  6241.      #pragma import 
  6242.      Declarators 
  6243.      volatile and const Qualifiers 
  6244.      _Packed Qualifier 
  6245.      _Export Keyword 
  6246.      __thread Keyword 
  6247.      __declspec Keyword 
  6248.  
  6249.  
  6250. ΓòÉΓòÉΓòÉ 4.6.6. __thread Keyword ΓòÉΓòÉΓòÉ
  6251.  
  6252. Use the __thread keyword with an external variable to allow each thread in 
  6253. multi-threaded process to allocate storage for its corresponding data. This 
  6254. storage is referred to as thread-local storage (TLS). 
  6255.  
  6256. Defining and initializing thread-local storage data is similar to defining and 
  6257. initializing ordinary static variables. 
  6258.  
  6259. Thread-local storage data objects are declared with the __thread keyword, which 
  6260. can apply to three kinds of data: 
  6261.  
  6262.      Global data objects (static and extern) 
  6263.      Local static data objects 
  6264.      Static data members of a class 
  6265.  
  6266.  Thread-local data cannot be imported or exported. 
  6267.  
  6268.  Refer to the IBM VisualAge for C++ for Windows Programming Guide for a full 
  6269.  description of using thread-local storage. 
  6270.  
  6271.  The #pragma data_seg directive does not affect the thread-local storage data 
  6272.  segment. 
  6273.  
  6274.  Thread-local storage objects can also be declared with the __declspec keyword. 
  6275.  For example, 
  6276.  
  6277.     __declspec(thread) int tls_i;
  6278.  
  6279.  is equivalent to: 
  6280.  
  6281.     __thread int tls_i;
  6282.  
  6283.  C++ Note:  In C++, for a given thread: 
  6284.  
  6285.      Each time a thread is created, the constructor of the thread object is 
  6286.       called. 
  6287.      Each time a thread is terminated, the destructor of the thread object is 
  6288.       called. 
  6289.  
  6290.  Related Information 
  6291.  
  6292.      extern Storage Class Specifier 
  6293.      static Storage Class Specifier 
  6294.      Declarators 
  6295.      volatile and const Qualifiers 
  6296.      _Packed Qualifier 
  6297.      _Export Keyword 
  6298.      _Import Keyword 
  6299.      __declspec Keyword 
  6300.  
  6301.  
  6302. ΓòÉΓòÉΓòÉ 4.6.7. __declspec Keyword ΓòÉΓòÉΓòÉ
  6303.  
  6304. Use the __declspec keyword to declare imported or exported functions and 
  6305. variables, or to declare thread-local storage (TLS) objects. 
  6306.  
  6307. The __declspec keyword is allowed anywhere in the declaration specifier. It is 
  6308. used with the following sub-specifiers: 
  6309.  
  6310.  dllexport   Declares that the function or variable is to be exported; that is, 
  6311.              made available to other modules. __declspec(dllexport) is 
  6312.              equivalent to the _Export specifier, described in _Export Keyword. 
  6313.  
  6314.  dllimport   Declares that the function or variable is to be imported from a 
  6315.              DLL. __declspec(dllimport) is equivalent to the _Import specifier, 
  6316.              described in _Import Keyword. 
  6317.  
  6318.              __declspec(dllimport) implies extern. For example, the declaration 
  6319.              int __declspec(dllimport) b; is equivalent to extern int 
  6320.              __declspec(dllimport) b; You must mark data imports by _Import or 
  6321.              __declspec(dllimport). Code is generated more efficiently if you 
  6322.              also mark function imports this way. 
  6323.  
  6324.  thread      Declares thread-local storage variables, which allow each thread 
  6325.              in multi-threaded process to allocate storage for its 
  6326.              corresponding data. __declspec(thread) is equivalent to the 
  6327.              __thread specifier, described in __thread Keyword. 
  6328.  
  6329.  Only __declspec (and _declspec) are keywords; the sub-specifiers are not. 
  6330.  
  6331.  In the following declaration, function a() is exported: 
  6332.  
  6333.     int __declspec(dllexport) * a();
  6334.  
  6335.  Unlike _Export and _Import, which are part of the declarator, 
  6336.  __declspec(dllexport) applies to the entire declaration list. In the following 
  6337.  declaration, __declspec(dllexport) applies to both a and b: 
  6338.  
  6339.     __declspec(dllexport) int a, b;
  6340.  
  6341.  The __declspec construct is not allowed in a typedef. 
  6342.  
  6343.  The address of a name imported with __declspec(dllimport) is not considered a 
  6344.  constant; any expression involving such an address is not a constant 
  6345.  expression. 
  6346.  
  6347.  An external pointer cannot be initialized with the address of an imported C 
  6348.  variable. This is allowed in C++. Both C and C++ allow a function pointer to 
  6349.  be statically initialized to the address of an imported function. 
  6350.  
  6351.  Note:  The Microsoft Visual C++ sub-specifier naked is not supported by 
  6352.  VisualAge for C++. A warning is issued if it is used. 
  6353.  
  6354.  Related Information 
  6355.  
  6356.      Declarators 
  6357.      volatile and const Qualifiers 
  6358.      _Packed Qualifier 
  6359.      _Export Keyword 
  6360.      _Import Keyword 
  6361.      __thread Keyword 
  6362.      #pragma export 
  6363.  
  6364.  
  6365. ΓòÉΓòÉΓòÉ 4.7. Initializers ΓòÉΓòÉΓòÉ
  6366.  
  6367. An initializer is an optional part of a data declaration that specifies an 
  6368. initial value of a data object. 
  6369.  
  6370. Syntax of an Initializer 
  6371.  
  6372. The initializer consists of the = symbol followed by an initial expression or a 
  6373. braced list of initial expressions separated by commas. The number of 
  6374. initializers must not be more than the number of elements to be initialized. An 
  6375. initializer list with fewer initializers than elements, can end with a comma, 
  6376. indicating that the rest of the uninitialized elements are initialized to zero. 
  6377. The initial expression evaluates to the first value of the data object. 
  6378.  
  6379. To assign a value to a scalar object, use the simple initializer: = expression. 
  6380. For example, the following data definition uses the initializer = 3 to set the 
  6381. initial value of group to 3: 
  6382.  
  6383. int group = 3;
  6384.  
  6385. For unions, structures, and aggregate classes (classes with no constructors, 
  6386. base classes, virtual functions, or private or protected members), the set of 
  6387. initial expressions must be enclosed in { } (braces) unless the initializer is 
  6388. a string literal. 
  6389.  
  6390. If the initializer of a character string is a string literal, the { } are 
  6391. optional. Individual expressions must be separated by commas, and groups of 
  6392. expressions can be enclosed in braces and separated by commas. 
  6393.  
  6394. In an array, structure, or union initialized using a brace-enclosed initializer 
  6395. list, any members or subscripts that are not initialized are implicitly 
  6396. initialized to zero of the appropriate type. 
  6397.  
  6398. The initialization properties of each data type are described in the section 
  6399. for that data type. 
  6400.  
  6401. Note: 
  6402.  
  6403.    1. An initializer of the form (expression) can be used to initialize 
  6404.       fundamental types in C++. For example, the following two initializations 
  6405.       are identical: 
  6406.  
  6407.             int group = 3;
  6408.             int group(3);
  6409.  
  6410.    2. You can also use the (expression) form to initialize C++ classes. For 
  6411.       more information on initializing classes, see Initialization by 
  6412.       Constructor. 
  6413.  
  6414.    3. You can initialize variables at file scope with nonconstant expressions. 
  6415.       This is not allowed in ANSI/ISO C. 
  6416.  
  6417.    4. If your code jumps over declarations that contain initializations, the 
  6418.       compiler generates an error. For example, the following code is not valid 
  6419.       in C++: 
  6420.  
  6421.             goto skiplabel;   // error - jumped over declaration
  6422.             int i = 3;     //  and initialization of i
  6423.  
  6424.             skiplabel: i = 4;
  6425.  
  6426.    5. You can initialize classes in external, static, and automatic 
  6427.       definitions. The initializer contains an = (equal sign) followed by a 
  6428.       brace-enclosed, comma-separated list of values. You do not need to 
  6429.       initialize all members of a class. 
  6430.  
  6431.  In the following example, only the first eight elements of the array grid are 
  6432.  explicitly initialized. The remaining four elements that are not explicitly 
  6433.  initialized are initialized as if they were explicitly initialized to zero. 
  6434.  
  6435.   static short grid[3] [4] = {0, 0, 0, 1, 0, 0, 1, 1};
  6436.  
  6437.  The initial values of grid are: 
  6438.  
  6439.  Element               Value 
  6440.  grid[0][0]            0 
  6441.  grid[0][1]            0 
  6442.  grid[0][2]            0 
  6443.  grid[0][3]            1 
  6444.  grid[1][0]            0 
  6445.  grid[1][1]            0 
  6446.  grid[1][2]            1 
  6447.  grid[1][3]            1 
  6448.  grid[2][0]            0 
  6449.  grid[2][1]            0 
  6450.  grid[2][2]            0 
  6451.  grid[2][3]            0 
  6452.  
  6453.  Related Information 
  6454.  
  6455.      Block Scope Data Declarations 
  6456.      File Scope Data Declarations 
  6457.      Arrays 
  6458.      Characters 
  6459.      Enumerations 
  6460.      Floating-Point Variables 
  6461.      Integer Variables 
  6462.      Pointers 
  6463.      Structures 
  6464.      Unions 
  6465.  
  6466.  
  6467. ΓòÉΓòÉΓòÉ <hidden> Initializer Syntax ΓòÉΓòÉΓòÉ
  6468.  
  6469. An initializer has the form: 
  6470.  
  6471.     ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  6472.            Γöé
  6473. >>ΓöÇΓöÇΓö¼ΓöÇ(ΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  6474.   ΓööΓöÇ=ΓöÇΓöÇΓö¼ΓöÇexpressionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  6475.      Γöé    ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ         Γöé
  6476.      Γöé           Γöé         Γöé
  6477.      ΓööΓöÇ{ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ}ΓöÇΓöÿ
  6478.        Γöé ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  6479.        Γöé Γöé   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé Γöé
  6480.        Γöé           Γöé   Γöé Γöé
  6481.        ΓööΓöÇΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓö┤ΓöÇΓöÿ
  6482.  
  6483. The form (expression) is allowed in C++ only. 
  6484.  
  6485.  
  6486. ΓòÉΓòÉΓòÉ 4.8. Function Specifiers ΓòÉΓòÉΓòÉ
  6487.  
  6488. The function specifiers inline and virtual are used only in C++ function 
  6489. declarations, which are described on page Function Declarations. 
  6490.  
  6491. The function specifier inline is used to make a suggestion to the compiler to 
  6492. incorporate the code of a function into the code at the point of the call. For 
  6493. more information, see Inline Functions. 
  6494.  
  6495. The function specifier virtual can only be used in nonstatic member function 
  6496. declarations. For more information, see Virtual Functions. 
  6497.  
  6498.  
  6499. ΓòÉΓòÉΓòÉ 4.9. References ΓòÉΓòÉΓòÉ
  6500.  
  6501. A C++ reference is an alias or an alternative name for an object. All 
  6502. operations applied to a reference act on the object the reference refers to. 
  6503. The address of a reference is the address of the aliased object. 
  6504.  
  6505. A reference type is defined by placing the & after the type specifier. You must 
  6506. initialize all references except function parameters when they are defined. 
  6507.  
  6508. Because arguments of a function are passed by value, a function call does not 
  6509. modify the actual values of the arguments. If a function needs to modify the 
  6510. actual value of an argument, the argument must be passed by reference (as 
  6511. opposed to being passed by value). Passing arguments by reference can be done 
  6512. using either references or pointers. In C++, this is accomplished 
  6513. transparently. Unlike C, C++ does not force you to use pointers if you want to 
  6514. pass arguments by reference. For example: 
  6515.  
  6516. int f(int&);
  6517. void main()
  6518. {
  6519.    extern int i;
  6520.    f(i);
  6521. }
  6522.  
  6523. You cannot tell from the function call f(i) that the argument is being passed 
  6524. by reference. 
  6525.  
  6526. References to NULL are not allowed. 
  6527.  
  6528. Additional information is provided on Initializing References. 
  6529.  
  6530. Related Information 
  6531.  
  6532.      Passing Arguments by Reference 
  6533.      Pointers 
  6534.      Declarators 
  6535.      Initializers 
  6536.  
  6537.  
  6538. ΓòÉΓòÉΓòÉ <hidden> Initializing References ΓòÉΓòÉΓòÉ
  6539.  
  6540. The object that you use to initialize a reference must be of the same type as 
  6541. the reference, or it must be of a type that is convertible to the reference 
  6542. type. If you initialize a reference to a constant using an object that requires 
  6543. conversion, a temporary object is created. In the following example, a 
  6544. temporary object of type float is created: 
  6545.  
  6546. int i;
  6547. const float& f = i; // reference to a constant float
  6548.  
  6549. Attempting to initialize a nonconstant reference with an object that requires a 
  6550. conversion is an error. 
  6551.  
  6552. Once a reference has been initialized, it cannot be modified to refer to 
  6553. another object. For example: 
  6554.  
  6555. int num1 = 10;
  6556. int num2 = 20;
  6557.  
  6558. int &RefOne = num1;     // valid
  6559. int &RefOne = num2;     // error, two definitions of RefOne
  6560. RefOne = num2;        // assign num2 to num1
  6561. int &RefTwo;         // error, uninitialized reference
  6562. int &RefTwo = num2;     // valid
  6563.  
  6564. Note that the initialization of a reference is not the same as an assignment to 
  6565. a reference. Initialization operates on the actual reference by initializing 
  6566. the reference with the object it is an alias for. Assignment operates through 
  6567. the reference on the object referred to. 
  6568.  
  6569. A reference can be declared without an initializer: 
  6570.  
  6571.      When it is used in an argument declaration 
  6572.      In the declaration of a return type for a function call 
  6573.      In the declaration of class member within its class declaration 
  6574.      When the extern specifier is explicitly used. 
  6575.  
  6576.  You cannot have references to any of: 
  6577.  
  6578.      Other references 
  6579.      Bit fields 
  6580.      Arrays of references 
  6581.      Pointers to references 
  6582.  Additional information is provided on Initializing References. 
  6583.  
  6584.  Related Information 
  6585.  
  6586.      Passing Arguments by Reference 
  6587.      Pointers 
  6588.      Declarators 
  6589.      Initializers 
  6590.      Temporary Objects 
  6591.  
  6592.  
  6593. ΓòÉΓòÉΓòÉ 4.10. Assembler Declarations (asm Keyword) ΓòÉΓòÉΓòÉ
  6594.  
  6595. The asm keyword is used to pass information through the compiler to the 
  6596. assembler. An asm declaration has the form: 
  6597.  
  6598. >>ΓöÇΓöÇasmΓöÇΓöÇ(ΓöÇΓöÇstring_literalΓöÇΓöÇ)ΓöÇΓöÇ;ΓöÇΓöÇ><
  6599.  
  6600. The string_literal can be any arbitrary text. 
  6601.  
  6602. Note:  The asm keyword is recognized by VisualAge for C++, but no code is 
  6603. generated for the inlined assembler instructions. 
  6604.  
  6605. For example, the compiler accepts the string literal in the following asm 
  6606. declaration, but a warning is issued: 
  6607.  
  6608.  asm (VULTURES ARE COWARDLY AND SUPERSTITIOUS);
  6609.  
  6610. Valid assembler instructions are also permitted, but no code is generated: 
  6611.  
  6612.  asm (mov ax, bx __asm mov bx, ax __asm mov ax, bx);
  6613.  
  6614.  
  6615. ΓòÉΓòÉΓòÉ 5. Expressions and Operators ΓòÉΓòÉΓòÉ
  6616.  
  6617. Expressions are sequences of operators, operands, and punctuators that specify 
  6618. a computation. The evaluation of expressions is based on the operators that the 
  6619. expressions contain and the context in which they are used. 
  6620.  
  6621. This section discusses: 
  6622.  
  6623.      Primary Expressions 
  6624.      Unary Expressions 
  6625.      Binary Expressions 
  6626.      Conditional Expressions 
  6627.      Assignment Expressions 
  6628.      Comma Expression  , 
  6629.      lvalues 
  6630.      Constant Expressions 
  6631.  
  6632.  An expression can result in an lvalue, rvalue, or no value, and can produce 
  6633.  side effects in each case. 
  6634.  
  6635.  C++ Note:  C++ operators can be defined to behave differently when applied to 
  6636.  operands of class type. This is called operator overloading. This section 
  6637.  describes the behavior of operators that are not overloaded. The C language 
  6638.  does not permit overloading. 
  6639.  
  6640.  Related Information 
  6641.  
  6642.      Declarations 
  6643.      Overloading Operators 
  6644.  
  6645.  
  6646. ΓòÉΓòÉΓòÉ 5.1. Operator Precedence and Associativity ΓòÉΓòÉΓòÉ
  6647.  
  6648. Two operator characteristics determine how operands group with operators: 
  6649. precedence and associativity. Precedence is the priority for grouping different 
  6650. types of operators with their operands. Associativity is the left-to-right or 
  6651. right-to-left order for grouping operands to operators that have the same 
  6652. precedence. 
  6653.  
  6654. For example, in the following statements, the value of 5 is assigned to both a 
  6655. and b because of the right-to-left associativity of the = operator. The value 
  6656. of c is assigned to b first, and then the value of b is assigned to a. 
  6657.  
  6658. b = 9;
  6659. c = 5;
  6660. a = b = c;
  6661.  
  6662. Because the order of subexpression evaluation is not specified, you can 
  6663. explicitly force the grouping of operands with operators by using parentheses. 
  6664.  
  6665. In the expression a + b * c / d, the * and / operations are performed before + 
  6666. because of precedence. b is multiplied by c before it is divided by d because 
  6667. of associativity. 
  6668.  
  6669. Table of Operator Precedence and Associativity lists the C and C++ language 
  6670. operators in order of precedence and shows the direction of associativity for 
  6671. each operator. In C++, the primary scope resolution operator (::) has the 
  6672. highest precedence, followed by the other primary operators. In C, because 
  6673. there is no scope resolution operator, the other primary operators have the 
  6674. highest precedence. The comma operator has the lowest precedence. Operators 
  6675. that appear in the same group have the same precedence. 
  6676.  
  6677. The order of evaluation for function call arguments or for the operands of 
  6678. binary operators is not specified. Avoid writing such ambiguous expressions as: 
  6679.  
  6680. z = (x * ++y) / func1(y);
  6681. func2(++i, x[i]);
  6682.  
  6683. In the example above, the order of evaluation of ++y and func1(y) is not 
  6684. defined. If y had the value of 1 before the first statement, it is not known 
  6685. whether or not the value of 1 or 2 is passed to func1(). In the second 
  6686. statement, if i had the value of 1, it is not known whether the first or second 
  6687. array element of x[ ] is passed as the second argument to func2(). Do not write 
  6688. code that depends on a particular order of evaluation of operators with the 
  6689. same precedence. 
  6690.  
  6691. The order of grouping operands with operators in an expression containing more 
  6692. than one instance of an operator with both associative and commutative 
  6693. properties is not specified. The operators that have the same associative and 
  6694. commutative properties are:  *, +, &, |, and ^ (or ╨║). The grouping of operands 
  6695. can be forced by grouping the expression in parentheses. 
  6696.  
  6697. Examples of Expressions and Precedence 
  6698.  
  6699. Related Information 
  6700.  
  6701.      Parenthesized Expressions ( ) 
  6702.      Expressions and Operators 
  6703.      Table of Operator Precedence and Associativity 
  6704.  
  6705.  
  6706. ΓòÉΓòÉΓòÉ <hidden> Examples of Expressions and Precedence ΓòÉΓòÉΓòÉ
  6707.  
  6708. The parentheses in the following expressions explicitly show how the compiler 
  6709. groups operands and operators. If parentheses did not appear in these 
  6710. expressions, the operands and operators are grouped in the same manner as 
  6711. indicated by the parentheses. 
  6712.  
  6713. total = (4 + (5 * 3));
  6714. total = (((8 * 5) / 10) / 3);
  6715. total = (10 + (5/3));
  6716.  
  6717. Because the order of grouping operands with operators that are both associative 
  6718. and commutative is not specified, the compiler can group the operands and 
  6719. operators in the expression: 
  6720.  
  6721. total = price + prov_tax + city_tax;
  6722.  
  6723. in the following ways (as indicated by parentheses): 
  6724.  
  6725. total = (price + (prov_tax + city_tax));
  6726. total = ((price + prov_tax) + city_tax);
  6727. total = ((price + city_tax) + prov_tax);
  6728.  
  6729. If the values in this expression are integers, the grouping of operands and 
  6730. operators does not affect the result. Because intermediate values are rounded, 
  6731. different groupings of floating-point operators may give different results. 
  6732.  
  6733. In certain expressions, the grouping of operands and operators can affect the 
  6734. result. For example, in the following expression, each function call might be 
  6735. modifying the same global variables. 
  6736.  
  6737. a = b() + c() + d();
  6738.  
  6739. This expression can give different results depending on the order in which the 
  6740. functions are called. 
  6741.  
  6742. If the expression contains operators that are both associative and commutative 
  6743. and the order of grouping operands with operators can affect the result of the 
  6744. expression, separate the expression into several expressions. For example, the 
  6745. following expressions could replace the previous expression if the called 
  6746. functions do not produce any side effects that affect the variable a. 
  6747.  
  6748. a = b();
  6749. a += c();
  6750. a += d();
  6751.  
  6752. Integer overflows are ignored. Division by zero and floating-point exceptions 
  6753. are implementation dependent. 
  6754.  
  6755. See the IBM VisualAge for C++ for Windows User's Guide for information about 
  6756. VisualAge for C++ implementation dependencies. 
  6757.  
  6758.  
  6759. ΓòÉΓòÉΓòÉ <hidden> Table of Operator Precedence and Associativity ΓòÉΓòÉΓòÉ
  6760.  
  6761.  Operator Name           Operators 
  6762.  
  6763.  Primary scope resolution :: 
  6764.                             Associativity:  left to right 
  6765.  
  6766.  Primary                 ()  [ ]  .  ->  (type_name)
  6767.                             Associativity:  left to right 
  6768.  
  6769.  Unary                   ++  --  -  +  !  ~  &  *  sizeof  new  delete 
  6770.                          (typename) (C cast) 
  6771.                             Associativity:  right to left 
  6772.  
  6773.  C++ Cast                (typename) 
  6774.                             Associativity:  left to right 
  6775.  
  6776.  C++ Pointer to Member   .*  ->* 
  6777.                             Associativity:  left to right 
  6778.  
  6779.  Multiplicative          *  /  % 
  6780.                             Associativity:  left to right 
  6781.  
  6782.  Additive                +  - 
  6783.                             Associativity:  left to right 
  6784.  
  6785.  Bitwise Shift           <<  >> 
  6786.                             Associativity:  left to right 
  6787.  
  6788.  Relational              <  >  <=  >= 
  6789.                             Associativity:  left to right 
  6790.  
  6791.  Equality                ==  != 
  6792.                             Associativity:  left to right 
  6793.  
  6794.  Bitwise Logical AND     & 
  6795.                             Associativity:  left to right 
  6796.  
  6797.  Bitwise Exclusive OR    ^  or  ╨║ 
  6798.                             Associativity:  left to right 
  6799.  
  6800.  Bitwise Inclusive OR    | 
  6801.                             Associativity:  left to right 
  6802.  
  6803.  Logical AND             && 
  6804.                             Associativity:  left to right 
  6805.  
  6806.  Logical OR              || 
  6807.                             Associativity:  left to right 
  6808.  
  6809.  Conditional             ?  : 
  6810.                             Associativity:  right to left 
  6811.  
  6812.  Assignment              =  +=  -=  *=  /=  <<=  >>=  %=  &=  ^=  |= 
  6813.                             Associativity:  right to left 
  6814.  
  6815.  Comma                   , 
  6816.                             Associativity:  left to right 
  6817.  
  6818.  
  6819. ΓòÉΓòÉΓòÉ 5.2. Operands ΓòÉΓòÉΓòÉ
  6820.  
  6821. Most expressions can contain several different, but related, types of operands. 
  6822. The following type classes describe related types of operands: 
  6823.  
  6824.  Integral    Character objects and constants, objects having an enumeration 
  6825.              type, and objects having the type short, int, long, unsigned 
  6826.              short, unsigned int, unsigned long, long long, or unsigned long 
  6827.              long. 
  6828.  
  6829.  Arithmetic  Integral objects and objects having the type float, double, and 
  6830.              long double. 
  6831.  
  6832.  Scalar      Arithmetic objects and pointers to objects of any type. Also C++ 
  6833.              references. 
  6834.  
  6835.  Aggregate   Arrays, structures, and unions. Also C++ classes. 
  6836.  
  6837.  Many operators cause conversions from one data type to another. Conversions 
  6838.  are discussed in Implicit Type Conversions. 
  6839.  
  6840.  
  6841. ΓòÉΓòÉΓòÉ 5.3. lvalues ΓòÉΓòÉΓòÉ
  6842.  
  6843. An lvalue is an expression that represents an object that can be examined or 
  6844. changed. A modifiable lvalue is an expression representing an object that can 
  6845. be changed. It is typically the left operand in an assignment expression. For 
  6846. example, arrays and const objects are not modifiable lvalues, but static int 
  6847. objects are. 
  6848.  
  6849. All assignment operators evaluate their right operand and assign that value to 
  6850. their left operand. The left operand must evaluate to a reference to an object. 
  6851.  
  6852. The address operator (&) requires an lvalue as an operand while the increment 
  6853. (++) and the decrement (--) operators require a modifiable lvalue as an 
  6854. operand. 
  6855.  
  6856. Examples of Lvalues 
  6857.  
  6858. Related Information 
  6859.  
  6860.      Assignment Expressions 
  6861.      Address  & 
  6862.      Dot Operator . 
  6863.      Arrow Operator -> 
  6864.  
  6865.  
  6866. ΓòÉΓòÉΓòÉ <hidden> Examples of Lvalues ΓòÉΓòÉΓòÉ
  6867.  
  6868.  Expression               Lvalue 
  6869.  x = 42;                  x 
  6870.  *ptr = newvalue;         *ptr 
  6871.  a++                      a 
  6872.  
  6873.  
  6874. ΓòÉΓòÉΓòÉ 5.4. Primary Expressions ΓòÉΓòÉΓòÉ
  6875.  
  6876. A primary expression can be: 
  6877.  
  6878.      Identifiers 
  6879.      String Literals 
  6880.      C++ Scope Resolution Operator :: 
  6881.      Parenthesized Expressions ( ) 
  6882.      Constant Expressions 
  6883.      Function Calls ( ) 
  6884.      Array Subscript [ ] (Array Element Specification) 
  6885.      Dot Operator . 
  6886.      Arrow Operator -> 
  6887.      C++ Runtime Type Identification Operators 
  6888.  
  6889.  All primary operators have the same precedence and have left-to-right 
  6890.  associativity. 
  6891.  
  6892.  Related Information 
  6893.  
  6894.      Expressions and Operators 
  6895.      Operator Precedence and Associativity 
  6896.  
  6897.  
  6898. ΓòÉΓòÉΓòÉ 5.4.1. C++ Scope Resolution Operator :: ΓòÉΓòÉΓòÉ
  6899.  
  6900. The :: (scope resolution) operator is used to qualify hidden names so that you 
  6901. can still use them. You can use the unary scope operator if a file scope name 
  6902. is hidden by an explicit declaration of the same name in a block or class. For 
  6903. example: 
  6904.  
  6905. int i = 10;
  6906. int f(int i)
  6907. {
  6908.    return i ? i : :: i; // return global i if local i is zero
  6909. }
  6910.  
  6911. You can also use the class scope operator to qualify class names or class 
  6912. member names. If a class member name is hidden, you can use it by qualifying it 
  6913. with its class name and the class scope operator. Whenever a name is followed 
  6914. by a :: operator, the name is interpreted as a class name. 
  6915.  
  6916. In the following example, the declaration of the variable X hides the class 
  6917. type X, but you can still use the static class member count by qualifying it 
  6918. with the class type X and the scope resolution operator. 
  6919.  
  6920. #include <iostream.h>
  6921. class X
  6922. {
  6923. public:
  6924.    static int count;
  6925. };
  6926. int X::count = 10;         // define static data member
  6927. void main ()
  6928. {
  6929.    int X = 0;          // hides class type X
  6930.    cout << X::count << endl;  // use static member of class X
  6931. }
  6932.  
  6933. The scope resolution operator is also discussed in Class Names and in Scope of 
  6934. Class Names. 
  6935.  
  6936. Related Information 
  6937.  
  6938.      Class Names 
  6939.      Scope of Class Names 
  6940.      Expressions and Operators 
  6941.  
  6942.  
  6943. ΓòÉΓòÉΓòÉ 5.4.2. Parenthesized Expressions ( ) ΓòÉΓòÉΓòÉ
  6944.  
  6945. Use parentheses to explicitly force the order of expression evaluation. The 
  6946. following expression does not contain any parentheses used for grouping 
  6947. operands and operators. The parentheses surrounding weight, zipcode are used to 
  6948. form a function call. Note how the compiler groups the operands and operators 
  6949. in the expression according to the rules for operator precedence and 
  6950. associativity: 
  6951.  
  6952.  
  6953. -discount * item + handling(weight, zipcode) < .10 * item
  6954. |    |    |  |            |  |     |
  6955. '---.---'    |  '-----------.-----------'  '----.---'
  6956.   '----.-----'        |           |
  6957.      '----------.----------'           |
  6958.           '-------------------------------'
  6959.  
  6960. The following expression is similar to the previous expression, but it contains 
  6961. parentheses that change how the operands and operators are grouped: 
  6962.  
  6963.  
  6964. (-discount * (item + handling(weight, zipcode) ) ) < (.10 * item)
  6965.  |    |   |    |            |    |      |
  6966.  '---.---'   |    '----------.------------'    '-----.----'
  6967.    |     '--------.--------'              |
  6968.    '-------.---------'                  |
  6969.        '---------------------------------------------'
  6970.  
  6971. In an expression that contains both associative and commutative operators, you 
  6972. can use parentheses to specify the grouping of operands with operators. The 
  6973. parentheses in the following expression guarantee the order of grouping 
  6974. operands with the operators: 
  6975.  
  6976. x = f + (g + h);
  6977.  
  6978. Related Information 
  6979.  
  6980.      Operator Precedence and Associativity 
  6981.      Function Calls ( ) 
  6982.      Expressions and Operators 
  6983.  
  6984.  
  6985. ΓòÉΓòÉΓòÉ 5.4.3. Constant Expressions ΓòÉΓòÉΓòÉ
  6986.  
  6987. A constant expression is an expression with a value that may be determined 
  6988. during compilation and cannot be changed at runtime, it can only be evaluated. 
  6989. Constant expressions can be composed of integer constants, character constants, 
  6990. floating-point constants, and enumeration constants, address constants, and 
  6991. other constant expressions. Some constant expressions, such as a string literal 
  6992. or an address constant, are lvalues. 
  6993.  
  6994. The C and C++ languages require integral constant expressions in the following 
  6995. places: 
  6996.  
  6997.      In the subscript declarator, as the description of an array bound 
  6998.      After the keyword case in a switch statement 
  6999.      In an enumerator, as the numeric value of an enum constant 
  7000.      In a bit-field width specifier 
  7001.      In the preprocessor #if statement (Enumeration constants, address 
  7002.       constants, and sizeof cannot be specified in the preprocessor #if 
  7003.       statement.) 
  7004.      In the initializer of a file scope data definition. 
  7005.  
  7006.  In all these contexts except for an initializer of a file scope data 
  7007.  definition, the constant expression can contain integer, character, and 
  7008.  enumeration constants, casts to integral types, and sizeof expressions. 
  7009.  Function-scope static and extern declarations can be initialized with the 
  7010.  address of a previously defined static or extern. 
  7011.  
  7012.  In a file scope data definition, the initializer must evaluate to a constant 
  7013.  or to the address of a static storage (extern or static) object (plus or minus 
  7014.  an integer constant) that is defined or declared earlier in the file. The 
  7015.  constant expression in the initializer can contain: 
  7016.  
  7017.      integer, character, enumeration, and float constants 
  7018.      casts to any type 
  7019.      sizeof expressions 
  7020.      unary address expressions (static objects only) 
  7021.  
  7022.  Functions, class objects, pointers, and references are not allowed unless they 
  7023.  occur in sizeof expressions. Comma operators and assignment operators cannot 
  7024.  appear in constant expressions. 
  7025.  
  7026.  Examples of Constant Expressions 
  7027.  
  7028.  Related Information 
  7029.  
  7030.      Arrays 
  7031.      Initializers 
  7032.      File Scope Data Declarations 
  7033.      switch 
  7034.      Enumerations 
  7035.      Structures 
  7036.      Conditional Compilation Directives 
  7037.      sizeof (Size of an Object) 
  7038.  
  7039.  
  7040. ΓòÉΓòÉΓòÉ <hidden> Examples of Constant Expressions ΓòÉΓòÉΓòÉ
  7041.  
  7042. The following examples show constants used in expressions. 
  7043.  
  7044.  Expression                         Constant 
  7045.  x = 42;                            42 
  7046.  extern int cost = 1000;            1000 
  7047.  y = 3 * 29;                        3 * 29 
  7048.  
  7049.  
  7050. ΓòÉΓòÉΓòÉ 5.4.4. Function Calls ( ) ΓòÉΓòÉΓòÉ
  7051.  
  7052. A function call is a primary expression containing a simple type name and a 
  7053. parenthesized argument list. The argument list can contain any number of 
  7054. expressions separated by commas. It can also be empty. 
  7055.  
  7056. For example: 
  7057.  
  7058. stub()
  7059. overdue(account, date, amount)
  7060. notify(name, date + 5)
  7061. report(error, time, date, ++num)
  7062.  
  7063. The arguments are evaluated, and each formal parameter is initialized with the 
  7064. value of the corresponding argument. The semantics of argument passing are 
  7065. identical to those of assignment. Assigning a value to a formal parameter 
  7066. within the function body changes the value of the parameter within the 
  7067. function, but has no effect on the argument. 
  7068.  
  7069. The type of a function call expression is the return type of the function. The 
  7070. return value is determined by the return statement in the function definition. 
  7071. The result of a function call is an lvalue only if the function returns a 
  7072. reference. A function can call itself. 
  7073.  
  7074. If you want a function to change the value of a variable, pass a pointer to the 
  7075. variable you want changed. When a pointer is passed as a parameter, the pointer 
  7076. is copied; the object pointed to is not copied. (See Pointers.) 
  7077.  
  7078. Arguments that are arrays and functions are converted to pointers before being 
  7079. passed as function arguments. 
  7080.  
  7081. Arguments passed to nonprototyped C functions undergo conversions: type short 
  7082. or char parameters are converted to int, and float parameters to double. Use a 
  7083. cast expression for other conversions. (See Cast Expressions.) 
  7084.  
  7085. In C only, if a function definition has external linkage and a return type of 
  7086. int, calls to the function can be made before it is explicitly declared because 
  7087. an implicit declaration of extern int func(); is assumed. This is not true for 
  7088. C++. 
  7089.  
  7090. The compiler compares the data types provided by the calling function with the 
  7091. data types that the called function expects. The compiler might also perform 
  7092. type conversions if the declaration of the function is in function prototype 
  7093. format and the parameters differ from the prototype or visible at the point 
  7094. where the function is called. 
  7095.  
  7096. The order in which parameters are evaluated is not specified. Avoid such calls 
  7097. as: 
  7098.  
  7099. method(samp1, bat.proc--, bat.proc);
  7100.  
  7101. In this example, bat.proc-- might be evaluated last, causing the last two 
  7102. arguments to be passed with the same value. 
  7103.  
  7104. Example of a Function Call 
  7105.  
  7106. Related Information 
  7107.  
  7108.      Functions 
  7109.      Pointers 
  7110.      Cast Expressions 
  7111.      Primary Expressions 
  7112.  
  7113.  
  7114. ΓòÉΓòÉΓòÉ <hidden> Example of a Function Call ΓòÉΓòÉΓòÉ
  7115.  
  7116. /************************************************************************
  7117. *
  7118.  
  7119. In the following example, main passes func two values: 5 and 7. The function 
  7120. func receives copies of these values and accesses them by the identifiers: a 
  7121. and b. The function func changes the value of a. When control passes back to 
  7122. main, the actual values of x and y are not changed. The called function func 
  7123. only receives copies of x and y, not the values themselves. 
  7124.  
  7125.                                     *
  7126. ************************************************************************/
  7127.  
  7128. /**
  7129.  ** This example illustrates function calls
  7130.  **/
  7131.  
  7132. #include <stdio.h>
  7133.  
  7134. int main(void)
  7135. {
  7136.   int x = 5, y = 7;
  7137.  
  7138.   func(x, y);
  7139.   printf("In main, x = %d   y = %d\n", x, y);
  7140. }
  7141.  
  7142. void func (int a, int b)
  7143. {
  7144.   a += b;
  7145.   printf("In func, a = %d   b = %d\n", a, b);
  7146. }
  7147.  
  7148. /************************************************************************
  7149. *
  7150.  
  7151. This program produces the following output: 
  7152.  
  7153. In func, a = 12  b = 7
  7154. In main, x = 5   y = 7
  7155.  
  7156.                                     *
  7157. ************************************************************************/
  7158.  
  7159.  
  7160. ΓòÉΓòÉΓòÉ 5.4.5. Array Subscript [ ] (Array Element Specification) ΓòÉΓòÉΓòÉ
  7161.  
  7162. A primary expression followed by an expression in [ ] (square brackets) 
  7163. specifies an element of an array. The expression within the square brackets is 
  7164. referred to as a subscript. 
  7165.  
  7166. The primary expression must have a pointer type, and the subscript must have 
  7167. integral type. The result of an array subscript is an lvalue. 
  7168.  
  7169. The first element of each array has the subscript 0. The expression 
  7170. contract[35] refers to the 36th element in the array contract. 
  7171.  
  7172. In a multidimensional array, you can reference each element (in the order of 
  7173. increasing storage locations) by incrementing the rightmost subscript most 
  7174. frequently. 
  7175.  
  7176. For example, the following statement gives the value 100 to each element in the 
  7177. array code[4][3][6]: 
  7178.  
  7179. for (first = 0; first <= 3; ++first)
  7180.   for (second = 0; second <= 2; ++second)
  7181.    for (third = 0; third <= 5; ++third)
  7182.      code[first][second][third] = 100;
  7183.  
  7184. By definition, the expression: 
  7185.  
  7186. *((exp1) + (exp2))
  7187.  
  7188. is identical to the expression: 
  7189.  
  7190. exp1[exp2]
  7191.  
  7192. which is also identical to: 
  7193.  
  7194. exp2[exp1]
  7195.  
  7196. Related Information 
  7197.  
  7198.      Arrays 
  7199.      lvalues 
  7200.      Primary Expressions 
  7201.  
  7202.  
  7203. ΓòÉΓòÉΓòÉ 5.4.6. Dot Operator . ΓòÉΓòÉΓòÉ
  7204.  
  7205. The . (dot) operator is used to access structure or C++ class members using a 
  7206. structure object. The member is specified by a primary expression, followed by 
  7207. a . (dot) operator, followed by a name. For example: 
  7208.  
  7209.   roster[num].name
  7210.   roster[num].name[1]
  7211.  
  7212. The primary expression must be an object of type class, struct or union. The 
  7213. name must be a member of that object. 
  7214.  
  7215. The value of the expression is the value of the selected member. If the primary 
  7216. expression and the name are lvalues, the expression value is also an lvalue. 
  7217.  
  7218. For more information on class members, see C++ Class Members and Friends. 
  7219.  
  7220. Related Information 
  7221.  
  7222.      Arrow Operator -> 
  7223.      C++ Class Members and Friends 
  7224.      Unions 
  7225.      Structures 
  7226.      lvalues 
  7227.      Primary Expressions 
  7228.  
  7229.  
  7230. ΓòÉΓòÉΓòÉ 5.4.7. Arrow Operator -> ΓòÉΓòÉΓòÉ
  7231.  
  7232. The -> (arrow) operator is used to access structure or C++ class members using 
  7233. a pointer. A primary expression, followed by an -> (arrow) operator, followed 
  7234. by a name, designates a member of the object to which the pointer points. For 
  7235. example: 
  7236.  
  7237.   roster -> name
  7238.  
  7239. The primary expression must be a pointer to an object of type class, struct or 
  7240. union. The name must be a member of that object. 
  7241.  
  7242. The value of the expression is the value of the selected member. If the name is 
  7243. an lvalue, the expression value is also an lvalue. 
  7244.  
  7245. For more information on class members, see C++ Class Members and Friends. 
  7246.  
  7247. Related Information 
  7248.  
  7249.      Dot Operator . 
  7250.      C++ Class Members and Friends 
  7251.      Unions 
  7252.      Structures 
  7253.      lvalues 
  7254.      Pointers 
  7255.      Primary Expressions 
  7256.  
  7257.  
  7258. ΓòÉΓòÉΓòÉ 5.5. C++ Runtime Type Identification Operators ΓòÉΓòÉΓòÉ
  7259.  
  7260. Runtime type identification (RTTI) provides a standardized mechanism for 
  7261. determining the class of an object at run time. 
  7262.  
  7263. VisualAge for C++ support for RTTI is composed of: 
  7264.  
  7265.  A dynamic_cast operator Allows type conversions that are checked at run time. 
  7266.              It combines type-checking and casting in one operation by 
  7267.              verifying the requested cast and performing it only if it is 
  7268.              valid. 
  7269.  
  7270.  A typeid operator Returns the runtime type of an object. 
  7271.  
  7272.  A type_info class Describes the RTTI available and is used to define the type 
  7273.              return by the typeid operator. 
  7274.  
  7275.  RTTI is not a replacement for static (compile-time) checking. You should use 
  7276.  virtual functions instead of RTTI wherever possible. RTTI is necessary when 
  7277.  the code for the base class or the code for some of the derived classes is not 
  7278.  available to users. Extending base classes provided by libraries is one 
  7279.  example. 
  7280.  
  7281.  Note:  The I/O Stream classes do not support RTTI. The dynamic_cast and typeid 
  7282.  operators will yield unpredict results when used with I/O Stream objects. 
  7283.  
  7284.  See the IBM VisualAge for C++ for Windows Programming Guide for more 
  7285.  information about using RTTI. 
  7286.  
  7287.  
  7288. ΓòÉΓòÉΓòÉ 5.5.1. dynamic_cast<>() ΓòÉΓòÉΓòÉ
  7289.  
  7290. A dynamic cast expression is used to cast a base class pointer to a derived 
  7291. class pointer (referred to as downcasting.) 
  7292.  
  7293. The dynamic_cast operator makes downcasting much safer than conventional static 
  7294. casting. It obtains a pointer to an object of a derived class given a pointer 
  7295. to a base class of that object. The operator dynamic_cast returns the pointer 
  7296. only if the specific derived class actually exists. If not, it returns zero. 
  7297.  
  7298. Dynamic casts have the form: 
  7299.  
  7300. >>ΓöÇΓöÇdynamic_castΓöÇΓöÇΓöÉΓöÇΓöÇtype_nameΓöÇΓöÇ>ΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇ><
  7301.  
  7302. The operator converts the expression to the desired type type_name. The 
  7303. type_name can be a pointer or a reference to a class type. 
  7304.  
  7305.  
  7306. ΓòÉΓòÉΓòÉ 5.5.1.1. Dynamic Casts with Pointers ΓòÉΓòÉΓòÉ
  7307.  
  7308. A dynamic cast using pointers is used to get a pointer to a derived class in 
  7309. order to use some detail of the derived class that is not otherwise available. 
  7310. If the dynamic cast to a pointer type_name fails, the value of the expression 
  7311. is zero. 
  7312.  
  7313. For example, 
  7314.  
  7315. class employee {
  7316. public:
  7317.   virtual int salary();
  7318. };
  7319.  
  7320. class manager : public employee {
  7321. public:
  7322.   int salary();
  7323.   virtual int bonus();
  7324. };
  7325.  
  7326. In this class hierarchy, dynamic casts can be used to include the 
  7327. manager::bonus() function in the manager's salary calculation but not in the 
  7328. calculation for a regular employee. The dynamic_cast operator uses a pointer to 
  7329. the base class employee and gets a pointer to the derived class manager in 
  7330. order to use the bonus member function. 
  7331.  
  7332. void payroll::calc (employee *pe) {
  7333.   // employee salary calculation
  7334.   if (manager *pm = dynamic_cast<manager*>(pe)) {
  7335.      // use manager::bonus()
  7336.   }
  7337.   else {
  7338.      // use employee's member functions
  7339.   }
  7340. }
  7341.  
  7342. If pe actually points to a manager object at run time, the dynamic cast is 
  7343. successful, pm is initialized to a pointer to a manager, and the bonus function 
  7344. is used. If not, pm is initialized to zero and only the functions in the 
  7345. employee base class are used. 
  7346.  
  7347. Note:  In this example, dynamic casts are needed only if the base class 
  7348. employee and its derived classes are not available to users (as in part of a 
  7349. library where it is undesirable to modify the source code.) Otherwise, adding 
  7350. new virtual functions and providing derived classes with specialized 
  7351. definitions for those functions is a better choice to solve this problem. 
  7352.  
  7353.  
  7354. ΓòÉΓòÉΓòÉ 5.5.1.2. Dynamic Casts with References ΓòÉΓòÉΓòÉ
  7355.  
  7356. The dynamic_cast operator can also be used to cast to reference types. This is 
  7357. because C++ reference casts are similar to pointer casts: they can be used to 
  7358. cast from references to base class objects to references to derived class 
  7359. objects. 
  7360.  
  7361. In dynamic casts to reference types, type_name represents a type and expression 
  7362. represents a reference. The operator converts the expression to the desired 
  7363. type type_name&. 
  7364.  
  7365. Because there is no such thing as a zero reference, it is not possible to 
  7366. verify the success of a dynamic cast using reference types by comparing the 
  7367. result (the reference that results from the dynamic cast) with zero. A failing 
  7368. dynamic cast to a reference type throws a bad_cast exception. 
  7369.  
  7370. A dynamic cast with a reference is a good way to test for a coding assumption. 
  7371. The employee example above using reference casts is: 
  7372.  
  7373. void payroll::calc (employee &re) {
  7374.   // employee salary calculation
  7375.   try {
  7376.    manager &rm = dynamic_cast<manager&>(re);
  7377.    // use manager::bonus()
  7378.   }
  7379.   catch (bad_cast) {
  7380.    // use employee's member functions
  7381.   }
  7382. }
  7383.  
  7384. Note:  This example is only intended to illustrate the dynamic_cast operator 
  7385. used as a test. This example does not demonstrate good programming style, since 
  7386. it uses exceptions to control execution flow. Using dynamic_cast with pointers 
  7387. as shown above is a better choice. 
  7388.  
  7389. Related Information 
  7390.  
  7391.      typeid() 
  7392.      Inheritance Overview 
  7393.      Virtual Functions 
  7394.      Classes for Runtime Type Identification 
  7395.      Unary Expressions 
  7396.  
  7397.  
  7398. ΓòÉΓòÉΓòÉ 5.5.2. typeid() ΓòÉΓòÉΓòÉ
  7399.  
  7400. The typeid operator identifies the exact type of an object given a pointer to a 
  7401. base class. It is typically used to gain access to information needed to 
  7402. perform some operation where no common interface can be assumed for every 
  7403. object manipulated by the system. For example, object I/O and database systems 
  7404. often need to perform services on objects where no virtual function is 
  7405. available to do so. The typeid operator enables this. 
  7406.  
  7407. A typeid operation has the following form: 
  7408.  
  7409. >>ΓöÇΓöÇtypeidΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇtype_nameΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  7410.         ΓööΓöÇexpressionΓöÇΓöÿ
  7411.  
  7412. The result of a typeid operation has type const type_info&. 
  7413.  
  7414. The following table summarizes the results if various typeid operations. 
  7415.  
  7416.  Operand                 typeid Returns 
  7417.  typename                A reference to a type_info object that represents it. 
  7418.  expression              A reference to a type_info that represents the type of 
  7419.                          the expression. 
  7420.  Reference to a polymorphic type The type_info for the complete object referred 
  7421.                          to. 
  7422.  Pointer to a polymorphic type The dynamic type of the complete object pointed 
  7423.                          to. If the pointer is zero, the typeid expression 
  7424.                          throws the bad_typeid exception. 
  7425.  Nonpolymorphic type     The type_info that represents the static type of the 
  7426.                          expression. The expression is not evaluated. 
  7427.  
  7428.  The following examples use the typeid operator in expressions that compare the 
  7429.  runtime type of objects in the employee class hierarchy: 
  7430.  
  7431.   // ...
  7432.   employee *pe = new manager;
  7433.   employee& re = *pe;
  7434.   // ...
  7435.     typeid(pe) == typeid(employee*)   //  1. True - not a polymorphic type
  7436.     typeid(&re) == typeid(employee*)   //  2. True - not a polymorphic type
  7437.     typeid(*pe) == typeid(manager)    //  3. True - *pe represents a polymorphic type
  7438.     typeid(re) == typeid(manager)    //  4. True - re represents the object manager
  7439.  
  7440.     typeid(pe) == typeid(manager*)    //  5. False - static type of pe returned
  7441.     typeid(pe) == typeid(employee)    //  6. False - static type of pe returned
  7442.     typeid(pe) == typeid(manager)    //  7. False - static type of pe returned
  7443.  
  7444.     typeid(*pe) == typeid(employee)   //  8. False - dynamic type of expression is manager
  7445.     typeid(re) == typeid(employee)    //  9. False - re actually represents manager
  7446.     typeid(&re) == typeid(manager*)   // 10. False - manager* not the static type of re
  7447.   // ...
  7448.  
  7449.  In comparison 1, pe is a pointer (i.e. not a polymorphic type); therefore, the 
  7450.  expression typeid(pe) returns the static type of pe, which is equivalent to 
  7451.  employee*. 
  7452.  
  7453.  Similarly, re in comparison 2 represents the addess of the object referred to 
  7454.  (i.e. not a polymorphic type); therefore, the expression typeid(re) returns 
  7455.  the static type of re, which is a pointer to employee. 
  7456.  
  7457.  The type returned by typeid represents the dynamic type of the expression only 
  7458.  when the expression represents a polymorphic type, as in comparisons 3 and 4. 
  7459.  
  7460.  Comparisons 5, 6, and 7 are false because it is the type of the expression 
  7461.  (pe) that is examined, not the type of the object pointed to by pe. 
  7462.  
  7463.  Note that these examples do not directly manipulate type_info objects. Using 
  7464.  the typeid operator with builtin types requires interaction with type_info 
  7465.  objects. 
  7466.  
  7467.  For example: 
  7468.  
  7469.   int i;
  7470.   // ...
  7471.     typeid(i) == typeid(int)   // True
  7472.     typeid(8) == typeid(int)   // True
  7473.   // ...
  7474.  
  7475.  The class type_info is described in Classes for Runtime Type Identification. 
  7476.  
  7477.  Related Information 
  7478.  
  7479.      dynamic_cast<>() 
  7480.      Inheritance Overview 
  7481.      Virtual Functions 
  7482.      Classes for Runtime Type Identification 
  7483.      Unary Expressions 
  7484.  
  7485.  
  7486. ΓòÉΓòÉΓòÉ 5.6. Unary Expressions ΓòÉΓòÉΓòÉ
  7487.  
  7488. A unary expression contains one operand and a unary operator. All unary 
  7489. operators have the same precedence and have right-to-left associativity. 
  7490.  
  7491. As indicated in the following descriptions, the usual arithmetic conversions 
  7492. are performed on the operands of most unary expressions. See Arithmetic 
  7493. Conversions for more information. 
  7494.  
  7495.      Increment  ++ 
  7496.      Decrement  - - 
  7497.      Unary Plus  + 
  7498.      Unary Minus  - 
  7499.      Logical Negation  ! 
  7500.      Bitwise Negation  ~ 
  7501.      Address  & 
  7502.      Indirection  * 
  7503.      Cast Expressions 
  7504.      sizeof (Size of an Object) 
  7505.      C++ new Operator 
  7506.      C++ delete Operator 
  7507.      C++ throw Expressions 
  7508.  
  7509.  Related Information 
  7510.  
  7511.      Binary Expressions 
  7512.      Expressions and Operators 
  7513.      Operator Precedence and Associativity 
  7514.  
  7515.  
  7516. ΓòÉΓòÉΓòÉ 5.6.1. Increment  ++ ΓòÉΓòÉΓòÉ
  7517.  
  7518. The ++ (increment) operator adds 1 to the value of a scalar operand, or if the 
  7519. operand is a pointer, increments the operand by the size of the object to which 
  7520. it points. The operand receives the result of the increment operation. The 
  7521. operand must be a modifiable lvalue of arithmetic or pointer type. 
  7522.  
  7523. You can put the ++ before or after the operand. If it appears before the 
  7524. operand, the operand is incremented. Then the incremented value is used in the 
  7525. expression. If you put the ++ after the operand, the value of the operand is 
  7526. used in the expression before the operand is incremented. For example: 
  7527.  
  7528. play = ++play1 + play2++;
  7529.  
  7530. is equivalent to the following three expressions: 
  7531.  
  7532. play1 = play1 + 1;
  7533. play  = play1 + play2;
  7534. play2 = play2 + 1;
  7535.  
  7536. C++ Note:  C++ distinguishes between prefix and postfix forms of the increment 
  7537. operator. The result of a C++ postfix increment has the same type as the 
  7538. operand after integral promotion, but is not an lvalue. The result of a C++ 
  7539. prefix increment has the same type as the operand after integral promotion, and 
  7540. is an lvalue. The C language makes no such distinction. The result in C has the 
  7541. same type as the operand after integral promotion, but is not an lvalue. 
  7542.  
  7543. Related Information 
  7544.  
  7545.      Decrement  - - 
  7546.      Addition  + 
  7547.      Pointer Arithmetic 
  7548.      Unary Expressions 
  7549.      Arithmetic Conversions 
  7550.  
  7551.  
  7552. ΓòÉΓòÉΓòÉ 5.6.2. Decrement  - - ΓòÉΓòÉΓòÉ
  7553.  
  7554. The -- (decrement) operator subtracts 1 from the value of a scalar operand, or 
  7555. if the operand is a pointer, decreases the operand by the size of the object to 
  7556. which it points. The operand receives the result of the decrement operation. 
  7557. The operand must be a modifiable lvalue. 
  7558.  
  7559. You can put the -- before or after the operand. If it appears before the 
  7560. operand, the operand is decremented, and the decremented value is used in the 
  7561. expression. If the -- appears after the operand, the current value of the 
  7562. operand is used in the expression and the operand is decremented. 
  7563.  
  7564. For example: 
  7565.  
  7566. play = --play1 + play2--;
  7567.  
  7568. is equivalent to the following three expressions: 
  7569.  
  7570. play1 = play1 - 1;
  7571. play = play1 + play2;
  7572. play2 = play2 - 1;
  7573.  
  7574. C++ Note:  C++ distinguishes between prefix and postfix forms of the decrement 
  7575. operator. The result of a C++ postfix decrement has the same type as the 
  7576. operand after integral promotion, but is not an lvalue. The result of a C++ 
  7577. prefix decrement has the same type as the operand after integral promotion, and 
  7578. is an lvalue. The C language makes no such distinction. The result in C has the 
  7579. same type as the operand after integral promotion, but is not an lvalue. 
  7580.  
  7581. Related Information 
  7582.  
  7583.      Increment  ++ 
  7584.      Subtraction  - 
  7585.      Pointer Arithmetic 
  7586.      Unary Expressions 
  7587.      Arithmetic Conversions 
  7588.  
  7589.  
  7590. ΓòÉΓòÉΓòÉ 5.6.3. Unary Plus  + ΓòÉΓòÉΓòÉ
  7591.  
  7592. The + (unary plus) operator maintains the value of the operand.  The operand 
  7593. can have any arithmetic type. The result is not an lvalue. 
  7594.  
  7595. The result has the same type as the operand after integral promotion. 
  7596.  
  7597. Note:  Any plus sign in front of a constant is not part of the constant. 
  7598.  
  7599. Related Information 
  7600.  
  7601.      Unary Minus  - 
  7602.      Unary Expressions 
  7603.      Arithmetic Conversions 
  7604.  
  7605.  
  7606. ΓòÉΓòÉΓòÉ 5.6.4. Unary Minus  - ΓòÉΓòÉΓòÉ
  7607.  
  7608. The - (unary minus) operator negates the value of the operand.  The operand can 
  7609. have any arithmetic type. The result is not an lvalue. 
  7610.  
  7611. For example, if quality has the value 100, -quality has the value -100. 
  7612.  
  7613. The result has the same type as the operand after integral promotion. 
  7614.  
  7615. Note:  Any minus sign in front of a constant is not part of the constant. 
  7616.  
  7617. Related Information 
  7618.  
  7619.      Unary Plus  + 
  7620.      Unary Expressions 
  7621.      Arithmetic Conversions 
  7622.  
  7623.  
  7624. ΓòÉΓòÉΓòÉ 5.6.5. Logical Negation  ! ΓòÉΓòÉΓòÉ
  7625.  
  7626. The ! (logical negation) operator determines whether the operand evaluates to 0 
  7627. (false) or nonzero (true). The expression yields the value 1 (true) if the 
  7628. operand evaluates to 0, and yields the value 0 (false) if the operand evaluates 
  7629. to a nonzero value. The operand must have a scalar data type, but the result of 
  7630. the operation has always type int and is not an lvalue. 
  7631.  
  7632. The following two expressions are equivalent: 
  7633.  
  7634. !right;
  7635. right == 0;
  7636.  
  7637. Related Information 
  7638.  
  7639.      Equality  ==  != 
  7640.      Relational  <  >  <=  >= 
  7641.      Unary Expressions 
  7642.      Arithmetic Conversions 
  7643.  
  7644.  
  7645. ΓòÉΓòÉΓòÉ 5.6.6. Bitwise Negation  ~ ΓòÉΓòÉΓòÉ
  7646.  
  7647. The ~ (bitwise negation) operator yields the bitwise complement of the operand. 
  7648. In the binary representation of the result, every bit has the opposite value of 
  7649. the same bit in the binary representation of the operand. The operand must have 
  7650. an integral type. The result has the same type as the operand but is not an 
  7651. lvalue. 
  7652.  
  7653. Suppose x represents the decimal value 5. The 32-bit binary representation of x 
  7654. is: 
  7655.  
  7656. 00000000000000000000000000000101
  7657.  
  7658. The expression ~x yields the following result, represented here as a 32-bit 
  7659. binary number: 
  7660.  
  7661. 11111111111111111111111111111010
  7662.  
  7663. The 32-bit binary representation of ~0 is: 
  7664.  
  7665. 11111111111111111111111111111111
  7666.  
  7667. Related Information 
  7668.  
  7669.      Bitwise Left and Right Shift  <<  >> 
  7670.      Bitwise AND  & 
  7671.      Bitwise Exclusive OR  ^ 
  7672.      Bitwise Inclusive OR  | 
  7673.      Unary Expressions 
  7674.      Arithmetic Conversions 
  7675.  
  7676.  
  7677. ΓòÉΓòÉΓòÉ 5.6.7. Address  & ΓòÉΓòÉΓòÉ
  7678.  
  7679. The & (address) operator yields a pointer to its operand. The operand must be 
  7680. an lvalue, a function designator, or a qualified name. It cannot be a bit 
  7681. field, nor can it have the storage class register. 
  7682.  
  7683. If the operand is an lvalue or function, the resulting type is a pointer to the 
  7684. expression type. For example, if the expression has type int, the result is a 
  7685. pointer to an object having type int. 
  7686.  
  7687. If the operand is a qualified name and the member is not static, the result is 
  7688. a pointer to a member of class and has the same type as the member. The result 
  7689. is not an lvalue. 
  7690.  
  7691. If p_to_y is defined as a pointer to an int and y as an int, the following 
  7692. expression assigns the address of the variable y to the pointer p_to_y: 
  7693.  
  7694. p_to_y = &y;
  7695.  
  7696. C++ Note:  You can use the & operator with overloaded functions only in an 
  7697. initialization or assignment where the left side uniquely determines which 
  7698. version of the overloaded function is used. For more information, see 
  7699. Overloading Functions. 
  7700.  
  7701. Related Information 
  7702.  
  7703.      Pointers 
  7704.      lvalues 
  7705.      register Storage Class Specifier 
  7706.      Overloading Functions 
  7707.      Unary Expressions 
  7708.  
  7709.  
  7710. ΓòÉΓòÉΓòÉ 5.6.8. Indirection  * ΓòÉΓòÉΓòÉ
  7711.  
  7712. The * (indirection) operator determines the value referred to by the 
  7713. pointer-type operand. The operand cannot be a pointer to an incomplete type. 
  7714. The operation yields an lvalue or a function designator if the operand points 
  7715. to a function. Arrays and functions are converted to pointers. 
  7716.  
  7717. The type of the operand determines the type of the result. For example, if the 
  7718. operand is a pointer to an int, the result has type int. 
  7719.  
  7720. Do not apply the indirection operator to any pointer that contains an address 
  7721. that is not valid, such as NULL. The result is not defined. 
  7722.  
  7723. If p_to_y is defined as a pointer to an int and y as an int, the expressions: 
  7724.  
  7725. p_to_y = &y;
  7726. *p_to_y = 3;
  7727.  
  7728. cause the variable y to receive the value 3. 
  7729.  
  7730. Related Information 
  7731.  
  7732.      Pointers 
  7733.      lvalues 
  7734.      Functions 
  7735.      Unary Expressions 
  7736.  
  7737.  
  7738. ΓòÉΓòÉΓòÉ 5.6.9. Cast Expressions ΓòÉΓòÉΓòÉ
  7739.  
  7740. The cast operator is used for explicit type conversions. It converts the value 
  7741. of the operand to a specified data type and performs the necessary conversions 
  7742. to the operand for the type. 
  7743.  
  7744. For C, the operand must be scalar and the type must be either scalar or void. 
  7745. For C++, the operand can have class type. If the operand has class type, it can 
  7746. be cast to any type for which the class has a user-defined conversion function. 
  7747. User-defined conversion functions are described in Conversion Functions. 
  7748.  
  7749. The result of a cast is not an lvalue unless the cast is to a reference type. 
  7750. When you cast to a reference type, no user-defined conversions are performed 
  7751. and the result is an lvalue. 
  7752.  
  7753. There are two types of casts that take one argument: 
  7754.  
  7755.      C-style casts, with the format (X)a. These are the only casts allowed in 
  7756.       C. 
  7757.      function-style casts with one argument, such as X(a). These are allowed 
  7758.       in C++ only. 
  7759.  
  7760.  Both types of casts convert the argument a to the type X. In C++, they can 
  7761.  invoke a constructor, if the target type is a class, or they can invoke a 
  7762.  conversion function, if the source type is a class. They can be ambiguous if 
  7763.  both conditions hold. 
  7764.  
  7765.  A function-style cast with no arguments, such as X(), creates a temporary 
  7766.  object of type X. If X is a class with constructors, the default constructor 
  7767.  X::X() is called. 
  7768.  
  7769.  A function-style cast with more than one argument, such as X(a,b), creates a 
  7770.  temporary object of type X. This object must be a class with a constructor 
  7771.  that takes two arguments of types compatible with the types of a and b. The 
  7772.  constructor is called with a and b as arguments. 
  7773.  
  7774.  Related Information 
  7775.  
  7776.      Implicit Type Conversions 
  7777.      Conversion by Constructor 
  7778.      Conversion Functions 
  7779.      Type Specifiers 
  7780.  
  7781.  
  7782. ΓòÉΓòÉΓòÉ 5.6.10. sizeof (Size of an Object) ΓòÉΓòÉΓòÉ
  7783.  
  7784. The sizeof operator yields the size in bytes of the operand. Types cannot be 
  7785. defined in a sizeof expression. The sizeof operation cannot be performed on 
  7786.  
  7787.      A bit field 
  7788.      A function 
  7789.      An undefined structure or class 
  7790.      An incomplete type (such as void) 
  7791.  
  7792.  The operand can be the parenthesized name of a type or expression. 
  7793.  
  7794.  The compiler must be able to evaluate the size at compile time. The expression 
  7795.  is not evaluated; there are no side effects. For example, the value of b is 5 
  7796.  from initialization to the end of program runtime: 
  7797.  
  7798.   #include <stdio.h>
  7799.  
  7800.   int main(void){
  7801.    int b = 5;
  7802.    sizeof(b++);
  7803.   }
  7804.  
  7805.  The result is an integer constant. 
  7806.  
  7807.  The size of a char object is the size of a byte. For example, if a variable x 
  7808.  has type char, the expression sizeof(x) always evaluates to 1. 
  7809.  
  7810.  The result of a sizeof operation has type size_t, which is an unsigned 
  7811.  integral type defined in the <stddef.h> header. 
  7812.  
  7813.  The size of an object is determined on the basis of its definition. The sizeof 
  7814.  operator does not perform any conversions. If the operand contains operators 
  7815.  that perform conversions, the compiler does take these conversions into 
  7816.  consideration. The following expression causes the usual arithmetic 
  7817.  conversions to be performed. The result of the expression x + 1 has type int 
  7818.  (if x has type char, short, or int or any enumeration type) and is equivalent 
  7819.  to sizeof(int): 
  7820.  
  7821.   sizeof (x + 1);
  7822.  
  7823.  Except in preprocessor directives, you can use a sizeof expression wherever an 
  7824.  integral constant is required. One of the most common uses for the sizeof 
  7825.  operator is to determine the size of objects that are referred to during 
  7826.  storage allocation, input, and output functions. 
  7827.  
  7828.  Another use of sizeof is in porting code across platforms. You should use the 
  7829.  sizeof operator to determine the size that a data type represents. For 
  7830.  example: 
  7831.  
  7832.   sizeof(int);
  7833.  
  7834.  C++ Notes:  The result of a sizeof expression depends on the type it is 
  7835.  applied to: 
  7836.  
  7837.  An array    The result is the total number of bytes in the array. For example, 
  7838.              in an array with 10 elements, the size is equal to 10 times the 
  7839.              size of a single element. The compiler does not convert the array 
  7840.              to a pointer before evaluating the expression. 
  7841.  
  7842.  A class     The result is always nonzero, and is equal to the number of bytes 
  7843.              in an object of that class including any padding required for 
  7844.              placing class objects in an array. 
  7845.  
  7846.  A reference The result is the size of the referenced object. 
  7847.  
  7848.  Related Information 
  7849.  
  7850.      Constant Expressions 
  7851.      Implicit Type Conversions 
  7852.      Type Specifiers 
  7853.      Unary Expressions 
  7854.  
  7855.  
  7856. ΓòÉΓòÉΓòÉ 5.6.11. C++ new Operator ΓòÉΓòÉΓòÉ
  7857.  
  7858. The new operator provides dynamic storage allocation. The syntax for an 
  7859. allocation expression containing the new operator is: 
  7860.  
  7861. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇnewΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇ(type)ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>
  7862.   ΓööΓöÇ::ΓöÇΓöÿ    ΓööΓöÇ(argument_list)ΓöÇΓöÿ  ΓööΓöÇnew_typeΓöÇΓöÿ
  7863. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  7864.   ΓööΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÿ
  7865.     ΓööΓöÇinitial_valueΓöÇΓöÿ
  7866.  
  7867. If you prefix new with the scope resolution operator (::), the global operator 
  7868. new() is used. If you specify an argument_list, the overloaded new operator 
  7869. that corresponds to that argument_list is used. The type is an existing 
  7870. built-in or user-defined type. A new_type is a type that has not already been 
  7871. defined and can include type specifiers and declarators. 
  7872.  
  7873. An allocation expression containing the new operator is used to find storage in 
  7874. free store for the object being created. The new expression returns a pointer 
  7875. to the object created and can be used to initialize the object. If the object 
  7876. is an array, a pointer to the initial element is returned. 
  7877.  
  7878. You can use the routine set_new_handler() to change the default behavior of 
  7879. new. You can also use the /Tm option to enable a debug version of new, as 
  7880. described in Debug Versions of new and delete. 
  7881.  
  7882. You cannot use the new operator to allocate function types, void, or incomplete 
  7883. class types because these are not object types. However, you can allocate 
  7884. pointers to functions with the new operator. You cannot create a reference with 
  7885. the new operator. 
  7886.  
  7887. When the object being created is an array, only the first dimension can be a 
  7888. general expression. All subsequent dimensions must be constant integral 
  7889. expressions. The first dimension can be a general expression even when an 
  7890. existing type is used. You can create an array with zero bounds with the new 
  7891. operator. For example: 
  7892.  
  7893. char * c = new char[0];
  7894.  
  7895. In this case, a pointer to a unique object is returned. 
  7896.  
  7897. An object created with operator new() or operator new[]() exists until the 
  7898. operator delete() or operator delete[]() is called to deallocate the object's 
  7899. memory, or until program ends. 
  7900.  
  7901. If parentheses are used within a new_type, parentheses should also surround the 
  7902. new_type to prevent syntax errors. 
  7903.  
  7904. Example of Allocating Storage with new() 
  7905.  
  7906. The type of the object being created cannot contain class declarations, 
  7907. enumeration declarations, or const or volatile types. It can contain pointers 
  7908. to const or volatile objects. 
  7909.  
  7910. For example, const char* is allowed, but char* const is not. 
  7911.  
  7912. Additional arguments can be supplied to new by using the argument_list, also 
  7913. called the placement syntax. If placement arguments are used, a declaration of 
  7914. operator new() or operator new[]() with these arguments must exist. For 
  7915. example: 
  7916.  
  7917. #include <stddef.h>
  7918. class X
  7919. {
  7920. public:
  7921.    void* operator new(size_t,int, int){ /* ... */ }
  7922. };
  7923. void main ()
  7924. {
  7925.    X* ptr = new(1,2) X;
  7926. }
  7927.  
  7928. Additional information is provided on: 
  7929.  
  7930.      Member Functions and the Global operator new() and operator new[]() 
  7931.      Initializing Objects Created with the new Operator 
  7932.  
  7933.  Related Information 
  7934.  
  7935.      set_new_handler() - Set Behavior for new Failure 
  7936.      Overloaded new and delete 
  7937.      Debug Versions of new and delete 
  7938.      Constructors and Destructors Overview 
  7939.      Free Store 
  7940.      C++ delete Operator 
  7941.      Unary Expressions 
  7942.      /Tm option 
  7943.  
  7944.  
  7945. ΓòÉΓòÉΓòÉ 5.6.11.1. Member Functions and the Global operator new() and operator new[]() ΓòÉΓòÉΓòÉ
  7946.  
  7947. When an object of a class type is created with the new operator, the member 
  7948. operator new() function (for objects that are not arrays) or the member 
  7949. operator new[]() function (for arrays of any number of dimensions) is 
  7950. implicitly called. The first argument is the amount of space requested. 
  7951.  
  7952. The following rules determine which storage allocation function is used: 
  7953.  
  7954.    1. If your own operator new[]() exists, the object is an array, and the :: 
  7955.       (scope resolution) operator is not used, your operator new[]() is used. 
  7956.  
  7957.    2. If you have not defined an operator new[]() function, the global 
  7958.       ::operator new[]() function defined in <new.h> is used. The allocation 
  7959.       expression of the form ::operator new[]() ensures that the global new 
  7960.       operator is called, rather than your class member operator. 
  7961.  
  7962.    3. If your own operator new() exists, and the object is not an array, and 
  7963.       the :: operator is not used, your operator new() is used. 
  7964.  
  7965.    4. If you have not defined an operator new() function, the global ::operator 
  7966.       new() function defined in <new.h> is used. The allocation expression of 
  7967.       the form ::operator new() ensures that the global new operator is called, 
  7968.       rather than your class member operator. 
  7969.  
  7970.  When a nonclass object is created with the new operator, the global ::operator 
  7971.  new() is used. 
  7972.  
  7973.  The order of evaluation of a call to an operator new() is undefined in the 
  7974.  evaluation of arguments to constructors. If operator new() returns 0, the 
  7975.  arguments to a constructor may or may not have been evaluated. 
  7976.  
  7977.  
  7978. ΓòÉΓòÉΓòÉ 5.6.11.2. Initializing Objects Created with the new Operator ΓòÉΓòÉΓòÉ
  7979.  
  7980. You can initialize objects created with the new operator in several ways. For 
  7981. nonclass objects, or for class objects without constructors, a new initializer 
  7982. expression can be provided in a new expression by specifying ( expression ) or 
  7983. (). For example: 
  7984.  
  7985. double* pi = new double(3.1415926);
  7986. int* score = new int(89);
  7987. float* unknown = new float();
  7988.  
  7989. If a class has a constructor, the new initializer must be provided when any 
  7990. object of that class is allocated. The arguments of the new initializer must 
  7991. match the arguments of a class constructor, unless the class has a default 
  7992. constructor. 
  7993.  
  7994. You cannot specify an initializer for arrays. You can initialize an array of 
  7995. class objects only if the class has a default constructor. The constructor is 
  7996. called to initialize each array element (class object). 
  7997.  
  7998. Initialization using the new initializer is performed only if new successfully 
  7999. allocates storage. 
  8000.  
  8001.  
  8002. ΓòÉΓòÉΓòÉ <hidden> Example of Allocating Storage with new() ΓòÉΓòÉΓòÉ
  8003.  
  8004. /***********************************************************************
  8005. *
  8006.  
  8007. In the following example, storage is allocated for an array of pointers to 
  8008. functions: 
  8009.  
  8010.                                     *
  8011. ************************************************************************/
  8012.  
  8013. void f();
  8014. void g();
  8015. void main()
  8016. {
  8017.    void (**p)(), (**q)();
  8018.    // declare p and q as pointers to pointers to void functions
  8019.    p = new (void (*[3])());
  8020.    // p now points to an array of pointers to functions
  8021.    q = new void(*[3])(); // error
  8022.    // error - bound as 'q = (new void) (*[3])();'
  8023.    p[0] = f;  // p[0] to point to function f
  8024.    q[2] = g;  // q[2] to point to function g
  8025.    p[0]();   // call f()
  8026.    q[2]();   // call g()
  8027. }
  8028.  
  8029. /************************************************************************
  8030. *
  8031.  
  8032. However, the second use of new causes an erroneous binding of q = (new void) 
  8033. (*[3])(). 
  8034.  
  8035.                                     *
  8036. ************************************************************************/
  8037.  
  8038.  
  8039. ΓòÉΓòÉΓòÉ 5.6.11.3. set_new_handler() - Set Behavior for new Failure ΓòÉΓòÉΓòÉ
  8040.  
  8041. When the new operator creates a new object, it calls the operator new() or 
  8042. operator new[]() function to obtain the needed storage. 
  8043.  
  8044. When new cannot allocate storage to create a new object, it calls a new handler 
  8045. function if one has been installed by a call to set_new_handler(). The 
  8046. set_new_handler() function is defined in <new.h>. Use it to call a new handler 
  8047. you have defined or the default new handler. 
  8048.  
  8049. The set_new_handler() function has the prototype: 
  8050.  
  8051. typedef void(*PNH)();
  8052. PNH set_new_handler(PNH);
  8053.  
  8054. set_new_handler() takes as an argument a pointer to a function (the new 
  8055. handler), which has no arguments and returns void.  It returns a pointer to the 
  8056. previous new handler function. 
  8057.  
  8058. If you do not specify your own set_new_handler() function, new returns the NULL 
  8059. pointer. 
  8060.  
  8061. The _set_mt_new_handler() function behaves exactly the same way as 
  8062. set_new_handler(), except that it only affects the current thread. When a new 
  8063. handler function needs to be called, the code first checks for a thread new 
  8064. handler. If one has been registered, it is called. If not, the new handler 
  8065. registered with set_new_handler() is called. 
  8066.  
  8067. Example of set_new_handler() 
  8068.  
  8069. Related Information 
  8070.  
  8071.      C++ new Operator 
  8072.      Member Functions and the Global operator new() 
  8073.      Initializing Objects Created with the new Operator 
  8074.      Overloaded new and delete 
  8075.      Constructors and Destructors Overview 
  8076.      Free Store 
  8077.  
  8078.  
  8079. ΓòÉΓòÉΓòÉ <hidden> Example of set_new_handler() ΓòÉΓòÉΓòÉ
  8080.  
  8081. The following program fragment shows how you could use set_new_handler() to 
  8082. return a message if the new operator cannot allocate storage: 
  8083.  
  8084. #include <iostream.h>
  8085. #include <new.h>
  8086. void no_storage()
  8087. {
  8088.   cerr << "Operator new failed: no storage is available.\n";
  8089.    exit(1);
  8090. }
  8091. main()
  8092. {
  8093.    set_new_handler(&no_storage);
  8094.   // Rest of program ...
  8095. }
  8096.  
  8097. If the program fails because new cannot allocate storage, the program exits 
  8098. with the message: 
  8099.  
  8100.  Operator new failed: no storage is available.
  8101.  
  8102.  
  8103. ΓòÉΓòÉΓòÉ 5.6.12. C++ delete Operator ΓòÉΓòÉΓòÉ
  8104.  
  8105. The delete operator destroys the object created with new by deallocating the 
  8106. memory associated with the object. 
  8107.  
  8108. The delete operator has a void return type. It has the syntax: 
  8109.  
  8110. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdeleteΓöÇΓöÇobject_pointerΓöÇΓöÇ><
  8111.   ΓööΓöÇ::ΓöÇΓöÿ
  8112.  
  8113. For example:   delete myobj; 
  8114.  
  8115. The operand of delete must be a pointer returned by new, and cannot be a 
  8116. pointer to constant. If an attempt to create an object with new fails, the 
  8117. pointer returned by new will have a zero value, but it can still be used with 
  8118. delete. Deleting a null pointer has no effect. 
  8119.  
  8120. The delete[] operator frees storage allocated for array objects created with 
  8121. new[]. The delete operator frees storage allocated for individual objects 
  8122. created with new. 
  8123.  
  8124. It has the syntax: 
  8125.  
  8126. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdeleteΓöÇΓöÇ[ΓöÇΓöÇ]ΓöÇΓöÇarrayΓöÇΓöÇ><
  8127.   ΓööΓöÇ::ΓöÇΓöÿ
  8128.  
  8129. For example:   delete [] myarray; 
  8130.  
  8131. The result of deleting an array object with delete is undefined, as is deleting 
  8132. an individual object with delete[]. The array dimensions do not need to be 
  8133. specified with delete[]. 
  8134.  
  8135. The results of attempting to access a deleted object are undefined because the 
  8136. deletion of an object can change its value. 
  8137.  
  8138. If a destructor has been defined for a class, delete invokes that destructor. 
  8139. Whether a destructor exists or not, delete frees the storage pointed to by 
  8140. calling the function operator delete() of the class if one exists. 
  8141.  
  8142. The global ::operator delete() is used if: 
  8143.  
  8144.      The class has no operator delete(). 
  8145.      The object is of a nonclass type. 
  8146.      The object is deleted with the ::delete expression. For example: 
  8147.       ::delete p; 
  8148.  
  8149.  The global ::operator delete[]() is used if: 
  8150.  
  8151.      The class has no operator delete[]() 
  8152.      The object is of a nonclass type 
  8153.      The object is deleted with the ::delete[] expression. 
  8154.  
  8155.  The default global operator delete() only frees storage allocated by the 
  8156.  default global operator new(). The default global operator delete[]() only 
  8157.  frees storage allocated for arrays by the default global operator new[](). 
  8158.  
  8159.  You can also use the /Tm compiler option to enable a debug version of the 
  8160.  delete operator, as described in Debug Versions of new and delete. 
  8161.  
  8162.  Related Information 
  8163.  
  8164.      Overloaded new and delete 
  8165.      Debug Versions of new and delete 
  8166.      Constructors and Destructors Overview 
  8167.      Free Store 
  8168.      C++ new Operator 
  8169.      Unary Expressions 
  8170.      /Tm option 
  8171.  
  8172.  
  8173. ΓòÉΓòÉΓòÉ 5.6.13. C++ throw Expressions ΓòÉΓòÉΓòÉ
  8174.  
  8175. A throw expression is used to throw exceptions to C++ exception handlers. It 
  8176. causes control to be passed out of the block enclosing the throw statement to 
  8177. the first C++ exception handler whose catch argument matches the throw 
  8178. expression. A throw expression is a unary expression of type void. 
  8179.  
  8180. For more information on the throw expression, see C++ Exception Handling. 
  8181.  
  8182. Related Information 
  8183.  
  8184.      C++ Exception Handling 
  8185.      Unary Expressions 
  8186.  
  8187.  
  8188. ΓòÉΓòÉΓòÉ 5.7. Binary Expressions ΓòÉΓòÉΓòÉ
  8189.  
  8190. A binary expression contains two operands separated by one operator. 
  8191.  
  8192. Not all binary operators have the same precedence. The table in the section 
  8193. Operator Precedence and Associativity shows the order of precedence among 
  8194. operators. All binary operators have left-to-right associativity. 
  8195.  
  8196. The order in which the operands of most binary operators are evaluated is not 
  8197. specified. To ensure correct results, avoid creating binary expressions that 
  8198. depend on the order in which the compiler evaluates the operands. 
  8199.  
  8200. As indicated in the following descriptions, the usual arithmetic conversions 
  8201. are performed on the operands of most binary expressions. See Arithmetic 
  8202. Conversions for more information. 
  8203.  
  8204.      Multiplication  * 
  8205.      Division  / 
  8206.      Remainder  % 
  8207.      Addition  + 
  8208.      Subtraction  - 
  8209.      Bitwise Left and Right Shift  <<  >> 
  8210.      Relational  <  >  <=  >= 
  8211.      Equality  ==  != 
  8212.      Bitwise AND  & 
  8213.      Bitwise Exclusive OR  ^ 
  8214.      Bitwise Inclusive OR  | 
  8215.      Logical AND  && 
  8216.      Logical OR  || 
  8217.      C++ Pointer to Member Operators .* ->* 
  8218.  
  8219.  Related Information 
  8220.  
  8221.      Unary Expressions 
  8222.      Expressions and Operators 
  8223.      Operator Precedence and Associativity 
  8224.  
  8225.  
  8226. ΓòÉΓòÉΓòÉ 5.7.1. Multiplication  * ΓòÉΓòÉΓòÉ
  8227.  
  8228. The * (multiplication) operator yields the product of its operands.  The 
  8229. operands must have an arithmetic type.  The result is not an lvalue. 
  8230.  
  8231. Because the multiplication operator has both associative and commutative 
  8232. properties, the compiler can rearrange the operands in an expression that 
  8233. contains more than one multiplication operator. For example, the expression: 
  8234.  
  8235. sites * number * cost
  8236.  
  8237. can be interpreted in any of the following ways: 
  8238.  
  8239. (sites * number) * cost
  8240. sites * (number * cost)
  8241. (cost * sites) * number
  8242.  
  8243. Related Information 
  8244.  
  8245.      Division  / 
  8246.      Remainder  % 
  8247.      Binary Expressions 
  8248.      Arithmetic Conversions 
  8249.  
  8250.  
  8251. ΓòÉΓòÉΓòÉ 5.7.2. Division  / ΓòÉΓòÉΓòÉ
  8252.  
  8253. The / (division) operator yields the quotient of its operands. The operands 
  8254. must have an arithmetic type. The result is not an lvalue. 
  8255.  
  8256. If both operands are positive integers and the operation produces a remainder, 
  8257. the remainder is ignored. For example, expression 7 / 4 yields the value 1 
  8258. (rather than 1.75 or 2). On all IBM C and C++ compilers, if either operand is 
  8259. negative, the result is rounded towards zero. 
  8260.  
  8261. The result is undefined if the second operand evaluates to 0. 
  8262.  
  8263. Related Information 
  8264.  
  8265.      Multiplication  * 
  8266.      Remainder  % 
  8267.      Binary Expressions 
  8268.      Arithmetic Conversions 
  8269.  
  8270.  
  8271. ΓòÉΓòÉΓòÉ 5.7.3. Remainder  % ΓòÉΓòÉΓòÉ
  8272.  
  8273. The % (remainder) operator yields the remainder from the division of the left 
  8274. operand by the right operand. For example, the expression 5 % 3 yields 2. The 
  8275. result is not an lvalue. 
  8276.  
  8277. Both operands must have an integral type. If the right operand evaluates to 0, 
  8278. the result is undefined. If either operand has a negative value, the result is 
  8279. such that the following expression always yields the value of a if b is not 0 
  8280. and a/b is representable: 
  8281.  
  8282.   ( a / b ) * b + a % b;
  8283.  
  8284. The sign of the remainder is the same as the sign of the quotient. Related 
  8285. Information 
  8286.  
  8287.      Multiplication  * 
  8288.      Division  / 
  8289.      Binary Expressions 
  8290.      Arithmetic Conversions 
  8291.  
  8292.  
  8293. ΓòÉΓòÉΓòÉ 5.7.4. Addition  + ΓòÉΓòÉΓòÉ
  8294.  
  8295. The + (addition) operator yields the sum of its operands. Both operands must 
  8296. have an arithmetic type, or one operand must be a pointer to an object type and 
  8297. the other operand must have an integral type. 
  8298.  
  8299. When both operands have an arithmetic type, the usual arithmetic conversions on 
  8300. the operands are performed. The result has the type produced by the conversions 
  8301. on the operands and is not an lvalue. 
  8302.  
  8303. A pointer to an object in an array can be added to a value having integral 
  8304. type. The result is a pointer of the same type as the pointer operand. The 
  8305. result refers to another element in the array, offset from the original element 
  8306. by the amount specified by the integral value. If the resulting pointer points 
  8307. to storage outside the array, other than the first location outside the array, 
  8308. the result is undefined. The compiler does not provide boundary checking on the 
  8309. pointers. 
  8310.  
  8311. Related Information 
  8312.  
  8313.      Pointers 
  8314.      Unary Plus  + 
  8315.      Subtraction  - 
  8316.      Binary Expressions 
  8317.      Arithmetic Conversions 
  8318.  
  8319.  
  8320. ΓòÉΓòÉΓòÉ 5.7.5. Subtraction  - ΓòÉΓòÉΓòÉ
  8321.  
  8322. The - (subtraction) operator yields the difference of its operands. Both 
  8323. operands must have an arithmetic type, or the left operand must have a pointer 
  8324. type and the right operand must have the same pointer type or an integral type. 
  8325. You cannot subtract a pointer from an integral value. 
  8326.  
  8327. When both operands have an arithmetic type, the usual arithmetic conversions on 
  8328. the operands are performed. The result has the type produced by the conversions 
  8329. on the operands and is not an lvalue. 
  8330.  
  8331. When the left operand is a pointer and the right operand has an integral type, 
  8332. the compiler converts the value of the right to an address offset. The result 
  8333. is a pointer of the same type as the pointer operand. 
  8334.  
  8335. If both operands are pointers to the same type, the compiler converts the 
  8336. result to an integral type that represents the number of objects separating the 
  8337. two addresses. Behavior is undefined if the pointers do not refer to objects in 
  8338. the same array. 
  8339.  
  8340. Related Information 
  8341.  
  8342.      Pointers 
  8343.      Unary Minus  - 
  8344.      Addition  + 
  8345.      Binary Expressions 
  8346.      Arithmetic Conversions 
  8347.  
  8348.  
  8349. ΓòÉΓòÉΓòÉ 5.7.6. Bitwise Left and Right Shift  <<  >> ΓòÉΓòÉΓòÉ
  8350.  
  8351. The bitwise shift operators move the bit values of a binary object.  The left 
  8352. operand specifies the value to be shifted.  The right operand specifies the 
  8353. number of positions that the bits in the value are to be shifted. The result is 
  8354. not an lvalue. Both operands have the same precedence and are left-to-right 
  8355. associative. 
  8356.  
  8357. The << (bitwise left shift) operator indicates the bits are to be shifted to 
  8358. the left.  The >> (bitwise right shift) operator indicates the bits are to be 
  8359. shifted to the right. 
  8360.  
  8361. Each operand must have an integral type.  The compiler performs integral 
  8362. promotions on the operands.  Then the right operand is converted to type int. 
  8363. The result has the same type as the left operand (after the arithmetic 
  8364. conversions). 
  8365.  
  8366. The right operand should not have a negative value or a value that is greater 
  8367. than or equal to the width in bits of the expression being shifted. The result 
  8368. of bitwise shifts on such values is unpredictable. 
  8369.  
  8370. If the right operand has the value 0, the result is the value of the left 
  8371. operand (after the usual arithmetic conversions). 
  8372.  
  8373. The << operator fills vacated bits with zeros. For example, if left_op has the 
  8374. value 4019, the bit pattern (in 32-bit format) of left_op is: 
  8375.  
  8376. 00000000000000000000111110110011
  8377.  
  8378. The expression left_op << 3 yields: 
  8379.  
  8380. 00000000000000000111110110011000
  8381.  
  8382. If the left operand has an unsigned type, the >> operator fills vacated bits 
  8383. with zeros. Otherwise, the compiler fills the vacated bits of a signed value 
  8384. with a copy of the value's sign bit. 
  8385.  
  8386. For example, if left_op has the value -25, the bit pattern (in 32-bit format) 
  8387. of left_op is: 
  8388.  
  8389. 11111111111111111111111111100111
  8390.  
  8391. The expression left_op >> 3 yields: 
  8392.  
  8393. 11111111111111111111111111111100
  8394.  
  8395. Related Information 
  8396.  
  8397.      Bitwise Negation  ~ 
  8398.      Bitwise AND  & 
  8399.      Bitwise Exclusive OR  ^ 
  8400.      Bitwise Inclusive OR  | 
  8401.      Binary Expressions 
  8402.      Arithmetic Conversions 
  8403.  
  8404.  
  8405. ΓòÉΓòÉΓòÉ 5.7.7. Relational  <  >  <=  >= ΓòÉΓòÉΓòÉ
  8406.  
  8407. The relational operators compare two operands and determine the validity of a 
  8408. relationship. If the relationship stated by the operator is true, the value of 
  8409. the result is 1. If false, the value of the result is 0. The result is not an 
  8410. lvalue. 
  8411.  
  8412. The following table describes the four relational operators: 
  8413.  
  8414.  Operator   Usage 
  8415.  
  8416.  <          Indicates whether the value of the left operand is less than the 
  8417.             value of the right operand. 
  8418.  
  8419.  >          Indicates whether the value of the left operand is greater than the 
  8420.             value of the right operand. 
  8421.  
  8422.  <=         Indicates whether the value of the left operand is less than or 
  8423.             equal to the value of the right operand. 
  8424.  
  8425.  >=         Indicates whether the value of the left operand is greater than or 
  8426.             equal to the value of the right operand. 
  8427.  
  8428.  Both operands must have arithmetic types or be pointers to the same type. The 
  8429.  result has type int. If the operands have arithmetic types, the usual 
  8430.  arithmetic conversions on the operands are performed. 
  8431.  
  8432.  When the operands are pointers, the result is determined by the locations of 
  8433.  the objects to which the pointers refer. If the pointers do not refer to 
  8434.  objects in the same array, the result is not defined. 
  8435.  
  8436.  A pointer can be compared to a constant expression that evaluates to 0. You 
  8437.  can also compare a pointer to a pointer of type void*. The pointer is 
  8438.  converted to a pointer of type void*. 
  8439.  
  8440.  If two pointers refer to the same object, they are considered equal. If two 
  8441.  pointers refer to nonstatic members of the same object, the pointer to the 
  8442.  object declared later has the higher address value. If two pointers refer to 
  8443.  data members of the same union, they have the same address value. 
  8444.  
  8445.  If two pointers refer to elements of the same array, or to the first element 
  8446.  beyond the last element of an array, the pointer to the element with the 
  8447.  higher subscript value has the higher address value. 
  8448.  
  8449.  You can only compare members of the same object with relational operators. 
  8450.  
  8451.  Relational operators have left-to-right associativity. For example, the 
  8452.  expression: 
  8453.  
  8454.   a < b <= c
  8455.  
  8456.  is interpreted as: 
  8457.  
  8458.   (a < b) <= c
  8459.  
  8460.  If the value of a is less than the value of b, the first relationship is true 
  8461.  and yields the value 1. The compiler then compares the value 1 with the value 
  8462.  of c. 
  8463.  
  8464.  Related Information 
  8465.  
  8466.      Equality  ==  != 
  8467.      Logical Negation  ! 
  8468.      Pointers 
  8469.      Binary Expressions 
  8470.      Arithmetic Conversions 
  8471.  
  8472.  
  8473. ΓòÉΓòÉΓòÉ 5.7.8. Equality  ==  != ΓòÉΓòÉΓòÉ
  8474.  
  8475. The equality operators, like the relational operators, compare two operands for 
  8476. the validity of a relationship. The equality operators, however, have a lower 
  8477. precedence than the relational operators. If the relationship stated by an 
  8478. equality operator is true, the value of the result is 1. Otherwise, the value 
  8479. of the result is 0. 
  8480.  
  8481. The following table describes the two equality operators: 
  8482.  
  8483.  Operator   Usage 
  8484.  
  8485.  ==         Indicates whether the value of the left operand is equal to the 
  8486.             value of the right operand. 
  8487.  
  8488.  !=         Indicates whether the value of the left operand is not equal to the 
  8489.             value of the right operand. 
  8490.  
  8491.  Both operands must have arithmetic types or be pointers to the same type, or 
  8492.  one operand must have a pointer type and the other operand must be a pointer 
  8493.  to void or NULL. The result has type int. 
  8494.  
  8495.  If the operands have arithmetic types, the usual arithmetic conversions on the 
  8496.  operands are performed. If the operands are pointers, the result is determined 
  8497.  by the locations of the objects to which the pointers refer. 
  8498.  
  8499.  If one operand is a pointer and the other operand is an integer having the 
  8500.  value 0, the == expression is true only if the pointer operand evaluates to 
  8501.  NULL. The != operator evaluates to true if the pointer operand does not 
  8502.  evaluate to NULL. 
  8503.  
  8504.  You can also use the equality operators to compare pointers to members that 
  8505.  are of the same type but do not belong to the same object. 
  8506.  
  8507.  Note:  The equality operator (==) should not be confused with the assignment 
  8508.  (=) operator. 
  8509.  
  8510.  For example, 
  8511.  
  8512.  if(x == 3)    evaluates to 1 if x is equal to three. Equality tests like this 
  8513.                should be coded with spaces between the operator and the 
  8514.                operands to prevent unintentional assignments. 
  8515.  
  8516.                while 
  8517.  if(x = 3)     is taken to be true because (x = 3) evaluates to a non-zero 
  8518.                value (3). The expression also assigns the value 3 to x. 
  8519.  
  8520.  Related Information 
  8521.  
  8522.      Relational  <  >  <=  >= 
  8523.      Logical Negation  ! 
  8524.      Pointers 
  8525.      Binary Expressions 
  8526.      Arithmetic Conversions 
  8527.  
  8528.  
  8529. ΓòÉΓòÉΓòÉ 5.7.9. Bitwise AND  & ΓòÉΓòÉΓòÉ
  8530.  
  8531. The & (bitwise AND) operator compares each bit of its first operand to the 
  8532. corresponding bit of the second operand.  If both bits are 1's, the 
  8533. corresponding bit of the result is set to 1. Otherwise, it sets the 
  8534. corresponding result bit to 0. 
  8535.  
  8536. Both operands must have an integral type.  The usual arithmetic conversions on 
  8537. each operand are performed. The result has the same type as the converted 
  8538. operands. 
  8539.  
  8540. Because the bitwise AND operator has both associative and commutative 
  8541. properties, the compiler can rearrange the operands in an expression that 
  8542. contains more than one bitwise AND operator. 
  8543.  
  8544. The following example shows the values of a, b, and the result of a & b 
  8545. represented as 32-bit binary numbers: 
  8546.  
  8547.  bit pattern of a              00000000000000000000000001011100 
  8548.  bit pattern of b              00000000000000000000000000101110 
  8549.  bit pattern of a & b          00000000000000000000000000001100 
  8550.  
  8551.  Note:  The bitwise AND (&) should not be confused with the logical AND. (&&) 
  8552.  operator. For example, 
  8553.  
  8554.     1 & 4 evaluates to 0
  8555.   while
  8556.     1 && 4 evaluates to 1
  8557.  
  8558.  Related Information 
  8559.  
  8560.      Bitwise Exclusive OR  ^ 
  8561.      Bitwise Inclusive OR  | 
  8562.      Logical AND  && 
  8563.      Binary Expressions 
  8564.      Arithmetic Conversions 
  8565.  
  8566.  
  8567. ΓòÉΓòÉΓòÉ 5.7.10. Bitwise Exclusive OR  ^ ΓòÉΓòÉΓòÉ
  8568.  
  8569. The bitwise exclusive OR operator compares each bit of its first operand to the 
  8570. corresponding bit of the second operand. If both bits are 1's or both bits are 
  8571. 0's, the corresponding bit of the result is set to 0. Otherwise, it sets the 
  8572. corresponding result bit to 1. 
  8573.  
  8574. Both operands must have an integral type. The usual arithmetic conversions on 
  8575. each operand are performed. The result has the same type as the converted 
  8576. operands and is not an lvalue. 
  8577.  
  8578. Because the bitwise exclusive OR operator has both associative and commutative 
  8579. properties, the compiler can rearrange the operands in an expression that 
  8580. contains more than one bitwise exclusive OR operator even when the 
  8581. sub-expressions are explicitly grouped with parentheses. 
  8582.  
  8583. The following example shows the values of a, b, and the result of a ^ b 
  8584. represented as 32-bit binary numbers: 
  8585.  
  8586.  bit pattern of a              00000000000000000000000001011100 
  8587.  bit pattern of b              00000000000000000000000000101110 
  8588.  bit pattern of a ^ b          00000000000000000000000001110010 
  8589.  
  8590.  Related Information 
  8591.  
  8592.      Bitwise Inclusive OR  | 
  8593.      Bitwise AND  & 
  8594.      Logical OR  || 
  8595.      Binary Expressions 
  8596.      Arithmetic Conversions 
  8597.  
  8598.  
  8599. ΓòÉΓòÉΓòÉ 5.7.11. Bitwise Inclusive OR  | ΓòÉΓòÉΓòÉ
  8600.  
  8601. The | (bitwise inclusive OR) operator compares the values (in binary format) of 
  8602. each operand and yields a value whose bit pattern shows which bits in either of 
  8603. the operands has the value 1. If both of the bits are 0, the result of that bit 
  8604. is 0;  otherwise, the result is 1. 
  8605.  
  8606. Both operands must have an integral type.  The usual arithmetic conversions on 
  8607. each operand are performed. The result has the same type as the converted 
  8608. operands and is not an lvalue. 
  8609.  
  8610. Because the bitwise inclusive OR operator has both associative and commutative 
  8611. properties, the compiler can rearrange the operands in an expression that 
  8612. contains more than one bitwise inclusive OR operator even when the 
  8613. subexpressions are explicitly grouped with parentheses. 
  8614.  
  8615. The following example shows the values of a, b, and the result of a | b 
  8616. represented as 32-bit binary numbers: 
  8617.  
  8618.  bit pattern of a              00000000000000000000000001011100 
  8619.  bit pattern of b              00000000000000000000000000101110 
  8620.  bit pattern of a | b          00000000000000000000000001111110 
  8621.  
  8622.  Note:  The bitwise OR (|) should not be confused with the logical OR (||) 
  8623.  operator. For example, 
  8624.  
  8625.     1 | 4 evaluates to 5
  8626.   while
  8627.     1 || 4 evaluates to 1
  8628.  
  8629.  Related Information 
  8630.  
  8631.      Bitwise Exclusive OR  ^ 
  8632.      Bitwise AND  & 
  8633.      Logical OR  || 
  8634.      Binary Expressions 
  8635.      Arithmetic Conversions 
  8636.  
  8637.  
  8638. ΓòÉΓòÉΓòÉ 5.7.12. Logical AND  && ΓòÉΓòÉΓòÉ
  8639.  
  8640. The && (logical AND) operator indicates whether both operands have a nonzero 
  8641. value.  If both operands have nonzero values, the result has the value 1. 
  8642. Otherwise, the result has the value 0. 
  8643.  
  8644. Both operands must have a scalar type. The usual arithmetic conversions on each 
  8645. operand are performed. The result has type int and is not an lvalue. 
  8646.  
  8647. Unlike the & (bitwise AND) operator, the && operator guarantees left-to-right 
  8648. evaluation of the operands. If the left operand evaluates to 0, the right 
  8649. operand is not evaluated. 
  8650.  
  8651. The following examples show how the expressions that contain the logical AND 
  8652. operator are evaluated: 
  8653.  
  8654.  Expression          Result 
  8655.  1 && 0              0 
  8656.  1 && 4              1 
  8657.  0 && 0              0 
  8658.  
  8659.  The following example uses the logical AND operator to avoid division by zero: 
  8660.  
  8661.   (y != 0) && (x / y)
  8662.  
  8663.  The expression x / y is not evaluated when y != 0 evaluates to 0. 
  8664.  
  8665.  Note:  The logical AND (&&) should not be confused with the bitwise AND (&) 
  8666.  operator. For example: 
  8667.  
  8668.     1 && 4 evaluates to 1
  8669.   while
  8670.     1 & 4 evaluates to 0
  8671.  
  8672.  Related Information 
  8673.  
  8674.      Logical OR  || 
  8675.      Bitwise AND  & 
  8676.      Binary Expressions 
  8677.      Arithmetic Conversions 
  8678.  
  8679.  
  8680. ΓòÉΓòÉΓòÉ 5.7.13. Logical OR  || ΓòÉΓòÉΓòÉ
  8681.  
  8682. The || (logical OR) operator indicates whether either operand has a nonzero 
  8683. value. If either operand has a nonzero value, the result has the value 1. 
  8684. Otherwise, the result has the value 0. 
  8685.  
  8686. Both operands must have a scalar type. The usual arithmetic conversions on each 
  8687. operand are performed. The result has type int and is not an lvalue. 
  8688.  
  8689. Unlike the | (bitwise inclusive OR) operator, the || operator guarantees 
  8690. left-to-right evaluation of the operands. If the left operand has a nonzero 
  8691. value, the right operand is not evaluated. 
  8692.  
  8693. The following examples show how expressions that contain the logical OR 
  8694. operator are evaluated: 
  8695.  
  8696.  Expression          Result 
  8697.  1 || 0              1 
  8698.  1 || 4              1 
  8699.  0 || 0              0 
  8700.  
  8701.  The following example uses the logical OR operator to conditionally increment 
  8702.  y: 
  8703.  
  8704.   ++x || ++y;
  8705.  
  8706.  The expression ++y is not evaluated when the expression ++x evaluates to a 
  8707.  nonzero quantity. 
  8708.  
  8709.  Note:  The logical OR (||) should not be confused with the bitwise OR (|) 
  8710.  operator. For example: 
  8711.  
  8712.     1 || 4 evaluates to 1
  8713.   while
  8714.     1 | 4 evaluates to 5
  8715.  
  8716.  Related Information 
  8717.  
  8718.      Logical AND  && 
  8719.      Bitwise Inclusive OR  | 
  8720.      Binary Expressions 
  8721.      Arithmetic Conversions 
  8722.  
  8723.  
  8724. ΓòÉΓòÉΓòÉ 5.7.14. C++ Pointer to Member Operators .* ->* ΓòÉΓòÉΓòÉ
  8725.  
  8726. The .* operator is used to dereference pointers to class members. The first 
  8727. operand must be a class type. If the type of the first operand is class type T, 
  8728. or is a class that has been derived from class type T, the second operand must 
  8729. be a pointer to a member of a class type T. 
  8730.  
  8731. The ->* operator is also used to dereference pointers to class members. The 
  8732. first operand must be a pointer to a class type. If the type of the first 
  8733. operand is a pointer to class type T, or is a pointer to a class derived from 
  8734. class type T, the second operand must be a pointer to a member of class type T. 
  8735.  
  8736. The .* and ->* operators bind the second operand to the first, resulting in an 
  8737. object or function of the type specified by the second operand. 
  8738.  
  8739. If the result of.* or ->* is a function, you can only use the result as the 
  8740. operand for the ( ) (function call) operator. If the second operand is an 
  8741. lvalue, the result of .* or ->* is an lvalue. 
  8742.  
  8743. For more information on pointer to member operators, see Pointers to Members. 
  8744.  
  8745. Related Information 
  8746.  
  8747.      Pointers to Members 
  8748.      Pointers 
  8749.      C++ Classes 
  8750.      Binary Expressions 
  8751.  
  8752.  
  8753. ΓòÉΓòÉΓòÉ 5.8. Conditional Expressions ΓòÉΓòÉΓòÉ
  8754.  
  8755. A conditional expression is a compound expression that contains a condition 
  8756. (operand{1}), an expression to be evaluated if the condition has a nonzero 
  8757. value (operand{2}), and an expression to be evaluated if the condition has the 
  8758. value 0 (operand{3}). 
  8759.  
  8760. Conditional expressions have right-to-left associativity. The left operand is 
  8761. evaluated first, and then only one of the remaining two operands is evaluated. 
  8762.  
  8763. The conditional expression contains one two-part operator.  The ? symbol 
  8764. follows the condition, and the : symbol appears between the two action 
  8765. expressions. All expressions that occur between the ? and : are treated as one 
  8766. expression. 
  8767.  
  8768. The first operand must have a scalar type. The type of the second and third 
  8769. operands must be one of the following: 
  8770.  
  8771.      An arithmetic type 
  8772.      A compatible pointer, structure, or union type 
  8773.      void. 
  8774.  
  8775.  The second and third operands can also be a pointer or a null pointer 
  8776.  constant. 
  8777.  
  8778.  Two objects are compatible when they have the same type but not necessarily 
  8779.  the same type qualifiers (volatile, const, or _Packed). Pointer objects are 
  8780.  compatible if they have the same type or are pointers to void. 
  8781.  
  8782.  The first operand is evaluated, and its value determines whether the second or 
  8783.  third operand is evaluated: 
  8784.  
  8785.      If the value is not equal to 0, the second operand is evaluated. 
  8786.      If the value is equal to 0, the third operand is evaluated. 
  8787.  The result is the value of the second or third operand. 
  8788.  
  8789.  If the second and third expressions evaluate to arithmetic types, the usual 
  8790.  arithmetic conversions are performed on the values. The types of the second 
  8791.  and third operands determine the type of the result as shown in the following 
  8792.  tables. 
  8793.  
  8794.  
  8795. ΓòÉΓòÉΓòÉ 5.8.1. Type of Conditional C Expressions ΓòÉΓòÉΓòÉ
  8796.  
  8797. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8798. Γöé TYPE OF ONE OPERAND   Γöé TYPE OF OTHER OPERAND   Γöé TYPE OF RESULT      Γöé
  8799. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8800. Γöé Arithmetic        Γöé Arithmetic        Γöé Arithmetic type after  Γöé
  8801. Γöé             Γöé              Γöé usual arithmetic con-  Γöé
  8802. Γöé             Γöé              Γöé versions         Γöé
  8803. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8804. Γöé Structure or union type Γöé Compatible structure or  Γöé Structure or union type Γöé
  8805. Γöé             Γöé union type        Γöé with all the qualifiers Γöé
  8806. Γöé             Γöé              Γöé on both operands     Γöé
  8807. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8808. Γöé VOID           Γöé VOID           Γöé VOID           Γöé
  8809. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8810. Γöé Pointer to compatible  Γöé Pointer to compatible   Γöé Pointer to type with   Γöé
  8811. Γöé type           Γöé type           Γöé all the qualifiers    Γöé
  8812. Γöé             Γöé              Γöé specified for the type  Γöé
  8813. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8814. Γöé Pointer to type     Γöé "NULL" pointer (the con- Γöé Pointer to type     Γöé
  8815. Γöé             Γöé stant "0")        Γöé             Γöé
  8816. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8817. Γöé Pointer to object or   Γöé Pointer to VOID      Γöé Pointer to VOID with   Γöé
  8818. Γöé incomplete type     Γöé              Γöé all the qualifiers    Γöé
  8819. Γöé             Γöé              Γöé specified for the type  Γöé
  8820. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  8821.  
  8822.  
  8823. ΓòÉΓòÉΓòÉ 5.8.2. Type of Conditional C++ Expressions ΓòÉΓòÉΓòÉ
  8824.  
  8825. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8826. Γöé TYPE OF ONE OPERAND   Γöé TYPE OF OTHER OPERAND   Γöé TYPE OF RESULT      Γöé
  8827. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8828. Γöé Reference to type    Γöé Reference to type     Γöé Reference after usual  Γöé
  8829. Γöé             Γöé              Γöé reference conversions  Γöé
  8830. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8831. Γöé Class "T"        Γöé Class "T"         Γöé Class "T"        Γöé
  8832. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8833. Γöé Class "T"        Γöé Class "X"         Γöé Class type for which a  Γöé
  8834. Γöé             Γöé              Γöé conversion exists.  If  Γöé
  8835. Γöé             Γöé              Γöé more than one possible  Γöé
  8836. Γöé             Γöé              Γöé conversion exists, the  Γöé
  8837. Γöé             Γöé              Γöé result is ambiguous.   Γöé
  8838. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8839. Γöé THROW expression     Γöé Other (type, pointer,   Γöé Type of the expression  Γöé
  8840. Γöé             Γöé reference)        Γöé that is not a THROW   Γöé
  8841. Γöé             Γöé              Γöé expression        Γöé
  8842. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  8843.  
  8844. Examples of Conditional Expressions 
  8845.  
  8846. Related Information 
  8847.  
  8848.      Type Specifiers 
  8849.      Declarators 
  8850.      Expressions and Operators 
  8851.      Arithmetic Conversions 
  8852.      Operator Precedence and Associativity 
  8853.  
  8854.  
  8855. ΓòÉΓòÉΓòÉ <hidden> Examples of Conditional Expressions ΓòÉΓòÉΓòÉ
  8856.  
  8857. The following expression determines which variable has the greater value, y or 
  8858. z, and assigns the greater value to the variable x: 
  8859.  
  8860. x = (y > z) ? y : z;
  8861.  
  8862. The following is an equivalent statement: 
  8863.  
  8864. if (y > z)
  8865.   x = y;
  8866. else
  8867.   x = z;
  8868.  
  8869. The following expression calls the function printf, which receives the value of 
  8870. the variable c, if c evaluates to a digit. Otherwise, printf receives the 
  8871. character constant 'x'. 
  8872.  
  8873. printf(" c = %c\n", isdigit(c) ? c : 'x');
  8874.  
  8875. If the last operand of a conditional expression contains an assignment 
  8876. operator, use parentheses to ensure the expression evaluates properly. For 
  8877. example, the = operator has higher precedence than the ?: operator in the 
  8878. following expression: 
  8879.  
  8880. int i,j,k;
  8881. (i == 7) ? j ++ : k = j;
  8882.  
  8883. This expression generates an error because it is interpreted as if it were 
  8884. parenthesized this way: 
  8885.  
  8886. int i,j,k;
  8887. ((i == 7) ? j ++ : k) = j;
  8888.  
  8889. That is, k is treated as the third operand, not the entire assignment 
  8890. expression k = j. The error arises because a conditional expression is not an 
  8891. lvalue, and the assignment is not valid. 
  8892.  
  8893. To make the expression evaluate correctly, enclose the last operand in 
  8894. parentheses: 
  8895.  
  8896. int i,j,k;
  8897. (i == 7) ? j ++ : (k = j);
  8898.  
  8899.  
  8900. ΓòÉΓòÉΓòÉ 5.9. Assignment Expressions ΓòÉΓòÉΓòÉ
  8901.  
  8902. An assignment expression stores a value in the object designated by the left 
  8903. operand. There are two types of assignment operators: simple assignment and 
  8904. compound assignment. 
  8905.  
  8906. The left operand in all assignment expressions must be a modifiable lvalue. The 
  8907. type of the expression is the type of the left operand. The value of the 
  8908. expression is the value of the left operand after the assignment has completed. 
  8909.  
  8910. In C, the result of an assignment expression is not an lvalue. The result of an 
  8911. assignment expression is an lvalue in C++ 
  8912.  
  8913. All assignment operators have the same precedence and have right-to-left 
  8914. associativity. 
  8915.  
  8916.      Simple Assignment  = 
  8917.      Compound Assignment 
  8918.  
  8919.  Related Information 
  8920.  
  8921.      Expressions and Operators 
  8922.      Operator Precedence and Associativity 
  8923.  
  8924.  
  8925. ΓòÉΓòÉΓòÉ 5.9.1. Simple Assignment  = ΓòÉΓòÉΓòÉ
  8926.  
  8927. The simple assignment operator stores the value of the right operand in the 
  8928. object designated by the left operand. 
  8929.  
  8930. Both operands must have arithmetic types, the same structure type, or the same 
  8931. union type.  Otherwise, both operands must be pointers to the same type, or the 
  8932. left operand must be a pointer and the right operand must be the constant 0 or 
  8933. NULL. 
  8934.  
  8935. If both operands have arithmetic types, the system converts the type of the 
  8936. right operand to the type of the left operand before the assignment. 
  8937.  
  8938. If the right operand is a pointer to a type, the left operand can be a pointer 
  8939. to a const of the same type. If the right operand is a pointer to a const type, 
  8940. the left operand must also be a pointer to a const type. 
  8941.  
  8942. If the right operand is a pointer to a type, the left operand can be a pointer 
  8943. to a volatile of the same type. If the right operand is a pointer to a volatile 
  8944. type, the left operand must also be a pointer to a volatile type. 
  8945.  
  8946. If the left operand is a pointer to a member, the right operand must be a 
  8947. pointer to a member or a constant expression that evaluates to zero. The right 
  8948. operand is converted to the type of the left operand before assignment. 
  8949.  
  8950. If the left operand is an object of reference type, the assignment is to the 
  8951. object denoted by the reference. 
  8952.  
  8953. If the left operand is a pointer and the right operand is the constant 0, the 
  8954. result is NULL. 
  8955.  
  8956. Pointers to void can appear on either side of the simple assignment operator. 
  8957.  
  8958. A packed structure or union can be assigned to a nonpacked structure or union 
  8959. of the same type, and a nonpacked structure or union can be assigned to a 
  8960. packed structure or union of the same type. 
  8961.  
  8962. If one operand is packed and the other is not, the layout of the right operand 
  8963. is remapped to match the layout of the left. This remapping of structures might 
  8964. degrade performance. For efficiency, when you perform assignment operations 
  8965. with structures or unions, you should ensure that both operands are either 
  8966. packed or nonpacked. 
  8967.  
  8968. Note:  If you assign pointers to structures or unions, the objects they point 
  8969. to must both be either packed or nonpacked. See Pointers for more information 
  8970. on assignments with pointers. 
  8971.  
  8972. You can assign values to operands with the type qualifier volatile. You cannot 
  8973. assign a pointer of an object with the type qualifier const to a pointer of an 
  8974. object without the const type qualifier. For example: 
  8975.  
  8976. const int *p1;
  8977. int *p2;
  8978. p2 = p1;  /* this is NOT allowed */
  8979.  
  8980. p1 = p2;  /* this IS allowed */
  8981.  
  8982. Examples of Simple Assignments 
  8983.  
  8984. Note:  The assignment (=) operator should not be confused with the equality 
  8985. comparison (==) operator. For example: 
  8986.  
  8987.  if(x == 3)  evaluates to 1 if x is equal to three 
  8988.  
  8989.              while 
  8990.  if(x = 3)   is taken to be true because (x = 3) evaluates to a non-zero value 
  8991.              (3). The expression also assigns the value 3 to x. 
  8992.  
  8993.  Related Information 
  8994.  
  8995.      Compound Assignment 
  8996.      Equality  ==  != 
  8997.      Pointers 
  8998.      volatile and const Qualifiers 
  8999.      Type Specifiers 
  9000.      Arithmetic Conversions 
  9001.  
  9002.  
  9003. ΓòÉΓòÉΓòÉ <hidden> Examples of Simple Assignments ΓòÉΓòÉΓòÉ
  9004.  
  9005. The following example assigns the value of number to the member employee of the 
  9006. structure payroll: 
  9007.  
  9008. payroll.employee = number;
  9009.  
  9010. The following example assigns in order the value 0 (zero) to strangeness, the 
  9011. value of strangeness to charm, the value of charm to beauty, and the value of 
  9012. beauty to truth: 
  9013.  
  9014. truth = beauty = charm = strangeness = 0;
  9015.  
  9016.  
  9017. ΓòÉΓòÉΓòÉ 5.9.2. Compound Assignment ΓòÉΓòÉΓòÉ
  9018.  
  9019. The compound assignment operators consist of a binary operator and the simple 
  9020. assignment operator. They perform the operation of the binary operator on both 
  9021. operands and give the result of that operation to the left operand. 
  9022.  
  9023. The following table shows the operand types of compound assignment expressions: 
  9024.  
  9025. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9026. Γöé OPERATOR         Γöé LEFT OPERAND       Γöé RIGHT OPERAND      Γöé
  9027. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9028. Γöé += or -=         Γöé Arithmetic        Γöé Arithmetic        Γöé
  9029. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9030. Γöé += or -=         Γöé Pointer          Γöé Integral type      Γöé
  9031. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9032. Γöé *=, /=, and %=      Γöé Arithmetic        Γöé Arithmetic        Γöé
  9033. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9034. Γöé <<=, >>=, &=, ^=, and  Γöé Integral type       Γöé Integral type      Γöé
  9035. Γöé |=            Γöé              Γöé             Γöé
  9036. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  9037.  
  9038. Note that the expression a *= b + c is equivalent to a = a * (b + c), and not 
  9039. a = a * b + c. 
  9040.  
  9041. The following table lists the compound assignment operators and shows an 
  9042. expression using each operator: 
  9043.  
  9044.  Operator    Example 
  9045.  
  9046.  +=          index += 2 
  9047.                 Equivalent expression:  index = index + 2 
  9048.  
  9049.  -=          *(pointer++) -= 1 
  9050.                 Equivalent expression:  *pointer = *(pointer++) - 1 
  9051.  
  9052.  *=          bonus *= increase 
  9053.                 Equivalent expression:  bonus = bonus * increase 
  9054.  
  9055.  /=          time /= hours 
  9056.                 Equivalent expression:  time = time / hours 
  9057.  
  9058.  %=          allowance %= 1000 
  9059.                 Equivalent expression:  allowance = allowance % 1000 
  9060.  
  9061.  <<=         result <<= num 
  9062.                 Equivalent expression:  result = result << num 
  9063.  
  9064.  >>=         form >>= 1 
  9065.                 Equivalent expression:  form = form >> 1 
  9066.  
  9067.  &=          mask &= 2 
  9068.                 Equivalent expression:  mask = mask & 2 
  9069.  
  9070.  ^=          test ^= pre_test 
  9071.                 Equivalent expression:  test = test ^ pre_test 
  9072.  
  9073.  |=          flag |= ON 
  9074.                 Equivalent expression:  flag = flag | ON 
  9075.  
  9076.  Although the equivalent expression column shows the left operands (from the 
  9077.  example column) evaluated twice, the left operand is evaluated only once. 
  9078.  
  9079.  Related Information 
  9080.  
  9081.      Simple Assignment  = 
  9082.      Binary Expressions 
  9083.  
  9084.  
  9085. ΓòÉΓòÉΓòÉ 5.10. Comma Expression  , ΓòÉΓòÉΓòÉ
  9086.  
  9087. A comma expression contains two operands separated by a comma. Although the 
  9088. compiler evaluates both operands, the value of the right operand is the value 
  9089. of the expression. The left operand is evaluated, possibly producing side 
  9090. effects, and the value is discarded. The result of a comma expression is not an 
  9091. lvalue. 
  9092.  
  9093. Both operands of a comma expression can have any type.  All comma expressions 
  9094. have left-to-right associativity. The left operand is fully evaluated before 
  9095. the right operand. 
  9096.  
  9097. In the following example, if omega has the value 11, the expression increments 
  9098. delta and assigns the value 3 to alpha: 
  9099.  
  9100. alpha = (delta++, omega % 4);
  9101.  
  9102. Any number of expressions separated by commas can form a single expression. The 
  9103. compiler evaluates the leftmost expression first. The value of the rightmost 
  9104. expression becomes the value of the entire expression. 
  9105.  
  9106. For example, the value of the expression: 
  9107.  
  9108. intensity++, shade * increment, rotate(direction);
  9109.  
  9110. is the value of the expression: 
  9111.  
  9112. rotate(direction)
  9113.  
  9114. The primary use of the comma operator is to produce side effects in the 
  9115. following situations: 
  9116.  
  9117.      Calling a function 
  9118.      Entering or repeating an iteration loop 
  9119.      Testing a condition 
  9120.      Other situations where a side effect is required but the result of the 
  9121.       expression is not immediately needed 
  9122.  
  9123.  To use the comma operator in a context where the comma has other meanings, 
  9124.  such as in a list of function arguments or a list of initializers, you must 
  9125.  enclose the comma operator in parentheses. For example, the function 
  9126.  
  9127.   f(a, (t = 3, t + 2), c);
  9128.  
  9129.  has only three arguments: the value of a, the value 5, and the value of c. The 
  9130.  value of the second argument is the result of the comma expression in 
  9131.  parentheses: 
  9132.  
  9133.   t = 3, t + 2
  9134.  
  9135.  which has the value 5. 
  9136.  
  9137.  The following table gives some examples of the uses of the comma operator: 
  9138.  
  9139.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9140.   Γöé STATEMENT             Γöé EFFECTS                  Γöé
  9141.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9142.   Γöé  for (i=0; i<2; ++i, f() );    Γöé A FOR statement in which "i" is incre-  Γöé
  9143.   Γöé                  Γöé mented and "f()" is called at each iter- Γöé
  9144.   Γöé                  Γöé ation.                  Γöé
  9145.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9146.   Γöé  if ( f(), ++i, i>1 )       Γöé An IF statement in which function "f()"  Γöé
  9147.   Γöé    { /* ... */ }         Γöé is called, variable "i" is incremented,  Γöé
  9148.   Γöé                  Γöé and variable "i" is tested against a   Γöé
  9149.   Γöé                  Γöé value.  The first two expressions within Γöé
  9150.   Γöé                  Γöé this comma expression are evaluated    Γöé
  9151.   Γöé                  Γöé before the expression "i>1".  Regardless Γöé
  9152.   Γöé                  Γöé of the results of the first two      Γöé
  9153.   Γöé                  Γöé expressions, the third is evaluated and  Γöé
  9154.   Γöé                  Γöé its result determines whether the IF   Γöé
  9155.   Γöé                  Γöé statement is processed.          Γöé
  9156.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9157.   Γöé  func( ( ++a, f(a) ) );      Γöé A function call to "func()" in which "a" Γöé
  9158.   Γöé                  Γöé is incremented, the resulting value is  Γöé
  9159.   Γöé                  Γöé passed to a function "f()", and the    Γöé
  9160.   Γöé                  Γöé return value of "f()" is passed to    Γöé
  9161.   Γöé                  Γöé "func()".  The function "func()" is    Γöé
  9162.   Γöé                  Γöé passed only a single argument, because  Γöé
  9163.   Γöé                  Γöé the comma expression is enclosed in    Γöé
  9164.   Γöé                  Γöé parentheses within the function argument Γöé
  9165.   Γöé                  Γöé list.                   Γöé
  9166.   Γöé                  Γöé                      Γöé
  9167.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  9168.  
  9169.  Related Information 
  9170.  
  9171.      Expressions and Operators 
  9172.      Operator Precedence and Associativity 
  9173.  
  9174.  
  9175. ΓòÉΓòÉΓòÉ 6. Implicit Type Conversions ΓòÉΓòÉΓòÉ
  9176.  
  9177. There are two kinds of implicit type conversions: standard conversions and 
  9178. user-defined conversions. This chapter describes the following standard type 
  9179. conversions: 
  9180.  
  9181.      integral promotions. 
  9182.      Implicit standard type conversions: 
  9183.         -  Signed-integer conversions 
  9184.         -  Unsigned-integer conversions 
  9185.         -  Floating-point conversions 
  9186.         -  Pointer conversions 
  9187.         -  Reference conversions 
  9188.         -  Pointer-to-member conversions 
  9189.         -  Function argument conversions 
  9190.         -  Other conversions 
  9191.      Arithmetic conversions. 
  9192.  
  9193.  Related Information 
  9194.  
  9195.      Expressions and Operators 
  9196.      Functions 
  9197.      Cast Expressions. 
  9198.      User-Defined Conversions. 
  9199.  
  9200.  
  9201. ΓòÉΓòÉΓòÉ 6.1. Integral Promotions ΓòÉΓòÉΓòÉ
  9202.  
  9203. Certain fundamental types can be used wherever an integer can be used. The 
  9204. fundamental types that can be converted through integral promotion are: 
  9205.  
  9206.      char 
  9207.      wchar_t 
  9208.      short int 
  9209.      enumerators 
  9210.      objects of enumeration type 
  9211.      integer bit fields (both signed and unsigned) 
  9212.  
  9213.  Except for wchar_t, if the value cannot be represented by an int, the value is 
  9214.  converted to an unsigned int. For wchar_t, if an int can represent all the 
  9215.  values of the original type, the value is converted to the type that can best 
  9216.  represent all the values of the original type. For example, if a long can 
  9217.  represent all the values, the value is converted to a long. 
  9218.  
  9219.  Note:  Integral promotions are not performed on long long integers. 
  9220.  
  9221.  
  9222. ΓòÉΓòÉΓòÉ 6.2. Standard Type Conversions ΓòÉΓòÉΓòÉ
  9223.  
  9224. Many C and C++ operators cause implicit type conversions, which change the type 
  9225. of a value. When you add values having different data types, both values are 
  9226. first converted to the same type. For example, when a short int value and an 
  9227. int value are added together, the short int value is converted to the int type. 
  9228.  
  9229. Implicit type conversions can occur when: 
  9230.  
  9231.      An operand is prepared for an arithmetic or logical operation. 
  9232.      An assignment is made to an lvalue that has a different type than the 
  9233.       assigned value. 
  9234.      A prototyped function is provided a value that has a different type than 
  9235.       the parameter. 
  9236.      The value specified in the return statement of a function has a different 
  9237.       type from the defined return type for the function. 
  9238.  
  9239.  You can perform explicit type conversions using the cast operator or the 
  9240.  function style cast. For more information on explicit type conversions, see 
  9241.  Cast Expressions. 
  9242.  
  9243.  
  9244. ΓòÉΓòÉΓòÉ 6.2.1. Signed-Integer Conversions ΓòÉΓòÉΓòÉ
  9245.  
  9246. The compiler converts a signed integer to a shorter integer by truncating the 
  9247. high-order bits and converting the variable to a longer signed integer by 
  9248. sign-extension. 
  9249.  
  9250. Conversion of signed integers to floating-point values takes place without loss 
  9251. of information, except when an int or long int value is converted to a float, 
  9252. in which case some precision may be lost. When a signed integer is converted to 
  9253. an unsigned integer, the signed integer is converted to the size of the 
  9254. unsigned integer, and the result is interpreted as an unsigned value. 
  9255.  
  9256.  
  9257. ΓòÉΓòÉΓòÉ 6.2.2. Unsigned-Integer Conversions ΓòÉΓòÉΓòÉ
  9258.  
  9259. An unsigned integer is converted to a shorter unsigned or signed integer by 
  9260. truncating the high-order bits. An unsigned integer is converted to a longer 
  9261. unsigned or signed integer by zero-extending. Zero-extending pads the leftmost 
  9262. bits of the longer integer with binary zeros. 
  9263.  
  9264. When an unsigned integer is converted to a signed integer of the same size, no 
  9265. change in the bit pattern occurs. However, the value changes if the sign bit is 
  9266. set. 
  9267.  
  9268.  
  9269. ΓòÉΓòÉΓòÉ 6.2.3. Floating-Point Conversions ΓòÉΓòÉΓòÉ
  9270.  
  9271. A float value converted to a double undergoes no change in value. A double 
  9272. converted to a float is represented exactly, if possible. If the compiler 
  9273. cannot exactly represent the double value as a float, the value loses 
  9274. precision. If the value is too large to fit into a float, the result is 
  9275. undefined. 
  9276.  
  9277. When a floating-point value is converted to an integer value, the decimal 
  9278. fraction portion of the floating-point value is discarded in the conversion. If 
  9279. the result is too large for the given integer type, the result of the 
  9280. conversion is undefined. 
  9281.  
  9282.  
  9283. ΓòÉΓòÉΓòÉ 6.2.4. Pointer Conversions ΓòÉΓòÉΓòÉ
  9284.  
  9285. Pointer conversions are performed when pointers are used, including pointer 
  9286. assignment, initialization, and comparison. 
  9287.  
  9288. A constant expression that evaluates to zero can be converted to a pointer. 
  9289. This pointer will be a null pointer (pointer with a zero value), and is 
  9290. guaranteed not to point to any object. 
  9291.  
  9292. Any pointer to an object that is not a const or volatile object can be 
  9293. converted to a void*. You can also convert any pointer to a function to a 
  9294. void*, provided that a void* has sufficient bits to hold it. 
  9295.  
  9296. You can convert an expression with type array of some type to a pointer to the 
  9297. initial element of the array, except when the expression is used as the operand 
  9298. of the & (address) operator or the sizeof operator. 
  9299.  
  9300. You can convert an expression with a type of function returning T to a pointer 
  9301. to a function returning T, except when the expression is used as the operand of 
  9302. the & (address) operator, the () (function call) operator, or the sizeof 
  9303. operator. 
  9304.  
  9305. You can convert an integer value to an address offset. 
  9306.  
  9307. You can convert a pointer to a class A to a pointer to an accessible base class 
  9308. B of that class, as long as the conversion is not ambiguous. The conversion is 
  9309. ambiguous if the expression for the accessible base class can refer to more 
  9310. than one distinct class. The resulting value points to the base class subobject 
  9311. of the derived class object. A null pointer (pointer with a zero value) is 
  9312. converted into itself. 
  9313.  
  9314. Note:  You cannot convert a pointer to a class into a pointer to its base class 
  9315. if the base class is a virtual base class of the derived class. 
  9316.  
  9317. For more information on pointer conversions, see Pointer Arithmetic. 
  9318.  
  9319.  
  9320. ΓòÉΓòÉΓòÉ 6.2.5. Reference Conversions ΓòÉΓòÉΓòÉ
  9321.  
  9322. A reference conversion can be performed wherever a reference initialization 
  9323. occurs, including reference initialization done in argument passing and 
  9324. function return values. A reference to a class can be converted to a reference 
  9325. to an accessible base class of that class as long as the conversion is not 
  9326. ambiguous. The result of the conversion is a reference to the base class 
  9327. subobject of the derived class object. 
  9328.  
  9329. Reference conversion is allowed if the corresponding pointer conversion is 
  9330. allowed. 
  9331.  
  9332.  
  9333. ΓòÉΓòÉΓòÉ 6.2.6. Pointer-to-Member Conversions ΓòÉΓòÉΓòÉ
  9334.  
  9335. Pointer-to-member conversion can occur when pointers to members are 
  9336. initialized, assigned, or compared. 
  9337.  
  9338. A constant expression that evaluates to zero is converted to a distinct pointer 
  9339. to a member. 
  9340.  
  9341. Note:  A pointer to a member is not the same as a pointer to an object or a 
  9342. pointer to a function. 
  9343.  
  9344. A pointer to a member of a base class can be converted to a pointer to a member 
  9345. of a derived class if the following conditions are true: 
  9346.  
  9347.      The conversion is not ambiguous. The conversion is ambiguous if multiple 
  9348.       instances of the base class are in the derived class. 
  9349.      A pointer to the derived class can be converted to a pointer to the base 
  9350.       class. If this is the case, the base class is said to be accessible. See 
  9351.       Derivation Access of Base Classes for more information. 
  9352.  
  9353.  For more information, see Pointers to Members and C++ Pointer to Member 
  9354.  Operators .* ->*. 
  9355.  
  9356.  
  9357. ΓòÉΓòÉΓòÉ 6.2.7. Function Argument Conversions ΓòÉΓòÉΓòÉ
  9358.  
  9359. If no function prototype declaration is visible when a function is called, the 
  9360. compiler can perform default argument promotions, which consist of the 
  9361. following: 
  9362.  
  9363.      Integral promotions 
  9364.      Arguments with type float are converted to type double. 
  9365.  
  9366.  
  9367. ΓòÉΓòÉΓòÉ 6.2.8. Other Conversions ΓòÉΓòÉΓòÉ
  9368.  
  9369. By definition, the void type has no value. Therefore, it cannot be converted to 
  9370. any other type, and no other value can be converted to void by assignment. 
  9371. However, a value can be explicitly cast to void. 
  9372.  
  9373. No conversions between structure or union types are allowed. 
  9374.  
  9375. There are no standard conversions between class types. 
  9376.  
  9377. In C, when you define a value using the enum type specifier, the value is 
  9378. treated as an int. Conversions to and from an enum value proceed as for the int 
  9379. type. 
  9380.  
  9381. In C++, you can convert from an enum to any integral type but not from an 
  9382. integral type to an enum. 
  9383.  
  9384.  
  9385. ΓòÉΓòÉΓòÉ 6.3. Arithmetic Conversions ΓòÉΓòÉΓòÉ
  9386.  
  9387. Most C++ operators perform type conversions to bring the operands of an 
  9388. expression to a common type or to extend short values to the integer size used 
  9389. by the machine. The conversions depend on the specific operator and the type of 
  9390. the operand or operands. However, many operators perform similar conversions on 
  9391. operands of integer and floating-point types. These standard conversions are 
  9392. known as the arithmetic conversions because they apply to the types of values 
  9393. ordinarily used in arithmetic. 
  9394.  
  9395. Arithmetic conversions are used for matching operands of arithmetic operators. 
  9396.  
  9397. Arithmetic conversion proceeds in the following order: 
  9398.  
  9399. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9400. Γöé OPERAND TYPE              Γöé CONVERSION              Γöé
  9401. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9402. Γöé One operand has LONG DOUBLE type    Γöé The other operand is converted to   Γöé
  9403. Γöé                    Γöé LONG DOUBLE type.           Γöé
  9404. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9405. Γöé One operand has DOUBLE type      Γöé The other operand is converted to   Γöé
  9406. Γöé                    Γöé DOUBLE.                Γöé
  9407. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9408. Γöé One operand has FLOAT type       Γöé The other operand is converted to   Γöé
  9409. Γöé                    Γöé FLOAT.                Γöé
  9410. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9411. Γöé One operand has UNSIGNED LONG INT   Γöé The other operand is converted to   Γöé
  9412. Γöé type                  Γöé UNSIGNED LONG INT.          Γöé
  9413. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9414. Γöé One operand has UNSIGNED LONG LONG   Γöé The other operand is converted to   Γöé
  9415. Γöé INT type                Γöé UNSIGNED LONG LONG INT.        Γöé
  9416. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9417. Γöé One operand has UNSIGNED INT type and Γöé The operand with UNSIGNED INT type  Γöé
  9418. Γöé the other operand has LONG INT type  Γöé is converted to LONG INT.       Γöé
  9419. Γöé and the value of the UNSIGNED INT can Γöé                    Γöé
  9420. Γöé be represented in a LONG INT      Γöé                    Γöé
  9421. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9422. Γöé One operand has UNSIGNED INT type and Γöé Both operands are converted to    Γöé
  9423. Γöé the other operand has LONG INT type  Γöé UNSIGNED LONG INT           Γöé
  9424. Γöé and the value of the UNSIGNED INT   Γöé                    Γöé
  9425. Γöé cannot be represented in a LONG INT  Γöé                    Γöé
  9426. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9427. Γöé One operand has LONG INT type     Γöé The other operand is converted to   Γöé
  9428. Γöé                    Γöé LONG INT.               Γöé
  9429. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9430. Γöé One operand has LONG LONG INT type   Γöé The other operand is converted to   Γöé
  9431. Γöé                    Γöé LONG LONG INT.            Γöé
  9432. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9433. Γöé One operand has UNSIGNED INT type   Γöé The other operand is converted to   Γöé
  9434. Γöé                    Γöé UNSIGNED INT.             Γöé
  9435. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9436. Γöé Both operands have INT type      Γöé The result is type INT.        Γöé
  9437. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  9438.  
  9439.  
  9440. ΓòÉΓòÉΓòÉ 7. Functions ΓòÉΓòÉΓòÉ
  9441.  
  9442. This section describes the structure and use of functions in C and C++. It 
  9443. discusses the following topics: 
  9444.  
  9445.      C++ Enhancements to C Functions 
  9446.      Function Declarations 
  9447.      Function Definitions 
  9448.      The main() Function 
  9449.      Calling Functions and Passing Arguments 
  9450.      Default Arguments in C++ Functions 
  9451.      Inline Functions 
  9452.  
  9453.  Related Information 
  9454.  
  9455.      Member Functions 
  9456.      Inline Member Functions 
  9457.      C++ Overloading 
  9458.      Special C++ Member Functions 
  9459.      Virtual Functions 
  9460.  
  9461.  Functions specify the logical structure of a program and define how particular 
  9462.  operations are to be implemented. 
  9463.  
  9464.  A function declaration consists of a return type, a name, and an argument 
  9465.  list. It is used to declare the format and existence of a function prior to 
  9466.  its use. 
  9467.  
  9468.  A function definition contains a function declaration and the body of the 
  9469.  function. A function can only have one definition. 
  9470.  
  9471.  Both C++ and ANSI/ISO C use the style of declaration called prototyping. A 
  9472.  prototype refers to the return type, name, and argument list components of a 
  9473.  function. It is used by the compiler for argument type checking and argument 
  9474.  conversions. Prototypes can appear several times in a program, provided the 
  9475.  declarations are compatible. They allow the compiler to check for mismatches 
  9476.  between the parameters of a function call and those in the function 
  9477.  declaration. 
  9478.  
  9479.  C++ Note:  C++ functions must use prototypes. They are usually placed in 
  9480.  header files, while function definitions appear in source files. Nonprototype 
  9481.  functions are allowed in C only. 
  9482.  
  9483.  
  9484. ΓòÉΓòÉΓòÉ 7.1. C++ Enhancements to C Functions ΓòÉΓòÉΓòÉ
  9485.  
  9486. The C++ language provides many enhancements to C functions. These are: 
  9487.  
  9488.      Reference arguments 
  9489.      Default arguments 
  9490.      Reference return types 
  9491.      Member functions 
  9492.      Overloaded functions 
  9493.      Operator functions 
  9494.      Constructor and destructor functions 
  9495.      Conversion functions 
  9496.      Virtual functions 
  9497.      Function templates 
  9498.  
  9499.  
  9500. ΓòÉΓòÉΓòÉ 7.2. Function Declarations ΓòÉΓòÉΓòÉ
  9501.  
  9502. A function declaration establishes the name and the parameters of the function. 
  9503.  
  9504. Syntax of a Function Declaration 
  9505.  
  9506. A function is declared implicitly by its appearance in an expression if it has 
  9507. not been defined or declared previously; the implicit declaration is equivalent 
  9508. to a declaration of extern int func_name(). The default return type of a 
  9509. function is int. 
  9510.  
  9511. To indicate that the function does not return a value, declare it with a return 
  9512. type of void. 
  9513.  
  9514. C++ Note:  The use of the const and volatile specifiers is only supported by 
  9515. C++. 
  9516.  
  9517.  
  9518. ΓòÉΓòÉΓòÉ 7.2.1. C Function Declarations ΓòÉΓòÉΓòÉ
  9519.  
  9520. A function cannot be declared as returning a data object having a volatile or 
  9521. const type but it can return a pointer to a volatile or const object. Also, a 
  9522. function cannot return a value that has a type of array or function. 
  9523.  
  9524. If the called function returns a value that has a type other than int, you must 
  9525. declare the function before the function call. Even if a called function 
  9526. returns a type int, explicitly declaring the function prior to its call is good 
  9527. programming practice. 
  9528.  
  9529. Some declarations do not have parameter lists; the declarations simply specify 
  9530. the types of parameters and the return values, such as in the following 
  9531. example: 
  9532.  
  9533.   int func(int,long);
  9534.  
  9535. Examples of Function Declarations and Definitions 
  9536.  
  9537. Related Information 
  9538.  
  9539.      Function Declarator 
  9540.      Function Definitions 
  9541.      Calling Functions and Passing Arguments 
  9542.      extern Storage Class Specifier 
  9543.  
  9544.  
  9545. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Function Declaration ΓòÉΓòÉΓòÉ
  9546.  
  9547. A function declaration has the form: 
  9548.  
  9549.                               ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9550.                                      Γöé
  9551. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇfunction_declaratorΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>
  9552.   Γö£ΓöÇexternΓöÇΓöñ  ΓööΓöÇtype_specifierΓöÇΓöÿ              ΓööΓöÇparameterΓöÇΓöÿ
  9553.   ΓööΓöÇstaticΓöÇΓöÿ
  9554. >ΓöÇΓöÇ)ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  9555.    Γö£ΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöñ
  9556.    ΓööΓöÇvolatileΓöÇΓöÿ
  9557.  
  9558. C++ Note:  The use of the const and volatile specifiers is only supported by 
  9559. C++. 
  9560.  
  9561.  
  9562. ΓòÉΓòÉΓòÉ 7.2.2. C++ Function Declarations ΓòÉΓòÉΓòÉ
  9563.  
  9564. In C++, you can specify the qualifiers volatile and const in member function 
  9565. declarations. You can also specify exception specifications in function 
  9566. declarations. All C++ functions must be declared before they can be called. 
  9567.  
  9568. Types cannot be defined in return or argument types. For example, the following 
  9569. declarations are not valid in C++: 
  9570.  
  9571. void print(struct X { int i; } x);      //error
  9572. enum count{one, two, three} counter();    //error
  9573.  
  9574. This example attempts to declare a function print() that takes an object x of 
  9575. class X as its argument. However, the class definition is not allowed within 
  9576. the argument list. In the attempt to declare counter(), the enumeration type 
  9577. definition cannot appear in the return type of the function declaration. The 
  9578. two function declarations and their corresponding type definitions can be 
  9579. rewritten as follows: 
  9580.  
  9581. struct X { int i; };
  9582. void print(X x);
  9583. enum count {one, two, three};
  9584. count counter();
  9585.  
  9586. Multiple Function Declarations 
  9587.  
  9588. All function declarations for a particular function must have the same number 
  9589. and type of arguments, and must have the same return type and the same linkage 
  9590. keywords. These return and argument types are part of the function type, 
  9591. although the default arguments are not. 
  9592.  
  9593. For the purposes of argument matching, ellipsis and linkage keywords are 
  9594. considered a part of the function type. They must be used consistently in all 
  9595. declarations of a function. If the only difference between the argument types 
  9596. in two declarations is in the use of typedef names or unspecified argument 
  9597. array bounds, the declarations are the same. A const or volatile specifier is 
  9598. also part of the function type, but can only be part of a declaration or 
  9599. definition of a nonstatic member function. 
  9600.  
  9601. Declaring two functions differing only in return type is not valid function 
  9602. overloading, and is flagged as an error. For example: 
  9603.  
  9604. void f();
  9605. int f();    // error, two definitions differ only in
  9606.        // return type
  9607. int g()
  9608. {
  9609.   return f();
  9610. }
  9611.  
  9612. Checking Function Calls 
  9613.  
  9614. The compiler checks C++ function calls by comparing the number and type of the 
  9615. actual arguments used in the function call with the number and type of the 
  9616. formal arguments in the function declaration. Implicit type conversion is 
  9617. performed when necessary. 
  9618. Argument Names in Function Declarations 
  9619.  
  9620. You can supply argument names in a function declaration, but the compiler 
  9621. ignores them except in the following two situations: 
  9622.  
  9623.    1. If two argument names have the same name within a single declaration. 
  9624.       This is an error. 
  9625.  
  9626.    2. If an argument name is the same as a name outside the function. In this 
  9627.       case the name outside the function is hidden and cannot be used in the 
  9628.       argument declaration. 
  9629.  
  9630.  In the following example, the third argument intersects is meant to have 
  9631.  enumeration type subway_line, but this name is hidden by the name of the first 
  9632.  argument. The declaration of the function subway() causes a compile-time error 
  9633.  because subway_line is not a valid type name in the context of the argument 
  9634.  declarations. 
  9635.  
  9636.   enum subway_line {yonge, university, spadina, bloor};
  9637.   int subway(char * subway_line, int stations,
  9638.            subway_line intersects);
  9639.  
  9640.  
  9641. ΓòÉΓòÉΓòÉ <hidden> Examples of Function Declarations and Definitions ΓòÉΓòÉΓòÉ
  9642.  
  9643. /************************************************************************
  9644. *
  9645.  
  9646. The following example defines the function absolute with the return type 
  9647. double. Because this is a noninteger return type, absolute is declared prior to 
  9648. the function call. 
  9649.  
  9650.                                     *
  9651. ************************************************************************/
  9652.  
  9653. /**
  9654.  ** This example shows how a function is declared and defined
  9655.  **/
  9656.  
  9657. #include <stdio.h>
  9658. double absolute(double);
  9659.  
  9660. int main(void)
  9661. {
  9662.   double f = -3.0;
  9663.  
  9664.   printf("absolute number = %lf\n", absolute(f));
  9665.  
  9666.   return (0);
  9667. }
  9668.  
  9669. double absolute(double number)
  9670. {
  9671.   if (number < 0.0)
  9672.    number = -number;
  9673.  
  9674.   return (number);
  9675. }
  9676.  
  9677. /************************************************************************
  9678. *
  9679.  
  9680. Specifying a return type of void on a function declaration indicates that the 
  9681. function does not return a value. The following example defines the function 
  9682. absolute with the return type void. Within the function main, absolute is 
  9683. declared with the return type void. 
  9684.  
  9685.                                     *
  9686. ************************************************************************/
  9687.  
  9688. /**
  9689.  ** This example uses a function with a void return type
  9690.  **/
  9691.  
  9692. #include <stdio.h>
  9693.  
  9694. int main(void)
  9695. {
  9696.  void absolute(float);
  9697.  float f = -8.7;
  9698.  
  9699.  absolute(f);
  9700.  
  9701.  return(0);
  9702. }
  9703.  
  9704. void absolute(float number)
  9705. {
  9706.  if (number < 0.0)
  9707.   number = -number;
  9708.  
  9709.  printf("absolute number = %f\n", number);
  9710. }
  9711.  
  9712. The following code fragments show several function declarations. The first 
  9713. declares a function f that takes two integer arguments and has a return type of 
  9714. void: 
  9715.  
  9716.    void f(int, int);
  9717.  
  9718. The following code fragment declares a function f1 that takes an integer 
  9719. argument, and returns a pointer to a function that takes an integer argument 
  9720. and returns an integer: 
  9721.  
  9722.    int (*f1(int))(int);
  9723.  
  9724. Alternatively, a typedef can be used for the complicated return type of 
  9725. function f1: 
  9726.  
  9727.    typedef int pf1(int);
  9728.    pf1* f1(int);
  9729.  
  9730. The following code fragment declares a pointer p1 to a function that takes a 
  9731. pointer to a constant character and returns an integer: 
  9732.  
  9733.    int (*p1) (const char*);
  9734.  
  9735. The following declaration is of an external function f2 that takes a constant 
  9736. integer as its first argument, can have a variable number and variable types of 
  9737. other arguments, and returns type int. 
  9738.  
  9739.    int extern f2(const int ...);
  9740.  
  9741. Function f3 takes an int argument with a default value that is the value 
  9742. returned from function f2, and that has a return type of int: 
  9743.  
  9744.    const int j = 5;
  9745.    int f3( int x = f2(j) );
  9746.  
  9747. Function f6 is a constant class member function of class X with no arguments, 
  9748. and with an int return type: 
  9749.  
  9750. class X
  9751. {
  9752. public:
  9753.    int f6() const;
  9754. };
  9755.  
  9756. Function f4 takes no arguments, has return type void, and can throw class 
  9757. objects of types X and Y. 
  9758.  
  9759. class X;
  9760. class Y;
  9761. //    .
  9762. //    .
  9763. //    .
  9764. void f4() throw(X,Y);
  9765.  
  9766. Function f5 takes no arguments, has return type void, and cannot throw an 
  9767. exception. 
  9768.  
  9769. void f5() throw();
  9770.  
  9771.  
  9772. ΓòÉΓòÉΓòÉ 7.3. Function Definitions ΓòÉΓòÉΓòÉ
  9773.  
  9774. A function definition contains a function declaration and the body of a 
  9775. function. It specifies the function name, formal parameters, the return type, 
  9776. and storage class of the function. 
  9777.  
  9778. Syntax of a Function Definition 
  9779.  
  9780. A function definition (either prototype or nonprototype) contains the 
  9781. following: 
  9782.  
  9783.      An optional storage class specifier extern or static, which determines 
  9784.       the scope of the function. If a storage class specifier is not given, the 
  9785.       function has external linkage. 
  9786.      An optional linkage keyword, which determines the calling convention used 
  9787.       to call the function. The keywords are a VisualAge for C++ extension to 
  9788.       the ANSI/ISO C definition. The default VisualAge for C++ calling 
  9789.       convention is _Optlink. The _Optlink calling convention is described in 
  9790.       the IBM VisualAge for C++ for Windows User's Guide. 
  9791.      An optional type specifier, which determines the type of value that the 
  9792.       function returns. If a type specifier is not given, the function has type 
  9793.       int. 
  9794.      A function declarator, which provides the function with a name, can 
  9795.       further describe the type of the value that the function returns, and can 
  9796.       list any parameters that the function expects and their types. The 
  9797.       parameters that the function is expecting are enclosed in parentheses. 
  9798.      A block statement, which contains data definitions and code. 
  9799.  
  9800.  A nonprototype function definition can also have a list of parameter 
  9801.  declarations, which describe the types of parameters that the function 
  9802.  receives. In nonprototype functions, parameters that are not declared have 
  9803.  type int. 
  9804.  
  9805.  A function can be called by itself or by other functions. Unless a function 
  9806.  definition has the storage class specifier static, the function also can be 
  9807.  called by functions that appear in other files. Functions with a storage class 
  9808.  specifier of static can only be directly invoked from within the same source 
  9809.  file. 
  9810.  
  9811.  If a function has the storage class specifier static or a return type other 
  9812.  than int, the function definition or a declaration for the function must 
  9813.  appear before, and in the same file as, a call to the function. 
  9814.  
  9815.  In C only, if a function definition has external linkage and a return type of 
  9816.  int, calls to the function can be made before it is visible because an 
  9817.  implicit declaration of extern int func(); is assumed. This is not true for 
  9818.  C++. 
  9819.  
  9820.  All declarations for a given function must be compatible; that is, the return 
  9821.  type is the same and the parameters have the same type. 
  9822.  
  9823.  The default type for the return value and parameters of a function is int, and 
  9824.  the default storage class specifier is extern. If the function does not return 
  9825.  a value or it is not passed any parameters, use the keyword void as the type 
  9826.  specifier. 
  9827.  
  9828.  A function can return a pointer or reference to a function, array, or to an 
  9829.  object with a volatile or const type. In C, you cannot declare a function as a 
  9830.  struct or union member. (This restriction does not apply to C++.) 
  9831.  
  9832.  A function cannot have a return type of function or array. In C, a function 
  9833.  cannot return any type having the volatile or const qualifier. (This 
  9834.  restriction does not apply to C++.) 
  9835.  
  9836.  You cannot define an array of functions. You can, however, define an array of 
  9837.  pointers to functions. 
  9838.  
  9839.  Examples of Function Definitions 
  9840.  
  9841.  Related Information 
  9842.  
  9843.      Storage Class Specifiers 
  9844.      Linkage Keywords 
  9845.      Type Specifiers 
  9846.      Function Declarator 
  9847.      Block 
  9848.      volatile and const Qualifiers 
  9849.      Function Declarations 
  9850.  
  9851.  
  9852. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Function Definition ΓòÉΓòÉΓòÉ
  9853.  
  9854. A function definition has the form: 
  9855.  
  9856. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>
  9857.   Γö£ΓöÇexternΓöÇΓöñ  ΓööΓöÇlinkage_specifierΓöÇΓöÿ  ΓööΓöÇtype_specifierΓöÇΓöÿ
  9858.   ΓööΓöÇstaticΓöÇΓöÿ
  9859.             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9860.                          Γöé
  9861. >ΓöÇΓöÇfunction_declaratorΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇblock_statementΓöÇΓöÇ><
  9862.              ΓööΓöÇparameter_declarationΓöÇΓöÿ
  9863.  
  9864.  
  9865. ΓòÉΓòÉΓòÉ <hidden> Examples of Function Definitions ΓòÉΓòÉΓòÉ
  9866.  
  9867. /************************************************************************
  9868. *
  9869.  
  9870. In the following example, ary is an array of two function pointers. Type 
  9871. casting is performed to the values assigned to ary for compatibility: 
  9872.  
  9873.                                     *
  9874. ************************************************************************/
  9875.  
  9876. /**
  9877.  ** This example uses an array of pointers to functions
  9878.  **/
  9879.  
  9880. #include <stdio.h>
  9881.  
  9882. int func1(void);
  9883. void func2(double a);
  9884.  
  9885. int main(void)
  9886. {
  9887.   double num;
  9888.   int retnum;
  9889.   void (*ary[2]) ();
  9890.   ary[0] = ((void(*)())func1);
  9891.   ary[1] = ((void(*)())func2);
  9892.  
  9893.   retnum=((int (*)())ary[0])();    /*  calls func1  */
  9894.   printf("number returned = %i\n", retnum);
  9895.   ((void (*)(double))ary[1])(num);  /*  calls func2  */
  9896.  
  9897.   return(0);
  9898. }
  9899.  
  9900. int func1(void)
  9901. {
  9902. int number=3;
  9903. return number;
  9904. }
  9905.  
  9906. void func2(double a)
  9907. {
  9908. a=333.3333;
  9909. printf("result of func2 = %f\n", a);
  9910. }
  9911.  
  9912. /************************************************************************
  9913. *
  9914.  
  9915. The following example is a complete definition of the function sum: 
  9916.  
  9917. int sum(int x,int y)
  9918. {
  9919.   return(x + y);
  9920. }
  9921.  
  9922. The function sum has external linkage, returns an object that has type int, and 
  9923. has two parameters of type int declared as x and y. The function body contains 
  9924. a single statement that returns the sum of x and y. 
  9925.  
  9926.                                     *
  9927. ************************************************************************/
  9928.  
  9929.  
  9930. ΓòÉΓòÉΓòÉ 7.3.1. Linkage Keywords ΓòÉΓòÉΓòÉ
  9931.  
  9932. Use linkage keywords to set calling conventions for function calls. Each 
  9933. calling convention has a corresponding keyword that you can use with a function 
  9934. name to set the convention for that function. 
  9935.  
  9936. Using linkage keywords with data generates an error. 
  9937.  
  9938. Note:  Using a linkage keyword is generally quicker and easier than using a 
  9939.        #pragma linkage and they let you declare both the function and its 
  9940.        linkage type in one statement. Because the #pragma linkage directive is 
  9941.        obsolete in VisualAge for C++, linkage keywords are the preferred method 
  9942.        for setting the calling conventions. Do not use #pragma linkage in new 
  9943.        code. For your new applications, use linkage keywords to specify the 
  9944.        calling convention for a function. 
  9945.  
  9946. C++ Note:  #pragma linkage is not supported at all for C++ functions. 
  9947.  
  9948.  The linkage keywords for calling conventions are: 
  9949.  
  9950.      _Optlink 
  9951.      _System 
  9952.      __stdcall 
  9953.      __cdecl 
  9954.  
  9955.  You can use these linkage keywords at any language level. The VisualAge for 
  9956.  C++ default linkage is _Optlink. 
  9957.  
  9958.  The default linkage convention for C++ member functions is _Optlink. Other 
  9959.  linkage conventions are permitted to allow a parameters to be passed in a 
  9960.  different order from _Optlink. 
  9961.  
  9962.  A member function with linkage other than _Optlink still has a this pointer. 
  9963.  The signature of a member function with linkage other than _Optlink is 
  9964.  unchanged. The _System calling convention is equivalent to __stdcall linkage 
  9965.  because __stdcall is the linkage  used by the system APIs. It is still treated 
  9966.  as a distinct linkage convention, however. 
  9967.  
  9968.  The keywords used in the following function calling conventions are reserved 
  9969.  by the compiler, but the calling conventions themselves are not supported by 
  9970.  IBM VisualAge for C++ for Windows 
  9971.  
  9972.      _Pascal 
  9973.      _Far32 _Pascal 
  9974.      _Far16 _Cdecl 
  9975.      _Far16 _Pascal 
  9976.      _Far16 _Fastcall 
  9977.  Using the keywords as calling conventions causes a warning to be issued, and 
  9978.  the default linkage, _Optlink, is used. 
  9979.  
  9980.  The VisualAge for C++ compiler provides the following linkage keywords in ansi 
  9981.  and extended modes for compatibility with Microsoft Visual C++: 
  9982.  
  9983.      __optlink 
  9984.      __system 
  9985.  
  9986.  The VisualAge for C++ compiler provides the following linkage keywords in 
  9987.  extended mode for compatibility with Microsoft Visual C++: 
  9988.  
  9989.      _cdecl 
  9990.      _stdcall 
  9991.  
  9992.  To set the calling convention for a function, place the linkage keyword 
  9993.  immediately before the function name or at the beginning of the declarator. 
  9994.  For example: 
  9995.  
  9996.     int _Optlink deborah(int);
  9997.     char (__stdcall * albert)(void);
  9998.  
  9999.  At link time, function names are decorated according to the linkage convention 
  10000.  specified. The following decorations are used: 
  10001.  
  10002.  Linkage Convention Name Decoration 
  10003.  
  10004.  _Optlink    Function names are decorated with a question mark prefix (?) when 
  10005.              they appear in object modules. For example, a function named fred 
  10006.              in the source program will appear as ?fred in the object. 
  10007.  
  10008.  __stdcall and _System Function names are decorated with an underscore prefix 
  10009.              (_), and a suffix which consists of an at sign (@), followed by 
  10010.              the number of bytes of parameters (in decimal). Parameters of less 
  10011.              than four bytes are rounded up to four bytes. Structure sizes are 
  10012.              also rounded up to a multiple of four bytes. For example, a 
  10013.              function fred prototyped as follows: 
  10014.  
  10015.                             int fred(int, int, short);
  10016.  
  10017.              would appear as: 
  10018.  
  10019.                             _fred@12
  10020.  
  10021.              in the object module. 
  10022.  
  10023.  __cdecl      Function names are decorated with an underscore prefix (_) when 
  10024.              they appear in object modules. For example, a function named fred 
  10025.              in the source program will appear as _fred in the object. 
  10026.  
  10027.  Linkage keywords take precedence over the compiler options that set calling 
  10028.  conventions (/Mc, /Mp, /Ms, and /Mt). Specifying conflicting linkage types for 
  10029.  a function generates an error. 
  10030.  
  10031.  When the /Wgen is used, a warning is issued if a declaration contains the same 
  10032.  keyword more than once. 
  10033.  
  10034.  For more information about using calling conventions and their keywords, see 
  10035.  the IBM VisualAge for C++ for Windows Programming Guide. 
  10036.  
  10037.  Related Information 
  10038.  
  10039.      #pragma linkage 
  10040.      /Mp and /Ms options 
  10041.      Function Declarations 
  10042.      Function Definitions 
  10043.  
  10044.  
  10045. ΓòÉΓòÉΓòÉ 7.3.2. Function Declarator ΓòÉΓòÉΓòÉ
  10046.  
  10047. The function declarator names the function and lists the function parameters. 
  10048. It contains an identifier that names the function and a list of the function 
  10049. parameters. You should always use prototype function declarators because of the 
  10050. parameter checking that can be performed. C++ functions must have prototype 
  10051. function declarators. 
  10052. Prototype Function Declarators 
  10053.  
  10054. Each parameter should be declared within the function declarator. Any calls to 
  10055. the function must pass the same number of arguments as there are parameters in 
  10056. the declaration. 
  10057. Nonprototype Function Declarators 
  10058.  
  10059. Each parameter should be declared in a parameter declaration list following the 
  10060. declarator. If a parameter is not declared, it has type int. 
  10061.  
  10062. char and short parameters are widened to int, and float to double. No type 
  10063. checking between the argument type and the parameter type is done for 
  10064. nonprototyped functions. As well, there are no checks to ensure that the number 
  10065. of arguments matches the number of parameters. 
  10066.  
  10067. Each value that a function receives should be declared in a parameter 
  10068. declaration list for nonprototype function definitions that follows the 
  10069. declarator. 
  10070.  
  10071. A parameter declaration determines the storage class specifier and the data 
  10072. type of the value. 
  10073.  
  10074. The only storage class specifier allowed is the register storage class 
  10075. specifier. Any type specifier for a parameter is allowed. If you do not specify 
  10076. the register storage class specifier, the parameter will have the auto storage 
  10077. class specifier. If you omit the type specifier and you are not using the 
  10078. prototype form to define the function, the parameter will have type int. 
  10079.  
  10080.   int func(i,j)
  10081.   {
  10082.     /*  i and j have type int  */
  10083.   }
  10084.  
  10085. You cannot declare a parameter in the parameter declaration list if it is not 
  10086. listed within the declarator. 
  10087.  
  10088. Related Information 
  10089.  
  10090.      Function Declarations 
  10091.      Function Definitions 
  10092.      Function Body 
  10093.      Functions 
  10094.      Declarations 
  10095.  
  10096.  
  10097. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Function Declarator ΓòÉΓòÉΓòÉ
  10098.  
  10099. A function declarator has the form: 
  10100.  
  10101. >>ΓöÇΓöÇdeclaratorΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇparameter_declaration_listΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  10102.           Γöé ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ       Γöé
  10103.           Γöé        Γöé       Γöé
  10104.           ΓööΓöÇΓöÇΓöÇidentifierΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  10105.  
  10106. A parameter declaration list has the form: 
  10107.  
  10108.   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  10109.   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ              Γöé
  10110.                  Γöé              Γöé
  10111. >>ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇstorage_class_specifierΓöÇΓö¼Γö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  10112.     Γö£ΓöÇtype_specifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ  Γö£ΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdeclaratorΓöÇΓöÇΓöÇΓöñ   ΓööΓöÇ,ΓöÇΓöÇ...ΓöÇΓöÿ
  10113.     ΓööΓöÇtype_qualifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ  Γöé ΓööΓöÇ*ΓöÇΓöÿ        Γöé
  10114.                    ΓööΓöÇabstract_declaratorΓöÇΓöÿ
  10115.  
  10116. An abstract declarator has the form: 
  10117.  
  10118. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  10119.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  10120.      Γöé
  10121. >>ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓö¼ΓöÇ(ΓöÇΓöÇabstract_declaratorΓöÇΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  10122.    ΓööΓöÇ*ΓöÇΓöÿ  ΓööΓöÇΓöñ  direct_abstract_declarator Γö£ΓöÇΓöÿ
  10123. DIRECT_ABSTRACT_DECLARATOR:
  10124. Γö£ΓöÇΓöÇabstract_declaratorΓöÇΓöÇΓö¼ΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöñ
  10125.             Γöé   ΓööΓöÇconstant_expressionΓöÇΓöÿ      Γöé
  10126.             ΓööΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÿ
  10127.                ΓööΓöÇparameter_declaration_listΓöÇΓöÿ
  10128. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  10129.  
  10130.  
  10131. ΓòÉΓòÉΓòÉ 7.3.3. Ellipsis and void ΓòÉΓòÉΓòÉ
  10132.  
  10133. An ellipsis at the end of a parameter declaration indicates that the number of 
  10134. arguments is equal to, or greater than, the number of specified argument types. 
  10135. At least one parameter declaration must come before the ellipsis. Where it is 
  10136. permitted, an ellipsis preceded by a comma is equivalent to a simple ellipsis. 
  10137.  
  10138.    int f(int,...);
  10139.  
  10140. The comma before the ellipsis is optional in C++ only 
  10141.  
  10142. Parameter promotions are performed as needed, but no type checking is done on 
  10143. the variable arguments. 
  10144.  
  10145. You can declare a function with no arguments in two ways: 
  10146.  
  10147.    int f(void);    // ANSI/ISO C Standard
  10148.  
  10149.    int f();      // C++ enhancement
  10150.             // Note: In ANSI/ISO C, this declaration means that
  10151.             // f may take any number or type or parameters
  10152.  
  10153. An empty argument declaration list or the argument declaration list of (void) 
  10154. indicates a function that takes no arguments. void cannot be used as an 
  10155. argument type, although types derived from void (such as pointers to void) can 
  10156. be used. 
  10157.  
  10158. In the following example, the function f() takes one integer parameter and 
  10159. returns no value, while g() expects no parameters and returns an integer. 
  10160.  
  10161. void f(int);
  10162. int g(void);
  10163.  
  10164.  
  10165. ΓòÉΓòÉΓòÉ 7.3.4. Function Body ΓòÉΓòÉΓòÉ
  10166.  
  10167. The body of a function is a block statement. 
  10168.  
  10169. The following function body contains a definition for the integer variable 
  10170. big_num, an if-else control statement, and a call to the function printf: 
  10171.  
  10172. void largest(int num1, int num2)
  10173. {
  10174.   int big_num;
  10175.  
  10176.   if (num1 >= num2)
  10177.    big_num = num1;
  10178.   else
  10179.    big_num = num2;
  10180.  
  10181.   printf("big_num = %d\n", big_num);
  10182. }
  10183.  
  10184. Examples of Prototype Function Declarators 
  10185.  
  10186.  
  10187. ΓòÉΓòÉΓòÉ <hidden> Examples of Prototype Function Declarators ΓòÉΓòÉΓòÉ
  10188.  
  10189. The following example contains a function declarator sort with table declared 
  10190. as a pointer to int and length declared as type int. Note that arrays as 
  10191. parameters are implicitly converted to a pointer to the type. 
  10192.  
  10193. /**
  10194.  ** This example illustrates function declarators.
  10195.  ** Note that arrays as parameters are implicitly
  10196.  ** converted to a pointer to the type.
  10197.  **/
  10198.  
  10199. #include <stdio.h>
  10200.  
  10201. void sort(int table[ ], int length);
  10202.  
  10203. int main(void)
  10204. {
  10205.   int table[ ]={1,5,8,4};
  10206.   int length=4;
  10207.   printf("length is %d\n",length);
  10208.   sort(table,length);
  10209. }
  10210.  
  10211. void sort(int table[ ], int length)
  10212. {
  10213.  int i, j, temp;
  10214.  
  10215.  for (i = 0; i < length -1; i++)
  10216.   for (j = i + 1; j < length; j++)
  10217.    if (table[i] > table[j])
  10218.    {
  10219.     temp = table[i];
  10220.     table[i] = table[j];
  10221.     table[j] = temp;
  10222.    }
  10223. }
  10224.  
  10225. The following examples contain prototype function declarators: 
  10226.  
  10227. double square(float x);
  10228. int area(int x,int y);
  10229. static char *search(char);
  10230.  
  10231. The following example illustrates how a typedef identifier can be used in a 
  10232. function declarator: 
  10233.  
  10234. typedef struct tm_fmt { int minutes;
  10235.            int hours;
  10236.            char am_pm;
  10237.           } struct_t;
  10238. long time_seconds(struct_t arrival)
  10239.  
  10240. The following function set_date declares a pointer to a structure of type date 
  10241. as a parameter.  date_ptr has the storage class specifier register. 
  10242.  
  10243. set_date(register struct date *date_ptr)
  10244. {
  10245.  date_ptr->mon = 12;
  10246.  date_ptr->day = 25;
  10247.  date_ptr->year = 87;
  10248. }
  10249.  
  10250. Related Information 
  10251.  
  10252.      Block 
  10253.      Function Definitions 
  10254.      Function Declarations 
  10255.  
  10256.  
  10257. ΓòÉΓòÉΓòÉ 7.4. The main() Function ΓòÉΓòÉΓòÉ
  10258.  
  10259. When a program begins running, the system automatically calls the function 
  10260. main, which marks the entry point of the program. Every program must have one 
  10261. function named main. No other function in the program can be called main. 
  10262.  
  10263. Syntax of the main Function 
  10264.  
  10265. By default, main has the storage class extern and a return type of int. It can 
  10266. also be declared to return void. 
  10267.  
  10268. In C++, you cannot declare main as inline or static. You cannot call main from 
  10269. within a program or take the address of main. 
  10270.  
  10271.  
  10272. ΓòÉΓòÉΓòÉ 7.4.1. Arguments to main ΓòÉΓòÉΓòÉ
  10273.  
  10274. Syntax of the Arguments to main 
  10275.  
  10276. The function main can be declared with or without arguments that pass program 
  10277. parameters and environment settings to the program. Although any name can be 
  10278. given to these parameters, they are usually referred to as argc, argv, and 
  10279. envp. 
  10280.  
  10281.  argc            Is the argument count. It has type int and indicates how many 
  10282.                  arguments are entered on the command line. 
  10283.  
  10284.  argv            Is the argument vector. It is an array of pointers to char 
  10285.                  array objects. These char objects are null-terminated strings 
  10286.                  that are the program arguments passed to the program when it 
  10287.                  is invoked. 
  10288.  
  10289.  envp            Is an optional environment pointer. It is an array of pointers 
  10290.                  to char objects that are the environment variables available 
  10291.                  to the program. These have the form name=value. The system 
  10292.                  determines the value of this parameter during program 
  10293.                  initialization (before calling main). Because you can use the 
  10294.                  function getenv to get the value of these pointers, there is 
  10295.                  usually no need to declare this parameter. 
  10296.  
  10297.  The value of argc indicates the number of pointers in the array argv. If a 
  10298.  program name is available, the first element in argv points to a character 
  10299.  array that contains the program name or the invocation name of the program 
  10300.  that is being run. If the name cannot be determined, the first element in argv 
  10301.  points to a null character. 
  10302.  
  10303.  This name is counted as one of the arguments to the function main. For 
  10304.  example, if only the program name is entered on the command line, argc has a 
  10305.  value of 1 and argv[0] points to the program name. 
  10306.  
  10307.  Regardless of the number of arguments entered on the command line, argv[argc] 
  10308.  always contains NULL. 
  10309.  
  10310.  Example of Arguments to main 
  10311.  
  10312.  Related Information 
  10313.  
  10314.      Function Definitions 
  10315.      Calling Functions and Passing Arguments 
  10316.      Type Specifiers 
  10317.      Identifiers 
  10318.      Block 
  10319.  
  10320.  
  10321. ΓòÉΓòÉΓòÉ <hidden> Syntax of the main Function ΓòÉΓòÉΓòÉ
  10322.  
  10323. The main function has the form: 
  10324.  
  10325. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇmainΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇblock_statementΓöÇΓöÇ><
  10326.   Γö£ΓöÇvoidΓöÇΓöñ      Γö£ΓöÇvoidΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  10327.   ΓööΓöÇintΓöÇΓöÇΓöÿ      ΓööΓöÇparametersΓöÇΓöÿ
  10328.  
  10329.  
  10330. ΓòÉΓòÉΓòÉ <hidden> Syntax of the Arguments to main ΓòÉΓòÉΓòÉ
  10331.  
  10332. The main function has the following arguments: 
  10333.  
  10334. >>ΓöÇΓöÇintΓöÇΓöÇargcΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  10335.         ΓööΓöÇ, char*ΓöÇΓöÇargvΓöÇΓöÇ[]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  10336.                   ΓööΓöÇ, char*ΓöÇΓöÇenvpΓöÇΓöÇ[]ΓöÇΓöÿ
  10337.  
  10338.  
  10339. ΓòÉΓòÉΓòÉ <hidden> Example of Arguments to main ΓòÉΓòÉΓòÉ
  10340.  
  10341. /************************************************************************
  10342. *
  10343.  
  10344. The following program backward prints the arguments entered on a command line 
  10345. such that the last argument is printed first: 
  10346.  
  10347.                                     *
  10348. ************************************************************************/
  10349.  
  10350. #include <stdio.h>
  10351. int main(int argc, char *argv[])
  10352. {
  10353.  while (--argc > 0)
  10354.   printf("%s ", argv[argc]);
  10355. }
  10356.  
  10357. /************************************************************************
  10358. *
  10359.  
  10360. Invoking this program from a command line with the following: 
  10361.  
  10362.   backward string1 string2
  10363.  
  10364. gives the following output: 
  10365.  
  10366.   string2 string1
  10367.  
  10368. The arguments argc and argv would contain the following values: 
  10369.  
  10370.  Object              Value 
  10371.  argc                3 
  10372.  argv[0]             pointer to string "backward" 
  10373.  argv[1]             pointer to string "string1" 
  10374.  argv[2]             pointer to string "string2" 
  10375.  argv[3]             NULL 
  10376.  
  10377.                                        *
  10378.   ************************************************************************/
  10379.  
  10380.  
  10381. ΓòÉΓòÉΓòÉ 7.5. Calling Functions and Passing Arguments ΓòÉΓòÉΓòÉ
  10382.  
  10383. A function call specifies a function name and a list of arguments. The calling 
  10384. function passes the value of each argument to the specified function. The 
  10385. argument list is surrounded by parentheses, and each argument is separated by a 
  10386. comma. The argument list can be empty. When a function is called, the actual 
  10387. arguments are used to initialize the formal arguments. 
  10388.  
  10389. The type of an actual argument is checked against the type of the corresponding 
  10390. formal argument in the function prototype. All standard and user-defined type 
  10391. conversions are applied as necessary. 
  10392.  
  10393. For example: 
  10394.  
  10395. #include <iostream.h>
  10396. #include <math.h>
  10397. extern double root(double, double);   // declaration
  10398. double root(double value, double base) // definition
  10399. {
  10400.    double temp = exp(log(value)/base);
  10401.    return temp;
  10402. }
  10403. void main()
  10404. {
  10405.    int value = 144;
  10406.    int base = 2;
  10407.    // Call function root and print return value
  10408.    cout << "The root is: " << root(value,base) << endl;
  10409. }
  10410.  
  10411. The output is The root is: 12 
  10412.  
  10413. In the above example, because the function root is expecting arguments of type 
  10414. double, the two int arguments value and base are implicitly converted to type 
  10415. double when the function is called. 
  10416.  
  10417. The arguments to a function are evaluated before the function is called. When 
  10418. an argument is passed in a function call, the function receives a copy of the 
  10419. argument value. If the value of the argument is an address, the called function 
  10420. can use indirection to change the contents pointed to by the address. If a 
  10421. function or array is passed as an argument, the argument is converted to a 
  10422. pointer that points to the function or array. 
  10423.  
  10424. Arguments passed to parameters in prototype declarations will be converted to 
  10425. the declared parameter type. For nonprototype function declarations, char and 
  10426. short parameters are promoted to int, and float to double. 
  10427.  
  10428. You can pass a packed structure argument to a function expecting a nonpacked 
  10429. structure of the same type and vice versa. (The same applies to packed and 
  10430. nonpacked unions.) 
  10431.  
  10432. Note:  If you do not use a function prototype and you send a packed structure 
  10433. when a nonpacked structure is expected, a runtime error may occur. 
  10434.  
  10435. The order in which arguments are evaluated and passed to the function is 
  10436. implementation-defined. For example, the following sequence of statements calls 
  10437. the function tester: 
  10438.  
  10439. int x;
  10440. x = 1;
  10441. tester(x++, x);
  10442.  
  10443. The call to tester in the example may produce different results on different 
  10444. compilers. Depending on the implementation, x++ may be evaluated first or x may 
  10445. be evaluated first. To avoid the ambiguity and have x++ evaluated first, 
  10446. replace the preceding sequence of statements with the following: 
  10447.  
  10448. int x, y;
  10449. x = 1;
  10450. y = x++;
  10451. tester(y, x);
  10452.  
  10453.  
  10454. ΓòÉΓòÉΓòÉ 7.5.1. Passing Arguments in C++ ΓòÉΓòÉΓòÉ
  10455.  
  10456. In C++, if a nonstatic class member function is passed as an argument, the 
  10457. argument is converted to a pointer to member. 
  10458.  
  10459. If a class has a destructor or a copy constructor that does more than a bitwise 
  10460. copy, passing a class object by value results in the construction of a 
  10461. temporary that is actually passed by reference. 
  10462.  
  10463. It is an error when a function argument is a class object and all of the 
  10464. following properties hold: 
  10465.  
  10466.      The class needs a copy constructor. 
  10467.      The class does not have a user-defined copy constructor. 
  10468.      A copy constructor cannot be generated for that class. 
  10469.  
  10470.  Examples of Calling Functions and Passing Arguments 
  10471.  
  10472.  Related Information 
  10473.  
  10474.      Passing Arguments by Reference 
  10475.      Constructors and Destructors Overview 
  10476.      Member Functions 
  10477.      Function Declarator 
  10478.      Function Declarations 
  10479.      Function Definitions 
  10480.      Type Specifiers 
  10481.  
  10482.  
  10483. ΓòÉΓòÉΓòÉ <hidden> Examples of Calling Functions ΓòÉΓòÉΓòÉ
  10484.  
  10485. /************************************************************************
  10486. *
  10487.  
  10488. The following statement calls the function startup and passes no parameters: 
  10489.  
  10490. startup();
  10491.  
  10492. The following function call causes copies of a and b to be stored in a local 
  10493. area for the function sum. The function sum runs using the copies of a and b. 
  10494.  
  10495. sum(a, b);
  10496.  
  10497. The following function call passes the value 2 and the value of the expression 
  10498. a +b to sum: 
  10499.  
  10500. sum(2, a + b);
  10501.  
  10502. The following statement calls the function printf, which receives a character 
  10503. string and the return value of the function sum, which receives the values of a 
  10504. and b: 
  10505.  
  10506. printf("sum = %d\n", sum(a,b));
  10507.  
  10508. The following program passes the value of count to the function increment. 
  10509. increment increases the value of the parameter x by 1. 
  10510.  
  10511.                                     *
  10512. ************************************************************************/
  10513.  
  10514. /**
  10515.  ** This example shows how a parameter is passed to a function
  10516.  **/
  10517.  
  10518. #include <stdio.h>
  10519.  
  10520. void increment(int);
  10521.  
  10522. int main(void)
  10523. {
  10524.  int count = 5;
  10525.  
  10526.  /* value of count is passed to the function */
  10527.  increment(count);
  10528.  printf("count = %d\n", count);
  10529.  
  10530.  return(0);
  10531. }
  10532.  
  10533. void increment(int x)
  10534. {
  10535.  ++x;
  10536.  printf("x = %d\n", x);
  10537. }
  10538.  
  10539. /************************************************************************
  10540. *
  10541.  
  10542. The output illustrates that the value of count in main remains unchanged: 
  10543.  
  10544. x = 6
  10545. count = 5
  10546.  
  10547. In the following program, main passes the address of count to increment. The 
  10548. function increment was changed to handle the pointer. The parameter x is 
  10549. declared as a pointer. The contents to which x points are then incremented. 
  10550.  
  10551.                                     *
  10552. ************************************************************************/
  10553.  
  10554. /**
  10555.  ** This example shows how an address is passed to a function
  10556.  **/
  10557.  
  10558. #include <stdio.h>
  10559.  
  10560. int main(void)
  10561. {
  10562.  void increment(int *x);
  10563.  int count = 5;
  10564.  
  10565.  /* address of count is passed to the function */
  10566.  increment(&count);
  10567.  printf("count = %d\n", count);
  10568.  
  10569.  return(0);
  10570. }
  10571.  
  10572. void increment(int *x)
  10573. {
  10574.  ++*x;
  10575.  printf("*x = %d\n", *x);
  10576. }
  10577.  
  10578. /************************************************************************
  10579. *
  10580.  
  10581. The output shows that the variable count is increased: 
  10582.  
  10583. *x = 6
  10584. count = 6
  10585.  
  10586.                                     *
  10587. ************************************************************************/
  10588.  
  10589.  
  10590. ΓòÉΓòÉΓòÉ 7.5.2. Passing Arguments by Reference ΓòÉΓòÉΓòÉ
  10591.  
  10592. If you use a reference type as a formal argument, you can make a 
  10593. pass-by-reference call to a function. In a pass-by-reference call, the values 
  10594. of arguments in the calling function can be modified in the called function. In 
  10595. pass-by-value calls, only copies of the arguments are passed to the function. 
  10596.  
  10597. Note:  The term pass by reference describes a general method of passing 
  10598. arguments from a calling routine to a called routine. 
  10599.  
  10600. C++ Note:  The term reference in the context of C++ refers to a specific way of 
  10601. declaring objects and functions. 
  10602.  
  10603. Example of Passing Arguments by Reference 
  10604.  
  10605. Ellipsis arguments cannot be passed as references. 
  10606.  
  10607. In addition, when the actual argument cannot be referenced directly by the 
  10608. formal argument, the compiler creates a temporary variable that is referenced 
  10609. by the formal argument and initialized using the value of the actual argument. 
  10610. In this case, the formal argument must be a const reference. 
  10611.  
  10612. Reference arguments declared const can be used to pass large objects 
  10613. efficiently to functions without making a temporary copy of the object that is 
  10614. passed to the function. Because the reference is declared const, the actual 
  10615. arguments cannot be changed by the function. For example: 
  10616.  
  10617. void printbig (const bigvar&); // Function prototype
  10618.  
  10619. When a function printbig is called, it cannot modify the object of type bigvar 
  10620. because the object was passed by constant reference. 
  10621.  
  10622. Related Information 
  10623.  
  10624.      Calling Functions and Passing Arguments 
  10625.      References 
  10626.      volatile and const Qualifiers 
  10627.  
  10628.  
  10629. ΓòÉΓòÉΓòÉ <hidden> Example of Passing Arguments by Reference ΓòÉΓòÉΓòÉ
  10630.  
  10631. /************************************************************************
  10632. *
  10633.  
  10634. The following example shows how arguments are passed by reference. Note that 
  10635. reference formal arguments are initialized with the actual arguments when the 
  10636. function is called. 
  10637.  
  10638.                                     *
  10639. ************************************************************************/
  10640.  
  10641. /**
  10642.  ** This example shows how arguments are passed by reference
  10643.  **/
  10644.  
  10645. #include <iostream.h>
  10646. void swapnum(int &i, int &j)
  10647. {
  10648.    int temp = i;
  10649.    i = j;
  10650.    j = temp;
  10651. }
  10652. //   .
  10653. //   .
  10654. //   .
  10655. main()
  10656. {
  10657.    int  a = 10,   // a is 10
  10658.       b = 20;   // b is 20
  10659.    swapnum(a,b);   // now a is 20 and b is 10
  10660.    cout << "A is : " << a
  10661.       << " and B is : " << b << endl;
  10662. }
  10663.  
  10664. /************************************************************************
  10665. *
  10666.  
  10667. When the function swapnum() is called, the actual values of the variables a and 
  10668. b are exchanged because they are passed by reference. The output is: 
  10669.  
  10670. A is : 20 and B is : 10
  10671.  
  10672. You must define the formal arguments of swapnum() as references if you want the 
  10673. values of the actual arguments to be modified by the function swapnum(). 
  10674.  
  10675.                                     *
  10676. ************************************************************************/
  10677.  
  10678. If the last argument specified in the function declaration before the ellipsis 
  10679. is a reference argument, arguments passed using an ellipsis (variable 
  10680. arguments) are accessible using the mechanism from the <stdarg.h> standard 
  10681. header file. 
  10682.  
  10683.  
  10684. ΓòÉΓòÉΓòÉ 7.6. Default Arguments in C++ Functions ΓòÉΓòÉΓòÉ
  10685.  
  10686. In C++, you can provide default values for function arguments. All default 
  10687. argument names of a function are bound when the function is declared. All 
  10688. functions have their types checked at declaration, and are evaluated at each 
  10689. point of call. 
  10690.  
  10691. For example: 
  10692.  
  10693. /**
  10694.  ** This example illustrates default function arguments
  10695.  **/
  10696.  
  10697. #include <iostream.h>
  10698. int a = 1;
  10699. int f(int a) {return a;}
  10700. int g(int x = f(a)) {return f(a);}
  10701.  
  10702. int h()
  10703. {
  10704.    a=2;
  10705.    {
  10706.       int a = 3;
  10707.       return g();
  10708.    }
  10709. }
  10710.  
  10711. main()
  10712. {
  10713.    cout << h() << endl;
  10714. }
  10715.  
  10716. This example prints 2 to standard output, because the a referred to in the 
  10717. declaration of g() is the one at file scope, which has the value 2 when g() is 
  10718. called. The value of a is determined after entry into function h() but before 
  10719. the call to g() is resolved. 
  10720.  
  10721. A default argument can have any type. 
  10722.  
  10723. A pointer to a function must have the same type as the function. Attempts to 
  10724. take the address of a function by reference without specifying the type of the 
  10725. function produce an error. The type of a function is not affected by arguments 
  10726. with default values. 
  10727.  
  10728. The following example shows that a function with default arguments does not 
  10729. change its type. The default argument allows you to call a function without 
  10730. specifying all of the arguments, it does not allow you to create a pointer to 
  10731. the function that does not specify the types of all the arguments. Function f 
  10732. can be called without an explicit argument, but the pointer badpointer cannot 
  10733. be defined without specifying the type of the argument: 
  10734.  
  10735. int f(int = 0);
  10736. void g()
  10737. {
  10738.   int a = f(1);         // ok
  10739.   int b = f();         // ok, default argument used
  10740. }
  10741. int (*pointer)(int) = &f;    // ok, type of f() specified (int)
  10742. int (*badpointer)() = &f;    // error, badpointer and f have
  10743.                 // different types. badpointer must
  10744.                 // be initialized with a pointer to
  10745.                 // a function taking no arguments.
  10746.  
  10747. For additional information about default arguments, see: 
  10748.  
  10749.      Restrictions on Default Arguments 
  10750.      Evaluating Default Arguments 
  10751.  
  10752.  Related Information 
  10753.  
  10754.      Calling Functions and Passing Arguments 
  10755.      Functions 
  10756.  
  10757.  
  10758. ΓòÉΓòÉΓòÉ 7.6.1. Restrictions on Default Arguments ΓòÉΓòÉΓòÉ
  10759.  
  10760. Of the operators, only the function call operator and the operator new can have 
  10761. default arguments when they are overloaded. 
  10762.  
  10763. Arguments with default values must be the trailing arguments in the function 
  10764. declaration argument list. For example: 
  10765.  
  10766. void f(int a, int b = 2, int c = 3);  // trailing defaults
  10767. void g(int a = 1, int b = 2, int c);  // error, leading defaults
  10768. void h(int a, int b = 3, int c);    // error, default in middle
  10769.  
  10770. Once a default argument has been given in a declaration or definition, you 
  10771. cannot redefine that argument, even to the same value. However, you can add 
  10772. default arguments not given in previous declarations. For example, the last 
  10773. declaration below attempts to redefine the default values for a and b: 
  10774.  
  10775. void f(int a, int b, int c=1);   // valid
  10776. void f(int a, int b=1, int c);   // valid, add another default
  10777. void f(int a=1, int b, int c);   // valid, add another default
  10778. void f(int a=1, int b=1, int c=1); // error, redefined defaults
  10779.  
  10780. You can supply any default argument values in the function declaration or in 
  10781. the definition. All subsequent arguments must have default arguments supplied 
  10782. in this or a previous declaration of the function. 
  10783.  
  10784. You cannot use local variables in default argument expressions. For example, 
  10785. the compiler generates errors for both function g() and function h() below: 
  10786.  
  10787. void f(int a)
  10788. {
  10789.    int b=4;
  10790.    void g(int c=a); // Local variable "a" inaccessible
  10791.    void h(int d=b); // Local variable "b" inaccessible
  10792. }
  10793.  
  10794. Related Information 
  10795.  
  10796.      Function Calls ( ) 
  10797.      C++ new Operator 
  10798.      Default Arguments in C++ Functions 
  10799.      Evaluating Default Arguments 
  10800.      Calling Functions and Passing Arguments 
  10801.      Functions 
  10802.  
  10803.  
  10804. ΓòÉΓòÉΓòÉ 7.6.2. Evaluating Default Arguments ΓòÉΓòÉΓòÉ
  10805.  
  10806. When a function defined with default arguments is called with trailing 
  10807. arguments missing, the default expressions are evaluated. For example: 
  10808.  
  10809. void f(int a, int b = 2, int c = 3); // declaration
  10810. // ...
  10811. int a = 1;
  10812. f(a);       // same as call f(a,2,3)
  10813. f(a,10);     // same as call f(a,10,3)
  10814. f(a,10,20);    // no default arguments
  10815.  
  10816. Default arguments are checked against the function declaration and evaluated 
  10817. when the function is called. The order of evaluation of default arguments is 
  10818. undefined. Default argument expressions cannot use formal arguments of a 
  10819. function. For example: 
  10820.  
  10821. int f(int q = 3, int r = q); // error
  10822.  
  10823. The argument r cannot be initialized with the value of the argument q because 
  10824. the value of q may not be known when it is assigned to r. If the above function 
  10825. declaration is rewritten: 
  10826.  
  10827. int q=5;
  10828. int f(int q = 3, int r = q); // error
  10829.  
  10830. the value of r in the function declaration still produces an error because the 
  10831. variable q defined outside of the function is hidden by the argument q declared 
  10832. for the function. Similarly: 
  10833.  
  10834. typedef double D;
  10835. int f(int D, int z = D(5.3) ); // error
  10836.  
  10837. Here the type D is interpreted within the function declaration as the name of 
  10838. an integer. The type D is hidden by the argument D. The cast D(5.3) is 
  10839. therefore not interpreted as a cast because D is the name of the argument not a 
  10840. type. 
  10841.  
  10842. In the following example, the nonstatic member a cannot be used as an 
  10843. initializer because a does not exist until an object of class X is constructed. 
  10844. You can use the static member b as an initializer because b is created 
  10845. independently of any objects of class X. You can declare the member b after its 
  10846. use as a default argument because the default values are not analyzed until 
  10847. after the final bracket } of the class declaration. 
  10848.  
  10849. class X
  10850. {
  10851.   int a;
  10852.   f(int z = a) ; // error
  10853.   g(int z = b) ; // valid
  10854.   static int b;
  10855. };
  10856.  
  10857. You must put parentheses around default argument expressions that contain 
  10858. template references. In the following example: 
  10859.  
  10860. class C {
  10861.   void f(int i = X<int,5>::y);
  10862. };
  10863.  
  10864. the compiler cannot tell that the < represents the start of a template argument 
  10865. list and not the less than operator because the default argument X<int,5>::y 
  10866. cannot be processed until the end of the class. 
  10867.  
  10868. To avoid error messages, put parentheses around the expression containing the 
  10869. default argumement: 
  10870.  
  10871. class C {
  10872.   void f( int i = (X<int,5>::y) );
  10873. };
  10874.  
  10875. Related Information 
  10876.  
  10877.      Default Arguments in C++ Functions 
  10878.      Restrictions on Default Arguments 
  10879.      Calling Functions and Passing Arguments 
  10880.      Functions 
  10881.      Constructors and Destructors Overview 
  10882.  
  10883.  
  10884. ΓòÉΓòÉΓòÉ 7.7. Function Return Values ΓòÉΓòÉΓòÉ
  10885.  
  10886. A value must be returned from a function unless the function has a return type 
  10887. of void. The return value is specified in a return statement. The following 
  10888. code fragment shows a function definition, including the return statement: 
  10889.  
  10890. int add(int i, int j)
  10891. {
  10892.  return i + j; // return statement
  10893. }
  10894.  
  10895. The function add() can be called as shown in the following code fragment: 
  10896.  
  10897. int a = 10,
  10898.   b = 20;
  10899. int answer = add(a, b); // answer is 30
  10900.  
  10901. In this example, the return statement initializes a variable of the returned 
  10902. type. The variable answer is initialized with the int value 30. The type of the 
  10903. returned expression is checked against the returned type. All standard and 
  10904. user-defined conversions are performed as necessary. 
  10905.  
  10906. The following return statements show different ways of returning values to a 
  10907. caller: 
  10908.  
  10909. return;           // Returns no value
  10910. return result;       // Returns the value of result
  10911. return 1;          // Returns the value 1
  10912. return (x * x);       // Returns the value of x * x
  10913.  
  10914. Other than main(), if a function that does not have type void returns without a 
  10915. value (as in the first return statement shown in the example above) the result 
  10916. returned is undefined. In C++, the compiler issues an error message as well. 
  10917.  
  10918. If main has a return type of int, and does not contain a return expression, it 
  10919. returns the value zero. 
  10920.  
  10921. Each time a function is called, new copies of its local variables are created. 
  10922. Because the storage for a local variable may be reused after the function has 
  10923. terminated, a pointer to a local variable or a reference to a local variable 
  10924. should not be returned. 
  10925.  
  10926. If a class object is returned, a temporary object may be created if the class 
  10927. has copy constructors or a destructor. 
  10928.  
  10929. References can also be used as return types for functions. The reference 
  10930. returns the lvalue of the object to which it refers. This allows you to place 
  10931. function calls on the left side of assignment statements. Referenced return 
  10932. values are used when assignment operators and subscripting operators are 
  10933. overloaded so that the results of the overloaded operators can be used as 
  10934. actual values. 
  10935.  
  10936. Note:  Returning a reference to an automatic variable gives unpredictable 
  10937. results. 
  10938.  
  10939. Related Information 
  10940.  
  10941.      return 
  10942.      Calling Functions and Passing Arguments 
  10943.      The main() Function 
  10944.      Temporary Objects 
  10945.      Special Overloaded Operators 
  10946.  
  10947.  
  10948. ΓòÉΓòÉΓòÉ 7.8. Pointers to Functions ΓòÉΓòÉΓòÉ
  10949.  
  10950. A pointer to a function points to the address of the function's executable 
  10951. code. You can use pointers to call functions and to pass functions as arguments 
  10952. to other functions. You cannot perform pointer arithmetic on pointers to 
  10953. functions. 
  10954.  
  10955. The type of a pointer to a function is based on both the return type and 
  10956. argument types of the function. 
  10957.  
  10958. A declaration of a pointer to a function must have the pointer name in 
  10959. parentheses. Without them, the compiler interprets the statement as a function 
  10960. that returns a pointer to a specified return type. For example: 
  10961.  
  10962. int *f(int a);    // function f returning an int*
  10963. int (*g)(int a);   // pointer g to a function returning an int
  10964.  
  10965. In the first declaration, f is interpreted as a function that takes an int as 
  10966. argument, and returns a pointer to an int. In the second declaration, g is 
  10967. interpreted as a pointer to a function that takes an int argument and that 
  10968. returns an int. 
  10969.  
  10970. For more information on pointers, see Pointers and Pointer Conversions. 
  10971.  
  10972.  
  10973. ΓòÉΓòÉΓòÉ 7.9. Inline Functions ΓòÉΓòÉΓòÉ
  10974.  
  10975. Inline functions are used to reduce the overhead of a normal function call. A 
  10976. function is declared inline by using the specifiers described below. The inline 
  10977. specifiers are a suggestion to the compiler that an inline expansion can be 
  10978. performed. Instead of transferring control to and from the function code 
  10979. segment, a modified copy of the function body may be substituted directly for 
  10980. the function call. 
  10981.  
  10982. An inline function can be declared and defined simultaneously. If it is 
  10983. declared with one of the inline specifier keywords, it can be declared without 
  10984. a definition. The following code fragment shows an inline function definition. 
  10985. Note that the definition includes both the declaration and body of the inline 
  10986. function. 
  10987.  
  10988. inline int add(int i, int j) { return i + j; }
  10989.  
  10990. Both member and nonmember functions can be inline, and both have internal 
  10991. linkage. 
  10992.  
  10993. The use of the inline specifier does not change the meaning of the function. 
  10994. The inline expansion of a function may not preserve the order of evaluation of 
  10995. the actual arguments. 
  10996.  
  10997. For more information on inlining, see the IBM VisualAge for C++ for Windows 
  10998. Programming Guide. 
  10999.  
  11000. Related Information 
  11001.  
  11002.      Inline Specifiers 
  11003.      Inline Member Functions 
  11004.      Functions 
  11005.  
  11006.  
  11007. ΓòÉΓòÉΓòÉ 7.9.1. Inline Specifiers ΓòÉΓòÉΓòÉ
  11008.  
  11009. VisualAge for C++ provides keywords that you can use to specify functions that 
  11010. you want the compiler to inline: 
  11011.  
  11012.      _Inline, _inline, and __inline for C programs 
  11013.      inline for C++ programs 
  11014.  For example: 
  11015.  
  11016.     _Inline int catherine(int a);
  11017.  
  11018.  causes catherine to be inlined, meaning that code is generated for the 
  11019.  function, rather than a function call. The inline keywords also implicitly 
  11020.  declare the function as static. 
  11021.  
  11022.  Using the inline specifiers with data generates an error. 
  11023.  
  11024.  By default, function inlining is turned off, and functions qualified with 
  11025.  inline specifiers are treated simply as static functions. To turn on function 
  11026.  inlining, specify the /Oi+ option. If you turn optimization on (/O+), /Oi+ 
  11027.  becomes the default. 
  11028.  
  11029.  Recursive functions (functions that call themselves) are inlined for the first 
  11030.  occurrence only. The call to the function from within itself will not be 
  11031.  inlined. 
  11032.  
  11033.  You can also use the /Oivalue option to automatically inline all functions 
  11034.  smaller than value abstract code units as well as those qualified with inline 
  11035.  specifiers. For best performance, use the inline keywords to choose the 
  11036.  functions you want to inline rather than using automatic inlining. 
  11037.  
  11038.  When inlining is turned on, the following functions are also considered 
  11039.  candidates to be inlined: 
  11040.  
  11041.      C++ member functions that are defined in class declarations. 
  11042.      For C programs only, small functions of static storage class that are 
  11043.       called only once. 
  11044.  
  11045.  Note:  If you plan to debug your code (specifying /Ti+), you should turn 
  11046.  inlining off. Profiling hooks are not generated for inlined functions. 
  11047.  
  11048.  For more information on function inlining, see the IBM VisualAge for C++ for 
  11049.  Windows User's Guide. 
  11050.  
  11051.  Related Information 
  11052.  
  11053.      static Storage Class Specifier 
  11054.      Storage Class Specifiers 
  11055.      Inline Functions 
  11056.      Inline Member Functions 
  11057.      /Oi option 
  11058.  
  11059.  
  11060. ΓòÉΓòÉΓòÉ 8. Statements ΓòÉΓòÉΓòÉ
  11061.  
  11062. This section describes the following C and C++ language statements: 
  11063.  
  11064.      Labels 
  11065.      Block 
  11066.      break 
  11067.      continue 
  11068.      do 
  11069.      Expression 
  11070.      for 
  11071.      goto 
  11072.      if 
  11073.      Null Statement 
  11074.      return 
  11075.      switch 
  11076.      while 
  11077.  
  11078.  Related Information 
  11079.  
  11080.      Scope in C 
  11081.      Scope in C++ 
  11082.      Declarations 
  11083.      Expressions and Operators 
  11084.      Functions 
  11085.  
  11086.  
  11087. ΓòÉΓòÉΓòÉ 8.1. Labels ΓòÉΓòÉΓòÉ
  11088.  
  11089. A label is an identifier that allows your program to transfer control to other 
  11090. statements within the same function. It is the only type of identifier that has 
  11091. function scope. Control is transferred to the statement following the label by 
  11092. means of the goto or switch statements. 
  11093.  
  11094. Syntax of a Labelled Statement 
  11095.  
  11096. The label is the identifier and the colon (:) character. 
  11097.  
  11098. The case and default labels can only appear within the body of a switch 
  11099. statement. 
  11100.  
  11101.  comment_complete : ;       /* null statement label */
  11102.  test_for_null : if (NULL == pointer)
  11103.  
  11104. Related Information 
  11105.  
  11106.      Scope in C 
  11107.      Scope in C++ 
  11108.      goto 
  11109.      switch 
  11110.  
  11111.  
  11112. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Labelled Statement ΓòÉΓòÉΓòÉ
  11113.  
  11114. A labelled statement has the form: 
  11115.  
  11116. >>ΓöÇΓöÇidentifierΓöÇΓöÇ:ΓöÇΓöÇstatementΓöÇΓöÇ><
  11117.  
  11118.  
  11119. ΓòÉΓòÉΓòÉ 8.2. Block ΓòÉΓòÉΓòÉ
  11120.  
  11121. A block statement, or compound statement, lets you group any number of data 
  11122. definitions, declarations, and statements into one statement. All definitions, 
  11123. declarations, and statements enclosed within a single set of braces are treated 
  11124. as a single statement. You can use a block wherever a single statement is 
  11125. allowed. 
  11126.  
  11127. Syntax of a Block Statement 
  11128.  
  11129. In C, Any definitions and declarations must come before the statements. 
  11130.  
  11131. Redefining a data object inside a nested block hides the outer object while the 
  11132. inner block runs. Defining several variables that have the same identifier can 
  11133. make a program difficult to understand and maintain. You should avoid 
  11134. redefining of identifiers within nested blocks. If a data object is usable 
  11135. within a block and its identifier is not redefined, all nested blocks can use 
  11136. that data object. 
  11137.  
  11138. Examples of Block Statements 
  11139.  
  11140. Related Information 
  11141.  
  11142.      Block Scope Data Declarations 
  11143.      Initialization within Block Statements 
  11144.      Function Body 
  11145.      auto Storage Class Specifier 
  11146.      register Storage Class Specifier 
  11147.      static Storage Class Specifier 
  11148.      extern Storage Class Specifier 
  11149.  
  11150.  
  11151. ΓòÉΓòÉΓòÉ <hidden> Initialization within Block Statements ΓòÉΓòÉΓòÉ
  11152.  
  11153. Initialization of an auto or register variable occurs each time the block is 
  11154. run from the beginning. If you transfer control from one block to the middle of 
  11155. another block, initializations are not always performed. You cannot initialize 
  11156. an extern variable within a block. 
  11157.  
  11158. A static local object is initialized only once, when control passes through its 
  11159. declaration for the first time. A static variable initialized with an 
  11160. expression other than a constant expression is initialized to 0 before its 
  11161. block is first entered. 
  11162.  
  11163. C++ Note:  Unlike ANSI/ISO C, in C++ it is an error to jump over a declaration 
  11164. or definition containing an initializer. For example, the following code 
  11165. produces an error in C++: 
  11166.  
  11167. goto skiplabel;
  11168. int i=3    // error, jumped over declaration of i with initializer
  11169. skiplabel: i=4;
  11170.  
  11171. When control exits from a block, all objects with destructors that are defined 
  11172. in the block are destroyed. The destructor for a static local object is called 
  11173. only if the object was constructed. The destructor must be called before or as 
  11174. part of the atexit function. 
  11175.  
  11176. Local variables declared in a block are also destroyed on exit. Automatic 
  11177. variables defined in a loop are destroyed at each iteration. 
  11178.  
  11179. Related Information 
  11180.  
  11181.      Block Scope Data Declarations 
  11182.      Block 
  11183.      auto Storage Class Specifier 
  11184.      register Storage Class Specifier 
  11185.      static Storage Class Specifier 
  11186.      extern Storage Class Specifier 
  11187.      Destructors 
  11188.  
  11189.  
  11190. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Block Statement ΓòÉΓòÉΓòÉ
  11191.  
  11192. A block statement has the form: 
  11193.  
  11194.     ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11195.                      Γöé         Γöé
  11196. >>ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  11197.     Γö£ΓöÇtype_definitionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ   ΓööΓöÇstatementΓöÇΓöÿ
  11198.     Γö£ΓöÇfile_scope_data_declarationΓöÇΓöÇΓöñ
  11199.     ΓööΓöÇblock_scope_data_declarationΓöÇΓöÿ
  11200.  
  11201.  
  11202. ΓòÉΓòÉΓòÉ <hidden> Examples of Block Statements ΓòÉΓòÉΓòÉ
  11203.  
  11204. /************************************************************************
  11205. *
  11206.  
  11207. The following program shows how the values of data objects change in nested 
  11208. blocks: 
  11209.  
  11210.                                     *
  11211. ************************************************************************/
  11212.  
  11213.  1 /**
  11214.  2  ** This example shows how data objects change in nested blocks.
  11215.  3  **/
  11216.  4  #include <stdio.h>
  11217.  5
  11218.  6  int main(void)
  11219.  7  {
  11220.  8    int x = 1;           /* Initialize x to 1  */
  11221.  9    int y = 3;
  11222. 10
  11223. 11    if (y > 0)
  11224. 12    {
  11225. 13     int x = 2;          /* Initialize x to 2  */
  11226. 14     printf("second x = %4d\n", x);
  11227. 15    }
  11228. 16    printf("first  x = %4d\n", x);
  11229. 17
  11230. 18    return(0);
  11231. 19  }
  11232.  
  11233. /************************************************************************
  11234. *
  11235.  
  11236. The program produces the following output: 
  11237.  
  11238. second x =   2
  11239. first  x =   1
  11240.  
  11241. Two variables named x are defined in main. The definition of x on line 8 
  11242. retains storage while main is running. However, because the definition of x on 
  11243. line 13 occurs within a nested block, line 14 recognizes x as the variable 
  11244. defined on line 13. Because line 16 is not part of the nested block, x is 
  11245. recognized as the variable defined on line 8. 
  11246.  
  11247.                                     *
  11248. ************************************************************************/
  11249.  
  11250.  
  11251. ΓòÉΓòÉΓòÉ 8.3. break ΓòÉΓòÉΓòÉ
  11252.  
  11253. A break statement lets you end an iterative (do, for, while) or switch 
  11254. statement and exit from it at any point other than the logical end. 
  11255.  
  11256. Syntax of a break Statement 
  11257.  
  11258. In an iterative statement the break statement ends the loop and moves control 
  11259. to the next statement outside the loop. Within nested statements, the break 
  11260. statement ends only the smallest enclosing do, for, switch, or while statement. 
  11261.  
  11262. In a switch body, the break passes control out of the switch body to the next 
  11263. statement outside the switch body. 
  11264.  
  11265. A break statement can only appear in the body of an iterative statement or a 
  11266. switch statement. 
  11267.  
  11268. Examples of break Statements 
  11269.  
  11270. Related Information 
  11271.  
  11272.      do 
  11273.      for 
  11274.      switch 
  11275.      while 
  11276.  
  11277.  
  11278. ΓòÉΓòÉΓòÉ <hidden> Syntax of a break Statement ΓòÉΓòÉΓòÉ
  11279.  
  11280. A break statement has the form: 
  11281.  
  11282. >>ΓöÇΓöÇbreakΓöÇΓöÇ;ΓöÇΓöÇ><
  11283.  
  11284.  
  11285. ΓòÉΓòÉΓòÉ <hidden> Examples of break Statements ΓòÉΓòÉΓòÉ
  11286.  
  11287. /************************************************************************
  11288. *
  11289.  
  11290. The following example shows a break statement in the action part of a for 
  11291. statement. If the ith element of the array string is equal to '\0', the break 
  11292. statement causes the for statement to end. 
  11293.  
  11294. for (i = 0; i < 5; i++)
  11295. {
  11296.   if (string[i] == '\0')
  11297.    break;
  11298.   length++;
  11299. }
  11300.  
  11301. The following is an equivalent for statement, if string does not contain any 
  11302. embedded null characters: 
  11303.  
  11304. for (i = 0; (i < 5)&& (string[i] != '\0'); i++)
  11305. {
  11306.   length++;
  11307. }
  11308.  
  11309. The following example shows a break statement in a nested iterative statement. 
  11310. The outer loop goes through an array of pointers to strings. The inner loop 
  11311. examines each character of the string. When the break statement is processed, 
  11312. the inner loop ends and control returns to the outer loop. 
  11313.  
  11314.                                     *
  11315. ************************************************************************/
  11316.  
  11317. /**
  11318.  **  This program counts the characters in the strings that are
  11319.  **  part of an array of pointers to characters.  The count stops
  11320.  **  when one of the digits 0 through 9 is encountered
  11321.  **  and resumes at the beginning of the next string.
  11322.  **/
  11323.  
  11324. #include <stdio.h>
  11325. #define  SIZE  3
  11326.  
  11327. int main(void)
  11328. {
  11329.   static char *strings[SIZE] = { "ab", "c5d", "e5" };
  11330.   int i;
  11331.   int letter_count = 0;
  11332.   char *pointer;
  11333.  
  11334.   for (i = 0; i < SIZE; i++)     /* for each string   */
  11335.                    /* for each character */
  11336.    for (pointer = strings[i]; *pointer != '\0'; ++pointer)
  11337.    {                  /* if a number     */
  11338.      if (*pointer >= '0' && *pointer <= '9')
  11339.       break;
  11340.      letter_count++;
  11341.    }
  11342.   printf("letter count = %d\n", letter_count);
  11343.  
  11344.   return(0);
  11345. }
  11346.  
  11347. /************************************************************************
  11348. *
  11349.  
  11350. The program produces the following output: 
  11351.  
  11352. letter count = 4
  11353.  
  11354. The following example is a switch statement that contains several break 
  11355. statements. Each break statement indicates the end of a specific clause and 
  11356. ends the switch statement. 
  11357.  
  11358. /**
  11359.  ** This example shows a switch statement with break statements.
  11360.  **/
  11361.  
  11362. #include <stdio.h>
  11363.  
  11364. enum {morning, afternoon, evening} timeofday = morning;
  11365.  
  11366. int main(void) {
  11367.  
  11368.   switch (timeofday) {
  11369.    case (morning):
  11370.      printf("Good Morning\n");
  11371.      break;
  11372.  
  11373.    case (evening):
  11374.      printf("Good Evening\n");
  11375.      break;
  11376.  
  11377.    default:
  11378.      printf("Good Day, eh\n");
  11379.   }
  11380. }
  11381.  
  11382.                                     *
  11383. ************************************************************************/
  11384.  
  11385.  
  11386. ΓòÉΓòÉΓòÉ 8.4. continue ΓòÉΓòÉΓòÉ
  11387.  
  11388. A continue statement lets you end the current iteration of a loop. Program 
  11389. control is passed from the continue statement to the end of the loop body. 
  11390.  
  11391. Syntax of a continue Statement 
  11392.  
  11393. The continue statement ends the processing of the action part of an iterative 
  11394. (do, for, or while) statement and moves control to the condition part of the 
  11395. statement. If the iterative statement is a for statement, control moves to the 
  11396. third expression in the condition part of the statement, then to the second 
  11397. expression (the test) in the condition part of the statement. 
  11398.  
  11399. Within nested statements, the continue statement ends only the current 
  11400. iteration of the do, for, or while statement immediately enclosing it. 
  11401.  
  11402. A continue statement can only appear within the body of an iterative statement. 
  11403.  
  11404. Examples of continue Statements 
  11405.  
  11406. Related Information 
  11407.  
  11408.      do 
  11409.      for 
  11410.      while 
  11411.  
  11412.  
  11413. ΓòÉΓòÉΓòÉ <hidden> Syntax of a continue Statement ΓòÉΓòÉΓòÉ
  11414.  
  11415. A continue statement has the form: 
  11416.  
  11417. >>ΓöÇΓöÇcontinueΓöÇΓöÇ;ΓöÇΓöÇ><
  11418.  
  11419.  
  11420. ΓòÉΓòÉΓòÉ <hidden> Examples of continue Statements ΓòÉΓòÉΓòÉ
  11421.  
  11422. /************************************************************************
  11423. *
  11424.  
  11425. The following example shows a continue statement in a for statement. The 
  11426. continue statement causes processing to skip over those elements of the array 
  11427. rates that have values less than or equal to 1. 
  11428.  
  11429.                                     *
  11430. ************************************************************************/
  11431.  
  11432. /**
  11433.  ** This example shows a continue statement in a for statement.
  11434.  **/
  11435.  
  11436. #include <stdio.h>
  11437. #define  SIZE  5
  11438.  
  11439. int main(void)
  11440. {
  11441.   int i;
  11442.   static float rates[SIZE] = { 1.45, 0.05, 1.88, 2.00, 0.75 };
  11443.  
  11444.   printf("Rates over 1.00\n");
  11445.   for (i = 0; i < SIZE; i++)
  11446.   {
  11447.    if (rates[i] <= 1.00)  /*  skip rates <= 1.00  */
  11448.      continue;
  11449.    printf("rate = %.2f\n", rates[i]);
  11450.   }
  11451.  
  11452.   return(0);
  11453. }
  11454.  
  11455. /************************************************************************
  11456. *
  11457.  
  11458. The program produces the following output: 
  11459.  
  11460. Rates over 1.00
  11461. rate = 1.45
  11462. rate = 1.88
  11463. rate = 2.00
  11464.  
  11465. The following example shows a continue statement in a nested loop. When the 
  11466. inner loop encounters a number in the array strings, that iteration of the loop 
  11467. ends. Processing continues with the third expression of the inner loop. The 
  11468. inner loop ends when the '\0' escape sequence is encountered. 
  11469.  
  11470.                                     *
  11471. ************************************************************************/
  11472.  
  11473. /**
  11474.  ** This program counts the characters in strings that are part
  11475.  ** of an array of pointers to characters.  The count excludes
  11476.  ** the digits 0 through 9.
  11477.  **/
  11478.  
  11479. #include <stdio.h>
  11480. #define  SIZE  3
  11481.  
  11482. int main(void)
  11483. {
  11484.   static char *strings[SIZE] = { "ab", "c5d", "e5" };
  11485.   int i;
  11486.   int letter_count = 0;
  11487.   char *pointer;
  11488.   for (i = 0; i < SIZE; i++)         /* for each string     */
  11489.                        /* for each each character */
  11490.    for (pointer = strings[i]; *pointer != '\0'; ++pointer)
  11491.    {                  /* if a number       */
  11492.      if (*pointer >= '0' && *pointer <= '9')
  11493.       continue;
  11494.      letter_count++;
  11495.    }
  11496.   printf("letter count = %d\n", letter_count);
  11497.  
  11498.   return(0);
  11499. }
  11500.  
  11501. /************************************************************************
  11502. *
  11503.  
  11504. The program produces the following output: 
  11505.  
  11506. letter count = 5
  11507.  
  11508.                                     *
  11509. ************************************************************************/
  11510.  
  11511.  
  11512. ΓòÉΓòÉΓòÉ 8.5. do ΓòÉΓòÉΓòÉ
  11513.  
  11514. A do statement repeatedly runs a statement until the test expression evaluates 
  11515. to 0. Because of the order of processing, the statement is run at least once. 
  11516.  
  11517. Syntax of a do Statement 
  11518.  
  11519. The body of the loop is run before the controlling while clause is evaluated. 
  11520. Further processing of the do statement depends on the value of the while 
  11521. clause. If the while clause does not evaluate to 0, the statement runs again. 
  11522. When the while clause evaluates to 0, the statement ends. The controlling 
  11523. expression must be evaluate to a scalar type. 
  11524.  
  11525. A break, return, or goto statement can cause the processing of a do statement 
  11526. to end, even when the while clause does not evaluate to 0. 
  11527.  
  11528. Example of a do Statement 
  11529.  
  11530. Related Information 
  11531.  
  11532.      break 
  11533.      continue 
  11534.      for 
  11535.      goto 
  11536.      return 
  11537.      while 
  11538.  
  11539.  
  11540. ΓòÉΓòÉΓòÉ <hidden> Syntax of a do Statement ΓòÉΓòÉΓòÉ
  11541.  
  11542. A do statement has the form: 
  11543.  
  11544. >>ΓöÇΓöÇdoΓöÇΓöÇstatementΓöÇΓöÇwhileΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇ;ΓöÇΓöÇ><
  11545.  
  11546.  
  11547. ΓòÉΓòÉΓòÉ <hidden> Example of a do Statement ΓòÉΓòÉΓòÉ
  11548.  
  11549. /************************************************************************
  11550. *
  11551.  
  11552. The following statement prompts the user to enter a 1. If the user enters a 1, 
  11553. the statement ends. If not, it displays another prompt. 
  11554.  
  11555.                                     *
  11556. ************************************************************************/
  11557. The example contains error-checking code to verify that the user entered an 
  11558. integer value and to clear the input stream if an error occurs. 
  11559.  
  11560. /**
  11561.  ** This example illustrates the do statement.
  11562.  **/
  11563.  
  11564. #include <iostream.h>
  11565. void main()
  11566. {
  11567.  int reply1;
  11568.  char c;
  11569.  do
  11570.  {
  11571.   cout << "Enter a 1: ";
  11572.   cin >> reply1;
  11573.   if (cin.fail())
  11574.     {
  11575.     cerr << "Not a valid number." << endl;
  11576.      // Clear the error flag.
  11577.     cin.clear(cin.rdstate() & ~ios::failbit);
  11578.      // Purge incorrect input.
  11579.     cin.ignore(cin.rdbuf()->in_avail());
  11580.     }
  11581.  }
  11582.  while (reply1 != 1);
  11583. }
  11584.  
  11585.  
  11586. ΓòÉΓòÉΓòÉ 8.6. Expression ΓòÉΓòÉΓòÉ
  11587.  
  11588. An expression statement contains an expression. The expression can be null. 
  11589. Expressions are described in Expressions and Operators. 
  11590.  
  11591. Syntax of an Expression Statement 
  11592.  
  11593. An expression statement evaluates the given expression. It is used to assign 
  11594. the value of the expression to a variable or to call a function. 
  11595.  
  11596. The following are examples of expressions: 
  11597.  
  11598. printf("Account Number: \n");       /* call to the printf   */
  11599. marks = dollars * exch_rate;        /* assignment to marks   */
  11600. (difference < 0) ? ++losses : ++gain;   /* conditional increment  */
  11601. switches = flags Γûî BIT_MASK;        /* assignment to switches */
  11602.  
  11603.      Resolving Ambiguous Statements in C++ 
  11604.  
  11605.  
  11606. ΓòÉΓòÉΓòÉ 8.7. Resolving Ambiguous Statements in C++ ΓòÉΓòÉΓòÉ
  11607.  
  11608. There are situations in C++ where a statement can be parsed as both a 
  11609. declaration and as an expression. Specifically, a declaration can look like a 
  11610. function call in certain cases. The compiler resolves these ambiguities by 
  11611. applying the following rules to the whole statement: 
  11612.  
  11613.      If the statement can be parsed as a declaration but there are no 
  11614.       declaration specifiers in the declaration and the statement is inside the 
  11615.       body of a function, the statement is assumed to be an expression. 
  11616.  
  11617.       The following statement, for example, is a declaration at file scope of 
  11618.       the function f() that returns type int. There is no declaration specifier 
  11619.       and int is the default, but at function scope this is a call to f(): 
  11620.  
  11621.              f();
  11622.  
  11623.      In every other case, if the statement can be parsed as a declaration, it 
  11624.       is assumed to be a declaration. The following statement, for example, is 
  11625.       a declaration of x with redundant parentheses around the declarator, not 
  11626.       a function-style cast of x to type int: 
  11627.  
  11628.              int (x);
  11629.  
  11630.  In some cases, C++ syntax does not disambiguate between expression statements 
  11631.  and declaration statements. The ambiguity arises when an expression statement 
  11632.  has a function-style cast as its leftmost subexpression. (Note that, because C 
  11633.  does not support function-style casts, this ambiguity does not occur in C 
  11634.  programs.) If the statement can be interpreted both as a declaration and as an 
  11635.  expression, the statement is interpreted as a declaration statement. 
  11636.  
  11637.  Note:  The ambiguity is resolved only on a syntactic level. The disambiguation 
  11638.  does not use the meaning of the names, except to assess whether or not they 
  11639.  are type names. 
  11640.  
  11641.  The following expressions disambiguate into expression statements because the 
  11642.  ambiguous subexpression is followed by an assignment or an operator. type_spec 
  11643.  in the expressions can be any type specifier: 
  11644.  
  11645.   type_spec(i)++;       // expression statement
  11646.   type_spec(i,3)<<d;      // expression statement
  11647.   type_spec(i)->l=24;     // expression statement
  11648.  
  11649.  In the following examples, the ambiguity cannot be resolved syntactically, and 
  11650.  the statements are interpreted as declarations. type_spec is any type 
  11651.  specifier: 
  11652.  
  11653.   type_spec(*i)(int);     // declaration
  11654.   type_spec(j)[5];       // declaration
  11655.   type_spec(m) = { 1, 2 };   // declaration
  11656.   type_spec(*k) (float(3));  // declaration
  11657.  
  11658.  The last statement above causes a compile-time error because you cannot 
  11659.  initialize a pointer with a float value. 
  11660.  
  11661.  Any ambiguous statement that is not resolved by the above rules is by default 
  11662.  a declaration statement. All of the following are declaration statements: 
  11663.  
  11664.   type_spec(a);        // declaration
  11665.   type_spec(*b)();       // declaration
  11666.   type_spec(c)=23;       // declaration
  11667.   type_spec(d),e,f,g=0;    // declaration
  11668.   type_spec(h)(e,3);      // declaration
  11669.  
  11670.  Another C++ ambiguity between expression statements and declaration statements 
  11671.  is resolved by requiring an explicit return type for function declarations 
  11672.  within a block: 
  11673.  
  11674.   a();     // declaration of a function returning int
  11675.          // and taking no arguments
  11676.   void func()
  11677.   {
  11678.     int a();  // declaration of a function
  11679.     int b;   // declaration of a variable
  11680.     a();    // expression-statement calling function a()
  11681.     b;     // expression-statement referring to a variable
  11682.   }
  11683.  
  11684.  The last statement above does not produce any action. It is semantically 
  11685.  equivalent to a null statement. However, it is a valid C++ statement. 
  11686.  
  11687.  Related Information 
  11688.  
  11689.      Function Declarations 
  11690.      Cast Expressions 
  11691.  
  11692.  Related Information 
  11693.  
  11694.      Expressions and Operators 
  11695.  
  11696.  
  11697. ΓòÉΓòÉΓòÉ <hidden> Syntax of an Expression Statement ΓòÉΓòÉΓòÉ
  11698.  
  11699. An expression statement has the form: 
  11700.  
  11701. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇ><
  11702.   ΓööΓöÇexpressionΓöÇΓöÿ
  11703.  
  11704.  
  11705. ΓòÉΓòÉΓòÉ 8.8. for ΓòÉΓòÉΓòÉ
  11706.  
  11707. A for statement lets you do the following: 
  11708.  
  11709.      Evaluate an expression before the first iteration of the statement 
  11710.       (initialization) 
  11711.      Specify an expression to determine whether or not the statement should be 
  11712.       processed (controlling part) 
  11713.      Evaluate an expression after each iteration of the statement 
  11714.      Repeatedly process the statement if the controlling part does not 
  11715.       evaluate to zero. 
  11716.  
  11717.  Syntax of a for Statement 
  11718.  
  11719.  A break, return, or goto statement can cause a for statement to end, even when 
  11720.  the second expression does not evaluate to 0. If you omit expression2, you 
  11721.  must use a break, return, or goto statement to end the for statement. 
  11722.  
  11723.  C++ Note:  In C++ programs, you can also use expression1 to declare a variable 
  11724.  as well as initialize it. If you declare a variable in this expression, the 
  11725.  variable has the same scope as the for statement and is not local to the for 
  11726.  statement. 
  11727.  
  11728.  Examples of for Statements 
  11729.  
  11730.  Related Information 
  11731.  
  11732.      break 
  11733.      continue 
  11734.      do 
  11735.      return 
  11736.      goto 
  11737.      while 
  11738.      Expressions and Operators 
  11739.  
  11740.  
  11741. ΓòÉΓòÉΓòÉ <hidden> Syntax of a for Statement ΓòÉΓòÉΓòÉ
  11742.  
  11743. A for statement has the form: 
  11744.  
  11745. >>ΓöÇΓöÇforΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ>
  11746.       ΓööΓöÇexpression1ΓöÇΓöÿ   ΓööΓöÇexpression2ΓöÇΓöÿ   ΓööΓöÇexpression3ΓöÇΓöÿ
  11747. >ΓöÇΓöÇstatementΓöÇΓöÇ><
  11748.  
  11749.  Expression1     Is the initialization expression. It is evaluated only before 
  11750.                  the statement is processed for the first time. You can use 
  11751.                  this expression to initialize a variable. If you do not want 
  11752.                  to evaluate an expression prior to the first iteration of the 
  11753.                  statement, you can omit this expression. 
  11754.  
  11755.  Expression2     Is the controlling part. It is evaluated before each iteration 
  11756.                  of the statement. It must evaluate to a scalar type. 
  11757.  
  11758.                  If it evaluates to 0 (zero), the statement is not processed 
  11759.                  and control moves to the next statement following the for 
  11760.                  statement. If expression2 does not evaluate to 0, the 
  11761.                  statement is processed. If you omit expression2, it is as if 
  11762.                  the expression had been replaced by a nonzero constant, and 
  11763.                  the for statement is not terminated by failure of this 
  11764.                  condition. 
  11765.  
  11766.  Expression3     Is evaluated after each iteration of the statement. You can 
  11767.                  use this expression to increase, decrease, or reinitialize a 
  11768.                  variable. This expression is optional. 
  11769.  
  11770.  
  11771. ΓòÉΓòÉΓòÉ <hidden> Examples of for Statements ΓòÉΓòÉΓòÉ
  11772.  
  11773. The following for statement prints the value of count 20 times. The for 
  11774. statement initially sets the value of count to 1. After each iteration of the 
  11775. statement, count is incremented. 
  11776.  
  11777. for (count = 1; count <= 20; count++)
  11778.   printf("count = %d\n", count);
  11779.  
  11780. The following sequence of statements accomplishes the same task. Note the use 
  11781. of the while statement instead of the for statement. 
  11782.  
  11783. count = 1;
  11784. while (count <= 20)
  11785. {
  11786.   printf("count = %d\n", count);
  11787.   count++;
  11788. }
  11789.  
  11790. The following for statement does not contain an initialization expression: 
  11791.  
  11792. for (; index > 10; --index)
  11793. {
  11794.   list[index] = var1 + var2;
  11795.   printf("list[%d] = %d\n", index, list[index]);
  11796. }
  11797.  
  11798. The following for statement will continue running until scanf receives the 
  11799. letter e: 
  11800.  
  11801. for (;;)
  11802. {
  11803.   scanf("%c", &letter);
  11804.   if (letter == '\n')
  11805.    continue;
  11806.   if (letter == 'e')
  11807.    break;
  11808.   printf("You entered the letter %c\n", letter);
  11809. }
  11810.  
  11811. The following for statement contains multiple initializations and increments. 
  11812. The comma operator makes this construction possible. The first comma in the for 
  11813. expression is a punctuator for a declaration. It declares and initializes two 
  11814. integers, i and j. The second comma, a comma operator, allows both i and j to 
  11815. be incremented at each step through the loop. 
  11816.  
  11817. for (int i = 0, j = 50; i < 10; ++i, j += 50)
  11818. {
  11819.   cout << "i = " << i << "and j = " << j << endl;
  11820. }
  11821.  
  11822. The following example shows a nested for statement. It prints the values of an 
  11823. array having the dimensions [5][3]. 
  11824.  
  11825. for (row = 0; row < 5; row++)
  11826.   for (column = 0; column < 3; column++)
  11827.    printf("%d\n", table[row][column]);
  11828.  
  11829. The outer statement is processed as long as the value of row is less than 5. 
  11830. Each time the outer for statement is executed, the inner for statement sets the 
  11831. initial value of column to zero and the statement of the inner for statement is 
  11832. executed 3 times. The inner statement is executed as long as the value of 
  11833. column is less than 3. 
  11834.  
  11835.  
  11836. ΓòÉΓòÉΓòÉ 8.9. goto ΓòÉΓòÉΓòÉ
  11837.  
  11838. A goto statement causes your program to unconditionally transfer control to the 
  11839. statement associated with the label specified on the goto statement. 
  11840.  
  11841. Syntax of a goto Statement 
  11842.  
  11843. Because the goto statement can interfere with the normal sequence of 
  11844. processing, it makes a program more difficult to read and maintain. Often, a 
  11845. break statement, a continue statement, or a function call can eliminate the 
  11846. need for a goto statement. 
  11847.  
  11848. If you use a goto statement to transfer control to a statement inside of a loop 
  11849. or block, initializations of automatic storage for the loop do not take place 
  11850. and the result is undefined. The label must appear in the same function as the 
  11851. goto. 
  11852.  
  11853. If an active block is exited using a goto statement, any local variables are 
  11854. destroyed when control is transferred from that block. 
  11855.  
  11856. Example of a goto Statement 
  11857.  
  11858. Related Information 
  11859.  
  11860.      Labels 
  11861.      break 
  11862.      continue 
  11863.      Functions 
  11864.  
  11865.  
  11866. ΓòÉΓòÉΓòÉ <hidden> Syntax of a goto Statement ΓòÉΓòÉΓòÉ
  11867.  
  11868. A goto statement has the form: 
  11869.  
  11870. >>ΓöÇΓöÇgotoΓöÇΓöÇlabel_identifierΓöÇΓöÇ;ΓöÇΓöÇ><
  11871.  
  11872.  
  11873. ΓòÉΓòÉΓòÉ <hidden> Example of a goto Statement ΓòÉΓòÉΓòÉ
  11874.  
  11875. The following example shows a goto statement that is used to jump out of a 
  11876. nested loop. This function could be written without using a goto statement. 
  11877.  
  11878. /**
  11879.  ** This example shows a goto statement that is used to
  11880.  ** jump out of a nested loop.
  11881.  **/
  11882.  
  11883. #include <stdio.h>
  11884. void display(int matrix[3][3]);
  11885.  
  11886. int main(void)
  11887. {
  11888.   int matrix[3][3]={1,2,3,4,5,2,8,9,10};
  11889.   display(matrix);
  11890.   return(0);
  11891. }
  11892.  
  11893. void display(int matrix[3][3])
  11894. {
  11895.   int i, j;
  11896.  
  11897.   for (i = 0; i < 3; i++)
  11898.    for (j = 0; j < 3; j++)
  11899.    {
  11900.      if ( (matrix[i][j] < 1) ΓûîΓûî (matrix[i][j] > 6) )
  11901.       goto out_of_bounds;
  11902.      printf("matrix[%d][%d] = %d\n", i, j, matrix[i][j]);
  11903.    }
  11904.   return;
  11905.   out_of_bounds: printf("number must be 1 through 6\n");
  11906. }
  11907.  
  11908.  
  11909. ΓòÉΓòÉΓòÉ 8.10. if ΓòÉΓòÉΓòÉ
  11910.  
  11911. An if statement lets you conditionally process a statement when the specified 
  11912. test expression evaluates to a nonzero value. The expression must evaluate to a 
  11913. scalar type. You can optionally specify an else clause on the if statement. If 
  11914. the test expression evaluates to 0 and an else clause exists, the statement 
  11915. associated with the else clause runs. If the test expression evaluates to a 
  11916. nonzero value, the statement following the expression runs and the else clause 
  11917. is ignored. 
  11918.  
  11919. Syntax of an if Statement 
  11920.  
  11921. When if statements are nested and else clauses are present, a given else is 
  11922. associated with the closest preceding if statement within the same block. 
  11923.  
  11924. Examples of if Statements 
  11925.  
  11926. Related Information 
  11927.  
  11928.      Conditional Compilation Directives 
  11929.      switch 
  11930.  
  11931.  
  11932. ΓòÉΓòÉΓòÉ <hidden> Syntax of an if Statement ΓòÉΓòÉΓòÉ
  11933.  
  11934. An if statement has the form: 
  11935.  
  11936. >>ΓöÇΓöÇifΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇstatementΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  11937.                    ΓööΓöÇelseΓöÇΓöÇstatementΓöÇΓöÿ
  11938.  
  11939.  
  11940. ΓòÉΓòÉΓòÉ <hidden> Examples of if Statements ΓòÉΓòÉΓòÉ
  11941.  
  11942. The following example causes grade to receive the value A if the value of score 
  11943. is greater than or equal to 90. 
  11944.  
  11945. if (score >= 90)
  11946.   grade = 'A';
  11947.  
  11948. The following example displays Number is positive if the value of number is 
  11949. greater than or equal to 0. If the value of number is less than 0, it displays 
  11950. Number is negative. 
  11951.  
  11952. if (number >= 0)
  11953.   printf("Number is positive\n");
  11954. else
  11955.   printf("Number is negative\n");
  11956.  
  11957. The following example shows a nested if statement: 
  11958.  
  11959. if (paygrade == 7)
  11960.   if (level >= 0 && level <= 8)
  11961.    salary *= 1.05;
  11962.   else
  11963.    salary *= 1.04;
  11964. else
  11965.   salary *= 1.06;
  11966. cout << "salary is " << salary << endl;
  11967.  
  11968. The following example shows a nested if statement that does not have an else 
  11969. clause. Because an else clause always associates with the closest if statement, 
  11970. braces might be needed to force a particular else clause to associate with the 
  11971. correct if statement. In this example, omitting the braces would cause the else 
  11972. clause to associate with the nested if statement. 
  11973.  
  11974. if (kegs > 0) {
  11975.   if (furlongs > kegs)
  11976.    fpk = furlongs/kegs;
  11977. }
  11978. else
  11979.   fpk = 0;
  11980.  
  11981. The following example shows an if statement nested within an else clause. This 
  11982. example tests multiple conditions. The tests are made in order of their 
  11983. appearance. If one test evaluates to a nonzero value, a statement runs and the 
  11984. entire if statement ends. 
  11985.  
  11986. if (value > 0)
  11987.   ++increase;
  11988. else if (value == 0)
  11989.   ++break_even;
  11990. else
  11991.   ++decrease;
  11992.  
  11993.  
  11994. ΓòÉΓòÉΓòÉ 8.11. Null Statement ΓòÉΓòÉΓòÉ
  11995.  
  11996. The null statement performs no operation. 
  11997.  
  11998. Syntax of a Null Statement 
  11999.  
  12000. A null statement can hold the label of a labeled statement or complete the 
  12001. syntax of an iterative statement. 
  12002.  
  12003. The following example initializes the elements of the array price. Because the 
  12004. initializations occur within the for expressions, a statement is only needed to 
  12005. finish the for syntax; no operations are required. 
  12006.  
  12007. for (i = 0; i < 3; price[i++] = 0)
  12008.   ;
  12009.  
  12010. A null statement can be used when a label is needed before the end of a block 
  12011. statement. For example: 
  12012.  
  12013. void func(void) {
  12014.  if (error_detected)
  12015.   goto depart;
  12016.  /* further processing */
  12017.  depart: ;  /* null statement required */
  12018. }
  12019.  
  12020. Related Information 
  12021.  
  12022.      Null Directive (#) 
  12023.      Labels 
  12024.  
  12025.  
  12026. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Null Statement ΓòÉΓòÉΓòÉ
  12027.  
  12028. A null statement has the form: 
  12029.  
  12030. >>ΓöÇΓöÇ;ΓöÇΓöÇ><
  12031.  
  12032.  
  12033. ΓòÉΓòÉΓòÉ 8.12. return ΓòÉΓòÉΓòÉ
  12034.  
  12035. A return statement ends the processing of the current function and returns 
  12036. control to the caller of the function. 
  12037.  
  12038. Syntax of a return Statement 
  12039.  
  12040. A return statement in a function is optional. The compiler issues a warning if 
  12041. a return statement is not found in a function declared with a return type. If 
  12042. the end of a function is reached without encountering a return statement, 
  12043. control is passed to the caller as if a return statement without an expression 
  12044. were encountered. A function can contain multiple return statements. 
  12045.  
  12046. If an expression is present on a return statement, the value of the expression 
  12047. is returned to the caller. If the data type of the expression is different from 
  12048. the function return type, conversion of the return value takes place as if the 
  12049. value of the expression were assigned to an object with the same function 
  12050. return type. 
  12051.  
  12052. If an expression is not present on a return statement, the value of the return 
  12053. statement is undefined. If an expression is not given on a return statement in 
  12054. a function declared with a nonvoid return type, an error message is issued, and 
  12055. the result of calling the function is unpredictable. For example: 
  12056.  
  12057. int func1()
  12058. {
  12059.  return;
  12060. }
  12061. int func2()
  12062. {
  12063.  return (4321);
  12064. }
  12065.  
  12066. void main() {
  12067. int a=func1(); // result is unpredictable!
  12068. int b=func2();
  12069. }
  12070.  
  12071. You cannot use a return statement with an expression when the function is 
  12072. declared as returning type void. 
  12073.  
  12074. You can use the /Wret compiler option to generate diagnostic messages about the 
  12075. use of return statements in your functions. 
  12076.  
  12077. C++ Note:  If a function returns a class object with constructors, a temporary 
  12078. class object might be constructed. The temporary object is not in the scope of 
  12079. the function returning the temporary object but is local to the caller of the 
  12080. function. 
  12081.  
  12082. When a function returns, all temporary local variables are destroyed. If local 
  12083. class objects with destructors exist, destructors are called. For more details, 
  12084. see Temporary Objects. 
  12085.  
  12086. Examples of return Statements 
  12087.  
  12088. Related Information 
  12089.  
  12090.      Functions 
  12091.      /W option 
  12092.      Expression 
  12093.  
  12094.  
  12095. ΓòÉΓòÉΓòÉ <hidden> Syntax of a return Statement ΓòÉΓòÉΓòÉ
  12096.  
  12097. A return statement has the form: 
  12098.  
  12099. >>ΓöÇΓöÇreturnΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇ><
  12100.       ΓööΓöÇexpressionΓöÇΓöÿ
  12101.  
  12102.  
  12103. ΓòÉΓòÉΓòÉ <hidden> Examples of return Statements ΓòÉΓòÉΓòÉ
  12104.  
  12105. return;       /* Returns no value       */
  12106. return result;   /* Returns the value of result */
  12107. return 1;      /* Returns the value 1     */
  12108. return (x * x);   /* Returns the value of x * x  */
  12109.  
  12110. The following function searches through an array of integers to determine if a 
  12111. match exists for the variable number. If a match exists, the function match 
  12112. returns the value of i. If a match does not exist, the function match returns 
  12113. the value -1 (negative one). 
  12114.  
  12115. int match(int number, int array[ ], int n)
  12116. {
  12117.   int i;
  12118.  
  12119.   for (i = 0; i < n; i++)
  12120.    if (number == array[i])
  12121.      return (i);
  12122.   return(-1);
  12123. }
  12124.  
  12125.  
  12126. ΓòÉΓòÉΓòÉ 8.13. Structured Exception Handling Statements ΓòÉΓòÉΓòÉ
  12127.  
  12128. Structured Exception Handling (SEH) is a Windows-specific mechanism for 
  12129. handling system exceptions. 
  12130.  
  12131. Note:  SEH is only available in the C compiler. 
  12132.  
  12133. SEH is different from C++ exception handling. C++ matches exceptions based on 
  12134. the type of the expression that is thrown. It does not allow resumption of 
  12135. execution after the exception. SEH matches exceptions with handlers based on 
  12136. the value returned from a filter expression. It can be resumptive or 
  12137. nonresumptive, and can catch any operating system exception. Unlike C++ 
  12138. exception handling, it is not portable; it is only available with the Win32 
  12139. API. 
  12140.  
  12141. Structured exception handling consists of two parts: 
  12142.  
  12143.      Termination handling with try-finally 
  12144.      Exception handling with try-except 
  12145.  
  12146.  See the IBM VisualAge for C++ for Windows Programming Guide for detailed 
  12147.  information about using structured exception handling with other error 
  12148.  handling mechanisms. 
  12149.  
  12150.  
  12151. ΓòÉΓòÉΓòÉ 8.13.1. Try-Finally Termination Handling ΓòÉΓòÉΓòÉ
  12152.  
  12153. Termination handling is performed using a try-finally block: 
  12154.  
  12155. >>ΓöÇΓöÇ__tryΓöÇΓöÇblock_statementΓöÇΓöÇ__finallyΓöÇΓöÇblock_statementΓöÇΓöÇ><
  12156.  
  12157. A termination handler has this structure: 
  12158.  
  12159.  // 1. Code before try block
  12160.  // ...
  12161.  __try {
  12162.     // 2. Guarded body
  12163.     // ...
  12164.  }
  12165.  __finally {
  12166.     // 3. termination handler
  12167.     // ...
  12168.  }
  12169.  // 4. Code after the termination handler
  12170.  // ...
  12171.  
  12172. The numbered comments indicate the order of execution. 
  12173.  
  12174. Termination handling guarantees that one block of code, called the termination 
  12175. handler, will be run no matter how another block, referred to as the guarded 
  12176. body, is exited. Regardless of whether the gaurded body runs normally or 
  12177. encounters an exception, exits because of a break, continue, goto, or return, 
  12178. or for some other reason, the termination handler is always be executed. 
  12179.  
  12180. Termination handlers are useful for simplifying error handling by moving all 
  12181. cleanup code into a common place. This improves program readability, and 
  12182. reduces maintenance. They are typically used for managing memory, closing file 
  12183. handles, and releasing semaphores. 
  12184.  
  12185.  
  12186. ΓòÉΓòÉΓòÉ 8.13.2. Try-Except Structured Exception Handling ΓòÉΓòÉΓòÉ
  12187.  
  12188. Exception handling is performed using a try-except block: 
  12189.  
  12190. >>ΓöÇΓöÇ__tryΓöÇΓöÇblock_statementΓöÇΓöÇ__exceptΓöÇΓöÇ(ΓöÇΓöÇexception_filterΓöÇΓöÇ)ΓöÇΓöÇ>
  12191. >ΓöÇΓöÇblock_statementΓöÇΓöÇ><
  12192.  
  12193. An exception handler has this structure: 
  12194.  
  12195.  // 1. Code before try block
  12196.  // ...
  12197.  __try {
  12198.     // 2. Guarded body
  12199.     // ...
  12200.  }
  12201.  __except( filter /* 3. exception filter */ ) {
  12202.     // 4. Exception handler
  12203.     // ...
  12204.  }
  12205.  // 5. Code after the exception handler
  12206.  // ...
  12207.  
  12208. The actual order of execution depends on the evaluation of the exception 
  12209. filter. The example above illustrates an exception in the guarded body where 
  12210. the exception filter has evaluated to EXCEPTION_EXECUTE_HANDLER. If no 
  12211. exception occurs in the guarded body the except block is not reached and the 
  12212. code after the exception handler is run. 
  12213.  
  12214. You must use the header <excpt.h>, which contains the data structure 
  12215. definitions for an exception. There can be no code between the try and the 
  12216. except or finally blocks. A try block also can only have one finally or except 
  12217. block associated with it. You can nest try-finally blocks inside try-except 
  12218. blocks and vice versa. 
  12219.  
  12220. When an exception is generated, the system locates the beginning of the except 
  12221. block and evaluates an an exception filter that you provide. It must evaluate 
  12222. to one of three values defined by the following macro names: 
  12223.  
  12224.  EXCEPTION_EXECUTE_HANDLER           1 
  12225.  
  12226.  EXCEPTION_CONTINUE_EXECUTION        -1 
  12227.  
  12228.  EXCEPTION_CONTINUE_SEARCH           0 
  12229.  
  12230.  The exception filter can be a function, a constant, or an expression. 
  12231.  
  12232.  The filter compares the exception with the list of exception signals in the 
  12233.  <winnt.h> header. If your filter finds a match, it should evaluate to the 
  12234.  value of EXCEPTION_EXECUTE_HANDLER (1), which causes your exception handler to 
  12235.  be executed. This results in a global unwind, which causes all outstanding 
  12236.  try-finally blocks below the try-except block to be run. After the exception 
  12237.  handler is executed, control resumes at the first instruction after the except 
  12238.  block. The global unwind process is described in detail in the IBM VisualAge 
  12239.  for C++ for Windows Programming Guide. 
  12240.  
  12241.  If your filter evaluates to the value of EXCEPTION_CONTINUE_EXECUTION (-1), 
  12242.  then you are indicating that you have taken care of the exception and that the 
  12243.  execution continues from the instruction that generated the exception. 
  12244.  Usually, the exception is repaired in the filter, and -1 is returned. However, 
  12245.  this is not guaranteed always to work exactly as expected since it depends on 
  12246.  the machine encoding. More than one instruction may be used to encode a single 
  12247.  line of code, and the specific machine instruction that caused the exception 
  12248.  may not have a value that has been repaired. This may cause an infinite loop. 
  12249.  
  12250.  If your exception filter evaluates to the value of EXCEPTION_CONTINUE_SEARCH 
  12251.  (0), the system looks for another exception handler by searching backwards 
  12252.  through the call stack. for the most-recently executing try-except block and 
  12253.  calls its exception filter. It ignores any try-finally blocks. If none is 
  12254.  found, it calls the system exception handler for an unhandled exception. 
  12255.  
  12256.  
  12257. ΓòÉΓòÉΓòÉ 8.13.3. Precedence of Exception Handler Registration ΓòÉΓòÉΓòÉ
  12258.  
  12259. If a function has both a #pragma handler registered for it and structured 
  12260. exception handling code in the function body, the #pragma handler is registered 
  12261. first. This allows the structured exception handlers to override both the 
  12262. default _Exception handler and your own handlers. 
  12263.  
  12264. See handler for the description of the #pragma handler directive. 
  12265.  
  12266.  
  12267. ΓòÉΓòÉΓòÉ 8.14. switch ΓòÉΓòÉΓòÉ
  12268.  
  12269. A switch statement lets you transfer control to different statements within the 
  12270. switch body depending on the value of the switch expression. The switch 
  12271. expression must evaluate to an integral value. The body of the switch statement 
  12272. contains case clauses that consist of 
  12273.  
  12274.      A case label 
  12275.      An optional default label 
  12276.      A case expression 
  12277.      A list of statements. 
  12278.  
  12279.  If the value of the switch expression equals the value of one of the case 
  12280.  expressions, the statements following that case expression are processed. If 
  12281.  not, the default label statements, if any, are processed. 
  12282.  
  12283.  A switch statement has the form: 
  12284.  
  12285.   >>ΓöÇΓöÇswitchΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇswitch_bodyΓöÇΓöÇ><
  12286.  
  12287.  Syntax of a switch Body 
  12288.  
  12289.  A case clause contains a case label followed by any number of statements. 
  12290.  
  12291.  A case label contains the word case followed by an integral constant 
  12292.  expression and a colon. Anywhere you can put one case label, you can put 
  12293.  multiple case labels. 
  12294.  
  12295.  A default clause contains a default label followed by one or more statements. 
  12296.  You can put a case label on either side of the default label. A switch 
  12297.  statement can have only one default label. 
  12298.  
  12299.  The switch statement passes control to the statement following one of the 
  12300.  labels or to the statement following the switch body. The value of the 
  12301.  expression that precedes the switch body determines which statement receives 
  12302.  control. This expression is called the switch expression. 
  12303.  
  12304.  The value of the switch expression is compared with the value of the 
  12305.  expression in each case label. If a matching value is found, control is passed 
  12306.  to the statement following the case label that contains the matching value. If 
  12307.  there is no matching value but there is a default label in the switch body, 
  12308.  control passes to the default labelled statement. If no matching value is 
  12309.  found, and there is no default label anywhere in the switch body, no part of 
  12310.  the switch body is processed. 
  12311.  
  12312.  When control passes to a statement in the switch body, control only leaves the 
  12313.  switch body when a break statement is encountered or the last statement in the 
  12314.  switch body is processed. 
  12315.  
  12316.  If necessary, an integral promotion is performed on the controlling 
  12317.  expression, and all expressions in the case statements are converted to the 
  12318.  same type as the controlling expression. 
  12319.  
  12320.  Restrictions 
  12321.  The switch expression and the case expressions must have an integral type. The 
  12322.  value of each case expression must represent a different value and must be a 
  12323.  constant expression. 
  12324.  
  12325.  Only one default label can occur in each switch statement. You cannot have 
  12326.  duplicate case labels in a switch statement. 
  12327.  
  12328.  You can put data definitions at the beginning of the switch body, but the 
  12329.  compiler does not initialize auto and register variables at the beginning of a 
  12330.  switch body. 
  12331.  
  12332.  C++ Note:  You can have declarations in the body of the switch statement. In 
  12333.  C++, you cannot transfer control over a declaration containing an initializer 
  12334.  unless the declaration is located in an inner block that is completely 
  12335.  bypassed by the transfer of control. All declarations within the body of a 
  12336.  switch statement that contain initializers must be contained in an inner 
  12337.  block. 
  12338.  
  12339.  Examples of switch Statements 
  12340.  
  12341.  Related Information 
  12342.  
  12343.      break 
  12344.      if 
  12345.      Labels 
  12346.      Expression 
  12347.      Type Specifiers 
  12348.      Storage Class Specifiers 
  12349.  
  12350.  
  12351. ΓòÉΓòÉΓòÉ <hidden> Syntax of a switch Body ΓòÉΓòÉΓòÉ
  12352.  
  12353. The switch body is enclosed in braces and can contain definitions, 
  12354. declarations, case clauses, and a default clause. Each case clause and default 
  12355. clause can contain statements. 
  12356.  
  12357.     ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12358.                      Γöé          Γöé
  12359. >>ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>
  12360.     Γö£ΓöÇtype_definitionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ   ΓööΓöÇcase_clauseΓöÇΓöÿ
  12361.     Γö£ΓöÇfile_scope_data_declarationΓöÇΓöÇΓöñ
  12362.     ΓööΓöÇblock_scope_data_declarationΓöÇΓöÿ
  12363.             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12364.                     Γöé
  12365. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  12366.   ΓööΓöÇdefault_clauseΓöÇΓöÿ  ΓööΓöÇcase_clauseΓöÇΓöÿ
  12367.  
  12368. A case clause has the form: 
  12369.  
  12370.         ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12371.               Γöé
  12372. >>ΓöÇΓöÇcase_labelΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ><
  12373.  
  12374. A case label has the form: 
  12375.  
  12376.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12377.                       Γöé
  12378. >>ΓöÇΓöÇΓöÇΓöÇcaseΓöÇΓöÇintegral_constant_expressionΓöÇΓöÇ:ΓöÇΓö┤ΓöÇΓöÇ><
  12379.  
  12380. A default clause has the form: 
  12381.  
  12382.                         ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12383.                               Γöé
  12384. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdefaultΓöÇΓöÇ:ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ><
  12385.   ΓööΓöÇcase_labelΓöÇΓöÿ        ΓööΓöÇcase_labelΓöÇΓöÿ
  12386.  
  12387.  
  12388. ΓòÉΓòÉΓòÉ <hidden> Examples of switch Statements ΓòÉΓòÉΓòÉ
  12389.  
  12390. The following switch statement contains several case clauses and one default 
  12391. clause. Each clause contains a function call and a break statement. The break 
  12392. statements prevent control from passing down through each statement in the 
  12393. switch body. 
  12394.  
  12395. If the switch expression evaluated to '/', the switch statement would call the 
  12396. function divide. Control would then pass to the statement following the switch 
  12397. body. 
  12398.  
  12399. char key;
  12400.  
  12401. cout << "Enter an arithmetic operator\n");
  12402. cin >> key;
  12403.  
  12404. switch (key)
  12405. {
  12406.   case '+':
  12407.    add();
  12408.    break;
  12409.  
  12410.   case '-':
  12411.    subtract();
  12412.    break;
  12413.  
  12414.   case '*':
  12415.    multiply();
  12416.    break;
  12417.  
  12418.   case '/':
  12419.    divide();
  12420.    break;
  12421.  
  12422.   default:
  12423.    cout << "The key you pressed is not valid\n";
  12424.    break;
  12425. }
  12426.  
  12427. If the switch expression matches a case expression, the statements following 
  12428. the case expression are processed until a break statement is encountered or the 
  12429. end of the switch body is reached. In the following example, break statements 
  12430. are not present. If the value of text[i] is equal to 'A', all three counters 
  12431. are incremented. If the value of text[i] is equal to 'a', lettera and total are 
  12432. increased. Only total is increased if text[i] is not equal to 'A' or 'a'. 
  12433.  
  12434. char text[100];
  12435. int capa, lettera, total;
  12436.  
  12437. for (i=0; i<sizeof(text); i++) {
  12438.  
  12439.   switch (text[i])
  12440.   {
  12441.     case 'A':
  12442.      capa++;
  12443.     case 'a':
  12444.      lettera++;
  12445.     default:
  12446.      total++;
  12447.   }
  12448. }
  12449.  
  12450. The following switch statement performs the same statements for more than one 
  12451. case label: 
  12452.  
  12453. /**
  12454.  ** This example contains a switch statement that performs
  12455.  ** the same statement for more than one case label.
  12456.  **/
  12457.  
  12458. #include <stdio.h>
  12459.  
  12460. int main(void)
  12461. {
  12462.  int month;
  12463.  
  12464.  /* Read in a month value */
  12465.  printf("Enter month: ");
  12466.  scanf("%d", &month);
  12467.  
  12468.  /* Tell what season it falls into */
  12469.  switch (month)
  12470.  {
  12471.    case 12:
  12472.    case 1:
  12473.    case 2:
  12474.     printf("month %d is a winter month\n", month);
  12475.     break;
  12476.  
  12477.    case 3:
  12478.    case 4:
  12479.    case 5:
  12480.     printf("month %d is a spring month\n", month);
  12481.     break;
  12482.  
  12483.    case 6:
  12484.    case 7:
  12485.    case 8:
  12486.     printf("month %d is a summer month\n", month);
  12487.     break;
  12488.  
  12489.    case 9:
  12490.    case 10:
  12491.    case 11:
  12492.     printf("month %d is a fall month\n", month);
  12493.     break;
  12494.  
  12495.    case 66:
  12496.    case 99:
  12497.    default:
  12498.     printf("month %d is not a valid month\n", month);
  12499.  }
  12500.  
  12501.  return(0);
  12502. }
  12503.  
  12504. If the expression month has the value 3, control passes to the statement: 
  12505.  
  12506. printf("month %d is a spring month\n", month);
  12507.  
  12508. The break statement passes control to the statement following the switch body. 
  12509.  
  12510.  
  12511. ΓòÉΓòÉΓòÉ 8.15. while ΓòÉΓòÉΓòÉ
  12512.  
  12513. A while statement repeatedly runs the body of a loop until the controlling 
  12514. expression evaluates to 0. 
  12515.  
  12516. Syntax of a while Statement 
  12517.  
  12518. The expression is evaluated to determine whether or not to process the body of 
  12519. the loop. The expression must be convertible to a scalar type. If the 
  12520. expression evaluates to 0, the body of the loop never runs. If the expression 
  12521. does not evaluate to 0, the loop body is processed. After the body has run, 
  12522. control passes back to the expression. Further processing depends on the value 
  12523. of the condition. 
  12524.  
  12525. A break, return, or goto statement can cause a while statement to end, even 
  12526. when the condition does not evaluate to 0. 
  12527.  
  12528. Example of a while Statement 
  12529.  
  12530. Related Information 
  12531.  
  12532.      break 
  12533.      continue 
  12534.      do 
  12535.      for 
  12536.      goto 
  12537.      return 
  12538.  
  12539.  
  12540. ΓòÉΓòÉΓòÉ <hidden> Syntax of a while Statement ΓòÉΓòÉΓòÉ
  12541.  
  12542. A while statement has the form: 
  12543.  
  12544. >>ΓöÇΓöÇwhileΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇstatementΓöÇΓöÇ><
  12545.  
  12546.  
  12547. ΓòÉΓòÉΓòÉ <hidden> Example of a while Statement ΓòÉΓòÉΓòÉ
  12548.  
  12549. /************************************************************************
  12550. *
  12551.  
  12552. In the following program, item[index] triples each time the value of the 
  12553. expression ++index is less than MAX_INDEX. When ++index evaluates to MAX_INDEX, 
  12554. the while statement ends. 
  12555.  
  12556.                                     *
  12557. ************************************************************************/
  12558.  
  12559. /**
  12560.  ** This example illustrates the while statement.
  12561.  **/
  12562.  
  12563. #define MAX_INDEX  (sizeof(item) / sizeof(item[0]))
  12564. #include <stdio.h>
  12565.  
  12566. int main(void)
  12567. {
  12568.   static int item[ ] = { 12, 55, 62, 85, 102 };
  12569.   int index = 0;
  12570.  
  12571.   while (index < MAX_INDEX)
  12572.   {
  12573.    item[index] *= 3;
  12574.    printf("item[%d] = %d\n", index, item[index]);
  12575.    ++index;
  12576.   }
  12577.  
  12578.   return(0);
  12579. }
  12580.  
  12581.  
  12582. ΓòÉΓòÉΓòÉ 9. Preprocessor Directives ΓòÉΓòÉΓòÉ
  12583.  
  12584. This section describes the VisualAge for C++ preprocessor directives. 
  12585. Preprocessing is a step that takes place before compilation that lets you: 
  12586.  
  12587.      Replace tokens in the current file with specified replacement tokens. 
  12588.      Imbed files within the current file 
  12589.      Conditionally compile sections of the current file 
  12590.      Generate diagnostic messages 
  12591.      Change the line number of the next line of source and change the file 
  12592.       name of the current file. 
  12593.  
  12594.  A token is a series of characters delimited by white space. The only white 
  12595.  space allowed on a preprocessor directive is the space, horizontal tab, 
  12596.  vertical tab, form feed, and comments. The new-line character can also 
  12597.  separate preprocessor tokens. 
  12598.  
  12599.  The preprocessed source program file must be a valid C or C++ program. 
  12600.  
  12601.  The preprocessor is controlled by the following directives: 
  12602.  
  12603.      Macro Definition and Expansion (#define) 
  12604.      Scope of Macro Names (#undef) 
  12605.      Preprocessor Error Directive (#error) 
  12606.      File Inclusion (#include) 
  12607.      #if, #elif 
  12608.      #ifdef 
  12609.      #ifndef 
  12610.      #else 
  12611.      #endif 
  12612.      Line Control (#line) 
  12613.      Pragma Directives (#pragma) 
  12614.  
  12615.  This section also describes: 
  12616.  
  12617.      The # operator 
  12618.      Macro concatenation with the ## operator 
  12619.      The null directive (#) 
  12620.      Predefined macros. 
  12621.  
  12622.  Related Information 
  12623.  
  12624.      The format of a preprocessor directive 
  12625.  
  12626.  
  12627. ΓòÉΓòÉΓòÉ 9.1. Preprocessor Directive Format ΓòÉΓòÉΓòÉ
  12628.  
  12629. Preprocessor directives begin with the # token followed by a preprocessor 
  12630. keyword. The # token must appear as the first character that is not white space 
  12631. on a line. The # is not part of the directive name and can be separated from 
  12632. the name with white spaces. 
  12633.  
  12634. A preprocessor directive ends at the new-line character unless the last 
  12635. character of the line is the \ (backslash) character. If the \ character 
  12636. appears as the last character in the preprocessor line, the preprocessor 
  12637. interprets the \ and the new-line character as a continuation marker. The 
  12638. preprocessor deletes the \ (and the following new-line character) and splices 
  12639. the physical source lines into continuous logical lines. 
  12640.  
  12641. Except for some #pragma directives, preprocessor directives can appear anywhere 
  12642. in a program. 
  12643.  
  12644. Related Information 
  12645.  
  12646.      Preprocessor Directives 
  12647.  
  12648.  
  12649. ΓòÉΓòÉΓòÉ 9.2. Phases of Preprocessing ΓòÉΓòÉΓòÉ
  12650.  
  12651. Preprocessing appears as if it occurs in several phases. 
  12652.  
  12653.    1. New-line characters are introduced as needed to replace system-dependent 
  12654.       end-of-line indicators, and any other system-dependent character-set 
  12655.       translations are done. Equivalent single characters replace trigraph 
  12656.       sequences. 
  12657.  
  12658.    2. Each \ (backslash) followed by a new-line character pair is deleted. The 
  12659.       next source line is appended to the line that contained the sequence. 
  12660.  
  12661.    3. The source text is decomposed into preprocessing tokens and sequences of 
  12662.       white space. A single white space replaces each comment. A source file 
  12663.       cannot end with a partial token or comment. 
  12664.  
  12665.    4. Preprocessing directives are executed, and macros are expanded. 
  12666.  
  12667.    5. Escape sequences in character constants and string literals are replaced 
  12668.       by their equivalent values. 
  12669.  
  12670.    6. Adjacent string literals are concatenated. 
  12671.  
  12672.  The rest of the compilation process operates on the preprocessor output, which 
  12673.  is syntactically and semantically analyzed and translated, and then linked as 
  12674.  necessary with other programs and libraries. 
  12675.  
  12676.  
  12677. ΓòÉΓòÉΓòÉ 9.3. Macro Definition and Expansion (#define) ΓòÉΓòÉΓòÉ
  12678.  
  12679. A preprocessor define directive directs the preprocessor to replace all 
  12680. subsequent occurrences of a macro with specified replacement tokens. 
  12681.  
  12682. A preprocessor #define directive has the form: 
  12683.  
  12684.                             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12685.                                     Γöé
  12686. >>ΓöÇΓöÇ#ΓöÇΓöÇdefineΓöÇΓöÇidentifierΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ><
  12687.               Γöé   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé  Γö£ΓöÇidentifierΓöÇΓöñ
  12688.               Γöé           Γöé   Γöé  Γöé       Γöé
  12689.               ΓööΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÿ  ΓööΓöÇcharacterΓöÇΓöÇΓöÿ
  12690.                  ΓööΓöÇidentifierΓöÇΓöÿ
  12691.  
  12692. The #define directive can contain an object-like definition or a function-like 
  12693. definition 
  12694.  
  12695. Arguments of the # and ## operators are converted before replacement of 
  12696. parameters in a function-like macro. 
  12697.  
  12698. The number of arguments in a macro invocation must be the same as the number of 
  12699. parameters in the corresponding macro definition. 
  12700.  
  12701. Commas in the macro invocation argument list do not act as argument separators 
  12702. when they are: 
  12703.  
  12704.      in character constants 
  12705.      in string literals 
  12706.      surrounded by parentheses. 
  12707.  
  12708.  Once defined, a preprocessor identifier remains defined and in scope 
  12709.  independent of the scoping rules of the language. The scope of a macro 
  12710.  definition begins at the definition and does not end until a corresponding 
  12711.  #undef directive is encountered. If there is no corresponding #undef 
  12712.  directive, the scope of the macro definition lasts until the end of the 
  12713.  compilation unit. 
  12714.  
  12715.  A recursive macro is not fully expanded. For example, the definition 
  12716.  
  12717.     #define x(a,b) x(a+1,b+1) + 4
  12718.  
  12719.  expands   x(20,10)   to   x(20+1,10+1) + 4   rather than trying to expand the 
  12720.  macro x over and over within itself. After the macro x is expanded, it is a 
  12721.  call to function x(). 
  12722.  
  12723.  A definition is not required to specify replacement tokens. The following 
  12724.  definition removes all instances of the token debug from subsequent lines in 
  12725.  the current file: 
  12726.  
  12727.   #define debug
  12728.  
  12729.  You can change the definition of a defined identifier or macro with a second 
  12730.  preprocessor #define directive only if the second preprocessor #define 
  12731.  directive is preceded by a preprocessor #undef directive, described in Scope 
  12732.  of Macro Names (#undef). The #undef directive nullifies the first definition 
  12733.  so that the same identifier can be used in a redefinition. 
  12734.  
  12735.  You can also use the /D compiler option to define macros on the command line. 
  12736.  Macros defined on the command line override macros defined in the source code. 
  12737.  The /D option is described in the IBM VisualAge for C++ for Windows User's 
  12738.  Guide. 
  12739.  
  12740.  Within the text of the program, the preprocessor does not scan character 
  12741.  constants or string constants for macro invocations. 
  12742.  
  12743.  Examples of #define Directives 
  12744.  
  12745.  Related Information 
  12746.  
  12747.      Object-Like Macros 
  12748.      Function-Like Macros 
  12749.      Scope of Macro Names (#undef) 
  12750.      # Operator 
  12751.      Macro Concatenation with the ## and /**/ Operators 
  12752.  
  12753.  
  12754. ΓòÉΓòÉΓòÉ 9.3.1. Object-Like Macros ΓòÉΓòÉΓòÉ
  12755.  
  12756. An object-like macro definition replaces a single identifier with the specified 
  12757. replacement tokens. The following object-like definition causes the 
  12758. preprocessor to replace all subsequent instances of the identifier COUNT with 
  12759. the constant 1000: 
  12760.  
  12761. #define COUNT 1000
  12762.  
  12763. If the statement 
  12764.  
  12765. int arry[COUNT];
  12766.  
  12767. appears after this definition and in the same file as the definition, the 
  12768. preprocessor would change the statement to 
  12769.  
  12770. int arry[1000];
  12771.  
  12772. in the output of the preprocessor. 
  12773.  
  12774. Other definitions can make reference to the identifier COUNT: 
  12775.  
  12776. #define MAX_COUNT COUNT + 100
  12777.  
  12778. The preprocessor replaces each subsequent occurrence of MAX_COUNT with 
  12779. COUNT + 100, which the preprocessor then replaces with 1000 + 100. 
  12780.  
  12781. If a number that is partially built by a macro expansion is produced, the 
  12782. preprocessor does not consider the result to be a single value. For example, 
  12783. the following will not result in the value 10.2 but in a syntax error. 
  12784.  
  12785. #define a 10
  12786. a.2
  12787.  
  12788. Using the following also results in a syntax error: 
  12789.  
  12790. #define a 10
  12791. #define b a.11
  12792.  
  12793. Identifiers that are partially built from a macro expansion may not be 
  12794. produced. Therefore, the following example contains two identifiers and results 
  12795. in a syntax error: 
  12796.  
  12797. #define d efg
  12798. abcd
  12799.  
  12800.  
  12801. ΓòÉΓòÉΓòÉ 9.3.2. Function-Like Macros ΓòÉΓòÉΓòÉ
  12802.  
  12803.  Function-like macro definition: 
  12804.       An identifier followed by a parenthesized parameter list in parenthesis 
  12805.       and the replacement tokens. The parameters are imbedded in the 
  12806.       replacement code. White space cannot separate the identifier (which is 
  12807.       the name of the macro) and the left parenthesis of the parameter list. A 
  12808.       comma must separate each parameter. For portability, you should not have 
  12809.       more than 31 parameters for a macro. 
  12810.  
  12811.  Function-like macro invocation: 
  12812.       An identifier followed by a list of arguments in parentheses. A comma 
  12813.       must separate each argument. Once the preprocessor identifies a 
  12814.       function-like macro invocation, argument substitution takes place. A 
  12815.       parameter in the replacement code is replaced by the corresponding 
  12816.       argument. Any macro invocations contained in the argument itself are 
  12817.       completely replaced before the argument replaces its corresponding 
  12818.       parameter in the replacement code. 
  12819.  
  12820.  The following line defines the macro SUM as having two parameters a and b and 
  12821.  the replacement tokens (a + b): 
  12822.  
  12823.   #define SUM(a,b) (a + b)
  12824.  
  12825.  This definition would cause the preprocessor to change the following 
  12826.  statements (if the statements appear after the previous definition): 
  12827.  
  12828.   c = SUM(x,y);
  12829.   c = d * SUM(x,y);
  12830.  
  12831.  In the output of the preprocessor, these statements would appear as: 
  12832.  
  12833.   c = (x + y);
  12834.   c = d * (x + y);
  12835.  
  12836.  Use parentheses to ensure correct evaluation of replacement text. For example, 
  12837.  the definition: 
  12838.  
  12839.   #define SQR(c)  ((c) * (c))
  12840.  
  12841.  requires parentheses around each parameter c in the definition in order to 
  12842.  correctly evaluate an expression like: 
  12843.  
  12844.   y = SQR(a + b);
  12845.  
  12846.  The preprocessor expands this statement to: 
  12847.  
  12848.   y = ((a + b) * (a + b));
  12849.  
  12850.  Without parentheses in the definition, the correct order of evaluation is not 
  12851.  preserved, and the preprocessor output is: 
  12852.  
  12853.   y = (a + b * a + b);
  12854.  
  12855.  See Operator Precedence and Associativity, and Parenthesized Expressions ( ) 
  12856.  for more information about using parentheses. 
  12857.  
  12858.  
  12859. ΓòÉΓòÉΓòÉ <hidden> Examples of #define Directives ΓòÉΓòÉΓòÉ
  12860.  
  12861. /************************************************************************
  12862. *
  12863.  
  12864. The following program contains two macro definitions and a macro invocation 
  12865. that refers to both of the defined macros: 
  12866.  
  12867.                                     *
  12868. ************************************************************************/
  12869.  
  12870. /**
  12871.  ** This example illustrates #define directives.
  12872.  **/
  12873.  
  12874. #include <stdio.h>
  12875.  
  12876. #define SQR(s)  ((s) * (s))
  12877. #define PRNT(a,b) \
  12878.  printf("value 1 = %d\n", a); \
  12879.  printf("value 2 = %d\n", b) ;
  12880.  
  12881. int main(void)
  12882. {
  12883.  int x = 2;
  12884.  int y = 3;
  12885.  
  12886.    PRNT(SQR(x),y);
  12887.  
  12888.  return(0);
  12889. }
  12890.  
  12891. /************************************************************************
  12892. *
  12893.  
  12894. After being interpreted by the preprocessor, this program is replaced by code 
  12895. equivalent to the following: 
  12896.  
  12897.                                     *
  12898. ************************************************************************/
  12899.  
  12900. #include <stdio.h>
  12901.  
  12902. int main(void)
  12903. {
  12904.  int x = 2;
  12905.  int y = 3;
  12906.  
  12907.    printf("value 1 = %d\n", ( (x) * (x) ) );
  12908.    printf("value 2 = %d\n", y);
  12909.  
  12910.  return(0);
  12911. }
  12912.  
  12913. /************************************************************************
  12914. *
  12915. This program produces the following output: 
  12916.  
  12917. value 1 = 4
  12918. value 2 = 3
  12919.  
  12920.                                     *
  12921. ************************************************************************/
  12922.  
  12923.  
  12924. ΓòÉΓòÉΓòÉ 9.4. Scope of Macro Names (#undef) ΓòÉΓòÉΓòÉ
  12925.  
  12926. A preprocessor undef directive causes the preprocessor to end the scope of a 
  12927. preprocessor definition. 
  12928.  
  12929. A preprocessor #undef directive has the form: 
  12930.  
  12931. >>ΓöÇΓöÇ#ΓöÇΓöÇundefΓöÇΓöÇidentifierΓöÇΓöÇ><
  12932.  
  12933. If the identifier is not currently defined as a macro, #undef is ignored 
  12934.  
  12935. You can also use the /U compiler option to undefine macros. The /U option does 
  12936. not undefine macros defined in source code. 
  12937.  
  12938. Examples of #undef Directives 
  12939.  
  12940. Related Information 
  12941.  
  12942.      Macro Definition and Expansion (#define) 
  12943.      Predefined Macro Names 
  12944.      Preprocessor Directives 
  12945.  
  12946.  
  12947. ΓòÉΓòÉΓòÉ <hidden> Examples of #undef Directives ΓòÉΓòÉΓòÉ
  12948.  
  12949. The following directives define BUFFER and SQR: 
  12950.  
  12951. #define BUFFER 512
  12952. #define SQR(x) ((x) * (x))
  12953.  
  12954. The following directives nullify these definitions: 
  12955.  
  12956. #undef BUFFER
  12957. #undef SQR
  12958.  
  12959. Any occurrences of the identifiers BUFFER and SQR that follow these #undef 
  12960. directives are not replaced with any replacement tokens. Once the definition of 
  12961. a macro has been removed by an #undef directive, the identifier can be used in 
  12962. a new #define directive. 
  12963.  
  12964.  
  12965. ΓòÉΓòÉΓòÉ 9.5. # Operator ΓòÉΓòÉΓòÉ
  12966.  
  12967. The # (single number sign) operator converts a parameter of a function-like 
  12968. macro into a character string literal. For example, if macro ABC is defined 
  12969. using the following directive: 
  12970.  
  12971.   #define ABC(x)  #x
  12972.  
  12973. all subsequent invocations of the macro ABC would be expanded into a character 
  12974. string literal containing the argument passed to ABC. For example: 
  12975.  
  12976. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12977. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  12978. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12979. Γöé "ABC(1)"       Γöé "1"            Γöé
  12980. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12981. Γöé "ABC(Hello there)"  Γöé "Hello there"       Γöé
  12982. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  12983.  
  12984. The # operator should not be confused with the null directive. 
  12985.  
  12986. Use the # operator in a function-like macro definition according to the 
  12987. following rules: 
  12988.  
  12989.      A parameter following # operator in a function-like macro is converted 
  12990.       into a character string literal containing the argument passed to the 
  12991.       macro. 
  12992.  
  12993.      White-space characters that appear before or after the argument passed to 
  12994.       the macro are deleted. 
  12995.  
  12996.      Multiple white-space characters imbedded within the argument passed to 
  12997.       the macro is replaced by a single space character. 
  12998.  
  12999.      If the argument passed to the macro contains a string literal and if a \ 
  13000.       (backslash) character appears within the literal, a second \ character is 
  13001.       inserted before the original \ when the macro is expanded. 
  13002.  
  13003.      If the argument passed to the macro contains a " (double quotation mark) 
  13004.       character, a \ character is inserted before the " when the macro is 
  13005.       expanded. 
  13006.  
  13007.      If the argument passed to the macro contains a ' (single quotation mark) 
  13008.       character, a \ character is inserted before the ' when the macro is 
  13009.       expanded. 
  13010.  
  13011.      The conversion of an argument into a string literal occurs before macro 
  13012.       expansion on that argument. 
  13013.  
  13014.      If more than one ## operator or # operator appears in the replacement 
  13015.       list of a macro definition, the order of evaluation of the operators is 
  13016.       not defined. 
  13017.  
  13018.      If the result of the macro expansion is not a valid character string 
  13019.       literal, the behavior is undefined. 
  13020.  
  13021.  See Function-Like Macros for more information about function-like macros. 
  13022.  
  13023.  Examples of the # Operator 
  13024.  
  13025.  Related Information 
  13026.  
  13027.      Macro Definition and Expansion (#define) 
  13028.      Scope of Macro Names (#undef) 
  13029.      Macro Concatenation with the ## and /**/ Operators 
  13030.      Function-Like Macros 
  13031.      Preprocessor Directives 
  13032.  
  13033.  
  13034. ΓòÉΓòÉΓòÉ <hidden> Examples of the # Operator ΓòÉΓòÉΓòÉ
  13035.  
  13036. The following examples demonstrate the use of the # operator: 
  13037.  
  13038.   #define STR(x)     #x
  13039.   #define XSTR(x)    STR(x)
  13040.   #define ONE      1
  13041.  
  13042. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13043. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  13044. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13045. Γöé "STR(\n "\n" '\n')"  Γöé ""\n \"\\n\" '\\n'""    Γöé
  13046. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13047. Γöé "STR(ONE)"      Γöé "ONE"           Γöé
  13048. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13049. Γöé "XSTR(ONE)"      Γöé "1"            Γöé
  13050. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13051. Γöé "XSTR("hello")"    Γöé "\"hello\""        Γöé
  13052. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13053.  
  13054.  
  13055. ΓòÉΓòÉΓòÉ 9.6. Macro Concatenation with the ## and /**/ Operators ΓòÉΓòÉΓòÉ
  13056.  
  13057. The ## (double number sign) operator concatenates two tokens in a macro 
  13058. invocation (text and/or arguments) given in a macro definition. In extended 
  13059. mode only, you can also use the /**/ (null comment) operator for macro 
  13060. concatenation. 
  13061.  
  13062. If a macro XY was defined using the following directive: 
  13063.  
  13064.   #define XY(x,y)   x##y
  13065.  
  13066. the last token of the argument for x is concatenated with the first token of 
  13067. the argument for y. 
  13068.  
  13069. The following is an equivalent macro definition using /**/: 
  13070.  
  13071. #define XY(x, y) x/**/y
  13072.  
  13073. Both definitions yield the same output: 
  13074.  
  13075. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13076. Γöé INVOCATION    Γöé RESULT OF MACRO EXPANSION Γöé
  13077. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13078. Γöé "XY(1, 2)"    Γöé "12"            Γöé
  13079. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13080. Γöé "XY(Green,    Γöé "Greenhouse"        Γöé
  13081. Γöé house)"     Γöé              Γöé
  13082. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13083.  
  13084. Use the ## operator according to the following rules: 
  13085.  
  13086.      The ## operator cannot be the very first or very last item in the 
  13087.       replacement list of a macro definition. 
  13088.  
  13089.      The last token of the item in front of the ## operator is concatenated 
  13090.       with first token of the item following the ## operator. 
  13091.  
  13092.      Concatenation takes place before any macros in arguments are expanded. 
  13093.  
  13094.      If the result of a concatenation is a valid macro name, it is available 
  13095.       for further replacement even if it appears in a context in which it would 
  13096.       not normally be available. 
  13097.  
  13098.      If more than one ## operator and/or # operator appears in the replacement 
  13099.       list of a macro definition, the order of evaluation of the operators is 
  13100.       not defined. 
  13101.  
  13102.  Examples of the ## Operator 
  13103.  
  13104.  Related Information 
  13105.  
  13106.      Macro Definition and Expansion (#define) 
  13107.      Scope of Macro Names (#undef) 
  13108.      # Operator 
  13109.      Preprocessor Directives 
  13110.  
  13111.  
  13112. ΓòÉΓòÉΓòÉ <hidden> Examples of the ## Operator ΓòÉΓòÉΓòÉ
  13113.  
  13114. The following examples demonstrate the use of the ## operator: 
  13115.  
  13116. #define ArgArg(x, y)      x##y
  13117. #define ArgText(x)       x##TEXT
  13118. #define TextArg(x)       TEXT##x
  13119. #define TextText        TEXT##text
  13120. #define Jitter         1
  13121. #define bug          2
  13122. #define Jitterbug       3
  13123.  
  13124. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13125. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  13126. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13127. Γöé "ArgArg(lady, bug)"  Γöé ""ladybug""        Γöé
  13128. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13129. Γöé "ArgText(con)"    Γöé ""conTEXT""        Γöé
  13130. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13131. Γöé "TextArg(book)"    Γöé ""TEXTbook""        Γöé
  13132. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13133. Γöé "TextText"      Γöé ""TEXTtext""        Γöé
  13134. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13135. Γöé "ArgArg(Jitter,    Γöé "3"            Γöé
  13136. Γöé bug)"         Γöé              Γöé
  13137. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13138.  
  13139.  
  13140. ΓòÉΓòÉΓòÉ 9.6.1. /**/ Operator ΓòÉΓòÉΓòÉ
  13141.  
  13142. The /**/ operator differs from the ## operator only in the way that the 
  13143. preprocessor treats white space between the operator and its arguments. 
  13144.  
  13145. For example, the macro definition: 
  13146.  
  13147. #define XY(x, y) x /**/y
  13148.  
  13149. does not give the same result as: 
  13150.  
  13151. #define XY(x, y) x ##y
  13152.  
  13153. because the preprocessor preserves white space with the /**/ operator. With the 
  13154. ## operator, arguments are concatenated without white space. For example, the 
  13155. invocation: 
  13156.  
  13157. XY(Turtle, neck)
  13158.  
  13159. gives the following results: 
  13160.  
  13161. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13162. Γöé DEFINITION               Γöé RESULT OF MACRO EXPANSION       Γöé
  13163. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13164. Γöé "#define XY(x, y) x /**/y"       Γöé "Turtle neck"             Γöé
  13165. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13166. Γöé "#define XY(x, y) x/*stew*/y"     Γöé "Turtle neck"             Γöé
  13167. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13168. Γöé "#define XY(x, y) x ##y"        Γöé "Turtleneck"             Γöé
  13169. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13170. Γöé "#define XY(x, y) x##y"        Γöé "Turtleneck"             Γöé
  13171. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13172.  
  13173. For /**/ to function the same way as ## in ANSI/ISO C, there can be no spaces 
  13174. between the operator and the arguments. 
  13175. Examples of the /**/ Operator 
  13176.  
  13177. The following examples demonstrate the use of the /**/ operator. 
  13178.  
  13179. #define lhk   lighthousekeeper
  13180. #define f(a,b)  a/**/b
  13181. #define g(a,b)  a /**/b
  13182. #define h(a,b)  a/**/ b
  13183. #define i(f)   light/**/f
  13184. #define a(f)   f /**/housekeeper
  13185. #define m    l/**/hk
  13186.  
  13187. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13188. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  13189. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13190. Γöé "f(l,hk)"       Γöé "lighthousekeeper"     Γöé
  13191. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13192. Γöé "g(light,housekeeper)Γöé "light housekeeper"    Γöé
  13193. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13194. Γöé "g(lighthouse,keeper)Γöé "lighthouse keeper"    Γöé
  13195. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13196. Γöé "h(lighthouse,keeper)Γöé "lighthouse keeper"    Γöé
  13197. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13198. Γöé "f(light,house)"   Γöé "lighthouse"        Γöé
  13199. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13200. Γöé "i(housekeeper)"   Γöé "lighthousekeeper"     Γöé
  13201. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13202. Γöé "a(light)"      Γöé "light housekeeper"    Γöé
  13203. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13204. Γöé "m"          Γöé "lighthousekeeper"     Γöé
  13205. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13206.  
  13207.  
  13208. ΓòÉΓòÉΓòÉ 9.7. Preprocessor Error Directive (#error) ΓòÉΓòÉΓòÉ
  13209.  
  13210. A preprocessor error directive causes the preprocessor to generate an error 
  13211. message and causes the compilation to fail. 
  13212.  
  13213. The #error directive has the form: 
  13214.  
  13215.        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13216.              Γöé
  13217. >>ΓöÇΓöÇ#ΓöÇΓöÇerrorΓöÇΓöÇΓöÇΓöÇcharacterΓöÇΓö┤ΓöÇΓöÇ><
  13218.  
  13219. Use the #error directive as a safety check during compilation. For example, if 
  13220. your program uses preprocessor conditional compilation directives, put #error 
  13221. directives in the source file to prevent code generation if a section of the 
  13222. program is reached that should be bypassed. 
  13223.  
  13224. For example, the directive 
  13225.  
  13226. #error Error in TESTPGM1 - This section should not be compiled
  13227.  
  13228. generates the following error message: 
  13229.  
  13230. Error in TESTPGM1 - This section should not be compiled
  13231.  
  13232. Related Information 
  13233.  
  13234.      Preprocessor Directives 
  13235.  
  13236.  
  13237. ΓòÉΓòÉΓòÉ 9.8. File Inclusion (#include) ΓòÉΓòÉΓòÉ
  13238.  
  13239. A preprocessor include directive causes the preprocessor to replace the 
  13240. directive with the contents of the specified file. 
  13241.  
  13242. A preprocessor #include directive has the form: 
  13243.  
  13244. >>ΓöÇΓöÇ#ΓöÇΓöÇincludeΓöÇΓöÇΓö¼ΓöÇ"file_name"ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  13245.         Γö£ΓöÇΓöÉfile_name>ΓöÇΓöÇΓöÇΓöñ
  13246.         Γö£ΓöÇΓöÉheader_name>ΓöÇΓöñ
  13247.         ΓööΓöÇidentifiersΓöÇΓöÇΓöÇΓöÿ
  13248.  
  13249. The preprocessor resolves macros contained in a #include directive. After macro 
  13250. replacement, the resulting token sequence must consist of a file name enclosed 
  13251. in either double quotation marks or the characters < and >. 
  13252.  
  13253. For example: 
  13254.  
  13255. #define MONTH <july.h>
  13256. #include MONTH
  13257.  
  13258. If the file name is enclosed in double quotation marks, for example:  #include 
  13259. "payroll.h"  the preprocessor treats it as a user-defined file, and searches 
  13260. for the file in: 
  13261.  
  13262.    1. The directory where the original .c source file resides. 
  13263.  
  13264.    2. Any directories specified using the /I compiler option (that have not 
  13265.       been removed by the /Xc option).  Directories specified in the ICC 
  13266.       environment variable are searched before those specified on the command 
  13267.       line. 
  13268.  
  13269.    3. Any directories specified using the INCLUDE environment variable, 
  13270.       provided the /Xi option is not in effect. 
  13271.  
  13272.  If the file name is enclosed in angle brackets, for example: #include 
  13273.  <stdio.h> it is treated as a system-defined file, and the preprocessor 
  13274.  searches the following places in the order given: 
  13275.  
  13276.    1. Any directories specified using the /I compiler option (that have not 
  13277.       been removed by the /Xc option).  Directories specified in the ICC 
  13278.       environment variable are searched before those specified on the command 
  13279.       line. 
  13280.  
  13281.    2. Any directories specified using the INCLUDE environment variable, 
  13282.       provided the /Xi option is not in effect. 
  13283.  
  13284.  Note:  If the file name is fully qualified, the preprocessor searches only the 
  13285.  directory specified by the name. 
  13286.  
  13287.  The new-line and > characters cannot appear in a file name delimited by < and 
  13288.  >. The new-line and " (double quotation marks) character cannot appear in a 
  13289.  file name delimited by " and ", although > can. 
  13290.  
  13291.  Declarations that are used by several files can be placed in one file and 
  13292.  included with #include in each file that uses them. For example, the following 
  13293.  file defs.h contains several definitions and an inclusion of an additional 
  13294.  file of declarations: 
  13295.  
  13296.   /* defs.h */
  13297.   #define TRUE 1
  13298.   #define FALSE 0
  13299.   #define BUFFERSIZE 512
  13300.   #define MAX_ROW 66
  13301.   #define MAX_COLUMN 80
  13302.   int hour;
  13303.   int min;
  13304.   int sec;
  13305.   #include "mydefs.h"
  13306.  
  13307.  You can embed the definitions that appear in defs.h with the following 
  13308.  directive: 
  13309.  
  13310.   #include "defs.h"
  13311.  
  13312.  In the following example, a #define combines several preprocessor macros to 
  13313.  define a macro that represents the name of the C standard I/O header file. A 
  13314.  #include makes the header file available to the program. 
  13315.  
  13316.   #define  IO_HEADER  <stdio.h>
  13317.      .
  13318.      .
  13319.      .
  13320.   #include IO_HEADER  /* equivalent to specifying #include <stdio.h> */
  13321.      .
  13322.      .
  13323.      .
  13324.  
  13325.  Related Information 
  13326.  
  13327.      Macro Definition and Expansion (#define) 
  13328.      Preprocessor Directives 
  13329.      Include Files 
  13330.  
  13331.  
  13332. ΓòÉΓòÉΓòÉ 9.9. Predefined Macro Names ΓòÉΓòÉΓòÉ
  13333.  
  13334. VisualAge for C++ provides the following predefined macro names: 
  13335.  
  13336.      ANSI/ISO Standard Predefined Macro Names 
  13337.      VisualAge for C++ Predefined Macro Names 
  13338.      Additional VisualAge for C++ Predefined Macros 
  13339.  These predefined names cannot be subject to a #define or #undef preprocessor 
  13340.  directive. 
  13341.  
  13342.  Examples of Predefined Macros 
  13343.  
  13344.  Related Information 
  13345.  
  13346.      langlvl 
  13347.      Macro Definition and Expansion (#define) 
  13348.      Scope of Macro Names (#undef) 
  13349.  
  13350.  
  13351. ΓòÉΓòÉΓòÉ 9.9.1. ANSI/ISO Standard Predefined Macro Names ΓòÉΓòÉΓòÉ
  13352.  
  13353. Both C and C++ provide the following predefined macro names as specified in the 
  13354. ANSI/ISO C language standard: 
  13355.  
  13356.  __DATE__ 
  13357.      A character string literal containing the date when the source file was 
  13358.      compiled. 
  13359.  
  13360.      The value of __DATE__ changes as the compiler processes any include files 
  13361.      that are part of your source program. The date is in the form: 
  13362.  
  13363.             "Mmm dd yyyy"
  13364.  
  13365.      where: 
  13366.  
  13367.      Mmm            Represents the month in an abbreviated form (Jan, Feb, Mar, 
  13368.                     Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec). 
  13369.  
  13370.      dd             Represents the day. If the day is less than 10, the first d 
  13371.                     is a blank character. 
  13372.  
  13373.      yyyy           Represents the year. 
  13374.  
  13375.      The date is always set to the system date. 
  13376.  
  13377.  __FILE__ 
  13378.      A character string literal containing the name of the source file. 
  13379.  
  13380.      The value of __FILE__ changes as the compiler processes include files that 
  13381.      are part of your source program. It can be set with the #line directive, 
  13382.      described in Line Control (#line). 
  13383.  
  13384.  __LINE__ 
  13385.      An integer representing the current source line number. 
  13386.  
  13387.      The value of __LINE__ changes during compilation as the compiler processes 
  13388.      subsequent lines of your source program. It can be set with the #line 
  13389.      directive, described in Line Control (#line). 
  13390.  
  13391.  __STDC__ 
  13392.      For C programs, the compiler sets this macro to the integer 1 (one) to 
  13393.      indicate that the C compiler conforms to the ANSI/ISO standard. For C++ 
  13394.      programs, this macro is not defined, It has the integer value 0 when used 
  13395.      in a #if statement, indicating that the C++ language is not a proper 
  13396.      superset of C, and that the compiler does not conform to ANSI/ISO C. 
  13397.  
  13398.      For more information on how C++ differs from ANSI/ISO C, see C and C++ 
  13399.      Compatibility. 
  13400.  
  13401.      Note:  This macro is not defined if the language level is set to anything 
  13402.      other than ANSI. 
  13403.  
  13404.  __TIME__ 
  13405.      A character string literal containing the time when the source file was 
  13406.      compiled. 
  13407.  
  13408.      The value of __TIME__ changes as the compiler processes any include files 
  13409.      that are part of your source program. The time is in the form: 
  13410.  
  13411.             "hh:mm:ss"
  13412.  
  13413.      where: 
  13414.  
  13415.      hh             Represents the hour. 
  13416.  
  13417.      mm             Represents the minutes. 
  13418.  
  13419.      ss             Represents the seconds. 
  13420.  
  13421.      The time is always set to the system time. 
  13422.  
  13423.  __cplusplus 
  13424.      For C++ programs, this macro is set to the integer 1, indicating that the 
  13425.      compiler is a C++ compiler. Note that this macro name has no trailing 
  13426.      underscores. 
  13427.  
  13428.  
  13429. ΓòÉΓòÉΓòÉ 9.9.2. VisualAge for C++ Predefined Macro Names ΓòÉΓòÉΓòÉ
  13430.  
  13431. VisualAge for C++ provides the following predefined macros. The value of all 
  13432. these macros is defined when the corresponding #pragma directive or compiler 
  13433. option is used. They cannot be the subject of a #define or #undef preprocessor 
  13434. directive. However, except for the __DATE__, __FUNCTION__, __LINE__, __TIME__, 
  13435. and __TIMESTAMP__ macros, they can be undefined on the command line using the 
  13436. /U option. 
  13437.  
  13438.  __ANSI__ 
  13439.      Allows only language constructs that conform to ANSI/ISO C standard. 
  13440.      Defined as 1 when using the #pragma langlvl directive or /Sa option. 
  13441.  
  13442.  __EXTENDED__ 
  13443.      Allows additional language constructs provided by the VisualAge for C++ 
  13444.      implementation. Defined using the #pragma langlvl directive or /S2 option. 
  13445.  
  13446.  __SAA__ 
  13447.      Allows only language constructs that conform to the most recent level of 
  13448.      SAA C standards. Defined as 1 using the #pragma langlvl directive or /S2 
  13449.      option. This macro is not defined for C++. 
  13450.  
  13451.  __SAA_L2__ 
  13452.      Allows only language constructs that conform to SAA Level 2 C standards. 
  13453.      Defined as 1 using the #pragma langlvldirective or /S2 option. This macro 
  13454.      is not defined for C++. 
  13455.  
  13456.  __COMPAT__ 
  13457.      Macro defined as 1 when the /Sc compiler option or the #pragma 
  13458.      langlvl(compat) directive is specified for C++ language files. Indicates 
  13459.      language constructs compatible with earlier versions of the C++ language 
  13460.      are allowed. This macro is not defined for C. 
  13461.  
  13462.  __FUNCTION__ 
  13463.      A character string containing the name of the function currently being 
  13464.      compiled. For C++ programs, expands to the actual function prototype. 
  13465.  
  13466.  _LONG_LONG 
  13467.      Macro defined when the compiler is in a mode that permits long long int 
  13468.      and unsigned long long int types. 
  13469.  
  13470.  __LONGDOUBLE80 
  13471.      Macro defined when the compiler is in a mode in which long double types 
  13472.      have 80 bits of precision. This macro is always defined for VisualAge for 
  13473.      C++. 80 bits of precision is the default for all language levels. 
  13474.  
  13475.  __SOM_ENABLED__ 
  13476.      Macro defined when the SOM compiler options are used. Indicates that 
  13477.      native SOM is supported. This option turns on implicit SOM mode, and also 
  13478.      causes the file som.h to be included. SOM support for VisualAge for C++ 
  13479.      and the SOM options are described in the IBM VisualAge for C++ for Windows 
  13480.      Programming Guide. 
  13481.  
  13482.  __TEMPINC__ 
  13483.      Indicates the template-implementation file method of resolving template 
  13484.      functions is being used. Defined as 1 using the /Ft compiler option. 
  13485.  
  13486.  __TIMESTAMP__ 
  13487.      A character string literal containing the date and time when the source 
  13488.      file was last modified. 
  13489.  
  13490.      The value of __TIMESTAMP__ changes as the compiler processes any include 
  13491.      files that are part of your source program. The date and time are in the 
  13492.      form: 
  13493.  
  13494.             "Day Mmm dd hh:mm:ss yyyy"
  13495.  
  13496.      where: 
  13497.  
  13498.      Day            Represents the day of the week (Mon, Tue, Wed, Thu, Fri, 
  13499.                     Sat, or Sun). 
  13500.  
  13501.      Mmm            Represents the month in an abbreviated form (Jan, Feb, Mar, 
  13502.                     Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec). 
  13503.  
  13504.      dd             Represents the day. If the day is less than 10, the first d 
  13505.                     is a blank character. 
  13506.  
  13507.      hh             Represents the hour. 
  13508.  
  13509.      mm             Represents the minutes. 
  13510.  
  13511.      ss             Represents the seconds. 
  13512.  
  13513.      yyyy           Represents the year. 
  13514.  
  13515.      The date and time are always set to the system date and time. 
  13516.  
  13517.  
  13518. ΓòÉΓòÉΓòÉ 9.9.3. Additional VisualAge for C++ Predefined Macros ΓòÉΓòÉΓòÉ
  13519.  
  13520. The macros identified in this section are provided to allow customers to write 
  13521. programs that use VisualAge for C++ services. Only those macros identified in 
  13522. this section should be used to request or receive VisualAge for C++ services. 
  13523.  
  13524.  _CHAR_UNSIGNED 
  13525.      Indicates default character type is unsigned. Defined when the #pragma 
  13526.      chars(unsigned) directive is in effect, or when the /J+ compiler option is 
  13527.      set. 
  13528.  
  13529.  _CHAR_SIGNED 
  13530.      Indicates default character type is signed. Defined when the #pragma 
  13531.      chars(signed) directive is in effect, or when the /J- compiler option is 
  13532.      set. 
  13533.  
  13534.  __DBCS__ 
  13535.      Indicates DBCS support is enabled. Defined using the /Sn compiler option. 
  13536.  
  13537.  __DDNAMES__ 
  13538.      Indicates ddnames are supported. Defined using the /Sh compiler option. 
  13539.  
  13540.  __DEBUG_ALLOC__ 
  13541.      Maps memory management functions to their debug versions. Defined using 
  13542.      the /Tm compiler option. 
  13543.  
  13544.  __DLL__ and _DLL 
  13545.      Indicates code for a DLL is being compiled. Defined using the /Ge- 
  13546.      compiler option. 
  13547.  
  13548.  _FP_INLINE_ 
  13549.      Inlines the trigonometric functions (cos, sin, and so on). 
  13550.  
  13551.  __FUNCTION__ 
  13552.      Indicates the name of the function currently being compiled. For C++ 
  13553.      programs, expands to the actual function prototype. 
  13554.  
  13555.  __HHW_INTEL__ 
  13556.      Indicates that the host hardware is an Intel** processor. 
  13557.  
  13558.  __HOS_WIN__ 
  13559.      Indicates that the host operating system is Windows. 
  13560.  
  13561.  __IBMC__ 
  13562.      Indicates the version number of the VisualAge C compiler. 
  13563.  
  13564.  __IBMCPP__ 
  13565.      Indicates the version number of the VisualAge C++ compiler. 
  13566.  
  13567.  __IMPORTLIB__ 
  13568.      Indicates that dynamic linking is used. Defined using the /Gd option. 
  13569.  
  13570.  _M_I386 
  13571.      Indicates code is being compiled for a 386 chip or higher. 
  13572.  
  13573.  _M_IX86 
  13574.      Indicates code is being compiled for a 386 chip or higher. Defined using 
  13575.      the /qtune compiler options: 
  13576.  
  13577.          /qtune=386 (equivalent to /G3) 
  13578.          /qtune=486 (equivalent to /G4) 
  13579.          /qtune=pentium (equivalent to /G5) 
  13580.          /qtune=pentiumpro 
  13581.          /qtune=blend 
  13582.  
  13583.  __MULTI__ and _MT 
  13584.      Indicates multithread code is being generated. Defined using the /Gm 
  13585.      compiler option. 
  13586.  
  13587.  __NO_DEFAULT_LIBS__ 
  13588.      Indicates that information about default libraries will not be included in 
  13589.      object files. Defined using the /Gn option. 
  13590.  
  13591.  __SOM_ENABLED__ 
  13592.      Indicates that native SOM is supported. 
  13593.  
  13594.  __SPC__ 
  13595.      Indicates the subsystem libraries are being used. Defined using the /Rn 
  13596.      compiler option. 
  13597.  
  13598.  _STDCALL_SUPPORTED 
  13599.      Indicates that the compiler supports __stdcall linkage. 
  13600.  
  13601.  __THW_INTEL__ 
  13602.      Indicates that the target hardware is an Intel processor. 
  13603.  
  13604.  __TOS_WIN__ 
  13605.      Indicates that the target operating system is Windows. 
  13606.  
  13607.  __WINDOWS__ 
  13608.      Set to the integer 1.  Indicates the product is a Windows compiler. 
  13609.  
  13610.  _WIN32 
  13611.      Indicates that the compiler generates Win32 code. Defined when the 
  13612.      /qwin32s compiler option is set. 
  13613.  
  13614.  __32BIT__ 
  13615.      Set to the integer 1. Indicates the product is a 32-bit compiler. 
  13616.  
  13617.  The value of the __IBMC__ and __IBMCPP__ macros is 300. One of these two 
  13618.  macros is always defined: when you compile C++ code, __IBMCPP__ is defined; 
  13619.  when you compile C code, __IBMC__ is defined. The macros __WINDOWS__, _M_I386, 
  13620.  and __32BIT__ are always defined also. The remaining macros, with the 
  13621.  exception of __FUNCTION__, are defined when the corresponding #pragma 
  13622.  directive or compiler option is used. 
  13623.  
  13624.  Related Information 
  13625.  
  13626.      #pragma chars. 
  13627.      #pragma langlvl 
  13628.  
  13629.  
  13630. ΓòÉΓòÉΓòÉ <hidden> Example of Predefined Macros ΓòÉΓòÉΓòÉ
  13631.  
  13632. /************************************************************************
  13633. *
  13634.  
  13635. /**
  13636.  ** This example illustrates the __FUNCTION__ predefined macro
  13637.  ** in a C program.
  13638.  **/
  13639. #include <stdio.h>
  13640.  
  13641. int foo(int);
  13642.  
  13643. main(int argc, char **argv) {
  13644.   int k = 1;
  13645.   printf (" In function %s \n",__FUNCTION__);
  13646.   foo(k);
  13647. }
  13648.  
  13649. int foo (int i) {
  13650.   printf (" In function %s \n",__FUNCTION__);
  13651. }
  13652.  
  13653. The output of this example is: 
  13654.  
  13655.    In function main
  13656.    In function foo
  13657.  
  13658. /**
  13659.  ** This example illustrates the __FUNCTION__ predefined macro
  13660.  ** in a C++ program.
  13661.  **/
  13662. #include <stdio.h>
  13663.  
  13664. int foo(int);
  13665.  
  13666. main(int argc, char **argv) {
  13667.   int k = 1;
  13668.   printf (" In function %s \n",__FUNCTION__);
  13669.   foo(k);
  13670. }
  13671.  
  13672. int foo (int i) {
  13673.   printf (" In function %s \n",__FUNCTION__);
  13674. }
  13675.  
  13676. The output of this example is: 
  13677.  
  13678.    In function main(int, char **)
  13679.    In function foo (int)
  13680.  
  13681. /**
  13682.  ** This example illustrates the __FUNCTION__ predefined macro
  13683.  ** in a C++ program with virtual functions.
  13684.  **/
  13685. #include <stdio.h>
  13686. class X { public: virtual void func() = 0;};
  13687.  
  13688. class Y : public X {
  13689.   public: void func() { printf("In function %s \n", __FUNCTION__);}
  13690. };
  13691.  
  13692. main() {
  13693.  Y aaa;
  13694.  aaa.func();
  13695. }
  13696.  
  13697. The output of this example is: 
  13698.  
  13699.    In function Y::func()
  13700.  
  13701.  
  13702. ΓòÉΓòÉΓòÉ 9.10. Conditional Compilation Directives ΓòÉΓòÉΓòÉ
  13703.  
  13704. A preprocessor conditional compilation directive causes the preprocessor to 
  13705. conditionally suppress the compilation of portions of source code. These 
  13706. directives test a constant expression or an identifier to determine which 
  13707. tokens the preprocessor should pass on to the compiler and which tokens should 
  13708. be bypassed during preprocessing. The directives are: 
  13709.  
  13710.      #if 
  13711.      #ifdef 
  13712.      #ifndef 
  13713.      #else 
  13714.      #elif 
  13715.      #endif 
  13716.  
  13717.  The preprocessor conditional compilation directive spans several lines: 
  13718.  
  13719.      The condition specification line 
  13720.      Lines containing code that the preprocessor passes on to the compiler if 
  13721.       the condition evaluates to a nonzero value (optional) 
  13722.      The #else line (optional) 
  13723.      Lines containing code that the preprocessor passes on to the compiler if 
  13724.       the condition evaluates to zero (optional) 
  13725.      The preprocessor #endif directive 
  13726.  
  13727.  For each #if, #ifdef, and #ifndef directive, there are zero or more #elif 
  13728.  directives, zero or one #else directive, and one matching #endif directive. 
  13729.  All the matching directives are considered to be at the same nesting level. 
  13730.  
  13731.  You can nest conditional compilation directives. In the following directives, 
  13732.  the first #else is matched with the #if directive. 
  13733.  
  13734.   #ifdef MACNAME
  13735.            /*  tokens added if MACNAME is defined        */
  13736.   #  if TEST <=10
  13737.            /* tokens added if MACNAME is defined and TEST <= 10 */
  13738.   #  else
  13739.            /* tokens added if MACNAME is defined and TEST >  10 */
  13740.   #  endif
  13741.   #else
  13742.            /*  tokens added if MACNAME is not defined      */
  13743.   #endif
  13744.  
  13745.  Each directive controls the block immediately following it. A block consists 
  13746.  of all the tokens starting on the line following the directive and ending at 
  13747.  the next conditional compilation directive at the same nesting level. 
  13748.  
  13749.  Each directive is processed in the order in which it is encountered. If an 
  13750.  expression evaluates to zero, the block following the directive is ignored. 
  13751.  
  13752.  When a block following a preprocessor directive is to be ignored, the tokens 
  13753.  are examined only to identify preprocessor directives within that block so 
  13754.  that the conditional nesting level can be determined. All tokens other than 
  13755.  the name of the directive are ignored. 
  13756.  
  13757.  Only the first block whose expression is nonzero is processed. The remaining 
  13758.  blocks at that nesting level are ignored. If none of the blocks at that 
  13759.  nesting level has been processed and there is a #else directive, the block 
  13760.  following the #else directive is processed. If none of the blocks at that 
  13761.  nesting level has been processed and there is no #else directive, the entire 
  13762.  nesting level is ignored. 
  13763.  
  13764.  Examples of Conditional Compilation 
  13765.  
  13766.  Related Information 
  13767.  
  13768.      #if, #elif 
  13769.      #ifdef 
  13770.      #ifndef 
  13771.      #else 
  13772.      #endif 
  13773.      Preprocessor Directives 
  13774.  
  13775.  
  13776. ΓòÉΓòÉΓòÉ 9.10.1. #if, #elif ΓòÉΓòÉΓòÉ
  13777.  
  13778. The #if and #elif directives compare the value of the expression to zero. 
  13779.  
  13780. If the constant expression evaluates to a nonzero value, the tokens that 
  13781. immediately follow the condition are passed on to the compiler. 
  13782.  
  13783. If the expression evaluates to zero and the conditional compilation directive 
  13784. contains a preprocessor #elif directive, the source text located between the 
  13785. #elif and the next #elif or preprocessor #else directive is selected by the 
  13786. preprocessor to be passed on to the compiler. The #elif directive cannot appear 
  13787. after the preprocessor #else directive. 
  13788.  
  13789. All macros are expanded, any defined() expressions are processed and all 
  13790. remaining identifiers are replaced with the token 0. 
  13791.  
  13792.                    ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13793.                             Γöé
  13794. >>ΓöÇΓöÇ#ΓöÇΓöÇΓö¼ΓöÇifΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇconstant_expressionΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  13795.     ΓööΓöÇelifΓöÇΓöÿ
  13796.  
  13797. The expressions that are tested must be integer constant expressions with the 
  13798. following properties: 
  13799.  
  13800.      No casts are performed. 
  13801.      Arithmetic is performed using long int values. 
  13802.      The expression can contain defined macros. No other identifiers can 
  13803.       appear in the expression. 
  13804.      The constant expression can contain the unary operator defined. This 
  13805.       operator can be used only with the preprocessor keyword #if. The 
  13806.       following expressions evaluate to 1 if the identifier is defined in the 
  13807.       preprocessor, otherwise to 0: 
  13808.  
  13809.             defined identifier
  13810.             defined(identifier)
  13811.  
  13812.       For example: 
  13813.  
  13814.             #if defined(TEST1) || defined(TEST2)
  13815.  
  13816.  Note:  If a macro is not defined, a value of 0 (zero) is assigned to it. In 
  13817.  the following example, TEST must be a macro identifier: 
  13818.  
  13819.   #if TEST >= 1
  13820.     printf("i = %d\n", i);
  13821.     printf("array[i] = %d\n", array[i]);
  13822.   #elif TEST < 0
  13823.     printf("array subscript out of bounds \n");
  13824.   #endif
  13825.  
  13826.  Example of #if and #elif Directives 
  13827.  
  13828.  Related Information 
  13829.  
  13830.      Conditional Compilation Directives 
  13831.      #ifdef 
  13832.      #ifndef 
  13833.      #endif 
  13834.      Preprocessor Directives 
  13835.      if 
  13836.  
  13837.  
  13838. ΓòÉΓòÉΓòÉ <hidden> Examples of #if and #elif Directives ΓòÉΓòÉΓòÉ
  13839.  
  13840. /************************************************************************
  13841. *
  13842.  
  13843. The following example uses the #if and #elif directives to assign values to an 
  13844. array. 
  13845.  
  13846.                                     *
  13847. ************************************************************************/
  13848.  
  13849. #include <stdio.h>
  13850.  
  13851. int main(void)
  13852. {
  13853.   int i;
  13854.   char *arrayname = "realarray";
  13855.   int realarray[] = { 1, 2, 3 };
  13856.   int array1[] = { 4, 5, 6 };
  13857.   int array2[] = { 7, 8, 9 };
  13858.  
  13859. #if ( (defined(LEVEL1)) && (TEST > 1) )
  13860.   for (i = 0; i < 3; i++)
  13861.    realarray[i] = array1[i];
  13862.    arrayname = "array1";
  13863. #elif (defined(LEVEL2))
  13864.   for (i = 0; i < 3; i++)
  13865.    realarray[i] = array2[i];
  13866.    arrayname = "array2";
  13867. #endif
  13868.  
  13869.   printf("realarray[] now has the contents of %s[]\n", arrayname);
  13870.  
  13871.   /* Assuming only LEVEL2 is defined, the expected output is:
  13872.  
  13873.    realarray[] now has the contents of array2[] */
  13874.  
  13875. }
  13876.  
  13877.  
  13878. ΓòÉΓòÉΓòÉ 9.10.2. #ifdef ΓòÉΓòÉΓòÉ
  13879.  
  13880. The #ifdef directive checks for the existence of macro definitions. 
  13881.  
  13882. If the identifier specified is defined as a macro, the tokens that immediately 
  13883. follow the condition are passed on to the compiler. 
  13884.  
  13885. The preprocessor #ifdef directive has the form: 
  13886.  
  13887.              ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13888.                       Γöé
  13889. >>ΓöÇΓöÇ#ΓöÇΓöÇifdefΓöÇΓöÇidentifierΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  13890.  
  13891. The following example defines MAX_LEN to be 75 if EXTENDED is defined for the 
  13892. preprocessor. Otherwise, MAX_LEN is defined to be 50. 
  13893.  
  13894. #ifdef EXTENDED
  13895. #  define MAX_LEN 75
  13896. #else
  13897. #  define MAX_LEN 50
  13898. #endif
  13899.  
  13900. Related Information 
  13901.  
  13902.      Conditional Compilation Directives 
  13903.      #ifndef 
  13904.      #if, #elif 
  13905.      #else 
  13906.      #endif 
  13907.      Macro Definition and Expansion (#define) 
  13908.      Scope of Macro Names (#undef) 
  13909.      Preprocessor Directives 
  13910.  
  13911.  
  13912. ΓòÉΓòÉΓòÉ 9.10.3. #ifndef ΓòÉΓòÉΓòÉ
  13913.  
  13914. The #ifndef directive checks for the existence of macro definitions. 
  13915.  
  13916. If the identifier specified is not defined as a macro, the tokens that 
  13917. immediately follow the condition are passed on to the compiler. 
  13918.  
  13919. The preprocessor #ifndef directive has the form: 
  13920.  
  13921.               ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13922.                        Γöé
  13923. >>ΓöÇΓöÇ#ΓöÇΓöÇifndefΓöÇΓöÇidentifierΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  13924.  
  13925. An identifier must follow the #ifndef keyword. The following example defines 
  13926. MAX_LEN to be 50 if EXTENDED is not defined for the preprocessor. Otherwise, 
  13927. MAX_LEN is defined to be 75. 
  13928.  
  13929. #ifndef EXTENDED
  13930. #  define MAX_LEN 50
  13931. #else
  13932. #  define MAX_LEN 75
  13933. #endif
  13934.  
  13935. Related Information 
  13936.  
  13937.      Conditional Compilation Directives 
  13938.      #ifdef 
  13939.      #if, #elif 
  13940.      #else 
  13941.      #endif 
  13942.      Macro Definition and Expansion (#define) 
  13943.      Scope of Macro Names (#undef) 
  13944.      Preprocessor Directives 
  13945.  
  13946.  
  13947. ΓòÉΓòÉΓòÉ 9.10.4. #else ΓòÉΓòÉΓòÉ
  13948.  
  13949. If the condition specified in the #if, #ifdef, or #ifndef directive evaluates 
  13950. to 0, and the conditional compilation directive contains a preprocessor #else 
  13951. directive, the source text located between the preprocessor #else directive and 
  13952. the preprocessor #endif directive is selected by the preprocessor to be passed 
  13953. on to the compiler. 
  13954.  
  13955. The preprocessor #else directive has the form: 
  13956.  
  13957.        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13958.                 Γöé
  13959. >>ΓöÇΓöÇ#ΓöÇΓöÇelseΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  13960.  
  13961. The following example defines MAX_LEN to be 50 if EXTENDED is not defined for 
  13962. the preprocessor. Otherwise, MAX_LEN is defined to be 75. 
  13963.  
  13964. #ifndef EXTENDED
  13965. #  define MAX_LEN 50
  13966. #else
  13967. #  define MAX_LEN 75
  13968. #endif
  13969.  
  13970. Related Information 
  13971.  
  13972.      Conditional Compilation Directives 
  13973.      #if, #elif 
  13974.      #ifdef 
  13975.      #ifndef 
  13976.      #endif 
  13977.      Macro Definition and Expansion (#define) 
  13978.      Preprocessor Directives 
  13979.  
  13980.  
  13981. ΓòÉΓòÉΓòÉ 9.10.5. #endif ΓòÉΓòÉΓòÉ
  13982.  
  13983. The preprocessor #endif directive ends the conditional compilation directive. 
  13984.  
  13985. It has the form: 
  13986.  
  13987. >>ΓöÇΓöÇ#ΓöÇΓöÇendifΓöÇΓöÇ><
  13988.  
  13989. The following example shows preprocessor conditional compilation directives 
  13990. ended by the #endif directive. 
  13991.  
  13992. #if defined(LEVEL1)
  13993. #  define SIZEOF_INT 16
  13994. #  ifdef PHASE2
  13995. #   define MAX_PHASE 2
  13996. #  else
  13997. #   define MAX_PHASE 8
  13998. #  endif
  13999. #elif defined(LEVEL2)
  14000. #  define SIZEOF_INT 32
  14001. #  define MAX_PHASE 16
  14002. #endif
  14003.  
  14004. Related Information 
  14005.  
  14006.      Conditional Compilation Directives 
  14007.      #if, #elif 
  14008.      #ifdef 
  14009.      #ifndef 
  14010.      #else 
  14011.      Preprocessor Directives 
  14012.  
  14013.  
  14014. ΓòÉΓòÉΓòÉ <hidden> Examples of Conditional Compilation Directives ΓòÉΓòÉΓòÉ
  14015.  
  14016. /************************************************************************
  14017. *
  14018.  
  14019. The following example shows how you can nest preprocessor conditional 
  14020. compilation directives: 
  14021.  
  14022. #if defined(TARGET1)
  14023. #  define SIZEOF_INT 16
  14024. #  ifdef PHASE2
  14025. #    define MAX_PHASE 2
  14026. #  else
  14027. #    define MAX_PHASE 8
  14028. #  endif
  14029. #elif defined(TARGET2)
  14030. #  define SIZEOF_INT 32
  14031. #  define MAX_PHASE 16
  14032. #else
  14033. #  define SIZEOF_INT 32
  14034. #  define MAX_PHASE 32
  14035. #endif
  14036.  
  14037. The following program contains preprocessor conditional compilation directives: 
  14038.  
  14039.                                     *
  14040. ************************************************************************/
  14041.  
  14042. /**
  14043.  ** This example contains preprocessor
  14044.  ** conditional compilation directives.
  14045.  **/
  14046.  
  14047. #include <stdio.h>
  14048.  
  14049. int main(void)
  14050. {
  14051.   static int array[ ] = { 1, 2, 3, 4, 5 };
  14052.   int i;
  14053.  
  14054.   for (i = 0; i <= 4; i++)
  14055.   {
  14056.    array[i] *= 2;
  14057.  
  14058. #if TEST >= 1
  14059.   printf("i = %d\n", i);
  14060.   printf("array[i] = %d\n", array[i]);
  14061. #endif
  14062.  
  14063.   }
  14064.   return(0);
  14065. }
  14066.  
  14067.  
  14068. ΓòÉΓòÉΓòÉ 9.11. Line Control (#line) ΓòÉΓòÉΓòÉ
  14069.  
  14070. A preprocessor line control directive supplies line numbers for compiler 
  14071. messages. It causes the compiler to view the line number of the next source 
  14072. line as the specified number. 
  14073.  
  14074. A preprocessor #line directive has the form: 
  14075.  
  14076. >>ΓöÇΓöÇ#ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇdecimal_constantΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇ><
  14077.     ΓööΓöÇlineΓöÇΓöÿ  Γöé          ΓööΓöÇ"file_name"ΓöÇΓöÿ Γöé
  14078.          ΓööΓöÇcharactersΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  14079.  
  14080. In order for the compiler to produce meaningful references to line numbers in 
  14081. preprocessed source, the preprocessor inserts #line directives where necessary 
  14082. (for example, at the beginning and after the end of included text). 
  14083.  
  14084. A file name specification enclosed in double quotation marks can follow the 
  14085. line number. If you specify a file name, the compiler views the next line as 
  14086. part of the specified file. If you do not specify a file name, the compiler 
  14087. views the next line as part of the current source file. 
  14088.  
  14089. The token sequence on a #line directive is subject to macro replacement. After 
  14090. macro replacement, the resulting character sequence must consist of a decimal 
  14091. constant, optionally followed by a file name enclosed in double quotation 
  14092. marks. 
  14093.  
  14094. You can use #line control directives to make the compiler provide more 
  14095. meaningful error messages. 
  14096.  
  14097. Example of #line Directives 
  14098.  
  14099. Related Information 
  14100.  
  14101.      Preprocessor Directives 
  14102.      Decimal Constants 
  14103.  
  14104.  
  14105. ΓòÉΓòÉΓòÉ <hidden> Example of #line Directives ΓòÉΓòÉΓòÉ
  14106.  
  14107. /************************************************************************
  14108. *
  14109.  
  14110. The following program uses #line control directives to give each function an 
  14111. easily recognizable line number: 
  14112.  
  14113.                                     *
  14114. ************************************************************************/
  14115.  
  14116. /**
  14117.  ** This example illustrates #line directives.
  14118.  **/
  14119.  
  14120. #include <stdio.h>
  14121. #define LINE200 200
  14122.  
  14123. int main(void)
  14124. {
  14125.   func_1();
  14126.   func_2();
  14127. }
  14128.  
  14129. #line 100
  14130. func_1()
  14131. {
  14132.   printf("Func_1 - the current line number is %d\n",__LINE__);
  14133. }
  14134.  
  14135. #line LINE200
  14136. func_2()
  14137. {
  14138.   printf("Func_2 - the current line number is %d\n",__LINE__);
  14139. }
  14140.  
  14141. /************************************************************************
  14142. *
  14143.  
  14144. This program produces the following output: 
  14145.  
  14146. Func_1 - the current line number is 102
  14147. Func_2 - the current line number is 202
  14148.  
  14149.                                     *
  14150. ************************************************************************/
  14151.  
  14152.  
  14153. ΓòÉΓòÉΓòÉ 9.12. Null Directive (#) ΓòÉΓòÉΓòÉ
  14154.  
  14155. The null directive performs no action. It consists of a single # on a line of 
  14156. its own. 
  14157.  
  14158. The null directive should not be confused with the # operator or the character 
  14159. that starts a preprocessor directive. 
  14160.  
  14161. In the following example, if MINVAL is a defined macro name, no action is 
  14162. performed. If MINVAL is not a defined identifier, it is defined 1. 
  14163.  
  14164. #ifdef MINVAL
  14165.  #
  14166. #else
  14167.  #define MINVAL 1
  14168. #endif
  14169.  
  14170. Related Information 
  14171.  
  14172.      Preprocessor Directives 
  14173.      Null Statement 
  14174.  
  14175.  
  14176. ΓòÉΓòÉΓòÉ 9.13. Pragma Directives (#pragma) ΓòÉΓòÉΓòÉ
  14177.  
  14178. A pragma is an implementation-defined instruction to the compiler. It has the 
  14179. general form: 
  14180.  
  14181.         ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14182.                    Γöé
  14183. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇΓöÇΓöÇcharacter_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  14184.  
  14185. where character_sequence is a series of characters giving a specific compiler 
  14186. instruction and arguments, if any. 
  14187.  
  14188. The character_sequence on a pragma is subject to macro substitutions. For 
  14189. example, 
  14190.  
  14191. #define XX_ISO_DATA isolated_call(LG_ISO_DATA)
  14192. // ...
  14193. #pragma XX_ISO_DATA
  14194.  
  14195. More than one pragma construct can be specified on a single #pragma directive. 
  14196. The compiler ignores unrecognized pragmas. 
  14197.  
  14198. The VisualAge for C++ compiler recognizes the following pragmas: 
  14199.  
  14200.  alloc_text        Groups functions into separate 32-bit code sections. 
  14201.  
  14202.  chars             Sets the sign type of character data. 
  14203.  
  14204.  comment           Places a comment into the object file. 
  14205.  
  14206.  data_seg          Places static and external variables in different 32-bit 
  14207.                    data sections. 
  14208.  
  14209.  define            Forces the definition of a template class without actually 
  14210.                    defining an object of the class. This directive is valid for 
  14211.                    C++ programs only. 
  14212.  
  14213.  disjoint          Lists the identifiers that are not aliased to each other 
  14214.                    within the scope of their use. 
  14215.  
  14216.  entry             Specifies the function to be used as the entry point for the 
  14217.                    application being built. 
  14218.  
  14219.  export            Declares that a DLL function is to be exported and specifies 
  14220.                    the name of the function outside the DLL. 
  14221.  
  14222.  handler           Registers an exception handler for a function. 
  14223.  
  14224.  hdrfile           Specifies the filename of the precompiled header to be 
  14225.                    generated and/or used. 
  14226.  
  14227.  hdrstop           Manually terminates the initial sequence of #include 
  14228.                    directives being considered for precompilation. 
  14229.  
  14230.  implementation    Tells the compiler the name of the file that contains the 
  14231.                    function template definitions corresponding to the template 
  14232.                    declarations in the include file containing the pragma. This 
  14233.                    directive is valid for C++ programs only. 
  14234.  
  14235.  info              Controls the diagnostic messages generated by the /Wgroup 
  14236.                    compiler options. 
  14237.  
  14238.  isolated_call     Lists functions that do not alter data objects visible at 
  14239.                    the time of the function call. 
  14240.  
  14241.  langlvl           Selects the C or C++ language level for compilation. 
  14242.  
  14243.  library           Instructs the linker to pull in the appropriate libraries at 
  14244.                    link time. 
  14245.  
  14246.  linkage           Identifies the linkage or calling convention used on a 
  14247.                    function call. This directive is valid for C programs only. 
  14248.  
  14249.  map               Tells the compiler that all references to an identifier are 
  14250.                    to be converted to a new name. 
  14251.  
  14252.  margins           Specifies the columns in the input line that are to be 
  14253.                    scanned for input to the compiler. This directive is valid 
  14254.                    for C programs only. 
  14255.  
  14256.  pack              Specifies the alignment rules to use for the structures, 
  14257.                    unions, and classes that follow it. 
  14258.  
  14259.  page              Skips pages of the generated source listing. 
  14260.  
  14261.  pagesize          Sets the number of lines per page for the generated source 
  14262.                    listing. 
  14263.  
  14264.  priority          Specifies the order in which static objects are to be 
  14265.                    initialized at run time. This directive is valid for C++ 
  14266.                    programs only. 
  14267.  
  14268.  sequence          Defines the section of the input line that is to contain 
  14269.                    sequence numbers. 
  14270.  
  14271.  skip              Skips lines of the generated source listing. 
  14272.  
  14273.  sourcedir         Defines a new path to the directory containing the original 
  14274.                    source of an include file. This directive is valid for C++ 
  14275.                    programs only. 
  14276.  
  14277.  strings           Sets storage type for strings. 
  14278.  
  14279.  subtitle          Places text on generated source listings. 
  14280.  
  14281.  title             Places text on generated source listings. 
  14282.  
  14283.  undeclared        Used by the compiler to mark template functions that were 
  14284.                    called but never declared. This directive is valid for C++ 
  14285.                    programs only. 
  14286.  
  14287.  weak              Adds an alternate function name with weak binding for the 
  14288.                    specified function. 
  14289.  
  14290.  The following #pragma directives must appear before any statements in the C 
  14291.  source code: 
  14292.  
  14293.      chars 
  14294.      langlvl 
  14295.      strings 
  14296.  
  14297.  The other #pragma directives can be used throughout your program to affect a 
  14298.  selected block of source code. 
  14299.  
  14300.  The following VisualAge for C++ for OS/2 pragmas are not supported by IBM 
  14301.  VisualAge for C++ for Windows: 
  14302.  
  14303.      checkout 
  14304.      import 
  14305.      stack16 
  14306.      seg16 
  14307.      linkage with the following subspecifiers: 
  14308.         -  far16 cdecl 
  14309.         -  far16 fastcall 
  14310.         -  far16 pascal 
  14311.         -  pascal 
  14312.  
  14313.  A warning is issued if any of these pragmas are used. 
  14314.  
  14315.  The following Microsoft Visual C++ #pragma directives are not supported by 
  14316.  VisualAge for C++: 
  14317.  
  14318.      function 
  14319.      intrinsic 
  14320.      inline_depth 
  14321.      warning 
  14322.  
  14323.  Related Information 
  14324.  
  14325.      Restrictions on #pragma Directives 
  14326.      Preprocessor Directives 
  14327.  
  14328.  VisualAge for C++ also provides several pragmas to support the IBM System 
  14329.  Object Model (SOM), which provides a common programming interface for building 
  14330.  and using software objects. 
  14331.  
  14332.  SOM support for VisualAge for C++ and the SOM pragmas are described in the IBM 
  14333.  VisualAge for C++ for Windows User's Guide. 
  14334.  
  14335.  
  14336. ΓòÉΓòÉΓòÉ 9.13.1. Restrictions on #pragma Directives ΓòÉΓòÉΓòÉ
  14337.  
  14338. Some #pragma directives must appear in a certain place in your source, or can 
  14339. appear a limited number of times. The following table lists the restrictions 
  14340. for #pragma directives. 
  14341.  
  14342. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14343. Γöé #PRAGMA  Γöé RESTRICTION OF PLACE-  Γöé RESTRICTION ON NUMBER OF OCCURRENCES   Γöé
  14344. Γöé      Γöé MENT          Γöé                      Γöé
  14345. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14346. Γöé "chars"  Γöé On the first #PRAGMA  Γöé Once                   Γöé
  14347. Γöé      Γöé directive, and before  Γöé                      Γöé
  14348. Γöé      Γöé any code or directive  Γöé                      Γöé
  14349. Γöé      Γöé (except "#line")    Γöé                      Γöé
  14350. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14351. Γöé "comment"Γöé "copyright" directive  Γöé "compiler" and "timestamp" directives   Γöé
  14352. Γöé      Γöé must appear before any Γöé can appear only once           Γöé
  14353. Γöé      Γöé code          Γöé                      Γöé
  14354. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14355. Γöé "entry"  Γöé No restriction     Γöé One per ".exe" or ".dll" If there is   Γöé
  14356. Γöé      Γöé             Γöé more than one, the result is undefined.  Γöé
  14357. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14358. Γöé "langlvl"Γöé On the first #PRAGMA  Γöé Once                   Γöé
  14359. Γöé      Γöé directive, and before  Γöé                      Γöé
  14360. Γöé      Γöé any code or directive  Γöé                      Γöé
  14361. Γöé      Γöé (except "#line")    Γöé                      Γöé
  14362. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14363. Γöé "linkage"Γöé Before any declaration Γöé Once for each function          Γöé
  14364. Γöé      Γöé of or call to the    Γöé                      Γöé
  14365. Γöé      Γöé function        Γöé                      Γöé
  14366. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14367. Γöé "strings"Γöé Before any code     Γöé Once                   Γöé
  14368. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  14369.  
  14370.  
  14371. ΓòÉΓòÉΓòÉ 9.13.2. alloc_text ΓòÉΓòÉΓòÉ
  14372.  
  14373. The #pragma alloc_text directive lets you group functions into different 32-bit 
  14374. code sections. 
  14375.  
  14376.                       ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14377.                              Γöé
  14378. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇalloc_textΓöÇΓöÇ(ΓöÇΓöÇcode_sectionΓöÇΓöÇΓöÇΓöÇ,ΓöÇΓöÇfunctionΓöÇΓö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  14379.  
  14380. The code_section is the name of the code segment where you want to place 
  14381. function. You can specify any number of functions to be included in the named 
  14382. code_section. 
  14383.  
  14384. Functions that are not grouped in a code section by #pragma alloc_text are 
  14385. placed in the default 32-bit code section CODE32, or whatever was specified on 
  14386. the /NT option. You can also use #pragma alloc_text to explicitly place 
  14387. functions in CODE32 by specifying it as the code_section. 
  14388.  
  14389. Defining your own code sections allows you to organize functions in memory so 
  14390. that the working set requires fewer pages of memory. You can also specify 
  14391. attributes for each section, such as execute-only or preload. Code section 
  14392. attributes are specified with the /SECTION and /CODE linker options. 
  14393.  
  14394. For example, the following creates two code sections, one load on call, the 
  14395. other preload: 
  14396.  
  14397.   #pragma alloc_text(pl_seg, func1)
  14398.   #pragma alloc_text(loc_seg, func2)
  14399.  
  14400. For more information on linker attributes and .DEF files, see the IBM VisualAge 
  14401. for C++ for Windows User's Guide. 
  14402.  
  14403. Related Information 
  14404.  
  14405.      data_seg 
  14406.      Pragma Directives (#pragma) 
  14407.      Preprocessor Directives 
  14408.  
  14409.  
  14410. ΓòÉΓòÉΓòÉ 9.13.3. chars ΓòÉΓòÉΓòÉ
  14411.  
  14412. The #pragma chars directive specifies that the compiler is to treat all char 
  14413. objects as signed or unsigned. 
  14414.  
  14415. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇcharsΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇunsignedΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14416.              ΓööΓöÇsignedΓöÇΓöÇΓöÇΓöÿ
  14417.  
  14418. This pragma must appear before any statements in a file. Once specified, it 
  14419. applies to the rest of the file and cannot be turned off. If a source file 
  14420. contains any functions that you want to be compiled without #pragma chars, 
  14421. place these functions in a different file. 
  14422.  
  14423. The default character type behaves like an unsigned char. 
  14424.  
  14425. Related Information 
  14426.  
  14427.      Characters 
  14428.      Pragma Directives (#pragma) 
  14429.      Preprocessor Directives 
  14430.  
  14431.  
  14432. ΓòÉΓòÉΓòÉ 9.13.4. comment ΓòÉΓòÉΓòÉ
  14433.  
  14434. The #pragma comment directive places a comment into the object file. 
  14435.  
  14436. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇcommentΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇcompilerΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14437.               Γö£ΓöÇdateΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14438.               Γö£ΓöÇtimestampΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14439.               Γö£ΓöÇΓö¼ΓöÇcopyrightΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöñ
  14440.               Γöé ΓööΓöÇuserΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ  ΓööΓöÇ,"token_sequence"ΓöÇΓöÿ Γöé
  14441.               ΓööΓöÇlibΓöÇΓöÇ,"<path_name>"ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  14442.  
  14443. The comment type can be: 
  14444.  
  14445.  compiler       The name and version of the compiler are appended to the end of 
  14446.                 the generated object module. 
  14447.  
  14448.  date           The date and time of compilation are appended to the end of the 
  14449.                 generated object module. 
  14450.  
  14451.  timestamp      The date and time of the last modification of the source is 
  14452.                 appended to the end of the generated object module. 
  14453.  
  14454.  copyright      The text specified by the token_sequence is placed by the 
  14455.                 compiler into the generated object module and is loaded into 
  14456.                 memory when the program is run. 
  14457.  
  14458.  user           The text specified by the token_sequence is placed by the 
  14459.                 compiler into the generated object but is not loaded into 
  14460.                 memory when the program is run. 
  14461.  
  14462.  lib            A library search record is place into the generated object 
  14463.                 module. Equivalent to #pragma library. 
  14464.  
  14465.  Related Information 
  14466.  
  14467.      Pragma Directives (#pragma) 
  14468.      Preprocessor Directives 
  14469.  
  14470.  
  14471. ΓòÉΓòÉΓòÉ 9.13.5. data_seg ΓòÉΓòÉΓòÉ
  14472.  
  14473. The #pragma data_seg directive lets you place static and external variables in 
  14474. different 32-bit data segments. 
  14475.  
  14476. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇdata_segΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14477.                Γö£ΓöÇdata_segmentΓöÇΓöÇΓöÇΓöñ  ΓööΓöÇ,ΓöÇΓöÇclassΓöÇΓöÿ
  14478.                ΓööΓöÇ"data_segment"ΓöÇΓöÿ
  14479.  
  14480. All static and external variables defined after the #pragma data_seg directive 
  14481. are placed in the named data_segment. The pragma is in effect until the next 
  14482. #pragma data_seg directive or the end of the compilation unit. 
  14483.  
  14484. Quotation marks around data_segment are optional and provided for compatibility 
  14485. with Microsoft Visual C++. 
  14486.  
  14487. Writable string literals used to initialize pointers are not placed in the 
  14488. named data_segment, but in the default 32-bit data segment (DATA32). To place a 
  14489. string in a particular data segment, use an array to initialize the string 
  14490. instead of a pointer. For example: 
  14491.  
  14492.   char a[ ] = "mystring";
  14493. instead of 
  14494.  
  14495.   char *a = "mystring";
  14496.  
  14497. Static and external variables defined before the first #pragma data_seg 
  14498. directive are placed in the default DATA32 segment, with the exception of 
  14499. uninitialized variables and variables explicitly initialized to zero, which are 
  14500. placed in the BSS32 segment. You can also use #pragma data_seg to explicitly 
  14501. place variables in the DATA32 segment by specifying no data_segment, for 
  14502. example, #pragma data_seg(). However, you cannot use the CONST32_RO or BSS32 
  14503. segments in a #pragma data_seg directive. 
  14504.  
  14505. Note:  Because the variables in the BSS32 data segment are initialized at load 
  14506. time and loaded separately from the rest of your program, they take less space 
  14507. in your executable file. If you place these variables in a different data 
  14508. segment, this optimization does not take place, and the size of your executable 
  14509. module increases. For this reason, if the size of your executable file is 
  14510. critical to you, you should define all variables initialized to zero (either 
  14511. explicitly or by default) before the first occurrence of #pragma data_seg. 
  14512.  
  14513. Defining your own data segments allows you to group data depending on how it is 
  14514. used and to specify different attributes for different groups of data, such as 
  14515. when the data should be loaded. Data section attributes are specified with the 
  14516. /SECTION and /DATA linker options. These are described in the IBM VisualAge for 
  14517. C++ for Windows User's Guide. 
  14518.  
  14519. For example, when you build a DLL, you might have one set of data that you want 
  14520. to make global for all processes that use the DLL, and a different set of data 
  14521. that you want to copy for each process. You could use #pragma data_seg to place 
  14522. the data in two different segments as follows: 
  14523.  
  14524.   #pragma data_seg(globdata)
  14525.  
  14526.   static int counter1 = 0;
  14527.   static int counter2 = 0;
  14528.   .
  14529.   .
  14530.   .
  14531.   #pragma data_seg(instdata)
  14532.  
  14533.   static int instcount1 = 0;
  14534.   static int instcount2 = 0;
  14535.   .
  14536.   .
  14537.   .
  14538.  
  14539. Related Information 
  14540.  
  14541.      alloc_text 
  14542.      Pragma Directives (#pragma) 
  14543.      Preprocessor Directives 
  14544.  
  14545.  
  14546. ΓòÉΓòÉΓòÉ 9.13.6. define ΓòÉΓòÉΓòÉ
  14547.  
  14548. The #pragma define directive forces the definition of a template class without 
  14549. actually defining an object of the class. 
  14550.  
  14551. C++ Note:  This directive is valid for C++ programs only. 
  14552.  
  14553. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇdefineΓöÇΓöÇ(ΓöÇΓöÇtemplate_class_nameΓöÇΓöÇ)ΓöÇΓöÇ><
  14554.  
  14555. The pragma can appear anywhere that a declaration is allowed. It is used when 
  14556. organizing your program for the efficient or automatic generation of template 
  14557. functions. "Using Templates in C++ Programs" in the IBM VisualAge for C++ for 
  14558. Windows Programming Guide gives more information about using #pragma define. 
  14559.  
  14560. Related Information 
  14561.  
  14562.      C++ Templates 
  14563.      Pragma Directives (#pragma) 
  14564.      Preprocessor Directives 
  14565.      "Using Templates in C++ Programs" in the IBM VisualAge for C++ for 
  14566.       Windows Programming Guide 
  14567.  
  14568.  
  14569. ΓòÉΓòÉΓòÉ 9.13.7. disjoint ΓòÉΓòÉΓòÉ
  14570.  
  14571. The #pragma disjoint directive lists the identifiers that are not aliased to 
  14572. each other within the scope of their use. This directive is valid for C 
  14573. programs only. 
  14574.  
  14575.               ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14576.                  Γöé          Γöé
  14577. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇdisjointΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  14578.                ΓööΓöÇ*ΓöÇΓöÿ   ΓööΓöÇidentifierΓöÇΓöÿ
  14579.  
  14580. where identifier is a primary expression that can be the name of an operator 
  14581. function, conversion function, destructor, or a qualified name. 
  14582.  
  14583. The directive informs the compiler that none of the identifiers listed shares 
  14584. the same physical storage, which provides more opportunity for optimizations. 
  14585. If any identifiers actually share physical storage, the pragma may give 
  14586. incorrect results. 
  14587.  
  14588. The pragma can appear anywhere in the source program that a declaration is 
  14589. allowed. An identifier in the directive must be visible at the point in the 
  14590. program where the pragma appears. The identifiers in the disjoint name list 
  14591. cannot refer to any of the following: 
  14592.  
  14593.      A member of a structure, or union 
  14594.      A structure, union, or enumeration tag 
  14595.      An enumeration constant 
  14596.      A typedef name 
  14597.      A label 
  14598.  
  14599.  The identifiers must be declared before they are used in the pragma. A pointer 
  14600.  in the identifier list must not have been dereferenced or used as a function 
  14601.  argument before appearing in the directive. 
  14602.  
  14603.  The following example shows the use of #pragma disjoint. 
  14604.  
  14605.   int a, b, *ptr_a, ptr_b;
  14606.   #pragma disjoint(*ptr_a, b)    // *ptr_a never points to b
  14607.   #pragma disjoint(*ptr_b, a)    // *ptr_b never points to a
  14608.   one_function()
  14609.   {
  14610.      b = 6;
  14611.      *ptr_a = 7;  // Assignment will not change the value of b
  14612.      another_function(b);    // Argument "b" has the value 6
  14613.   }
  14614.  
  14615.  Because external pointer ptr_a does not share storage with and never points to 
  14616.  the external variable b, the assignment of 7 to the object that ptr_a points 
  14617.  to will not change the value of b. Likewise, external pointer ptr_b does not 
  14618.  share storage with and never points to the external variable a. The compiler 
  14619.  can assume that the argument to another_function has the value 6 and will not 
  14620.  reload the variable from memory. 
  14621.  
  14622.  The ignprag compiler option causes aliasing pragmas to be ignored. Use this 
  14623.  option to debug applications containing the #pragma disjoint directive. 
  14624.  Compiler options are described in the IBM VisualAge for C++ for Windows User's 
  14625.  Guide. 
  14626.  
  14627.  Related Information 
  14628.  
  14629.      Pragma Directives (#pragma) 
  14630.      Preprocessor Directives 
  14631.  
  14632.  
  14633. ΓòÉΓòÉΓòÉ 9.13.8. entry ΓòÉΓòÉΓòÉ
  14634.  
  14635. The #pragma entry directive specifies the function to be used as the entry 
  14636. point for the application being built. 
  14637.  
  14638. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇentryΓöÇΓöÇ(ΓöÇΓöÇfunction_nameΓöÇΓöÇ)ΓöÇΓöÇ><
  14639.  
  14640. The function_name function must be in the same compilation unit as the #pragma 
  14641. entry directive, and must be a defined external function. 
  14642.  
  14643. Normally when an application is started, the Windows system calls the C library 
  14644. entry point. When you specify a different entry point using #pragma entry, the 
  14645. system calls that entry point and does not perform any C library initialization 
  14646. or termination. If you use #pragma entry, you must ensure that your executable 
  14647. file does not require library initialization or termination, or you must 
  14648. provide your own initialization and termination functions. 
  14649.  
  14650. Related Information 
  14651.  
  14652.      Pragma Directives (#pragma) 
  14653.      Preprocessor Directives 
  14654.  
  14655.  
  14656. ΓòÉΓòÉΓòÉ 9.13.9. export ΓòÉΓòÉΓòÉ
  14657.  
  14658. The #pragma export directive declares that a DLL function or variable is to be 
  14659. exported and specifies the name of the function or variable outside the DLL. 
  14660. #pragma export 
  14661.  
  14662. >>ΓöÇΓöÇ#-pragma-exportΓöÇΓöÇ(ΓöÇΓöÇidentifierΓöÇΓöÇ,ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ,ΓöÇΓöÇordinalΓöÇΓöÇΓöÇΓöÇΓöÇ>
  14663.                     ΓööΓöÇ"ΓöÇΓöÇexport_nameΓöÇΓöÇ"ΓöÇΓöÿ
  14664. >ΓöÇΓöÇ)ΓöÇΓöÇ><
  14665. NOTE:
  14666. (1)   The ordinal is optional in C++
  14667.  
  14668. The identifier is the name of the function or variable in the DLL. The 
  14669. export_name is the name for identifier outside of the DLL. If no export_name is 
  14670. specified, identifier is used. 
  14671.  
  14672. The export_name must be fully decorated according to the linkage convention 
  14673. that applies to it. 
  14674.  
  14675. The ordinal is the number of the identifier within the DLL. Import by ordinal 
  14676. number is only permitted using the Win32 API GetProcAddress. Refer to the Win32 
  14677. documentation for more information. Ordinal numbers for exports are described 
  14678. in more detail in the IBM VisualAge for C++ for Windows Programming Guide. 
  14679.  
  14680. For example, the statements: 
  14681.  
  14682.   int deborah(int);
  14683.   #pragma export(deborah, "?catherine", 4)
  14684.  
  14685. declare that the function deborah is to be exported, and can be imported by 
  14686. another module using the name ?catherine or the ordinal number 4. Note that 
  14687. ?catherine is decorated according to the default linkage convention, _Optlink. 
  14688. See #pragma import for information on importing functions and variables. 
  14689.  
  14690. You can also use the _Export keyword to export a function. If you use the 
  14691. keyword, you cannot specify a different name or an ordinal for the exported 
  14692. function. 
  14693.  
  14694. If you use #pragma export to export your function, you may still need to 
  14695. provide an EXPORTS entry for that function in your module definition (.DEF) 
  14696. file. If your function has any of the following default characteristics 
  14697.  
  14698.      Has shared data 
  14699.      Has no I/O privileges 
  14700.      Is not resident 
  14701.  
  14702.  it does not require an EXPORTS entry. If your function has characteristics 
  14703.  other than the defaults, the only way you can specify them is with an EXPORTS 
  14704.  entry in your .DEF file. 
  14705.  
  14706.  Note:  To create an import library for the DLL, and you are not passing 
  14707.  objects to ILIB, you must provide a .DEF file with an EXPORTS entry for every 
  14708.  function. You can create the .DEF file from the DLL itself. The description of 
  14709.  ILIB in the IBM VisualAge for C++ for Windows User's Guide describes how to do 
  14710.  this. 
  14711.  
  14712.  No .DEF file is needed if you use _Export on all exports and the object files 
  14713.  are passed to the ILIB program. 
  14714.  
  14715.  For more information on DLLs and .DEF files, see the IBM VisualAge for C++ for 
  14716.  Windows Programming Guide. 
  14717.  
  14718.  Related Information 
  14719.  
  14720.      #pragma import 
  14721.      _Export Keyword 
  14722.      Pragma Directives (#pragma) 
  14723.      Preprocessor Directives 
  14724.  
  14725.  
  14726. ΓòÉΓòÉΓòÉ 9.13.10. handler ΓòÉΓòÉΓòÉ
  14727.  
  14728. The #pragma handler directive registers an exception handler for a function. 
  14729.  
  14730. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇhandlerΓöÇΓöÇ(ΓöÇΓöÇfunctionΓöÇΓöÇ)ΓöÇΓöÇ><
  14731.  
  14732. The function is the name of the function for which the exception handler is to 
  14733. be registered. You should declare it before you use it in this directive. 
  14734.  
  14735. The #pragma handler directive generates the code at compile time to install the 
  14736. VisualAge for C++ exception handler _Exception before starting execution of the 
  14737. function. It also generates code to remove the exception handler at function 
  14738. exit. 
  14739.  
  14740. You must use this directive whenever you change library environments or enter a 
  14741. user-created DLL. 
  14742.  
  14743. Note:  If you are using the subsystem libraries, the _Exception function is not 
  14744. provided. To use the #pragma handler directive in a subsystem, you must provide 
  14745. your own exception handler named _Exception. Your exception hander must have 
  14746. __cdecl linkage. 
  14747.  
  14748. For more information on exception handling and _Exception, see the IBM 
  14749. VisualAge for C++ for Windows Programming Guide. 
  14750.  
  14751. Related Information 
  14752.  
  14753.      Pragma Directives (#pragma) 
  14754.      Preprocessor Directives 
  14755.  
  14756.  
  14757. ΓòÉΓòÉΓòÉ 9.13.11. hdrfile ΓòÉΓòÉΓòÉ
  14758.  
  14759. The #pragma hdrfile directive specifies the file name of the precompiled header 
  14760. to be generated and/or used. 
  14761.  
  14762. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇhdrfileΓöÇΓöÇ"file_name"ΓöÇΓöÇ><
  14763.  
  14764. It must appear before the first #include directive and either the /Fi option or 
  14765. the /Si option is specified. The /Si and /Fi options allow more than one 
  14766. precompiled header to be use for a single application. 
  14767.  
  14768. If a file name is specified both on the command line and on #pragma hdrfile, 
  14769. the name specified on the pragma takes precedence. If the name specified is a 
  14770. directory, the compiler searches for or generates a file with the default name 
  14771. in that directory. 
  14772.  
  14773. In order to maximize the reuse of precompiled headers, the use #pragma hdrfile 
  14774. in combination with #pragma hdrstop to manually limit the initial sequence of 
  14775. #include directives. 
  14776.  
  14777. Use precompiled header files to decrease compile time. Using precompiled 
  14778. headers will not improve compile time performance in most applications without 
  14779. some organization of the headers included by each source file. 
  14780.  
  14781. The IBM VisualAge for C++ for Windows Programming Guide describes how to 
  14782. structure your files so the compiler can take full advantage of the precompiled 
  14783. headers. 
  14784.  
  14785. Examples of #pragma hdrfile Directives 
  14786.  
  14787. Related Information 
  14788.  
  14789.      Precompiled header files 
  14790.      Pragma Directives (#pragma) 
  14791.      Preprocessor Directives 
  14792.  
  14793.  
  14794. ΓòÉΓòÉΓòÉ <hidden> Examples of #pragma hdrfile Directives ΓòÉΓòÉΓòÉ
  14795.  
  14796. /************************************************************************
  14797. *
  14798.  
  14799. In the following example, the headers h1.h and h2.h are precompiled using the 
  14800. file fred.pch (provided /Si or /Fi are specified). If /Fidave.pch is specified 
  14801. alone, the compiler looks for the precompiled headers in fred.pch but will not 
  14802. generate new headers. 
  14803.  
  14804.                                     *
  14805. ************************************************************************/
  14806.  
  14807.    #pragma hdrfile "fred.pch"
  14808.   #include "h1.h"
  14809.   #include "h2.h"
  14810.   main () {}
  14811.  
  14812. /************************************************************************
  14813. *
  14814.  
  14815. In the following example, only the header h1.h will be precompiled using the 
  14816. file fred.pch (provided /Si or /Fi are specified). If /Sidave.pch is specified 
  14817. alone, the compiler looks for the precompiled headers in fred.pch but will not 
  14818. generate new headers. 
  14819.  
  14820.                                     *
  14821. ************************************************************************/
  14822.  
  14823.    #pragma hdrfile "fred.pch"
  14824.   #include "h1.h"
  14825.   #pragma hdrstop
  14826.   #include "h2.h"
  14827.   main () {}
  14828.  
  14829.  
  14830. ΓòÉΓòÉΓòÉ 9.13.12. hdrstop ΓòÉΓòÉΓòÉ
  14831.  
  14832. The #pragma hdrstop directive manually terminates the initial sequence of 
  14833. #include directives being considered for precompilation. 
  14834.  
  14835. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇhdrstopΓöÇΓöÇ><
  14836.  
  14837. It has no effect if: 
  14838.  
  14839.      The initial sequence of #include directives has already ended 
  14840.      Neither the /Fi option nor the /Si option is specified 
  14841.      It does not appear in the primary source file 
  14842.  
  14843.  Use precompiled header files to decrease compile time. Using precompiled 
  14844.  headers will not improve compile time performance in most applications without 
  14845.  some organization of the headers included by each source file. 
  14846.  
  14847.  The IBM VisualAge for C++ for Windows User's Guide describes how to structure 
  14848.  your files so the compiler can take full advantage of the precompiled headers. 
  14849.  
  14850.  Examples of #pragma hdrstop Directives 
  14851.  
  14852.  Related Information 
  14853.  
  14854.      Precompiled header files 
  14855.      Pragma Directives (#pragma) 
  14856.      Preprocessor Directives 
  14857.  
  14858.  
  14859. ΓòÉΓòÉΓòÉ <hidden> Examples of #pragma hdrstop Directives ΓòÉΓòÉΓòÉ
  14860.  
  14861. /************************************************************************
  14862. *
  14863.  
  14864. In the following example, only the header h1.h will be precompiled using the 
  14865. file default.pch (provided /Si or /Fi are specified). If /Sidave.pch 
  14866. /Fijohn.pch are specified, the compiler will look for the precompiled headers 
  14867. in john.pch and will regenerate them if they are not found or not usable. 
  14868.  
  14869.                                     *
  14870. ************************************************************************/
  14871.  
  14872.    #include "h1.h"
  14873.   #pragma hdrstop
  14874.   #include "h2.h"
  14875.   main () {}
  14876.  
  14877. /************************************************************************
  14878. *
  14879.  
  14880. In the following example, no precompiled headers will be generated or used for 
  14881. the compilation, even if /Fi or /Si are specified. 
  14882.  
  14883.                                     *
  14884. ************************************************************************/
  14885.  
  14886.    #pragma hdrstop
  14887.   #include "h1.h"
  14888.   #include "h2.h"
  14889.   main () {}
  14890.  
  14891.  
  14892. ΓòÉΓòÉΓòÉ 9.13.13. implementation ΓòÉΓòÉΓòÉ
  14893.  
  14894. The #pragma implementation directive tells the compiler the name of the file 
  14895. containing the function-template definitions that correspond to the template 
  14896. declarations in the include file which contains the pragma. 
  14897.  
  14898. C++ Note:  This directive is valid for C++ programs only. 
  14899.  
  14900. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇimplementationΓöÇΓöÇ(ΓöÇΓöÇstring_literalΓöÇΓöÇ)ΓöÇΓöÇ><
  14901.  
  14902. This pragma can appear anywhere that a declaration is allowed. It is used when 
  14903. organizing your program for the efficient or automatic generation of template 
  14904. functions. "Using Templates in C++ Programs" in the IBM VisualAge for C++ for 
  14905. Windows Programming Guide gives more information about using #pragma 
  14906. implementation. 
  14907.  
  14908. Related Information 
  14909.  
  14910.      C++ Templates 
  14911.      Pragma Directives (#pragma) 
  14912.      Preprocessor Directives 
  14913.      "Using Templates in C++ Programs" in the IBM VisualAge for C++ for 
  14914.       Windows Programming Guide 
  14915.  
  14916.  
  14917. ΓòÉΓòÉΓòÉ 9.13.14. import ΓòÉΓòÉΓòÉ
  14918.  
  14919. Note:  The #pragma import directive is not supported in IBM VisualAge for C++ 
  14920. for Windows. The compiler accepts the directive, but issues a warning to use 
  14921. the _Import keyword or the __declspec(dllimport) keyword instead. 
  14922.  
  14923. The VisualAge for C++ linker does not recognize #pragma import; you must supply 
  14924. an import library. 
  14925.  
  14926. For more information on DLLs and importing functions see the IBM VisualAge for 
  14927. C++ for Windows Programming Guide. 
  14928.  
  14929. Related Information 
  14930.  
  14931.      export 
  14932.      _Export Keyword 
  14933.      _Import Keyword 
  14934.      Pragma Directives (#pragma) 
  14935.      Preprocessor Directives 
  14936.  
  14937.  
  14938. ΓòÉΓòÉΓòÉ 9.13.15. info ΓòÉΓòÉΓòÉ
  14939.  
  14940. The #pragma info directive controls the diagnostic messages generated by the 
  14941. /Wgroup compiler options. 
  14942.  
  14943. C++ Note:  This directive is valid for C++ programs only. 
  14944.  
  14945. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇinfoΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇallΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14946.             Γö£ΓöÇnoneΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14947.             Γö£ΓöÇrestoreΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14948.             Γöé ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  14949.             Γöé       Γöé Γöé
  14950.             ΓööΓöÇΓöÇΓö¼ΓöÇgroupΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÿ
  14951.               ΓööΓöÇnogroupΓöÇΓöÿ
  14952.  
  14953. The #pragma info directive replaces the #pragma checkout directive for 
  14954. controlling diagnostics. Specifying #pragma info(group) causes all messages 
  14955. associated with that diagnostic group to be generated. Specifying #pragma 
  14956. info(nogroup) suppresses all messages associated with that group. 
  14957.  
  14958. For example, to generate messages for missing function prototypes and 
  14959. statements with no effect, but not for uninitialized variables, specify: 
  14960.  
  14961.   #pragma info(pro, eff, nouni)
  14962.  
  14963. The #pragma directive overrides any /Wgroup options stated on the command line. 
  14964.  
  14965. Use #pragma info(all) to turn on all diagnostic checking. Use #pragma 
  14966. info(none) to turn off all diagnostic suboptions for specific portions of your 
  14967. program. Specifying #pragma info(restore) restores the options that were in 
  14968. effect before the previous #pragma info directive. 
  14969.  
  14970. Because #pragma info operates like a stack, the options restored may not be 
  14971. those given on the command line. If no options were previously in effect, 
  14972. #pragma info(restore) does nothing. 
  14973.  
  14974. The following list explains the groups of diagnostic messages controlled by 
  14975. each group option: 
  14976.  
  14977.  Group   Diagnostics 
  14978.  cmp     Possible redundancies in unsigned comparisons. 
  14979.  cnd     Possible redundancies or problems in conditional expressions. 
  14980.  cns     Operations involving constants. 
  14981.  cnv     Conversions. 
  14982.  dcl     Consistency of declarations. 
  14983.  eff     Statements with no effect. 
  14984.  enu     Consistency of enum variables. 
  14985.  ext     Unused external definitions. 
  14986.  gen     General diagnostics. 
  14987.  got     Usage of goto statements. 
  14988.  ini     Possible problems with initialization. 
  14989.  lan     Effects of the language level. 
  14990.  obs     Features that are obsolete. 
  14991.  ord     Unspecified order of evaluation. 
  14992.  par     Unused parameters. 
  14993.  por     Nonportable language constructs. 
  14994.  ppc     Possible problems with using the preprocessor. 
  14995.  ppt     Trace of preprocessor actions. 
  14996.  pro     Missing function prototypes. 
  14997.  rea     Code that cannot be reached. 
  14998.  ret     Consistency of return statements. 
  14999.  trd     Possible truncation or loss of data or precision. 
  15000.  tru     Variable names truncated by the compiler. 
  15001.  uni     Uninitialized variables. 
  15002.  use     Unused auto and static variables. 
  15003.  
  15004.  The /Wgroup options are described in the IBM VisualAge for C++ for Windows 
  15005.  User's Guide. 
  15006.  
  15007.  Related Information 
  15008.  
  15009.      Pragma Directives (#pragma) 
  15010.      Preprocessor Directives 
  15011.  
  15012.  
  15013. ΓòÉΓòÉΓòÉ 9.13.16. isolated_call ΓòÉΓòÉΓòÉ
  15014.  
  15015. The #pragma isolated_call directive lists functions that do not alter data 
  15016. objects visible at the time of the function call. 
  15017.  
  15018. The #pragma isolated_call directive has the form: 
  15019.  
  15020.                  ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  15021.                         Γöé
  15022. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇisolated_callΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓöÇidentifierΓöÇΓö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  15023.  
  15024. where identifier is a primary expression that can be an identifier, operator 
  15025. function, conversion function, or qualified name. 
  15026.  
  15027. The pragma must appear before calls to the functions in the identifier list. 
  15028. The identifiers listed must be declared before they are used in the pragma. 
  15029. They must be of type function or a typedef of function. If a name refers to an 
  15030. overloaded function, all variants of that function declared before the pragma 
  15031. are marked as isolated calls. 
  15032.  
  15033. The pragma informs the compiler that none of the functions listed has side 
  15034. effects. For example: 
  15035.  
  15036.      Accessing a volatile object 
  15037.      Modifying an external object 
  15038.      Modifying a file 
  15039.  
  15040.  or calling a function that does any of the above can be considered side 
  15041.  effects. 
  15042.  
  15043.  Essentially, any change in the state of the runtime environment is considered 
  15044.  a side effect. Passing function arguments by reference is one side effect that 
  15045.  is allowed, but in general, functions with side effects can give incorrect 
  15046.  results when listed in #pragma isolated_call directives. 
  15047.  
  15048.  Marking a function as isolated indicates to the optimizer that external and 
  15049.  static variables cannot be changed by the called function and that references 
  15050.  to storage can be deleted from the calling function where appropriate. 
  15051.  Instructions can be reordered with more freedom, resulting in fewer pipeline 
  15052.  delays and faster execution in the processor. 
  15053.  
  15054.  Note:  Instruction reordering might yield code with more values in 
  15055.  general-purpose and/or floating-point registers maintained across the isolated 
  15056.  call. 
  15057.  
  15058.  When the isolated call is not located in a loop, the overhead of saving and 
  15059.  restoring extra registers might not be worth the savings that result from 
  15060.  deleting the storage references. 
  15061.  
  15062.  Functions specified in the identifier list are permitted to examine external 
  15063.  objects and return results that depend on the state of the runtime 
  15064.  environment. The functions can also modify the storage pointed to by any 
  15065.  pointer arguments passed to the function, that is, calls by reference. Do not 
  15066.  specify a function that calls itself or relies on local static storage. 
  15067.  Listing such functions in the #pragma isolated_call directive can give 
  15068.  unpredictable results. 
  15069.  
  15070.  The following example shows the use of the #pragma isolated_call directive. 
  15071.  Because the function this_function does not have side effects, a call to it 
  15072.  will not change the value of the external variable a. The compiler can assume 
  15073.  that the argument to other_function has the value 6 and will not reload the 
  15074.  variable from memory. 
  15075.  
  15076.   int a, this_function(int);  // Assumed to have no side effects
  15077.   #pragma isolated_call(this_function)
  15078.   that_function()
  15079.   {
  15080.      a = 6;
  15081.      this_function(7);    // Call does not change the value of "a"
  15082.      other_function(a);   // Argument "a" has the value 6
  15083.   }
  15084.  
  15085.  The isolated_call compiler option has the same effect as this pragma. The 
  15086.  ignprag compiler option causes aliasing pragmas to be ignored. Use this option 
  15087.  to debug applications containing the #pragma isolated_call directive. Compiler 
  15088.  options are described in the IBM VisualAge for C++ for Windows User's Guide. 
  15089.  
  15090.  Related Information 
  15091.  
  15092.      Functions 
  15093.      Pragma Directives (#pragma) 
  15094.      Preprocessor Directives 
  15095.  
  15096.  
  15097. ΓòÉΓòÉΓòÉ 9.13.17. langlvl ΓòÉΓòÉΓòÉ
  15098.  
  15099. The #pragma langlvl directive lets you select elements of VisualAge for C++ 
  15100. implementation. 
  15101.  
  15102.                ΓöîΓöÇextendedΓöÇΓöÉ
  15103. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇlanglvlΓöÇΓöÇ(ΓöÇΓöÇΓö╝ΓöÇansiΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇ)ΓöÇΓöÇ><
  15104.                Γö£ΓöÇcompatΓöÇΓöÇΓöÇΓöñ
  15105.                Γö£ΓöÇsaaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15106.                ΓööΓöÇsaal2ΓöÇΓöÇΓöÇΓöÇΓöÿ
  15107.  
  15108. This directive can be specified only once in your source file, and must appear 
  15109. before any C or C++ code. 
  15110.  
  15111. The compiler defines preprocessor variables that are used in header files to 
  15112. define the language level. The options are: 
  15113.  
  15114.  extended    Defines the preprocessor variable __EXTENDED__. Allows ANSI and 
  15115.              SAA C constructs and all VisualAge for C++ extensions. 
  15116.  
  15117.  ansi        Defines the preprocessor variables __ANSI__ and __STDC__. Allows 
  15118.              only language constructs that conform to ANSI C standards. Note 
  15119.              that for C++, the __STDC__ macro is set to 0, while for C it is 
  15120.              set to 1. 
  15121.  
  15122.  compat      Defines the preprocessor variable __COMPAT__. Allows constructs 
  15123.              supported by earlier versions of the C++ language, as well as ANSI 
  15124.              constructs and VisualAge for C++ extensions. This language level 
  15125.              is valid for C++ programs only. 
  15126.  
  15127.  saa         Defines the preprocessor variables __SAA__ and __SAAL2__. Allows 
  15128.              only language constructs that conform to the most recent level of 
  15129.              SAA C standards (currently Level 2). These include ANSI C 
  15130.              constructs. This language level is valid for C programs only. 
  15131.  
  15132.  saal2       Defines the preprocessor variable __SAAL2__. Allows only language 
  15133.              constructs that conform to SAA Level 2 C standards. These include 
  15134.              ANSI C constructs. This language level is valid for C programs 
  15135.              only. 
  15136.  
  15137.  The default language level is extended. 
  15138.  
  15139.  You can also set the language level using the /Sa, /Sc, /S2, and /Se compiler 
  15140.  options. These options are described in /S options 
  15141.  
  15142.  Related Information 
  15143.  
  15144.      Predefined Macro Names 
  15145.      Pragma Directives (#pragma) 
  15146.      Preprocessor Directives 
  15147.  
  15148.  
  15149. ΓòÉΓòÉΓòÉ 9.13.18. library ΓòÉΓòÉΓòÉ
  15150.  
  15151. The #pragma library directive causes the compiler to insert an INCLUDELIB 
  15152. library search record into the object file. This tells the linker to pull in 
  15153. the appropriate libraries at link time. 
  15154.  
  15155. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇlibraryΓöÇΓöÇ(ΓöÇΓöÇ"library_name"ΓöÇΓöÇ)ΓöÇΓöÇ><
  15156.  
  15157. where library_name is the default library to be made available for the program. 
  15158.  
  15159. The library names specified by #pragma library are imbedded in INCLUDELIB 
  15160. library search records in the order that they are encountered in the source. 
  15161. The library search records are inserted into the object file before the default 
  15162. library search records, so that the behavior at link time is the same as if the 
  15163. library name were specified at link time. 
  15164.  
  15165. Related Information 
  15166.  
  15167.      Pragma Directives (#pragma) 
  15168.      Preprocessor Directives 
  15169.  
  15170.  
  15171. ΓòÉΓòÉΓòÉ 9.13.19. linkage ΓòÉΓòÉΓòÉ
  15172.  
  15173. The #pragma linkage directive identifies the linkage or calling convention used 
  15174. on a function call. 
  15175.  
  15176. This directive is valid for C programs only. 
  15177.  
  15178. Note:  The #pragma linkage directive is obsolete in VisualAge for C++. Do not 
  15179.        use it in new code. For your new applications, use linkage keywords to 
  15180.        specify the calling convention for a function. 
  15181.  
  15182. Linkage keywords are easier to use than the #pragma linkage directive, and they 
  15183. let you declare both the function and its linkage type in one statement. See 
  15184. Linkage Keywords for more information on these keywords. 
  15185.  
  15186.  
  15187. ΓòÉΓòÉΓòÉ 9.13.20. map ΓòÉΓòÉΓòÉ
  15188.  
  15189. The #pragma map directive tells the compiler that all references to an 
  15190. identifier are to be converted to "name". 
  15191.  
  15192. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇmapΓöÇΓöÇ>
  15193. >ΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ,ΓöÇΓöÇ"name"ΓöÇΓöÇ)ΓöÇΓöÇ><
  15194.    ΓööΓöÇfunc_or_op_identifierΓöÇΓöÇ(ΓöÇΓöÇargument_listΓöÇΓöÇ)ΓöÇΓöÿ
  15195.  
  15196.  identifier             A name of a data object or a nonoverloaded function 
  15197.                         with external linkage. 
  15198.  
  15199.  func_or_op_identifier  A name of a function or operator with internal linkage. 
  15200.                         The name can be qualified. 
  15201.  
  15202.  argument_list          A prototype list for the named function or operator. 
  15203.  
  15204.  name                   The external name that is to be bound to the given 
  15205.                         object, function or operator. 
  15206.  
  15207.  The directive can appear anywhere within a single compilation unit. It can 
  15208.  appear before any declaration or definition of the named object, function, or 
  15209.  operator. The identifiers appearing in the directive, including any type names 
  15210.  used in the prototype argument list, are resolved as though the directive had 
  15211.  appeared at file scope, independent of its actual point of occurrence. 
  15212.  
  15213.  For example: 
  15214.  
  15215.   int func(int);
  15216.  
  15217.   class X
  15218.   {
  15219.   public:
  15220.      void func(void);
  15221.   #pragma map(func, "funcname1")   // maps ::func
  15222.   #pragma map(X::func, "funcname2") // maps X::func
  15223.   };
  15224.  
  15225.  The name must be fully decorated according to the linkage convention that 
  15226.  applies to it. In the following example, the name func_alias is prefixed with 
  15227.  a ? character to indicate _Optlink linkage: 
  15228.  
  15229.   // File main.c - maps func to external name func_alias
  15230.   #pragma map(func, "?func_alias")  // "?" indicates _Optlink linkage
  15231.  
  15232.   void func(void);
  15233.  
  15234.   int main(void)
  15235.   {
  15236.    func();
  15237.    return 0;
  15238.   }
  15239.  
  15240.   // File func.c - defines func_alias
  15241.   #include<stdio.h>
  15242.  
  15243.   void func_alias(void)
  15244.   {
  15245.     printf("A simple example of #pragma map\n");
  15246.   }
  15247.  
  15248.  See the IBM VisualAge for C++ for Windows Programming Guide for more 
  15249.  information about using linkage keywords to specify the calling convention. 
  15250.  
  15251.  In C++, you should not use #pragma map to map the following: 
  15252.  
  15253.      C++ Member functions 
  15254.      Overloaded functions 
  15255.      Objects generated from templates 
  15256.      Functions with C++ or builtin linkage 
  15257.  
  15258.  Such mappings override the compiler-generated names, which could cause binder 
  15259.  errors. 
  15260.  
  15261.  Related Information 
  15262.  
  15263.      Pragma Directives (#pragma) 
  15264.      Preprocessor Directives 
  15265.  
  15266.  
  15267. ΓòÉΓòÉΓòÉ 9.13.21. margins ΓòÉΓòÉΓòÉ
  15268.  
  15269. The #pragma margins directive specifies the columns in the input line that are 
  15270. to be scanned for input to the compiler. 
  15271.  
  15272. Note:  This directive is valid for C programs only. 
  15273.  
  15274.          ΓöîΓöÇnomarginsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  15275. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇΓö┤ΓöÇmarginsΓöÇΓöÇ(ΓöÇΓöÇleftΓöÇΓöÇ,ΓöÇΓöÇrightΓöÇΓöÇ)ΓöÇΓö┤ΓöÇΓöÇ><
  15276.  
  15277. Use the #pragma margins directive if you want to have characters outside 
  15278. certain columns ignored in your source file. The compiler ignores any text in 
  15279. the source input that does not fall within the range specified in the 
  15280. directive. 
  15281.  
  15282. The variable left specifies the first column of the source input that is to be 
  15283. scanned, and must be between 1 and 65535, inclusive. The variable right 
  15284. specifies the last column of the source input that is to be scanned. It must be 
  15285. greater than or equal to left and less than or equal to 65535. An asterisk (*) 
  15286. can be assigned to right to indicate the last column of input. 
  15287.  
  15288. By default, the left margin is set to 1, and the right margin is set to 
  15289. infinity. The default for this directive is #pragma margins(), which has the 
  15290. effect of setting the right margin to infinity. 
  15291.  
  15292. The #pragma margins directive can be used with the #pragma sequence directive 
  15293. to specify the columns that are not to be scanned for sequence numbers. If the 
  15294. #pragma sequence settings do not fall within the #pragma margins settings, the 
  15295. #pragma sequence directive has no effect. 
  15296.  
  15297. You can also set margins using the /Sg option. 
  15298.  
  15299. Related Information 
  15300.  
  15301.      sequence 
  15302.      Pragma Directives (#pragma) 
  15303.      Preprocessor Directives 
  15304.  
  15305.  
  15306. ΓòÉΓòÉΓòÉ 9.13.22. pack ΓòÉΓòÉΓòÉ
  15307.  
  15308. The #pragma pack directive specifies the alignment rules to use for the 
  15309. structures, unions, and classes that follow it. In C++, packing is performed on 
  15310. declarations or types. This is different from C, where packing is also 
  15311. performed on definitions. 
  15312.  
  15313. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇpackΓöÇΓöÇ(ΓöÇΓöÇ>
  15314. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  15315.   Γö£ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöñ
  15316.   Γöé ΓööΓöÇΓö¼ΓöÇpushΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ Γöé
  15317.   Γöé  ΓööΓöÇpopΓöÇΓöÇΓöÿ  ΓööΓöÇ,ΓöÇΓöÇidentifierΓöÇΓöÿ  ΓööΓöÇ,ΓöÇΓöÇalignmentΓöÇΓöÿ  Γöé
  15318.   ΓööΓöÇalignmentΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  15319.  
  15320.  push      Stores the current boundary alignment value on the alignment stack. 
  15321.  
  15322.            If #pragma pack (push) appears first in a module, packing is 
  15323.            performed along the boundary specified by the /Sp compiler option, 
  15324.            or the system default alignment of 8 bytes if the /Sp option is not 
  15325.            set. 
  15326.  
  15327.  pop       Removes the current boundary alignment value from the alignment 
  15328.            stack and makes that value the new alignment. 
  15329.  
  15330.            Using pop on an empty stack causes a warning to be issued that the 
  15331.            current alignment may change. Packing is performed along the 
  15332.            boundary specified by the alignment value, if it has been specified. 
  15333.            If not, packing is performed along the boundary specified by the /Sp 
  15334.            compiler option, or the system default alignment of 8 bytes if the 
  15335.            /Sp option is not set. 
  15336.  
  15337.  identifier Associates a name with the new boundary alignment value. This value 
  15338.            can be pushed or popped from the alignment stack. 
  15339.  
  15340.            Using push with an identifier associates the identifier with a new 
  15341.            alignment value. 
  15342.  
  15343.            Using pop with an identifier pops all entries off the alignment 
  15344.            stack up to and including the entry associated with identifier. The 
  15345.            alignment value on the stack just before the entry associated with 
  15346.            identifier. becomes the new alignment. 
  15347.  
  15348.            If no matching identifier is on the stack, a warning is issued that 
  15349.            the current alignment may change. The stack is not affected. Packing 
  15350.            is performed along the boundary specified by the alignment value, if 
  15351.            it has been specified. If not, packing is performed along the 
  15352.            boundary specified by the /Sp compiler option, or the system default 
  15353.            alignment of 8 bytes if the /Sp option is not set. 
  15354.  
  15355.  alignment Is boundary alignment for packing in bytes. The alignment can be one 
  15356.            of 1, 2, 4, 8, or 16 bytes. 
  15357.  
  15358.            If no alignment is specified, packing is performed along the 
  15359.            boundary specified by the /Sp compiler option, or the system default 
  15360.            alignment of 8 bytes if the /Sp option is not set. 
  15361.  
  15362.            Using push with an alignment value causes that value to be the new 
  15363.            alignment. 
  15364.  
  15365.            Using pop with an alignment value pops a value off the stack and 
  15366.            sets the current alignment to alignment. 
  15367.  
  15368.  The #pragma pack directive causes all structures, unions and classes that 
  15369.  follow it in the program to be packed along a boundary specified in the 
  15370.  directive, until another #pragma pack directive changes the packing boundary. 
  15371.  
  15372.  If data types are by default packed along boundaries smaller than those 
  15373.  specified by #pragma pack, they are still aligned along the smaller 
  15374.  boundaries. For example, type char is always aligned along a 1-byte boundary, 
  15375.  regardless of the value of #pragma pack. 
  15376.  
  15377.  If more than one #pragma pack directive appears in a structure defined in an 
  15378.  inlined function, the #pragma pack directive effective at the beginning of the 
  15379.  structure takes precedence. 
  15380.  
  15381.  The following table summarizes how each data type is packed for the #pragma 
  15382.  pack alignment values: 
  15383.  
  15384.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  15385.   Γöé   DATA TYPE   Γöé      #PRAGMA PACK ALIGNMENT VALUE      Γöé
  15386.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15387.   Γöé         Γöé   1   Γöé   2   Γöé   4   Γöé   8   Γöé   16  Γöé
  15388.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15389.   Γöé CHAR       Γöé   1   Γöé   1   Γöé   1   Γöé   1   Γöé   1   Γöé
  15390.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15391.   Γöé SHORT      Γöé   1   Γöé   2   Γöé   2   Γöé   2   Γöé   2   Γöé
  15392.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15393.   Γöé pointer     Γöé   1   Γöé   2   Γöé   4   Γöé   4   Γöé   4   Γöé
  15394.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15395.   Γöé INT, LONG    Γöé   1   Γöé   2   Γöé   4   Γöé   4   Γöé   4   Γöé
  15396.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15397.   Γöé LONG LONG    Γöé   1   Γöé   2   Γöé   4   Γöé   8   Γöé   8   Γöé
  15398.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15399.   Γöé FLOAT, DOUBLE  Γöé   1   Γöé   2   Γöé   4   Γöé   8   Γöé   8   Γöé
  15400.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  15401.   Γöé LONG DOUBLE   Γöé   1   Γöé   2   Γöé   4   Γöé   8   Γöé   8   Γöé
  15402.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  15403.  
  15404.  For more information on the alignment of data types in structures, see the IBM 
  15405.  VisualAge for C++ for Windows Programming Guide. 
  15406.  
  15407.  For information on packing C structures, see _Packed Qualifier. 
  15408.  Examples 
  15409.  
  15410.  For example: 
  15411.  
  15412.     #pragma pack(1)
  15413.  
  15414.     struct hester{    /* this structure is packed */
  15415.      char philip;    /*   along 1-byte boundaries   */
  15416.      int mark;
  15417.     };
  15418.     .
  15419.     .
  15420.     .
  15421.     #pragma pack(2)
  15422.  
  15423.     struct jeff{     /* this structure is packed */
  15424.      float bill;     /*   along 2-byte boundaries   */
  15425.      int *chris;
  15426.     }
  15427.     .
  15428.     .
  15429.     .
  15430.     #pragma pack()
  15431.  
  15432.     struct dor{      /* this structure is packed  */
  15433.      double stephen;   /* along the default boundaries  */
  15434.      long alex;
  15435.     }
  15436.  
  15437.  The following example illustrates #pragma pack. In the example: 
  15438.  
  15439.  (n)       Is the current alignment 
  15440.  [n n ...] Is the status of alignment stack 
  15441.  {id}      Is the identifier associated with the previously listed packing 
  15442.            alignment 
  15443.  D         Is the default alignment for file (specified either by the /Sp 
  15444.            option, or be the system default.) 
  15445.  
  15446.   #pragma pack(1)
  15447.  
  15448.   struct T {  // (1) [D]
  15449.     char c;  // This struct is packed on 1 byte boundaries
  15450.     int i;  // sizeof(T) = 5 bytes.;
  15451.   };
  15452.  
  15453.   #pragma pack ( push ) // (1) [1 D]
  15454.  
  15455.   struct S {  // This struct is packed on 4 byte boundaries
  15456.     char c;  // Assume /Sp=4
  15457.     int i;  // sizeof(S) = 8 bytes.
  15458.   };
  15459.  
  15460.   #pragma pack ( push, 2 )  // (2) [1 1 D]
  15461.                // Packing: 2-byte boundary.
  15462.  
  15463.   #pragma pack ( push, level_1 ) // (2) [2{level_1} 1 1 D]
  15464.  
  15465.   #pragma pack ( push, level_2, 4 ) // (4) [2{level_2} 2{level_1} 1 1 D]
  15466.  
  15467.   #pragma pack ( push, level_3 ) // (4) [4{level_3} 2{level_2} 2{level_1} 1 1 D]
  15468.  
  15469.   #pragma pack ( 2 ) // (2) [4{level_3} 2{level_2} 2{level_1} 1 1 D]
  15470.  
  15471.   #pragma pack ( 1 ) // (1) [4{level_3} 2{level_2} 2{level_1} 1 1 D]
  15472.  
  15473.  Related Information 
  15474.  
  15475.      _Packed Qualifier 
  15476.      Structures 
  15477.      Type Specifiers 
  15478.      Pragma Directives (#pragma) 
  15479.      Preprocessor Directives 
  15480.  
  15481.  
  15482. ΓòÉΓòÉΓòÉ 9.13.23. page ΓòÉΓòÉΓòÉ
  15483.  
  15484. The #pragma page directive skips the number of pages specified by pages of the 
  15485. generated source listing. If pages is not specified, the next page is started. 
  15486.  
  15487. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇpageΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  15488.             ΓööΓöÇpagesΓöÇΓöÿ
  15489.  
  15490. Related Information 
  15491.  
  15492.      Pragma Directives (#pragma) 
  15493.      Preprocessor Directives 
  15494.  
  15495.  
  15496. ΓòÉΓòÉΓòÉ 9.13.24. pagesize ΓòÉΓòÉΓòÉ
  15497.  
  15498. The #pragma pagesize directive sets the number of lines per page to lines for 
  15499. the generated source listing. 
  15500.  
  15501. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇpagesizeΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  15502.                ΓööΓöÇlinesΓöÇΓöÿ
  15503.  
  15504. The value of lines must be between 16 and 32767, inclusive. The default page 
  15505. length is 66 lines. 
  15506.  
  15507. You can also use the /Lp compiler option to set the listing page size. 
  15508.  
  15509. Related Information 
  15510.  
  15511.      Pragma Directives (#pragma) 
  15512.      Preprocessor Directives 
  15513.  
  15514.  
  15515. ΓòÉΓòÉΓòÉ 9.13.25. priority ΓòÉΓòÉΓòÉ
  15516.  
  15517. The #pragma priority directive specifies the order in which static objects are 
  15518. to be initialized at run time. 
  15519.  
  15520. C++ Note:  This directive is valid for C++ programs only. 
  15521.  
  15522. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇpriorityΓöÇΓöÇ(ΓöÇΓöÇnΓöÇΓöÇ)ΓöÇΓöÇ><
  15523.  
  15524. Where n is an integer literal in the range of INT_MIN to INT_MAX. The default 
  15525. value is 0. A negative value indicates a higher priority; a positive value 
  15526. indicates a lower priority. 
  15527.  
  15528. The first 1024 priorities (INT_MIN to INT_MIN + 1023) are reserved for use by 
  15529. the compiler and its libraries. The priority value specified applies to all 
  15530. runtime static initialization in the current compilation unit. 
  15531.  
  15532. Any global object declared before another object in a file is constructed 
  15533. first. Use #pragma priority to specify the construction order of objects across 
  15534. files. 
  15535.  
  15536. To ensure that the objects are always constructed from top to bottom in a file, 
  15537. the compiler enforces the restriction that the priority specified all objects 
  15538. before and all objects after it until the next #pragma is at that priority. 
  15539.  
  15540. Related Information 
  15541.  
  15542.      Pragma Directives (#pragma) 
  15543.      Preprocessor Directives 
  15544.  
  15545.  
  15546. ΓòÉΓòÉΓòÉ 9.13.26. sequence ΓòÉΓòÉΓòÉ
  15547.  
  15548. The #pragma sequence directive defines the section of the input line that is to 
  15549. contain sequence numbers. 
  15550.  
  15551. Note:  This directive is valid for C programs only. 
  15552.  
  15553.          ΓöîΓöÇnosequenceΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  15554. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇΓö┤ΓöÇsequenceΓöÇΓöÇ(ΓöÇΓöÇleftΓöÇΓöÇ,ΓöÇΓöÇrightΓöÇΓöÇ)ΓöÇΓö┤ΓöÇΓöÇ><
  15555.  
  15556. If you are using a source file produced on a system that uses sequence numbers, 
  15557. you can use this option to have the sequence numbers ignored. 
  15558.  
  15559. The variable left specifies the column number of the left-hand margin. The 
  15560. value of left must be between 1 and 65535 inclusive, and must also be less than 
  15561. or equal to the value of right. The variable right specifies the column number 
  15562. of the right-hand margin. The value of right must be greater than or equal to 
  15563. left and less than or equal to 65535. An asterisk (*) can be assigned to right 
  15564. to indicate the last column of the line. 
  15565.  
  15566. The default for this directive is nosequence, which specifies there are no 
  15567. sequence numbers. 
  15568.  
  15569. The #pragma sequence directive can be used with the #pragma margins directive 
  15570. to specify the columns that are not to be scanned. If the #pragma sequence 
  15571. settings do not fall within the #pragma margins settings, the sequence 
  15572. directive has no effect. 
  15573.  
  15574. You can also set sequence numbers using the /Sq option. 
  15575.  
  15576. Related Information 
  15577.  
  15578.      margins 
  15579.      Pragma Directives (#pragma) 
  15580.      Preprocessor Directives 
  15581.  
  15582.  
  15583. ΓòÉΓòÉΓòÉ 9.13.27. skip ΓòÉΓòÉΓòÉ
  15584.  
  15585. The #pragma skip directive skips the specified number of lines of the generated 
  15586. source listing. The value of lines must be a positive integer less than 255. If 
  15587. lines is omitted, one line is skipped. 
  15588.  
  15589. Note:  This directive is valid for C programs only. 
  15590.  
  15591. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇskipΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  15592.             ΓööΓöÇlinesΓöÇΓöÿ
  15593.  
  15594. Related Information 
  15595.  
  15596.      Pragma Directives (#pragma) 
  15597.      Preprocessor Directives 
  15598.  
  15599.  
  15600. ΓòÉΓòÉΓòÉ 9.13.28. sourcedir ΓòÉΓòÉΓòÉ
  15601.  
  15602. The #pragma sourcedir directive defines a new path to the directory containing 
  15603. the original source from which the compiler generates files in the TEMPINC 
  15604. directory. 
  15605.  
  15606. C++ Note:  This directive is valid for C++ programs only. 
  15607.  
  15608. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇsourcedirΓöÇΓöÇ(ΓöÇΓöÇpathΓöÇΓöÇ)ΓöÇΓöÇ><
  15609.  
  15610. Instead of searching the TEMPINC directory first for the original source of the 
  15611. include file, the pragma directs the compiler to the directory specified by the 
  15612. supplied path. The compiler automatically inserts the necessary #pragma 
  15613. sourcedir directives into the source files it generates in the TEMPINC 
  15614. directory. 
  15615.  
  15616. Related Information 
  15617.  
  15618.      Pragma Directives (#pragma) 
  15619.      Preprocessor Directives 
  15620.  
  15621.  
  15622. ΓòÉΓòÉΓòÉ 9.13.29. strings ΓòÉΓòÉΓòÉ
  15623.  
  15624. The #pragma strings directive sets the storage type for strings. It specifies 
  15625. that the compiler can place strings into read-only memory or must place strings 
  15626. into read/write memory. 
  15627.  
  15628.               ΓöîΓöÇwriteableΓöÇΓöÉ
  15629. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇstringsΓöÇΓöÇ(ΓöÇΓöÇΓö┤ΓöÇreadonlyΓöÇΓöÇΓö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  15630.  
  15631. This pragma must appear before any C or C++ code in a file. 
  15632.  
  15633. Strings are readonly by default. 
  15634.  
  15635. Related Information 
  15636.  
  15637.      String Literals 
  15638.      Pragma Directives (#pragma) 
  15639.      Preprocessor Directives 
  15640.  
  15641.  
  15642. ΓòÉΓòÉΓòÉ 9.13.30. subtitle ΓòÉΓòÉΓòÉ
  15643.  
  15644. The #pragma subtitle directive places the text specified by subtitle on all 
  15645. subsequent pages of the generated source listing. 
  15646.  
  15647. Note:  This directive is valid for C programs only. 
  15648.  
  15649. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇsubtitleΓöÇΓöÇ(ΓöÇΓöÇ"subtitle"ΓöÇΓöÇ)ΓöÇΓöÇ><
  15650.  
  15651. The string subtitle must be less than 255 characters. 
  15652.  
  15653. You can also use the /Lu compiler option to specify the listing subtitle. 
  15654.  
  15655. Related Information 
  15656.  
  15657.      #pragma title 
  15658.      Pragma Directives (#pragma) 
  15659.      Preprocessor Directives 
  15660.  
  15661.  
  15662. ΓòÉΓòÉΓòÉ 9.13.31. title ΓòÉΓòÉΓòÉ
  15663.  
  15664. The #pragma title directive places the text specified by title on all 
  15665. subsequent pages of the generated source listing. 
  15666.  
  15667. Note:  This directive is valid for C programs only. 
  15668.  
  15669. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇtitleΓöÇΓöÇ(ΓöÇΓöÇ"title"ΓöÇΓöÇ)ΓöÇΓöÇ><
  15670.  
  15671. The string title must be less than 255 characters. 
  15672.  
  15673. You can also use the /Lt compiler option to specify the listing title. 
  15674.  
  15675. Related Information 
  15676.  
  15677.      #pragma subtitle 
  15678.      Pragma Directives (#pragma) 
  15679.      Preprocessor Directives 
  15680.  
  15681.  
  15682. ΓòÉΓòÉΓòÉ 9.13.32. undeclared ΓòÉΓòÉΓòÉ
  15683.  
  15684. The #pragma undeclared directive is used only by the compiler and only in 
  15685. template-include files. It is valid for C++ programs only. 
  15686.  
  15687. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇundeclaredΓöÇΓöÇ><
  15688.  
  15689. In the template-include file, template functions that were explicitly declared 
  15690. in at least one compilation unit appear before this line. Template functions 
  15691. that were called, but never declared, appear after this line. 
  15692.  
  15693. For more information on template-include files, see "Using Templates in C++ 
  15694. Programs" in the Programming Guide. 
  15695.  
  15696. Related Information 
  15697.  
  15698.      Pragma Directives (#pragma) 
  15699.      Preprocessor Directives 
  15700.  
  15701.  
  15702. ΓòÉΓòÉΓòÉ 9.13.33. weak ΓòÉΓòÉΓòÉ
  15703.  
  15704. The #pragma weak directive adds an alternate function name with weak binding 
  15705. for the function function_name. 
  15706.  
  15707. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇweakΓöÇΓöÇ(ΓöÇΓöÇfunction_nameΓöÇΓöÇ,ΓöÇΓöÇbackup_function_nameΓöÇΓöÇ)ΓöÇΓöÇ><
  15708.  
  15709. If the definition for the function function_name is not found, the linker 
  15710. resolves the function call to the definition for the function 
  15711. backup_function_name. If the definition for function_name is found, the linker 
  15712. resolves the function call to the definition for function_name. 
  15713.  
  15714. If function_name is not referenced, neither function_name nor 
  15715. backup_function_name needs to be declared. 
  15716.  
  15717. If function_name is referenced, both function_name and backup_function_name 
  15718. must be declared. 
  15719.  
  15720. Note:  Both functions must have full prototypes within the compilation unit. 
  15721. Neither function can be a C++ member function. 
  15722.  
  15723. In the following example, after the program is linked, the call to 
  15724. specialization resolves to the definition of generalization because no 
  15725. definition of specialization exists. 
  15726.  
  15727. #include <stdio.h>
  15728. int generalization(int i) {
  15729.  printf("in generalization\n");
  15730. }
  15731. #pragma weak (specialization, generalization)
  15732.  
  15733. int main() {
  15734.  printf("in main\n");
  15735.  return specialization(6);
  15736. }
  15737.  
  15738. Related Information 
  15739.  
  15740.      Pragma Directives (#pragma) 
  15741.      Preprocessor Directives 
  15742.  
  15743.  
  15744. ΓòÉΓòÉΓòÉ 10. C++ Classes ΓòÉΓòÉΓòÉ
  15745.  
  15746. A C++ class is a mechanism for creating user-defined data types. It is similar 
  15747. to the C-language structure data type. In C, a structure is composed of a set 
  15748. of data members. In C++, a class type is like a C structure, except that a 
  15749. class is composed of a set of data members and an optional set of operations 
  15750. that can be performed on the class. 
  15751.  
  15752. In C++, a class type can be declared with the keywords union, struct, or class. 
  15753. A union object can hold any one of a set of named members. Structure and class 
  15754. objects hold a complete set of members. Each class type represents a unique set 
  15755. of class members including data members, member functions, and other type 
  15756. names. The default access for members depends on the class key: 
  15757.  
  15758.      The members of a class declared with the class key class are private by 
  15759.       default. A class is inherited privately by default. 
  15760.      The members of a class declared with the class key struct are public be 
  15761.       default. A structure is inherited publicly by default. 
  15762.      The members of a union (declared with the class key union) are public by 
  15763.       default. A union cannot be used as a base class in derivation. Base 
  15764.       classes and derivation are described in C++ Inheritance. 
  15765.  
  15766.  Once you create a class type, you can declare one or more objects of that 
  15767.  class type. 
  15768.  
  15769.  For example: 
  15770.  
  15771.   class X
  15772.   { /* define class members here */ };
  15773.   void main()
  15774.   {
  15775.      X xobject1;    // create an object of class type X
  15776.      X xobject2;    // create another object of class type X
  15777.   }
  15778.  
  15779.  This chapter discusses the following topics: 
  15780.  
  15781.      Declaring Class Objects 
  15782.      Scope of Class Names 
  15783.  
  15784.  Classes are also used in C++ to support polymorphic functions through 
  15785.  overloaded functions (static compile time binding) and virtual functions 
  15786.  (dynamic binding). C++ allows you to redefine standard operators and functions 
  15787.  through the concept of overloading. Operator overloading facilitates data 
  15788.  abstraction by allowing you to use classes as easily as built-in types. 
  15789.  
  15790.  Related Information 
  15791.  
  15792.      C++ Class Members and Friends 
  15793.      C++ Inheritance 
  15794.      C++ Overloading 
  15795.      Virtual Functions 
  15796.      Structures 
  15797.      Unions 
  15798.  
  15799.  
  15800. ΓòÉΓòÉΓòÉ 10.1. Classes and Structures ΓòÉΓòÉΓòÉ
  15801.  
  15802. The C++ class is an extension of the C-language structure. Because the only 
  15803. difference between a structure and a class is that structure members have 
  15804. public access by default and a class members have private access by default, 
  15805. you can use the keywords class or struct to define equivalent classes. 
  15806.  
  15807. For example, in the following code fragment, the class X is equivalent to the 
  15808. structure Y: 
  15809.  
  15810. // In this example, class X is equivalent to struct Y
  15811.  
  15812. class X
  15813. {
  15814. int a; // private by default
  15815. public:
  15816.    int f() { return a = 5; }; // public member function
  15817. };
  15818. struct Y
  15819. {
  15820. int f() { return a = 5; };    // public by default
  15821. private:
  15822.    int a; // private data member
  15823. };
  15824.  
  15825. If you define a structure and then declare an object of that structure using 
  15826. the keyword class, the members of the object are still public by default. 
  15827.  
  15828. Example of Access for Classes and Structures 
  15829.  
  15830. An aggregate class is a class that has no user-defined constructors, no private 
  15831. or protected members, no  base classes, and no virtual functions. 
  15832.  
  15833. Initialization of aggregate classes is described in Initializers. 
  15834.  
  15835. Related Information 
  15836.  
  15837.      Structures 
  15838.      Declaring Class Objects 
  15839.      Scope of Class Names 
  15840.  
  15841.  
  15842. ΓòÉΓòÉΓòÉ <hidden> Example of Access for Classes and Structures ΓòÉΓòÉΓòÉ
  15843.  
  15844. /************************************************************************
  15845. *
  15846.  
  15847. In the following example, main() has access to the members of X even though X 
  15848. is declared as using the keyword class: 
  15849.  
  15850.                                     *
  15851. ************************************************************************/
  15852.  
  15853. // This example declares a structure, then declares a class
  15854. // that is an object of the structure.
  15855.  
  15856. #include <iostream.h>
  15857.  
  15858. struct x {
  15859.    int a;
  15860.    int b;
  15861.    } ;
  15862.  
  15863. class x X;
  15864.  
  15865. void main() {
  15866.    X.a = 0;
  15867.    X.b = 1;
  15868.    cout << "Here are a and b " << X.a << " " << X.b << endl;
  15869.    }
  15870.  
  15871.  
  15872. ΓòÉΓòÉΓòÉ 10.2. Declaring Class Objects ΓòÉΓòÉΓòÉ
  15873.  
  15874. A class declaration creates a unique type class name. 
  15875.  
  15876. A class specifier is a type specifier used to declare a class. Once a class 
  15877. specifier has been seen and its members declared, a class is considered to be 
  15878. defined even if the member functions of that class are not yet defined. A class 
  15879. specifier has the following form: 
  15880.  
  15881. >>ΓöÇΓöÇΓö¼ΓöÇclassΓöÇΓöÇΓö¼ΓöÇΓöÇclass_nameΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ}ΓöÇΓöÇ><
  15882.   Γö£ΓöÇstructΓöÇΓöñ        ΓööΓöÇ:base_classΓöÇΓöÿ   ΓööΓöÇmember_listΓöÇΓöÿ
  15883.   ΓööΓöÇunionΓöÇΓöÇΓöÿ
  15884.  
  15885. The member_list is optional. It specifies the class members, both data and 
  15886. functions, of the class class_name. If the member_list of a class is empty, 
  15887. objects of that class have a nonzero size. You can use a class_name within the 
  15888. member_list of the class specifier itself as long as the size of the class is 
  15889. not required. For more information, see Class Member Lists. 
  15890.  
  15891. The base_class is optional. It specifies the base class or classes from which 
  15892. the class class_name inherits members. If the base_class is not empty, the 
  15893. class class_name is called a derived class. 
  15894.  
  15895. The declarator for a class variable declared with the class, struct, or union 
  15896. keyword is an identifier. If the symbol * precedes the identifier, the 
  15897. identifier names a pointer to a class of the specified data type. If ** 
  15898. precedes the identifier, the identifier names a pointer to a pointer to a class 
  15899. of the specified data type. 
  15900.  
  15901. If a constant expression enclosed in [ ] (brackets) follows the identifier, the 
  15902. identifier names an array of classes of the specified data type. If * precedes 
  15903. the identifier and a constant expression enclosed in [ ] follows the 
  15904. identifier, the identifier names an array of pointers to classes of the 
  15905. specified data type. 
  15906.  
  15907. Related Information 
  15908.  
  15909.      Class Names 
  15910.      Scope of Class Names 
  15911.      Class Member Lists 
  15912.      Derivation 
  15913.  
  15914.  
  15915. ΓòÉΓòÉΓòÉ 10.2.1. Class Names ΓòÉΓòÉΓòÉ
  15916.  
  15917. A class name is a unique identifier that becomes a reserved word within its 
  15918. scope. Once a class name is declared, it hides other declarations of the same 
  15919. name within the enclosing scope. 
  15920.  
  15921. If a class name is declared in the same scope as a function, enumerator, or 
  15922. object with the same name, that class can be referred to by using an elaborated 
  15923. type specifier. In the following example, the elaborated type specifier is used 
  15924. to refer to the class print that is hidden by the later definition of the 
  15925. function print(): 
  15926.  
  15927. class print
  15928. {
  15929.    /* definition of class print */
  15930. };
  15931. void print (class print*);    // redefine print as a function
  15932. //    .             // prefix class-name by class-key
  15933. //    .             // to refer to class print
  15934. //    .
  15935. void main ()
  15936. {
  15937.    class print* paper;     // prefix class-name by class-key
  15938.                  // to refer to class print
  15939.    print(paper);        // call function print
  15940. }
  15941.  
  15942. You can use an elaborated type specifier with a class name to declare a class. 
  15943.  
  15944. For more information on elaborated type specifiers, see Incomplete Class 
  15945. Declarations. 
  15946.  
  15947. You can also qualify type names to refer to hidden type names in the current 
  15948. scope. You can reduce complex class name syntax by using a typedef to represent 
  15949. a nested class name. 
  15950.  
  15951. Example of Using a typedef for a Class Name 
  15952.  
  15953. Related Information 
  15954.  
  15955.      Declaring Class Objects 
  15956.      Scope of Class Names 
  15957.      Nested Classes 
  15958.  
  15959.  
  15960. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Nested Class Specifier ΓòÉΓòÉΓòÉ
  15961.  
  15962. The syntax of a nested class specifier is: 
  15963.  
  15964. >>ΓöÇΓöÇclass_nameΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  15965.         ΓööΓöÇ::nested_classΓöÇΓöÿ
  15966.  
  15967. where class_name specifies the name of the enclosing class and nested-class 
  15968. specifies the name of the nested class. For more information, see Nested 
  15969. Classes. 
  15970.  
  15971.  
  15972. ΓòÉΓòÉΓòÉ <hidden> Example of Using a typedef for a Class Name ΓòÉΓòÉΓòÉ
  15973.  
  15974. /************************************************************************
  15975. *
  15976.  
  15977. In the following example, a typedef is used so that the simple name nested can 
  15978. be used in place of outside::middle::inside. 
  15979.  
  15980. *
  15981. ************************************************************************/
  15982.  
  15983. // This example illustrates a typedef used to simplify
  15984. // a nested class name.
  15985.  
  15986. #include <iostream.h>
  15987.  
  15988. class outside {
  15989. public:
  15990.    class middle {
  15991.    public:
  15992.       class inside {
  15993.          private:
  15994.             int a;
  15995.          public:
  15996.             inside(int a_init = 0): a(a_init) {}
  15997.             void printa();
  15998.       };
  15999.    };
  16000. };
  16001.  
  16002. typedef outside::middle::inside nested;
  16003.  
  16004. void nested::printa() {
  16005.    cout << "Here is a " << this->a << endl;
  16006.    }
  16007.  
  16008. void main() {
  16009.    nested n(9);
  16010.    n.printa();
  16011. }
  16012.  
  16013.  
  16014. ΓòÉΓòÉΓòÉ 10.2.2. Using Class Objects ΓòÉΓòÉΓòÉ
  16015.  
  16016. You can use a class type to create instances or objects of that class type. For 
  16017. example, you can declare a class, structure, and union with class names X, Y, 
  16018. and Z respectively: 
  16019.  
  16020. class X {    /* definition of class X */ };
  16021. struct Y {    /* definition of struct Y */ };
  16022. union Z {    /* definition of union Z */ };
  16023.  
  16024. You can then declare objects of each of these class types. Remember that 
  16025. classes, structures, and unions are all types of C++ classes. 
  16026.  
  16027. void main()
  16028. {
  16029.    X xobj;    // declare a class object of class type X
  16030.    Y yobj;    // declare a struct object of class type Y
  16031.    Z zobj;    // declare a union object of class type Z
  16032. }
  16033.  
  16034. In C++, unlike C, you do not need to precede declarations of class objects with 
  16035. the keywords union, struct, and class unless the name of the class is hidden. 
  16036. For more information on hidden names, see Scope of Class Names. 
  16037.  
  16038. When you declare more than one class object in a declaration, the declarators 
  16039. are treated as if declared individually. For example, if you declare two 
  16040. objects of class S in a single declaration: 
  16041.  
  16042. class S { /* ... */ };
  16043. void main()
  16044. {
  16045.    S S,T; // declare two objects of class type S
  16046. }
  16047.  
  16048. this declaration is equivalent to: 
  16049.  
  16050. class S { /* ... */ };
  16051. void main()
  16052. {
  16053.    S S;
  16054.    class S T;    // keyword class is required
  16055.             // since variable S hides class type S
  16056. }
  16057.  
  16058. but is not equivalent to: 
  16059.  
  16060. class S { /* ... */ };
  16061. void main()
  16062. {
  16063.    S S;
  16064.    S T;       // error, S class type is hidden
  16065. }
  16066.  
  16067. You can also declare references to classes, pointers to classes, and arrays of 
  16068. classes. 
  16069.  
  16070. Examples of Declaring Class Objects 
  16071.  
  16072. Objects of class types that are not copy restricted can be assigned, passed as 
  16073. arguments to functions, and returned by functions. For more information, see 
  16074. Copying Class Objects. 
  16075.  
  16076. Related Information 
  16077.  
  16078.      Objects 
  16079.      Scope of Class Names 
  16080.      Initialization by Constructor 
  16081.      Copying Class Objects 
  16082.  
  16083.  
  16084. ΓòÉΓòÉΓòÉ <hidden> Examples of Declaring Class Objects ΓòÉΓòÉΓòÉ
  16085.  
  16086. /************************************************************************
  16087. *
  16088.  
  16089. In C++, unlike C, you do not need to precede declarations of class objects with 
  16090. the keywords union, struct, and class unless the name of the class is hidden. 
  16091. For example: 
  16092.  
  16093.                                     *
  16094. ************************************************************************/
  16095.  
  16096. struct Y { /* ... */ };
  16097. class X { /* ... */ };
  16098. void main ()
  16099. {
  16100.    int X;       // hides the class name X
  16101.    Y yobj;       // valid
  16102.    X xobj;       // error, class name X is hidden
  16103.    class X xobj;    // valid
  16104. }
  16105.  
  16106. /************************************************************************
  16107. *
  16108.  
  16109. The following example declares a reference, a pointer, and an array: 
  16110.  
  16111.                                     *
  16112. ************************************************************************/
  16113.  
  16114. class X { /* ... */ };
  16115. struct Y { /* ... */ };
  16116. union Z { /* ... */ };
  16117. void main()
  16118. {
  16119.    X xobj;
  16120.    X &xref = xobj;      // reference to class object of type X
  16121.    Y *yptr;          // pointer to struct object of type Y
  16122.    Z zarray[10];       // array of 10 union objects of type Z
  16123. }
  16124.  
  16125.  
  16126. ΓòÉΓòÉΓòÉ 10.3. Scope of Class Names ΓòÉΓòÉΓòÉ
  16127.  
  16128. A class declaration introduces the class name into the scope where it is 
  16129. declared. Any class, object, function or other declaration of that name in an 
  16130. enclosing scope is hidden. If a class name is declared in a scope where an 
  16131. object, function, or enumerator of the same name is also declared, you can only 
  16132. refer to the class by using the elaborated type specifier. The class key 
  16133. (class, struct, or union) must precede the class name to identify it. 
  16134.  
  16135. For example: 
  16136.  
  16137. // This example shows the scope of class names.
  16138.  
  16139. class x { int a; };       // declare a class type class-name
  16140.  
  16141. x xobject;           // declare object of class type x
  16142.  
  16143. int x(class x*)         // redefine x to be a function
  16144. {return 0;}           // use class-key class to define
  16145.                 // a pointer to the class type x
  16146.                 // as the function argument
  16147.  
  16148. void main()
  16149. {
  16150.    class x* xptr;      // use class-key class to define
  16151.                 // a pointer to class type x
  16152.    xptr = &xobject;     // assign pointer
  16153.    x(xptr);         // call function x with pointer to class x
  16154. }
  16155.  
  16156. An elaborated type specifier can be used in the declaration of objects and 
  16157. functions. See Class Names for an example. 
  16158.  
  16159. An elaborated type specifier can also be used in the incomplete declaration of 
  16160. a class type to reserve the name for a class type within the current scope. 
  16161.  
  16162. Related Information 
  16163.  
  16164.      Incomplete Class Declarations 
  16165.      Nested Classes 
  16166.      Local Classes 
  16167.      Local Type Names 
  16168.      Class Names 
  16169.      Declaring Class Objects 
  16170.      Scope in C 
  16171.  
  16172.  
  16173. ΓòÉΓòÉΓòÉ 10.3.1. Incomplete Class Declarations ΓòÉΓòÉΓòÉ
  16174.  
  16175. An incomplete class declaration is a class declaration that does not define any 
  16176. class members. You cannot declare any objects of the class type or refer to the 
  16177. members of a class until the declaration is complete. However, an incomplete 
  16178. declaration allows you to make specific references to a class prior to its 
  16179. definition as long as the size of the class is not required. 
  16180.  
  16181. For example, you can define a pointer to the structure first in the definition 
  16182. of the structure second. Structure first is declared in an incomplete class 
  16183. declaration prior to the definition of second, and the definition of oneptr in 
  16184. structure second does not require the size of first: 
  16185.  
  16186. struct first;      // incomplete declaration of struct first
  16187.  
  16188. struct second      // complete declaration of struct second
  16189. {
  16190.    first* oneptr;   // pointer to struct first refers to
  16191.             // struct first prior to its complete
  16192.             // declaration
  16193.  
  16194.    first one;     // error, you cannot declare an object of
  16195.             // an incompletely declared class type
  16196.    int x, y;
  16197. };
  16198.  
  16199. struct first       // complete declaration of struct first
  16200. {
  16201.    second two;    // define an object of class type second
  16202.    int z;
  16203. };
  16204.  
  16205. If you declare a class with an empty member list, it is a complete class 
  16206. declaration. For example: 
  16207.  
  16208. class X;         // incomplete class declaration
  16209. class Z {};       // empty member list
  16210. class Y
  16211. {
  16212. public:
  16213.    X yobj;      // error, cannot create an object of an
  16214.             // incomplete class type
  16215.    Z zobj;      // valid
  16216. };
  16217.  
  16218. Related Information 
  16219.  
  16220.      Declaring Class Objects 
  16221.      Class Member Lists 
  16222.      Scope of Class Names 
  16223.  
  16224.  
  16225. ΓòÉΓòÉΓòÉ 10.3.2. Nested Classes ΓòÉΓòÉΓòÉ
  16226.  
  16227. A nested class is declared within the scope of another class. The name of a 
  16228. nested class is local to its enclosing class.  Unless you use explicit 
  16229. pointers, references, or object names, declarations in a nested class can only 
  16230. use visible constructs, including type names, static members, and enumerators 
  16231. from the enclosing class and global variables. 
  16232.  
  16233. Member functions of a nested class follow regular access rules and have no 
  16234. special access privileges to members of their enclosing classes. Member 
  16235. functions of the enclosing class have no special access to members of a nested 
  16236. class. 
  16237.  
  16238. You can define member functions and static data members of a nested class in 
  16239. the global scope. For example, in the following code fragment, you can access 
  16240. the static members x and y and member functions f() and g() of the nested class 
  16241. nested by using a qualified type name. Qualified type names allow you to define 
  16242. a typedef to represent a qualified class name. You can then use the typedef 
  16243. with the :: (scope resolution) operator to refer to a nested class or class 
  16244. member, as shown in the following example: 
  16245.  
  16246. class outside
  16247. {
  16248. public:
  16249.    class nested
  16250.    {
  16251.    public:
  16252.       static int x;
  16253.       static int y;
  16254.       int f();
  16255.       int g();
  16256.    };
  16257. };
  16258. int outside::nested::x = 5;
  16259. int outside::nested::f() { return 0; };
  16260.  
  16261. typedef outside::nested outnest;    // define a typedef
  16262. int outnest::y = 10;          // use typedef with ::
  16263. int outnest::g() { return 0; };
  16264. //    . . .
  16265.  
  16266. Related Information 
  16267.  
  16268.      Class Names 
  16269.      Declaring Class Objects 
  16270.      Scope of Class Names 
  16271.  
  16272.  
  16273. ΓòÉΓòÉΓòÉ 10.3.3. Local Classes ΓòÉΓòÉΓòÉ
  16274.  
  16275. A local class is declared within a function definition. The local class is in 
  16276. the scope of the enclosing function scope. Declarations in a local class can 
  16277. only use type names, enumerations, static variables from the enclosing scope, 
  16278. as well as external variables and functions. 
  16279.  
  16280. Examples of Local Classes 
  16281.  
  16282. Member functions of a local class have to be defined within their class 
  16283. definition. Member functions of a local class must be inline functions. Like 
  16284. all member functions, those defined within the scope of a local class do not 
  16285. need the keyword inline. 
  16286.  
  16287. A local class cannot have static data members. In the following example, an 
  16288. attempt to define a static member of a local class causes an error: 
  16289.  
  16290. void f()
  16291. {
  16292.   class local
  16293.   {
  16294.     int f();        // error, local class has noninline
  16295.                // member function
  16296.     int g() {return 0;}  // valid, inline member function
  16297.     static int a;     // error, static is not allowed for
  16298.                // local class
  16299.     int b;         // valid, nonstatic variable
  16300.   };
  16301. }
  16302. //    . . .
  16303.  
  16304. An enclosing function has no special access to members of the local class. 
  16305.  
  16306. Related Information 
  16307.  
  16308.      Scope of Class Names 
  16309.      Function Scope 
  16310.      Inline Member Functions 
  16311.      Inline Functions 
  16312.      Local Type Names 
  16313.  
  16314.  
  16315. ΓòÉΓòÉΓòÉ <hidden> Examples of Local Classes ΓòÉΓòÉΓòÉ
  16316.  
  16317. /************************************************************************
  16318. *
  16319.  
  16320. The following example uses local classes. 
  16321.  
  16322.                                     *
  16323. ************************************************************************/
  16324.  
  16325. int x;             // global variable
  16326. void f()            // function definition
  16327. {
  16328.    static int y;       // static variable y can be used by
  16329.                 // local class
  16330.    int x;          // auto variable x cannot be used by
  16331.                 // local class
  16332.    extern int g();      // extern function g can be used by
  16333.                 // local class
  16334.  
  16335.    class local        // local class
  16336.    {
  16337.       int g() { return x; }    // error, local variable x
  16338.                     // cannot be used by g
  16339.       int h() { return y; }    // valid,static variable y
  16340.       int k() { return ::x; }   // valid, global x
  16341.       int l() { return g(); }   // valid, extern function g
  16342.    };
  16343. }
  16344.  
  16345. void main()
  16346. {
  16347.    local* z;         // error, local is undefined
  16348. //    .
  16349. //    .
  16350. //    .
  16351. }
  16352.  
  16353.  
  16354. ΓòÉΓòÉΓòÉ 10.3.4. Local Type Names ΓòÉΓòÉΓòÉ
  16355.  
  16356. Local type names follow the same scope rules as other names. Scope rules are 
  16357. described in Scope in C++. Type names defined within a class declaration have 
  16358. class scope and cannot be used outside their class without qualification. 
  16359.  
  16360. If you use a class name, typedef name, or a constant name that is used in a 
  16361. type name, in a class declaration, you cannot redefine that name after it is 
  16362. used in the class declaration. 
  16363.  
  16364. For example: 
  16365.  
  16366. void main ()
  16367. {
  16368.    typedef double db;
  16369.    struct st
  16370.    {
  16371.       db x;
  16372.       typedef int db; // error
  16373.       db y;
  16374.    };
  16375. }
  16376.  
  16377. The following declarations are valid: 
  16378.  
  16379. typedef float T;
  16380. class s {
  16381.    typedef int T;
  16382.    void f(const T);
  16383. };
  16384.  
  16385. Here, function f() takes an argument of type s::T. However, the following 
  16386. declarations, where the order of the members of s has been reversed, cause an 
  16387. error: 
  16388.  
  16389. typedef float T;
  16390. class s {
  16391.    void f(const T);
  16392.    typedef int T;
  16393. };
  16394.  
  16395. In a class declaration, you cannot redefine a name that is not a class name, or 
  16396. a typedef name to a class name or typedef name once you have used that name in 
  16397. the class declaration. 
  16398.  
  16399. Related Information 
  16400.  
  16401.      Scope in C 
  16402.      Declaring Class Objects 
  16403.      Scope of Class Names 
  16404.      Local Classes 
  16405.      typedef 
  16406.  
  16407.  
  16408. ΓòÉΓòÉΓòÉ 11. C++ Class Members and Friends ΓòÉΓòÉΓòÉ
  16409.  
  16410. This chapter describes class members and friends, including the following 
  16411. topics: 
  16412.  
  16413.      Class Member Lists 
  16414.      Data Members 
  16415.      Class-Type Class Members 
  16416.      Member Functions 
  16417.      Member Scope 
  16418.      Pointers to Members 
  16419.      The this Pointer 
  16420.      Static Members 
  16421.      Member Access 
  16422.      Friends 
  16423.  
  16424.  Related Information 
  16425.  
  16426.      C++ Classes 
  16427.      C++ Inheritance 
  16428.      Special C++ Member Functions 
  16429.  
  16430.  
  16431. ΓòÉΓòÉΓòÉ 11.1. Class Member Lists ΓòÉΓòÉΓòÉ
  16432.  
  16433. An optional member list declares sub-objects called class members. Class 
  16434. members can be data, functions, classes, enumeration, bit fields, and typedef 
  16435. names. A member list is the only place you can declare class members. Friend 
  16436. declarations are not class members but must appear in member lists. 
  16437.  
  16438. The member list follows the class name and is placed between braces. It can 
  16439. contain access specifiers, member declarations, and member definitions. 
  16440.  
  16441. You can access members by using the class access . (dot) and -> (arrow) 
  16442. operators. 
  16443.  
  16444. An access specifier is one of public, private, or protected. 
  16445.  
  16446. A member declaration declares a class member for the class containing the 
  16447. declaration. For more information on declarations, see Declarations, and 
  16448. Declaring Class Objects. 
  16449.  
  16450. A member declaration that is a qualified name followed by a ; (semicolon) is 
  16451. used to restore access to members of base classes and is described in Access 
  16452. Declarations. 
  16453.  
  16454. A member declarator declares an object, function, or type within a declaration. 
  16455. It cannot contain an initializer. You can initialize a member by using a 
  16456. constructor or, if the member belongs to an aggregate class, by using a brace 
  16457. initializer list (a list surrounded by braces { }) in the declarator list. You 
  16458. must explicitly initialize a class containing constant or reference members 
  16459. with a brace initializer list or explicitly with a constructor. 
  16460.  
  16461. A member declarator of the form: 
  16462.  
  16463.    [identifier] : constant-expression
  16464.  
  16465. specifies a bit field. 
  16466.  
  16467. A pure specifier (= 0) indicates that a function has no definition. It is only 
  16468. used with virtual member functions and replaces the function definition of a 
  16469. member function in the member list. Pure specifiers are described in Virtual 
  16470. Functions. 
  16471.  
  16472. You can use the storage-class specifier static (but not extern, auto or 
  16473. register) in a member list. 
  16474.  
  16475. The order of mapping of class members in a member list is implementation 
  16476. dependent. For the VisualAge for C++ compiler, class members are allocated in 
  16477. the order they are declared. For more information, see the IBM VisualAge for 
  16478. C++ for Windows User's Guide. 
  16479.  
  16480. Related Information 
  16481.  
  16482.      Member Access 
  16483.      Dot Operator . 
  16484.      Arrow Operator -> 
  16485.      Declaring Class Objects 
  16486.      Access Declarations 
  16487.      Initialization by Constructor 
  16488.      Virtual Functions 
  16489.      Initializers 
  16490.      Storage Class Specifiers 
  16491.  
  16492.  
  16493. ΓòÉΓòÉΓòÉ 11.2. Data Members ΓòÉΓòÉΓòÉ
  16494.  
  16495. Data members include members that are declared with any of the fundamental 
  16496. types, as well as other types, including pointer, reference, array types, and 
  16497. user-defined types. You can declare a data member the same way as a variable, 
  16498. except that explicit initializers are not allowed inside the class definition. 
  16499.  
  16500. If an array is declared as a nonstatic class member, you must specify all of 
  16501. the dimensions of the array. 
  16502.  
  16503. Related Information 
  16504.  
  16505.      Type Specifiers 
  16506.      Class Member Lists 
  16507.      Class-Type Class Members 
  16508.      Static Members 
  16509.      Member Access 
  16510.  
  16511.  
  16512. ΓòÉΓòÉΓòÉ 11.3. Class-Type Class Members ΓòÉΓòÉΓòÉ
  16513.  
  16514. A class can have members that are of a class type or are pointers or references 
  16515. to a class type. Members that are of a class type must be of a class type that 
  16516. is previously declared. An incomplete class type can be used in a member 
  16517. declaration as long as the size of the class is not needed. For example, a 
  16518. member can be declared that is a pointer to an incomplete class type. 
  16519.  
  16520. A class X cannot have a member that is of type X, but it can contain pointers 
  16521. to X, references to X, and static objects of X. Member functions of X can take 
  16522. arguments of type X and have a return type of X. For example: 
  16523.  
  16524. class X
  16525. {
  16526.    X();
  16527.    X *xptr;
  16528.    X &xref;
  16529.    static X xcount;
  16530.    X xfunc(X);
  16531. };
  16532.  
  16533. The bodies of member functions are always processed after the definition of 
  16534. their class is complete. For this reason, the body of a member function can 
  16535. refer to the name of the class that owns it. even if this requires information 
  16536. about the class definition. 
  16537.  
  16538. The language allows member functions to refer to any class member even if the 
  16539. member function definition appears before the declaration of that member in the 
  16540. class member list. For example, 
  16541.  
  16542. class Y
  16543. {
  16544. public:
  16545.    int a;
  16546.    Y ();
  16547. private:
  16548.    int f() {return sizeof(Y);};
  16549.    void g(Y yobj);
  16550.    Y h(int a);
  16551. };
  16552.  
  16553. In this example, it is permitted for the inline function f() to make use of the 
  16554. size of class Y. 
  16555.  
  16556. Related Information 
  16557.  
  16558.      Incomplete Class Declarations 
  16559.      Member Functions 
  16560.      Inline Member Functions 
  16561.      C++ Classes 
  16562.      Class Member Lists 
  16563.  
  16564.  
  16565. ΓòÉΓòÉΓòÉ 11.4. Member Functions ΓòÉΓòÉΓòÉ
  16566.  
  16567. Member functions are operators and functions that are declared as members of a 
  16568. class. Member functions do not include operators and functions declared with 
  16569. the friend specifier. These are called friends of a class. 
  16570.  
  16571. The default linkage convention for member functions is _Optlink. Other linkage 
  16572. conventions are permitted to allow a parameters to be passed in a different 
  16573. order from _Optlink. 
  16574.  
  16575. A member function with linkage other than _Optlink still has a this pointer. 
  16576. The signature of a member function with linkage other than _Optlink is 
  16577. unchanged. 
  16578.  
  16579. The definition of a member function is within the scope of its enclosing class. 
  16580. The body of a member function is analyzed after the class declaration so that 
  16581. members of that class can be used in the member function body. When the 
  16582. function add() is called in the following example, the data variables a, b, and 
  16583. c can be used in the body of add(). 
  16584.  
  16585. class x
  16586. {
  16587. public:
  16588.    int add()       // inline member function add
  16589.    {return a+b+c;};
  16590. private:
  16591.    int a,b,c;
  16592. };
  16593.  
  16594. There are several kinds of member functions: 
  16595.  
  16596.      const and volatile member functions 
  16597.      Virtual member functions 
  16598.      Special member functions 
  16599.      Inline member functions 
  16600.      Member function templates 
  16601.  
  16602.  Related Information 
  16603.  
  16604.      Member Scope 
  16605.      Static Member Functions 
  16606.      Functions 
  16607.      Class Member Lists 
  16608.  
  16609.  
  16610. ΓòÉΓòÉΓòÉ <hidden> const and volatile Member Functions ΓòÉΓòÉΓòÉ
  16611.  
  16612. A member function declared with the const qualifier can be called for constant 
  16613. and nonconstant objects. A nonconstant member function can only be called for a 
  16614. nonconstant object. Similarly, a member function declared with the volatile 
  16615. qualifier can be called for volatile and nonvolatile objects. A nonvolatile 
  16616. member function can only be called for a nonvolatile object. 
  16617.  
  16618.  
  16619. ΓòÉΓòÉΓòÉ <hidden> Virtual Member Functions ΓòÉΓòÉΓòÉ
  16620.  
  16621. Virtual member functions are declared with the keyword virtual. They allow 
  16622. dynamic binding of member functions. Because all virtual functions must be 
  16623. member functions, virtual member functions are simply called virtual functions. 
  16624.  
  16625. If the definition of a virtual function is replaced by a pure specifier in the 
  16626. declaration of the function, the function is said to be declared pure. A class 
  16627. that has at least one pure virtual function is called an abstract class. 
  16628.  
  16629.  
  16630. ΓòÉΓòÉΓòÉ <hidden> Special Member Functions ΓòÉΓòÉΓòÉ
  16631.  
  16632. Special member functions are used to create, destroy, initialize, convert, and 
  16633. copy class objects. These include: 
  16634.  
  16635.      Constructors 
  16636.      Destructors 
  16637.      Conversion constructors 
  16638.      Conversion functions 
  16639.      Copy constructors 
  16640.  
  16641.  
  16642. ΓòÉΓòÉΓòÉ <hidden> Inline Member Functions ΓòÉΓòÉΓòÉ
  16643.  
  16644. A member function that is both declared and defined in the class member list is 
  16645. called an inline member function. Member functions containing a few lines of 
  16646. code are usually declared inline. 
  16647.  
  16648. An equivalent way to declare an inline member function is to declare it outside 
  16649. of the class declaration using the keyword inline and the :: (scope resolution) 
  16650. operator to identify the class the member function belongs to. For example: 
  16651.  
  16652. class Y
  16653. {
  16654.    char* a;
  16655. public:
  16656.    char* f() {return a;};
  16657. };
  16658.  
  16659. is equivalent to: 
  16660.  
  16661. class Z
  16662. {
  16663.    char* a;
  16664. public:
  16665.    char* f();
  16666. };
  16667. inline char* Z::f() {return a;}
  16668.  
  16669. When you declare an inline function without the inline keyword and do not 
  16670. define it in the class member list, you cannot call the function before you 
  16671. define it. In the above example, you cannot call f() until after its 
  16672. definition. 
  16673.  
  16674. Inline member functions have internal linkage. Noninline member functions have 
  16675. external linkage. 
  16676.  
  16677. For more information, see Inline Functions. 
  16678.  
  16679.  
  16680. ΓòÉΓòÉΓòÉ <hidden> Member Function Templates ΓòÉΓòÉΓòÉ
  16681.  
  16682. Any member function (inlined or noninlined) declared within a class template is 
  16683. implicitly a function template. When a template class is declared, it 
  16684. implicitly generates template functions for each function defined in the class 
  16685. template. If a class template is instantiated, only the function templates 
  16686. whose instantiations will actually be used by the resulting template class are 
  16687. instantiated. 
  16688.  
  16689. For more information about member function templates, see Member Function 
  16690. Templates. 
  16691.  
  16692.  
  16693. ΓòÉΓòÉΓòÉ 11.5. Member Scope ΓòÉΓòÉΓòÉ
  16694.  
  16695. Member functions and static members can be defined outside their class 
  16696. declaration if they have already been declared, but not defined, in the class 
  16697. member list. Nonstatic data members are defined when their class is 
  16698. instantiated. The declaration of a static data member is not a definition. The 
  16699. declaration of a member function is a definition if the body of the function is 
  16700. also given. 
  16701.  
  16702. Whenever the definition of a class member appears outside of the class 
  16703. declaration, the member name must be qualified by the class name using the :: 
  16704. (scope resolution) operator. 
  16705.  
  16706. Example of Defining a Member outside of the Class 
  16707.  
  16708. All member functions are in class scope even if they are defined outside their 
  16709. class declaration. 
  16710.  
  16711. The name of a class member is local to its class. Unless you use one of the 
  16712. class access operators, . (dot), or -> (arrow), or :: (scope resolution) 
  16713. operator, you can only use a class member in a member function of its class and 
  16714. in nested classes. You can only use types, enumerations and static members in a 
  16715. nested class without qualification with the :: operator. 
  16716.  
  16717. The order of search for a name in a member function body is: 
  16718.  
  16719.    1. Within the member function body itself 
  16720.    2. Within all the enclosing classes, including inherited members of those 
  16721.       classes 
  16722.    3. Within the lexical scope of the body declaration 
  16723.  
  16724.  Example of Member Function Search Path 
  16725.  
  16726.  Note:  When the containing classes are being searched, only the definitions of 
  16727.  the containing classes and their base classes are searched. The scope 
  16728.  containing the base class definitions (global scope, in this example) is not 
  16729.  searched. 
  16730.  
  16731.  Related Information 
  16732.  
  16733.      Scope in C++ 
  16734.      C++ Scope Resolution Operator :: 
  16735.      Member Functions 
  16736.      Dot Operator . 
  16737.      Arrow Operator -> 
  16738.      Member Access 
  16739.  
  16740.  
  16741. ΓòÉΓòÉΓòÉ <hidden> Example of Defining a Member ΓòÉΓòÉΓòÉ
  16742.  
  16743. /************************************************************************
  16744. *
  16745.  
  16746. The following example defines a member function outside of its class 
  16747. declaration. 
  16748.  
  16749.                                     *
  16750. ************************************************************************/
  16751.  
  16752. // This example illustrates member scope.
  16753.  
  16754. #include <iostream.h>
  16755. class X
  16756. {
  16757. public:
  16758.    int a, b ;    // public data members
  16759.    int add();    // member function declaration only
  16760. };
  16761. int a  = 10;      // global variable
  16762. // define member function outside its class declaration
  16763. int X::add() {return a + b;};
  16764. //    .
  16765. //    .
  16766. //    .
  16767. void main()
  16768. {
  16769.   int answer;
  16770.   X xobject;
  16771.   xobject.a = 1;
  16772.   xobject.b = 2;
  16773.   answer = xobject.add();
  16774.   cout << xobject.a << " + " << xobject.b << " = " << answer<<endl;
  16775. }
  16776.  
  16777. /************************************************************************
  16778. *
  16779.  
  16780. The output for this example is: 1 + 2 = 3 
  16781.  
  16782. Note:  All member functions are in class scope even if they are defined outside 
  16783. their class declaration. In the above example, the member function add() 
  16784. returns the data member a, not the global variable a. 
  16785.  
  16786.                                     *
  16787. ************************************************************************/
  16788.  
  16789.  
  16790. ΓòÉΓòÉΓòÉ <hidden> Example of Member Function Search Path ΓòÉΓòÉΓòÉ
  16791.  
  16792. /************************************************************************
  16793. *
  16794.  
  16795. The search of the enclosing classes, including inherited members, is 
  16796. demonstrated in the following example: 
  16797.  
  16798.                                     *
  16799. ************************************************************************/
  16800.  
  16801. class A { /* ... */ };
  16802. class B { /* ... */ };
  16803. class C { /* ... */ };
  16804. class Z : A {
  16805.    class Y : B {
  16806.       class X : C { int f(); /* ... */ };
  16807.    };
  16808. };
  16809. int Z::Y::X f()
  16810. {
  16811.   // ...
  16812.    j();
  16813.   // ...
  16814. }
  16815.  
  16816. /************************************************************************
  16817. *
  16818.  
  16819. In this example, the search for the name j in the definition of the function f 
  16820. follows this order: 
  16821.  
  16822.    1. In the body of the function f 
  16823.    2. In X and in its base class C 
  16824.    3. In Y and in its base class B 
  16825.    4. In Z and in its base class A 
  16826.    5. In the lexical scope of the body of f. In this case, this is global 
  16827.       scope. 
  16828.  
  16829.                                        *
  16830.   ************************************************************************/
  16831.  
  16832.  
  16833. ΓòÉΓòÉΓòÉ 11.6. Pointers to Members ΓòÉΓòÉΓòÉ
  16834.  
  16835. Pointers to members allow you to refer to nonstatic members of class objects. 
  16836. You cannot use a pointer to member to point to a static class member because 
  16837. the address of a static member is not associated with any particular object. To 
  16838. point to a static class member, you must use a normal pointer. 
  16839.  
  16840. You can use pointers to member functions in the same manner as pointers to 
  16841. functions. You can compare pointers to member functions, assign values to them, 
  16842. and use them to call member functions. Note that a member function does not 
  16843. have the same type as a nonmember function that has the same number and type of 
  16844. arguments and the same return type. 
  16845.  
  16846. Example of Pointers to Members 
  16847.  
  16848. To reduce complex syntax, you can declare a typedef to be a pointer to a 
  16849. member. A pointer to a member can be declared and used as shown in the 
  16850. following code fragment: 
  16851.  
  16852. typedef void (X::*ptfptr) (int);    // declare typedef
  16853. void main ()
  16854. {
  16855. // ...
  16856. ptfptr ptf = &X::f;          // use typedef
  16857. X xobject;
  16858. (xobject.*ptf) (20);          // call function
  16859. }
  16860.  
  16861. The pointer to member operators .* and ->* are used to bind a pointer to a 
  16862. member of a specific class object. Because the precedence of () (function call 
  16863. operator) is higher than .* and ->*, you must use parentheses to call the 
  16864. function pointed to by ptf. 
  16865.  
  16866. Related Information 
  16867.  
  16868.      C++ Pointer to Member Operators .* ->* 
  16869.      Pointers 
  16870.      Static Members 
  16871.      The this Pointer 
  16872.  
  16873.  
  16874. ΓòÉΓòÉΓòÉ <hidden> Example of Pointers to Members ΓòÉΓòÉΓòÉ
  16875.  
  16876. /************************************************************************
  16877. *
  16878.  
  16879. Pointers to members can be declared and used as shown in the following example: 
  16880.  
  16881.                                     *
  16882. ************************************************************************/
  16883.  
  16884. // This example illustrates pointers to members.
  16885.  
  16886. #include <iostream.h>
  16887. class X
  16888. {
  16889. public:
  16890.    int a;
  16891.    void f(int b)
  16892.    {
  16893.        cout << "The value of b is "<< b << endl;
  16894.    }
  16895. };
  16896. //    .
  16897. //    .
  16898. //    .
  16899. void main ()
  16900. {
  16901.    // declare pointer to data member
  16902.    int X::*ptiptr = &X::a;
  16903.  
  16904.    // declare a pointer to member function
  16905.    void (X::* ptfptr) (int) = &X::f;
  16906.  
  16907.    X xobject;          // create an object of class type X
  16908.    xobject.*ptiptr = 10;    // initialize data member
  16909.  
  16910.    cout << "The value of a is " << xobject.*ptiptr << endl;
  16911.    (xobject.*ptfptr) (20);   // call member function
  16912. }
  16913.  
  16914. /************************************************************************
  16915. *
  16916.  
  16917. The output for this example is: 
  16918.  
  16919. The value of a is 10
  16920. The value of b is 20
  16921.  
  16922.                                     *
  16923. ************************************************************************/
  16924.  
  16925.  
  16926. ΓòÉΓòÉΓòÉ 11.7. The this Pointer ΓòÉΓòÉΓòÉ
  16927.  
  16928. The keyword this identifies a special type of pointer. When a nonstatic member 
  16929. function is called, the this pointer identifies the class object which the 
  16930. member function is operating on. You cannot declare the this pointer or make 
  16931. assignments to it. 
  16932.  
  16933. The type of the this pointer for a member function of a class type X, is X* 
  16934. const. If the member function is declared with the constant qualifier, the type 
  16935. of the this pointer for that member function for class X, is const X* const. If 
  16936. the member function is declared with the volatile qualifier, the type of the 
  16937. this pointer for that member function for class X is volatile X* const. 
  16938.  
  16939. this is passed as a hidden argument to all nonstatic member function calls and 
  16940. is available as a local variable within the body of all nonstatic functions. 
  16941.  
  16942. For example, you can refer to the particular class object that a member 
  16943. function is called for by using the this pointer in the body of the member 
  16944. function. The following code example produces the output a =  5: 
  16945.  
  16946. // This example illustrates the this pointer
  16947.  
  16948. #include <iostream.h>
  16949. class X
  16950. {
  16951.    int a;
  16952. public:
  16953.    // The 'this' pointer is used to retrieve 'xobj.a' hidden by
  16954.    // the automatic variable 'a'
  16955.    void Set_a(int a) { this->a = a; }
  16956.    void Print_a() { cout << "a = " << a << endl; }
  16957. };
  16958. void main()
  16959. {
  16960.    X xobj;
  16961.    int a = 5;
  16962.    xobj.Set_a(a);
  16963.    xobj.Print_a();
  16964. }
  16965.  
  16966. Unless a class member name is hidden, using the class member name is equivalent 
  16967. to using the class member name qualified with the this pointer. 
  16968.  
  16969. Example of the this Pointer 
  16970.  
  16971. Related Information 
  16972.  
  16973.      Pointers 
  16974.      Member Functions 
  16975.      Pointers to Members 
  16976.      C++ Classes 
  16977.  
  16978.  
  16979. ΓòÉΓòÉΓòÉ <hidden> Example of the this Pointer ΓòÉΓòÉΓòÉ
  16980.  
  16981. /************************************************************************
  16982. *
  16983.  
  16984. The following example shows code using class members without the this pointer. 
  16985. The comments on each line show the equivalent code with the hidden use of the 
  16986. this pointer. 
  16987.  
  16988.                                     *
  16989. ************************************************************************/
  16990.  
  16991. // This example uses class members without the this pointer.
  16992.  
  16993. #include <string.h>
  16994. #include <iostream.h>
  16995. class X
  16996. {
  16997.    int len;
  16998.     char *ptr;
  16999. public:
  17000.    int GetLen()      // int GetLen (X* const this)
  17001.    { return len; }    // { return this->len; }
  17002.    char * GetPtr()    // char * GetPtr (X* const this)
  17003.    { return ptr; }    // { return this->ptr; }
  17004.    X& Set(char *);
  17005.    X& Cat(char *);
  17006.    X& Copy(X&);
  17007.    void Print();
  17008. };
  17009.  
  17010. X& X::Set(char *pc)     // X& X::Set(X* const this, char *pc)
  17011. {
  17012.    len = strlen(pc);   // this->len = strlen(pc);
  17013.    ptr = new char[len];  // this->ptr =
  17014.               //  new char[this->len];
  17015.    strcpy(ptr, pc);    // strcpy(this->ptr, pc);
  17016.    return *this;
  17017. }
  17018.  
  17019. X& X::Cat(char *pc)     // X& X::Cat(X* const this, char *pc)
  17020. {
  17021.    len += strlen(pc);   // this->len += strlen(pc);
  17022.    strcat(ptr,pc);    // strcat(this->ptr,pc);
  17023.    return *this;
  17024. }
  17025.  
  17026. X& X::Copy(X& x)       // X& X::Copy(X* const this, X& x)
  17027. {
  17028.    Set(x.GetPtr());    // this->Set(x.GetPtr(&x));
  17029.    return *this;
  17030. }
  17031.  
  17032. void X::Print()       // void X::Print(X* const this)
  17033. {
  17034.    cout << ptr << endl;  // cout << this->ptr << endl;
  17035. }
  17036. void main()
  17037. {
  17038.    X xobj1;
  17039.    xobj1.Set("abcd").Cat("efgh");
  17040.    // xobj1.Set(&xobj1, "abcd").Cat(&xobj1, "efgh");
  17041.  
  17042.    xobj1.Print();     // xobj1.Print(&xobj1);
  17043.    X xobj2;
  17044.    xobj2.Copy(xobj1).Cat("ijkl");
  17045.    // xobj2.Copy(&xobj2, xobj1).Cat(&xobj2, "ijkl");
  17046.  
  17047.    xobj2.Print();     // xobj2.Print(&xobj2);
  17048. }
  17049.  
  17050. /************************************************************************
  17051. *
  17052.  
  17053. This example produces the following output: 
  17054.  
  17055. abcdefgh
  17056. abcdefghijkl
  17057.  
  17058.                                     *
  17059. ************************************************************************/
  17060.  
  17061.  
  17062. ΓòÉΓòÉΓòÉ 11.8. Static Members ΓòÉΓòÉΓòÉ
  17063.  
  17064. Class members can be declared using the storage-class specifier static in the 
  17065. class member list. Only one copy of the static member is shared by all objects 
  17066. of a class in a program. When you declare an object of a class having a static 
  17067. member, the static member is not part of the class object. 
  17068.  
  17069. A typical use of static members is for recording data common to all objects of 
  17070. a class. For example, you can use a static data member as a counter to store 
  17071. the number of objects of a particular class type that are created. Each time a 
  17072. new object is created, this static data member can be incremented to keep track 
  17073. of the total number of objects. 
  17074.  
  17075. The declaration of a static member in the member list of a class is not a 
  17076. definition. The definition of a static member is equivalent to an external 
  17077. variable definition. You must define the static member outside of the class 
  17078. declaration. 
  17079.  
  17080. For example: 
  17081.  
  17082. class X
  17083. {
  17084. public:
  17085.    static int i;
  17086. };
  17087. int X::i = 0; // definition outside class declaration
  17088. //    .
  17089. //    .
  17090. //    .
  17091.  
  17092. A static member can be accessed from outside of its class only if it is 
  17093. declared with the keyword public. You can then access the static member by 
  17094. qualifying the class name using the :: (scope resolution) operator. In the 
  17095. following example: 
  17096.  
  17097. class X
  17098. {
  17099. public:
  17100.    static int f();
  17101. };
  17102. void main ()
  17103. {
  17104.    X::f();
  17105. }
  17106.  
  17107. you can refer to the static member f() of class type X as X::f(). 
  17108.  
  17109. Related Information 
  17110.  
  17111.      static Storage Class Specifier 
  17112.      Using the Class Access Operators with Static Members 
  17113.      Static Data Members 
  17114.      Static Member Functions 
  17115.  
  17116.  
  17117. ΓòÉΓòÉΓòÉ 11.8.1. Using the Class Access Operators with Static Members ΓòÉΓòÉΓòÉ
  17118.  
  17119. You can also access a static member from a class object by using the class 
  17120. access operators . (dot) and -> (arrow). When a static member is accessed 
  17121. through a class access operator, the expression on the left of the . or -> 
  17122. operator is not evaluated. 
  17123.  
  17124. Example of Accessing Static Members 
  17125.  
  17126. A static member can be referred to independently of any association with a 
  17127. class object because there is only one static member shared by all objects of a 
  17128. class. A static member can exist even if no objects of its class have been 
  17129. declared. 
  17130.  
  17131. When you access a static member, the expression that you use to access it is 
  17132. not evaluated. In the following example, the external function f() returns 
  17133. class type X. The function f() can be used to access the static member i of 
  17134. class X. The function f() itself is not called. 
  17135.  
  17136. // This example shows that the expression used to
  17137. // access a static member is not evaluated.
  17138.  
  17139. class X
  17140. {
  17141. public:
  17142.    static int i;
  17143. };
  17144. int X::i = 10;
  17145. X f() { /* ... */ }
  17146. void main ()
  17147. {
  17148.    int a;
  17149.    a = f().i;    // f().i does not call f()
  17150. }
  17151.  
  17152. Related Information 
  17153.  
  17154.      Static Members 
  17155.      Dot Operator . 
  17156.      Arrow Operator -> 
  17157.      Static Data Members 
  17158.      Static Member Functions 
  17159.  x* 
  17160.  
  17161.  
  17162. ΓòÉΓòÉΓòÉ <hidden> Example of Accessing Static Members ΓòÉΓòÉΓòÉ
  17163.  
  17164. /************************************************************************
  17165. *
  17166.  
  17167. The following example uses the class access operators to access static members. 
  17168.  
  17169.                                     *
  17170. ************************************************************************/
  17171.  
  17172. // This example illustrates access to static
  17173. // members with class access operators.
  17174.  
  17175. #include <iostream.h>
  17176. class X
  17177. {
  17178.    static int cnt;
  17179. public:
  17180.    // The following routines all set X's static variable cnt
  17181.    // and print its value.
  17182.    void Set_Show (int i)
  17183.    {    X::cnt = i;
  17184.      cout << "X::cnt = " << X::cnt << endl; }
  17185.    void Set_Show (int i, int j )
  17186.    {    this->cnt = i+j;
  17187.      cout << "X::cnt = " << X::cnt << endl; }
  17188.    void Set_Show (X& x, int i)
  17189.    {    x.cnt = i;
  17190.      cout << "X::cnt = " << X::cnt << endl; }
  17191. };
  17192. int X::cnt;
  17193. void main()
  17194. {
  17195.    X xobj1, xobj2;
  17196.    xobj1.Set_Show(11);
  17197.    xobj1.Set_Show(11,22);
  17198.    xobj1.Set_Show(xobj2, 44);
  17199. }
  17200.  
  17201. /************************************************************************
  17202. *
  17203.  
  17204. The above example produces the following output: 
  17205.  
  17206. X::cnt = 11
  17207. X::cnt = 33
  17208. X::cnt = 44
  17209.  
  17210.                                     *
  17211. ************************************************************************/
  17212.  
  17213.  
  17214. ΓòÉΓòÉΓòÉ 11.8.2. Static Data Members ΓòÉΓòÉΓòÉ
  17215.  
  17216. Static data members of global classes have external linkage and can be 
  17217. initialized in file scope like other global objects. Static data members follow 
  17218. the usual class access rules, except that they can be initialized in file 
  17219. scope. Static data members and their initializers can access other static 
  17220. private and protected members of their class. The initializer for a static data 
  17221. member is in the scope of the class declaring the member. 
  17222.  
  17223. The following example shows how you can initialize static members using other 
  17224. static members, even though these members are private: 
  17225.  
  17226. class C {
  17227.    static int i;
  17228.    static int j;
  17229.    static int k;
  17230.    static int l;
  17231.    static int m;
  17232.    static int n;
  17233.    static int p;
  17234.    static int q;
  17235.    static int r;
  17236.    static int s;
  17237.    static int f() { return 0; }
  17238.    int a;
  17239. public:
  17240.    C() { a = 0; }
  17241.    };
  17242.  
  17243. C c;
  17244. int C::i = C::f();   // initialize with static member function
  17245. int C::j = C::i;    // initialize with another static data member
  17246. int C::k = c.f();   // initialize with member function from an object
  17247. int C::l = c.j;    // initialize with data member from an object
  17248. int C::s = c.a;    // initialize with nonstatic data member
  17249. int C::r = 1;     // initialize with a constant value
  17250.  
  17251. class Y : private C {} y;
  17252.  
  17253. int C::m = Y::f();
  17254. int C::n = Y::r;
  17255. int C::p = y.r;    // error
  17256. int C::q = y.f();   // error
  17257.  
  17258. The initializations of C::p and C::x cause errors because y is an object of a 
  17259. class that is derived privately from C, and its members are not accessible to 
  17260. members of C. 
  17261.  
  17262. You can only have one definition of a static member in a program. If a static 
  17263. data member is not initialized, it is assigned a zero default value. Local 
  17264. classes cannot have static data members. 
  17265.  
  17266. Example of Static Data Members 
  17267.  
  17268. Related Information 
  17269.  
  17270.      Static Member Functions 
  17271.      Static Members 
  17272.      Using the Class Access Operators with Static Members 
  17273.      External Linkage 
  17274.      Member Access 
  17275.      Local Classes 
  17276.  
  17277.  
  17278. ΓòÉΓòÉΓòÉ <hidden> Example of Static Data Members ΓòÉΓòÉΓòÉ
  17279.  
  17280. /************************************************************************
  17281. *
  17282.  
  17283. The following example shows the declaration, initialization, use, and scope of 
  17284. the static data member si and static member functions Set_si(int) and 
  17285. Print_si(). 
  17286.  
  17287.                                     *
  17288. ************************************************************************/
  17289.  
  17290. // This example shows the declaration, initialization,
  17291. // use, and scope of a static data member.
  17292.  
  17293. #include <iostream.h>
  17294. class X
  17295. {
  17296.    int i;
  17297.    static int si;
  17298. public:
  17299.    void Set_i(int i) { this->i = i; }
  17300.    void Print_i() { cout << "i = " << i << endl; }
  17301.    // Equivalent to:
  17302.    // void Print_i(X* this)
  17303.    // { cout << "X::i = " << this->i << endl; }
  17304.    static void Set_si(int si) { X::si = si; }
  17305.  
  17306.    static void Print_si()
  17307.    {
  17308.       cout << "X::si = " << X::si << endl;
  17309.    }
  17310.    // Print_si doesn't have a 'this' pointer
  17311. };
  17312. int X::si = 77;    // Initialize static data member
  17313.  
  17314. void main()
  17315. {
  17316.    X xobj;
  17317.    // Non-static data members and functions belong to specific
  17318.    // instances (here xobj) of class X
  17319.    xobj.Set_i(11);
  17320.    xobj.Print_i();
  17321.  
  17322.     // static data members and functions belong to the class and
  17323.    // can be accessed without using an instance of class X
  17324.    X::Print_si();
  17325.    X::Set_si(22);
  17326.    X::Print_si();
  17327. }
  17328.  
  17329. /************************************************************************
  17330. *
  17331.  
  17332. This example produces the following output: 
  17333.  
  17334. i = 11
  17335. X::si = 77
  17336. X::si = 22
  17337.  
  17338.                                     *
  17339. ************************************************************************/
  17340.  
  17341.  
  17342. ΓòÉΓòÉΓòÉ 11.8.3. Static Member Functions ΓòÉΓòÉΓòÉ
  17343.  
  17344. You cannot have static and nonstatic member functions with the same names and 
  17345. the same number and type of arguments. 
  17346.  
  17347. A static member function does not have a this pointer. You can call a static 
  17348. member function using the this pointer of a nonstatic member function. In the 
  17349. following example, the nonstatic member function printall() calls the static 
  17350. member function f() using the this pointer: 
  17351.  
  17352. // This example illustrates a static member function f().
  17353.  
  17354. #include <iostream.h>
  17355. class c {
  17356.       static void f() { cout << "Here is i"
  17357.                     << i << endl;}
  17358.       static int i;
  17359.       int j;
  17360.    public:
  17361.       c(int firstj): j(firstj) {}
  17362.       void printall();
  17363.       };
  17364. void c::printall() {
  17365.    cout << "Here is j " << this->j << endl;
  17366.    this->f();
  17367.    }
  17368. int c::i = 3;
  17369. void main() {
  17370.    class c C(0);
  17371.    C.printall();
  17372.    }
  17373.  
  17374. A static member function cannot be declared with the keyword virtual. 
  17375.  
  17376. A static member function can access only the names of static members, 
  17377. enumerators, and nested types of the class in which it is declared. 
  17378.  
  17379. Related Information 
  17380.  
  17381.      Member Functions 
  17382.      Using the Class Access Operators with Static Members 
  17383.      Static Data Members 
  17384.      Static Members 
  17385.      The this Pointer 
  17386.      Virtual Functions 
  17387.  
  17388.  
  17389. ΓòÉΓòÉΓòÉ 11.9. Member Access ΓòÉΓòÉΓòÉ
  17390.  
  17391. Member access determines if a class member is accessible in an expression or 
  17392. declaration. Note that accessibility and visibility are independent. Visibility 
  17393. is based on the scoping rules of C++. A class member can be visible and 
  17394. inaccessible at the same time. This section describes how you control the 
  17395. access to the individual nonderived class members by using access specifiers 
  17396. when you declare class members in a member list. 
  17397.  
  17398. Related Information 
  17399.  
  17400.      Access Declarations 
  17401.      Inherited Member Access 
  17402.      Class Member Lists 
  17403.      Classes and Access Control 
  17404.      Access Specifiers 
  17405.      C++ Classes 
  17406.  
  17407.  
  17408. ΓòÉΓòÉΓòÉ 11.9.1. Classes and Access Control ΓòÉΓòÉΓòÉ
  17409.  
  17410. C++ facilitates data abstraction and encapsulation by providing access control 
  17411. for members of class types. 
  17412.  
  17413. For example, if you declare private data members and public member functions, a 
  17414. client program can only access the private members through the public member 
  17415. functions and friends of that class. Such a class would have data hiding 
  17416. because client programs do not have access to implementation details and are 
  17417. forced to use a public interface to manipulate objects of the class. 
  17418.  
  17419. You can control access to class members by using access specifiers. In the 
  17420. following example, the class abc has three private data members a, b, and c, 
  17421. and three public member functions add(), mult(), and the constructor abc(). The 
  17422. main() function creates an object danforth of the abc class and then attempts 
  17423. to print the value of the member a for this object: 
  17424.  
  17425. // This example illustrates class member access specifiers
  17426.  
  17427. #include <iostream.h>
  17428.  
  17429. class abc
  17430. {
  17431. private:
  17432.    int a, b, c;
  17433. public:
  17434.    abc(int p1, int p2, int p3): a(p1), b(p2), c(p3) {}
  17435.    int add() { return a + b + c ; }
  17436.    int mult() { return a * b * c; }
  17437. };
  17438.  
  17439. void main() {
  17440.    abc danforth(1,2,3);
  17441.    cout << "Here is the value of a " << danforth.a << endl;
  17442.          // This causes an error because a is not
  17443.          // a public member and cannot be accessed
  17444.          // directly
  17445.    }
  17446.  
  17447. Because class members are private by default, you can omit the keyword private 
  17448. in the definition of abc. Because a is not a public member, the attempt to 
  17449. access its value directly causes an error. 
  17450.  
  17451. Related Information 
  17452.  
  17453.      Access Declarations 
  17454.      Inherited Member Access 
  17455.      Class Member Lists 
  17456.      Member Access 
  17457.      Access Specifiers 
  17458.      C++ Classes 
  17459.  
  17460.  
  17461. ΓòÉΓòÉΓòÉ 11.9.2. Access Specifiers ΓòÉΓòÉΓòÉ
  17462.  
  17463. The three class member access specifiers have the following effect: 
  17464.  
  17465.  public class members 
  17466.            can be accessed by any function, file or class. 
  17467.  
  17468.  private class members 
  17469.            can be accessed only by member functions and friends of the class in 
  17470.            which the member is declared. 
  17471.  
  17472.  protected class members 
  17473.            can be accessed only by member functions and friends of the class in 
  17474.            which they are declared and by member functions and friends of 
  17475.            classes derived with public or protected access from the class in 
  17476.            which the protected members are declared. The access specifier 
  17477.            protected can be used for nonbase class members, but it is 
  17478.            equivalent to private unless it is used in a base class member 
  17479.            declaration or in a base list. 
  17480.  
  17481.  The default access for an individual class member depends on the class key 
  17482.  used in the class declaration. Members of classes declared with the keyword 
  17483.  class are private by default. Members of classes declared with the keyword 
  17484.  struct or union are public by default. 
  17485.  
  17486.  The access specifier protected is meaningful only in the context of 
  17487.  derivation. You can control the access to inherited members (that is, base 
  17488.  class members) by including access specifiers in the base list of the derived 
  17489.  class declaration. You can also restore the access to an inherited member from 
  17490.  a derived class by using an access declaration. 
  17491.  
  17492.  Access for inherited members is described in Inherited Member Access. 
  17493.  
  17494.  Member lists can include access specifiers as labels. Members declared after 
  17495.  these labels have access as specified by the label they follow. An access 
  17496.  specifier determines the access for members until another access specifier is 
  17497.  used or until the end of the class declaration. You can use any number of 
  17498.  access specifiers in any order. 
  17499.  
  17500.  Examples of Access Specifiers 
  17501.  
  17502.  Related Information 
  17503.  
  17504.      Access Declarations 
  17505.      Inherited Member Access 
  17506.      Class Member Lists 
  17507.      Member Access 
  17508.      Classes and Access Control 
  17509.      C++ Classes 
  17510.  
  17511.  
  17512. ΓòÉΓòÉΓòÉ <hidden> Examples of Access Specifiers ΓòÉΓòÉΓòÉ
  17513.  
  17514. /************************************************************************
  17515. *
  17516.  
  17517. The following example shows access specifiers in member lists. 
  17518.  
  17519.                                     *
  17520. ************************************************************************/
  17521.  
  17522. class X
  17523. {
  17524.    int a;       // private data by default
  17525. public:
  17526.    void f(int);    // public function
  17527.    int b;       // public data
  17528. private:
  17529.    int c;       // private data
  17530. protected:
  17531.    void g(int);    // protected function
  17532. };
  17533. struct Y
  17534. {
  17535.    int a;       // public data by default
  17536. public:
  17537.    int b;       // public data
  17538. private:
  17539.    void g(int);    // private function
  17540.    int c;       // private data
  17541. };
  17542.  
  17543.  
  17544. ΓòÉΓòÉΓòÉ 11.10. Friends ΓòÉΓòÉΓòÉ
  17545.  
  17546. A friend of a class X is a function or class that is granted the same access to 
  17547. X as the members of X. Functions declared with the friend specifier in a class 
  17548. member list are called friend functions of that class. Classes declared with 
  17549. the friend specifier in the member list of another class are called friend 
  17550. classes of that class. 
  17551.  
  17552. A class Y must be defined before any member of Y can be declared a friend of 
  17553. another class. 
  17554.  
  17555. You can declare an entire class as a friend. 
  17556.  
  17557. If the class has not been previously declared, use an elaborated type specifier 
  17558. and a qualified type specifier to specify the class name. 
  17559.  
  17560. If the friend class has been previously declared, you can omit the keyword 
  17561. class, as shown in the following example: 
  17562.  
  17563. class F;
  17564. class X
  17565. {
  17566. public:
  17567.  
  17568.    X() {a=1; b=2;}
  17569. private:
  17570.    int a, b;
  17571.    friend F; // elaborated-type-specifier not required
  17572. };
  17573.  
  17574. Examples of Friends 
  17575.  
  17576. Related Information 
  17577.  
  17578.      Friend Scope 
  17579.      Friend Access 
  17580.      C++ Classes 
  17581.      Member Functions 
  17582.  
  17583.  
  17584. ΓòÉΓòÉΓòÉ <hidden> Example of a friend Function ΓòÉΓòÉΓòÉ
  17585.  
  17586. /************************************************************************
  17587. *
  17588.  
  17589. In the following example, the friend function print is a member of class Y and 
  17590. accesses the private data members a and b of class X. 
  17591.  
  17592.                                     *
  17593. ************************************************************************/
  17594.  
  17595. // This example illustrates a friend function.
  17596.  
  17597. #include <iostream.h>
  17598. class X;
  17599. class Y
  17600. {
  17601. public:
  17602.    void print(X& x);
  17603. };
  17604. class X
  17605. {
  17606. public:
  17607.    X() {a=1; b=2;}
  17608. private:
  17609.    int a, b;
  17610.    friend void Y::print(X& x);
  17611. };
  17612. void Y::print(X& x)
  17613. {
  17614.    cout << "A is "<< x.a << endl;
  17615.    cout << "B is " << x.b << endl;
  17616. }
  17617. void main ()
  17618. {
  17619.    X xobj;
  17620.    Y yobj;
  17621.    yobj.print(xobj);
  17622. }
  17623.  
  17624. /************************************************************************
  17625. *
  17626.  
  17627. In the following example, the friend class F has a member function print that 
  17628. accesses the private data members a and b of class X and performs the same task 
  17629. as the friend function print in the above example. Any other members declared 
  17630. in class F also have access to all members of class X. In the example, the 
  17631. friend class F has not been previously declared, so an elaborated type 
  17632. specifier and a qualified type specifier are used to specify the class name. 
  17633.  
  17634.                                     *
  17635. ************************************************************************/
  17636.  
  17637. // This example illustrates a friend class.
  17638.  
  17639. #include <iostream.h>
  17640. class X
  17641. {
  17642. public:
  17643.  
  17644.    X() {a=1; b=2;}      // constructor
  17645. private:
  17646.    int a, b;
  17647.    friend class F;      // friend class
  17648. };
  17649. class F
  17650. {
  17651. public:
  17652.    void print(X& x)
  17653.    {
  17654.       cout << "A is " << x.a << endl;
  17655.       cout << "B is " << x.b << endl;
  17656.    }
  17657. };
  17658. void main ()
  17659. {
  17660.    X xobj;
  17661.    F fobj;
  17662.    fobj.print(xobj);
  17663. }
  17664.  
  17665. /************************************************************************
  17666. *
  17667.  
  17668. Both the above examples produce the following output: 
  17669.  
  17670. A is 1
  17671. B is 2
  17672.  
  17673.                                     *
  17674. ************************************************************************/
  17675.  
  17676.  
  17677. ΓòÉΓòÉΓòÉ 11.10.1. Friend Scope ΓòÉΓòÉΓòÉ
  17678.  
  17679. The name of a friend function or class first introduced in a friend declaration 
  17680. is not in the scope of the class granting friendship (also called the enclosing 
  17681. class) and is not a member of the class granting friendship. 
  17682.  
  17683. The name of a function first introduced in a friend declaration is in the scope 
  17684. of the first nonclass scope that contains the enclosing class. The body of a 
  17685. function provided in a friend declaration is handled in the same way as a 
  17686. member function defined within a class. Processing of the definition does not 
  17687. start until the end of the outermost enclosing class. In addition, unqualified 
  17688. names in the body of the function definition are searched for starting from the 
  17689. class containing the function definition. 
  17690.  
  17691. A class that is first declared in a friend declaration is equivalent to an 
  17692. extern declaration. For example: 
  17693.  
  17694. class B {};
  17695. class A
  17696. {
  17697.    friend class B; // global class B is a friend of A
  17698. };
  17699.  
  17700. If the name of a friend class has been introduced before the friend 
  17701. declaration, the compiler searches for a class name that matches the name of 
  17702. the friend class beginning at the scope of the friend declaration. If the 
  17703. declaration of a nested class is followed by the declaration of a friend class 
  17704. with the same name, the nested class is a friend of the enclosing class. 
  17705.  
  17706. The scope of a friend class name is the first nonclass enclosing scope. For 
  17707. example: 
  17708.  
  17709. class A {
  17710.   class B { // arbitrary nested class definitions
  17711.    friend class C;
  17712.   };
  17713. };
  17714.  
  17715. is equivalent to: 
  17716.  
  17717. class C;
  17718. class A {
  17719.   class B { // arbitrary nested class definitions
  17720.    friend class C;
  17721.   };
  17722. };
  17723.  
  17724. If the friend function is a member of another class, you need to use the class 
  17725. member access operators. For example: 
  17726.  
  17727. class A
  17728. {
  17729. public:
  17730.    int f() { /* ... */ }
  17731. };
  17732. class B
  17733. {
  17734.    friend int A::f();
  17735. };
  17736.  
  17737. Friends of a base class are not inherited by any classes derived from that base 
  17738. class. 
  17739.  
  17740. Related Information 
  17741.  
  17742.      Scope of Class Names 
  17743.      Friend Access 
  17744.      Friends 
  17745.      Nested Classes 
  17746.      Derivation 
  17747.  
  17748.  
  17749. ΓòÉΓòÉΓòÉ 11.10.2. Friend Access ΓòÉΓòÉΓòÉ
  17750.  
  17751. A friend of a class can access the private and protected members of that class. 
  17752. Normally, you can only access the private members of a class through member 
  17753. functions of that class, and you can only access the protected members of a 
  17754. class through member functions of a class or classes derived from that class. 
  17755.  
  17756. Friend declarations are not affected by access specifiers. 
  17757.  
  17758. Related Information 
  17759.  
  17760.      Member Access 
  17761.      Friend Scope 
  17762.      Friends 
  17763.  
  17764.  
  17765. ΓòÉΓòÉΓòÉ 12. C++ Overloading ΓòÉΓòÉΓòÉ
  17766.  
  17767. Overloading enables you to redefine functions and most standard C++ operators. 
  17768. Typically, you overload a function or operator if you want to extend the 
  17769. operations the function or operator performs to different data types. 
  17770.  
  17771. This section discusses: 
  17772.  
  17773.      Overloading Functions 
  17774.      Argument Matching in Overloaded Functions 
  17775.      Overloading Operators 
  17776.      Overloading Unary Operators 
  17777.      Overloading Binary Operators 
  17778.      Special Overloaded Operators 
  17779.  
  17780.  Related Information 
  17781.  
  17782.      Expressions and Operators 
  17783.      Functions 
  17784.      C++ Classes 
  17785.  
  17786.  
  17787. ΓòÉΓòÉΓòÉ 12.1. Overloading Functions ΓòÉΓòÉΓòÉ
  17788.  
  17789. You can overload a function by having multiple declarations of the same 
  17790. function name in the same scope. The declarations differ in the type and number 
  17791. of arguments in the argument list. When an overloaded function is called, the 
  17792. correct function is selected by comparing the types of the actual arguments 
  17793. with the types of the formal arguments. 
  17794.  
  17795. Consider a function print, which displays an int. As shown in the following 
  17796. example, you can overload the function print to display other types, for 
  17797. example, double and char*. You can have three functions with the same name, 
  17798. each performing a similar operation on a different data type. 
  17799.  
  17800. // This example illustrates function overloading.
  17801.  
  17802. #include <iostream.h>
  17803.  
  17804. void print(int i) { cout << " Here is int " << i << endl; }
  17805. void print(double  f) { cout << " Here is float "
  17806.                  << f << endl; }
  17807. void print(char* c) { cout << " Here is char* " << c << endl; }
  17808. void main() {
  17809.    print(10);       // calls print(int)
  17810.    print(10.10);     // calls print(double)
  17811.    print("ten");     // calls print(char*)
  17812. }
  17813.  
  17814. Two function declarations are identical if all of the following are true: 
  17815.  
  17816.      They have the same function name 
  17817.      They are declared in the same scope 
  17818.      They have identical argument lists 
  17819.  
  17820.  When you declare a function name more than once in the same scope, the second 
  17821.  declaration of the function name is interpreted by the compiler as follows: 
  17822.  
  17823.      If the return type, argument types, and number of arguments of the two 
  17824.       declarations are identical, the second declaration is considered a 
  17825.       declaration of the same function as the first. 
  17826.      If only the return types of the two function declarations differ, the 
  17827.       second declaration is an error. 
  17828.      If either the argument types or number of arguments of the two 
  17829.       declarations differ, the function is considered to be overloaded. 
  17830.  
  17831.  Restrictions on Overloaded Functions 
  17832.  
  17833.  Related Information 
  17834.  
  17835.      Functions 
  17836.      Function Declarations 
  17837.      Scope in C++ 
  17838.      Argument Matching in Overloaded Functions 
  17839.      Member Functions 
  17840.      C++ Inheritance 
  17841.  
  17842.  
  17843. ΓòÉΓòÉΓòÉ <hidden> Restrictions on Overloaded Functions ΓòÉΓòÉΓòÉ
  17844.  
  17845.      Functions that differ only in return type cannot have the same name. 
  17846.  
  17847.      Two member functions that differ only in that one is declared with the 
  17848.       keyword static cannot have the same name. 
  17849.  
  17850.      A typedef is a synonym for another type, not a separate type. The 
  17851.       following two declarations of spadina() are declarations of the same 
  17852.       function: 
  17853.  
  17854.                typedef int I;
  17855.                void spadina(float, int);
  17856.                void spadina(float, I);
  17857.  
  17858.      A member function of a derived class is not in the same scope as a member 
  17859.       function in a base class with the same name. A derived class member hides 
  17860.       a base class member with the same name. 
  17861.  
  17862.      Argument types that differ only in that one is a pointer * and the other 
  17863.       is an array [] are identical. The following two declarations are 
  17864.       equivalent: 
  17865.  
  17866.                f(char*);
  17867.                f(char[10]);
  17868.  
  17869.       Only the second and subsequent array dimensions are significant. 
  17870.  
  17871.      The const and volatile type-specifiers on are ignored in distinguishing 
  17872.       argument types when they appear at the outermost level of the argument 
  17873.       type specification. The following declarations are equivalent: 
  17874.  
  17875.                int f (int);
  17876.                int f (const int);
  17877.                int f (volatile int);
  17878.  
  17879.       Pointers and references to types considered distinct parameter types. 
  17880.  
  17881.  
  17882. ΓòÉΓòÉΓòÉ 12.2. Argument Matching in Overloaded Functions ΓòÉΓòÉΓòÉ
  17883.  
  17884. When an overloaded function or overloaded operator is called, the compiler 
  17885. chooses the function declaration with the best match on all arguments from all 
  17886. the function declarations that are visible. The compiler compares the actual 
  17887. arguments of a function call with the formal arguments of all declarations of 
  17888. the function that are visible. For a best match to occur, the compiler must be 
  17889. able to distinguish a function that: 
  17890.  
  17891.      Has at least as good a match on all arguments as any other function with 
  17892.       the same name 
  17893.      Has at least one better argument match than any other function with the 
  17894.       same name 
  17895.  
  17896.  If no such function exists, the call is not allowed. A call to an overloaded 
  17897.  function has three possible outcomes. The compiler can find: 
  17898.  
  17899.      An exact match 
  17900.      No match 
  17901.      An ambiguous match 
  17902.  
  17903.  An ambiguous match occurs when the actual arguments of the function call match 
  17904.  more than one overloaded function. The ANSI C++ working group has made the 
  17905.  following clarifications of how and which built-in operators should 
  17906.  participate in the operator overload resolution process: 
  17907.  
  17908.      All appropriate built-in operators that are specified in section 13.6 of 
  17909.       the September 1995 ANSI draft participate in the process. 
  17910.  
  17911.      If you are using binary operators with pointer operands, the pointer 
  17912.       operands must point to the same data type. 
  17913.  
  17914.      The compiler distinguishes between integral/arithmetic and promoted 
  17915.       integral/arithmetic type operands. 
  17916.  
  17917.      The compiler only chooses the user-defined operator[] function for the 
  17918.       subscripting expression x[y], if the overload resolution process chooses 
  17919.       it as the best function match over the builtin operator. 
  17920.  
  17921.      For builtin assignment operators, conversions of the left operand are 
  17922.       restricted as follows: 
  17923.  
  17924.         -  No temporary objects are introduced to hold the left operand. 
  17925.         -  No user-defined conversions are applied to achieve a type match with 
  17926.            the left operand. 
  17927.  
  17928.  Argument matching can include performing standard and user-defined conversions 
  17929.  on the arguments to match the actual arguments with the formal arguments. Only 
  17930.  a single user-defined conversion is performed in a sequence of conversions on 
  17931.  an actual argument. In addition, the best-matching sequence of standard 
  17932.  conversions is performed on an actual argument. The best-matching sequence is 
  17933.  the shortest sequence of conversions between two standard types. For example, 
  17934.  the conversion: 
  17935.  
  17936.   int -> float -> double
  17937.  
  17938.  can be shortened to the best-matching conversion sequence: 
  17939.  
  17940.   int -> double
  17941.  
  17942.  because the conversion from int to double is allowed. 
  17943.  
  17944.  Trivial Conversions do not affect the choice of conversion sequence. 
  17945.  Conversion sequences are described in Sequence of Argument Conversions. 
  17946.  
  17947.  Related Information 
  17948.  
  17949.      Sequence of Argument Conversions 
  17950.      Trivial Conversions 
  17951.      Overloading Functions 
  17952.      Overloading Operators 
  17953.  
  17954.  
  17955. ΓòÉΓòÉΓòÉ 12.2.1. Sequence of Argument Conversions ΓòÉΓòÉΓòÉ
  17956.  
  17957. Argument-matching conversions occur in the following order: 
  17958.  
  17959.    1. An exact match in which the actual arguments match exactly (including a 
  17960.       match with one or more trivial conversions) with the type and number of 
  17961.       formal arguments of one declaration of the overloaded function 
  17962.  
  17963.    2. A match with promotions in which a match is found when one or more of the 
  17964.       actual arguments is promoted 
  17965.  
  17966.    3. A match with standard conversions in which a match is found when one or 
  17967.       more of the actual arguments is converted by a standard conversion 
  17968.  
  17969.    4. A match with user-defined conversions in which a match is found when one 
  17970.       or more of the actual arguments is converted by a user-defined conversion 
  17971.  
  17972.    5. A match with ellipses 
  17973.  
  17974.  Match through promotion follows the rules for Integral Promotions and Standard 
  17975.  Type Conversions. 
  17976.  
  17977.  You can override an exact match by using an explicit cast. In the following 
  17978.  example, the second call to f() matches with f(void*): 
  17979.  
  17980.   void f(int);
  17981.   void f(void*);
  17982.   void main()
  17983.   {
  17984.      f(0xaabb);       // matches f(int);
  17985.      f((void*) 0xaabb);   // matches f(void*)
  17986.   }
  17987.  
  17988.  The implicit first argument for a nonstatic member function or operator is the 
  17989.  this pointer. It refers to the class object for which the member function is 
  17990.  called. When you overload a nonstatic member function, the first implicit 
  17991.  argument, the this pointer, is matched with the object or pointer used in the 
  17992.  call to the member function. User-defined conversions are not applied in this 
  17993.  type of argument matching for overloaded functions or operators. 
  17994.  
  17995.  When you call an overloaded member function of class X using the . (dot) or -> 
  17996.  (arrow) operator, the this pointer has type X* const. The type of the this 
  17997.  pointer for a constant object is const X* const. The type of the this pointer 
  17998.  for a volatile object is volatile X* const. 
  17999.  
  18000.  Related Information 
  18001.  
  18002.      Argument Matching in Overloaded Functions 
  18003.      Trivial Conversions 
  18004.      Implicit Type Conversions 
  18005.      User-Defined Conversions 
  18006.      The this Pointer 
  18007.      Overloading Functions 
  18008.      Overloading Operators 
  18009.      Dot Operator . 
  18010.      Arrow Operator -> 
  18011.  
  18012.  
  18013. ΓòÉΓòÉΓòÉ 12.2.2. Trivial Conversions ΓòÉΓòÉΓòÉ
  18014.  
  18015. Functions cannot be distinguished if they have the same name and have arguments 
  18016. that differ only in that one is declared as a reference to a type and the other 
  18017. is that type. You cannot have two functions with the same name and with 
  18018. arguments differing only in this respect. Because the following two 
  18019. declarations cannot be distinguished, the second one causes an error: 
  18020.  
  18021. double f(double i);  // declaration
  18022.  
  18023. double f(double &i); // error
  18024.  
  18025. However, functions with the same name having arguments that differ only in that 
  18026. one is a pointer or reference and the other is a pointer to const or const 
  18027. reference can be distinguished. Functions with the same name having arguments 
  18028. that differ only in that one is a pointer or reference and the other is a 
  18029. pointer to volatile or volatile reference can also be distinguished. For the 
  18030. purpose of finding a best match of arguments, functions that have a volatile or 
  18031. const match (not requiring a trivial conversion) are better than those that 
  18032. have a volatile or const mismatch. 
  18033.  
  18034. Related Information 
  18035.  
  18036.      Argument Matching in Overloaded Functions 
  18037.      Sequence of Argument Conversions 
  18038.      Implicit Type Conversions 
  18039.      User-Defined Conversions 
  18040.      Overloading Functions 
  18041.      Overloading Operators 
  18042.  
  18043.  
  18044. ΓòÉΓòÉΓòÉ 12.3. Overloading Operators ΓòÉΓòÉΓòÉ
  18045.  
  18046. You can overload one of the standard C++ operators by redefining it to perform 
  18047. a particular operation when it is applied to an object of a particular class. 
  18048. Overloaded operators must have at least one argument that has class type. An 
  18049. overloaded operator is called an operator function and is declared with the 
  18050. keyword operator preceding the operator. Overloaded operators are distinct from 
  18051. overloaded functions, but, like overloaded functions, they are distinguished by 
  18052. the number and types of operands used with the operator. 
  18053.  
  18054. You can overload any of the following operators: 
  18055.  
  18056. +   -   *   /   %   ^   &   |   ~
  18057. !   =   <   >   +=   -=   *=   /=   %=
  18058. ^=   &=   |=   <<   >>   <<=  >>=  ==   !=
  18059. <=   >=   &&   ||   ++   --   ,   ->*  ->
  18060. ()   []   new  delete
  18061.  
  18062. where () is the function call operator and [] is the subscript operator. 
  18063.  
  18064. Consider the standard + (plus) operator. When this operator is used with 
  18065. operands of different standard types, the operators have slightly different 
  18066. meanings. For example, the addition of two integers is not implemented in the 
  18067. same way as the addition of two floating-point numbers. C++ allows you to 
  18068. define your own meanings for the standard C++ operators when they are applied 
  18069. to class types. 
  18070.  
  18071. Example of an Overloaded Operator 
  18072.  
  18073. You can overload both the unary and binary forms of: 
  18074.  
  18075.    +    -    *    &
  18076.  
  18077. When an overloaded operator is a member function, the first operand is matched 
  18078. against the class type of the overloaded operator. The second operand, if one 
  18079. exists, is matched against the argument in the overloaded operator call. 
  18080.  
  18081. When an overloaded operator is a nonmember function, at least one operand must 
  18082. have class or enumeration type. The first operand is matched against the first 
  18083. argument in the overloaded operator call. The second operand, if one exists, is 
  18084. matched against the second argument in the overloaded operator call. 
  18085.  
  18086. The argument-matching conventions and rules described in Argument Matching in 
  18087. Overloaded Functions apply to overloaded operators. 
  18088.  
  18089. An overloaded operator must be either a member function, as shown in the 
  18090. following example: 
  18091.  
  18092. class X
  18093. {
  18094. public:
  18095.    X operator!();
  18096.    X& operator =(X&);
  18097.    X operator+(X&);
  18098. };
  18099. X X::operator!() { /* ... */ }
  18100. X& X::operator=(X& x) { /* ... */ }
  18101. X X::operator+(X& x) { /* ... */ }
  18102.  
  18103. or take at least one argument of class, a reference to a class, an enumeration, 
  18104. or a reference to an enumeration, as shown below: 
  18105.  
  18106. class Y;
  18107. {
  18108. //    .
  18109. };
  18110. class Z;
  18111. {
  18112. //    .
  18113. };
  18114. Y operator!(Y& y);
  18115. Z operator+(Z& z, int);
  18116.  
  18117. Usually, overloaded operators are invoked using the normal operator syntax. You 
  18118. can also call overloaded operators explicitly by qualifying the operator name. 
  18119.  
  18120. Restrictions on Overloaded Operators 
  18121.  
  18122. Related Information 
  18123.  
  18124.      Overloading Unary Operators 
  18125.      Overloading Binary Operators 
  18126.      Special Overloaded Operators 
  18127.      Argument Matching in Overloaded Functions 
  18128.      Overloading Functions 
  18129.      Expressions and Operators 
  18130.  
  18131.  
  18132. ΓòÉΓòÉΓòÉ <hidden> Example of an Overloaded Operator ΓòÉΓòÉΓòÉ
  18133.  
  18134. /************************************************************************
  18135. *
  18136.  
  18137. In the following example, a class called complx is defined to model complex 
  18138. numbers, and the + (plus) operator is redefined in this class to add two 
  18139. complex numbers. 
  18140.  
  18141.                                     *
  18142. ************************************************************************/
  18143.  
  18144. // This example illustrates overloading the plus (+) operator.
  18145.  
  18146. #include <iostream.h>
  18147. class complx
  18148. {
  18149.    double real,
  18150.        imag;
  18151. public:
  18152.    complx( double real = 0., double imag = 0.); // constructor
  18153.    complx operator+(const complx&) const;    // operator+()
  18154. };
  18155. // define constructor
  18156. complx::complx( double r, double i )
  18157. {
  18158.    real = r; imag = i;
  18159. }
  18160. // define overloaded + (plus) operator
  18161. complx complx::operator+ (const complx& c) const
  18162. {
  18163.    complx result;
  18164.    result.real = (this->real + c.real);
  18165.    result.imag = (this->imag + c.imag);
  18166.    return result;
  18167. }
  18168. void main()
  18169. {
  18170.    complx x(4,4);
  18171.    complx y(6,6);
  18172.    complx z = x + y; // calls complx::operator+()
  18173. }
  18174.  
  18175. /************************************************************************
  18176. *
  18177.  
  18178. For the class complx, described above, you can call the overloaded + (plus) 
  18179. operator either implicitly or explicitly as shown below. 
  18180.  
  18181.                                     *
  18182. ************************************************************************/
  18183.  
  18184. // This example shows implicit and explicit calls
  18185. // to an overloaded plus (+) operator.
  18186.  
  18187. class complx
  18188. {
  18189.    double real,
  18190.        imag;
  18191. public:
  18192.    complx( double real = 0., double imag = 0.);
  18193.    complx operator+(const complx&) const;
  18194. };
  18195. //    .
  18196. //    .
  18197. //    .
  18198. void main()
  18199. {
  18200.    complx x(4,4);
  18201.    complx y(6,6);
  18202.    complx u = x.operator+(y); // explicit call
  18203.    complx z = x + y;      // implicit call to complx::operator+()
  18204. }
  18205.  
  18206.  
  18207. ΓòÉΓòÉΓòÉ 12.3.1. Restrictions on Overloaded Operators ΓòÉΓòÉΓòÉ
  18208.  
  18209.      The following C++ operators cannot be overloaded: 
  18210.  
  18211.                .    .*    ::    ?:
  18212.  
  18213.      You cannot overload the preprocessing symbols # and ##. 
  18214.  
  18215.      You cannot change the precedence, grouping, or number of operands of the 
  18216.       standard C++ operators. 
  18217.  
  18218.      An overloaded operator (except for the function call operator) cannot 
  18219.       have default arguments or an ellipsis in the argument list. 
  18220.  
  18221.      You must declare the overloaded =, [], () and -> operators as nonstatic 
  18222.       member functions to ensure that they receive lvalues as their first 
  18223.       operands. 
  18224.  
  18225.      The operators new and delete do not follow the general rules described in 
  18226.       this section. Overloading new and delete is described in Overloaded new 
  18227.       and delete. 
  18228.  
  18229.      All operators except the = operator are inherited. Copy by Assignment 
  18230.       describes the behavior of the assignment operator. 
  18231.  
  18232.      Unless they are explicitly mentioned in Special Overloaded Operators, 
  18233.       overloaded unary and binary operators follow the rules outlined in 
  18234.       Overloading Unary Operators and Overloading Binary Operators. 
  18235.  
  18236.  For more information on standard C and C++ operators, see Expressions and 
  18237.  Operators. 
  18238.  
  18239.  
  18240. ΓòÉΓòÉΓòÉ 12.3.2. Overloading Unary Operators ΓòÉΓòÉΓòÉ
  18241.  
  18242. You can overload a prefix unary operator by declaring a nonmember function 
  18243. taking one argument or a nonstatic member function taking no arguments. 
  18244.  
  18245. When you prefix a class object with an overloaded unary operator, for example: 
  18246.  
  18247. class X
  18248. {
  18249. // ...
  18250. };
  18251. void main ()
  18252. {
  18253.    X x;
  18254.    !x;    // overloaded unary operator
  18255. }
  18256.  
  18257. the operator function call !x can be interpreted as:  x.operator!()  or 
  18258. operator!(x) . depending on the declarations of the operator function. If both 
  18259. forms of the operator function have been declared, argument matching determines 
  18260. which interpretation is used. 
  18261.  
  18262. Related Information 
  18263.  
  18264.      Overloading Binary Operators 
  18265.      Overloading Operators 
  18266.      Special Overloaded Operators 
  18267.      Restrictions on Overloaded Operators 
  18268.      Unary Expressions 
  18269.  
  18270.  
  18271. ΓòÉΓòÉΓòÉ 12.3.3. Overloading Binary Operators ΓòÉΓòÉΓòÉ
  18272.  
  18273. You can overload a binary operator by declaring a nonmember function taking two 
  18274. arguments or a nonstatic member function taking one argument. 
  18275.  
  18276. When you use a class object with an overloaded binary operator, for example: 
  18277.  
  18278. class X
  18279. {
  18280. // ...
  18281. };
  18282. void main ()
  18283. {
  18284.    X x;
  18285.    int y=10;
  18286.    x*y;    // overloaded binary operator
  18287. }
  18288.  
  18289. the operator function call x*y can be interpreted as:  x.operator*(y)  or 
  18290. operator*(x,y)  depending on the declarations of the operator function. If both 
  18291. forms of the operator function have been declared, argument matching determines 
  18292. which interpretation is used. 
  18293.  
  18294. Related Information 
  18295.  
  18296.      Overloading Unary Operators 
  18297.      Overloading Operators 
  18298.      Special Overloaded Operators 
  18299.      Restrictions on Overloaded Operators 
  18300.      Binary Expressions 
  18301.  
  18302.  
  18303. ΓòÉΓòÉΓòÉ 12.4. Special Overloaded Operators ΓòÉΓòÉΓòÉ
  18304.  
  18305. The following overloaded operators do not fully follow the rules for unary or 
  18306. binary overloaded operators: 
  18307.  
  18308.      Assignment 
  18309.      Function Call 
  18310.      Subscripting 
  18311.      Class Member Access 
  18312.      Increment and Decrement 
  18313.      new and delete 
  18314.  
  18315.  Related Information 
  18316.  
  18317.      Overloading Unary Operators 
  18318.      Overloading Binary Operators 
  18319.      Overloading Operators 
  18320.      Restrictions on Overloaded Operators 
  18321.      Member Functions 
  18322.  
  18323.  
  18324. ΓòÉΓòÉΓòÉ 12.4.1. Overloaded Assignment ΓòÉΓòÉΓòÉ
  18325.  
  18326. You can only overload an assignment operator by declaring a nonstatic member 
  18327. function. The following example shows how you can overload the assignment 
  18328. operator for a particular class: 
  18329.  
  18330. class X
  18331. {
  18332. public:
  18333.    X();
  18334.    X& operator=(X&);
  18335.    X& operator=(int);
  18336.  
  18337. };
  18338. X& X::operator=(X& x) { /* ... */ }
  18339. X& X::operator=(int i) { /* ... */ }
  18340.  
  18341. void main()
  18342. {
  18343.    X x1, x2;
  18344.    x1 = x2;    // call x1.operator=(x2)
  18345.    x1 = 5;    // call x1.operator=(5)
  18346. }
  18347.  
  18348. You cannot declare an overloaded assignment operator that is a nonmember 
  18349. function. Overloaded assignment operators are not inherited. 
  18350.  
  18351. If a copy assignment operator function is not defined for a class, the copy 
  18352. assignment operator function is defined by default as a memberwise assignment 
  18353. of the class members. If assignment operator functions exist for base classes 
  18354. or class members, these operators are used when the compiler generates default 
  18355. copy assignment operators. See Copy by Assignment for more information. 
  18356.  
  18357. For more information on standard assignment operators, see Assignment 
  18358. Expressions. 
  18359.  
  18360.  
  18361. ΓòÉΓòÉΓòÉ 12.4.2. Overloaded Function Calls ΓòÉΓòÉΓòÉ
  18362.  
  18363. The operands are function_name and an optional expression_list. The operator 
  18364. function operator() must be defined as a nonstatic member function. You cannot 
  18365. declare an overloaded function call operator that is a nonmember function. 
  18366.  
  18367. If you make the following call for the class object x: 
  18368.  
  18369. x (arg1, arg2, arg3)
  18370.  
  18371. it is interpreted as 
  18372.  
  18373. x.operator()(arg1, arg2, arg3)
  18374.  
  18375. Unlike all other overloaded operators, you can provide default arguments and 
  18376. ellipses in the argument list for the function call operator. For example: 
  18377.  
  18378. class X
  18379. {
  18380. public:
  18381.    X& operator() (int = 5);
  18382. };
  18383.  
  18384. For more information on the standard function call operator, see Function 
  18385. Calls ( ). 
  18386.  
  18387.  
  18388. ΓòÉΓòÉΓòÉ 12.4.3. Overloaded Subscripting ΓòÉΓòÉΓòÉ
  18389.  
  18390. An expression containing the subscripting operator has syntax of the form: 
  18391.  
  18392.    identifier [ expression ]
  18393.  
  18394. and is considered a binary operator. The operands are identifier and 
  18395. expression. The operator function operator[] must be defined as a nonstatic 
  18396. member function. You cannot declare an overloaded subscript operator that is a 
  18397. nonmember function. 
  18398.  
  18399. A subscripting expression for the class object x: 
  18400.  
  18401. x [y]
  18402.  
  18403. is interpreted as x.operator[](y). It is not interpreted as operator[](x,y) 
  18404. because it is defined as a nonstatic member function. 
  18405.  
  18406. For more information on the standard subscripting operator, see Array 
  18407. Subscript[ ] (Array Element Specification). 
  18408.  
  18409.  
  18410. ΓòÉΓòÉΓòÉ 12.4.4. Overloaded Class Member Access ΓòÉΓòÉΓòÉ
  18411.  
  18412. An expression containing the class member access -> (arrow) operator has syntax 
  18413. of the form: 
  18414.  
  18415.    identifier -> name-expression
  18416.  
  18417. and is considered a unary operator. The operator function operator->() must be 
  18418. defined as a nonstatic member function. 
  18419.  
  18420. The following restrictions apply to class member access operators: 
  18421.  
  18422.      You cannot declare an overloaded arrow operator that is a nonmember 
  18423.       function. 
  18424.      You cannot overload the class member access . (dot) operator. 
  18425.  
  18426.  Consider the following example of overloading the -> (arrow) operator: 
  18427.  
  18428.   class Y
  18429.   {
  18430.   public:
  18431.      void f();
  18432.   };
  18433.   class X
  18434.   {
  18435.   public:
  18436.      Y* operator->();
  18437.   };
  18438.   X x;
  18439.   x->f();
  18440.  
  18441.  Here x->f() is interpreted as:  ( x.operator->() )-> f() . 
  18442.  
  18443.  x.operator->() must return either a reference to a class object or a class 
  18444.  object for which the overloaded operator-> function is defined or a pointer to 
  18445.  any class. If the overloaded operator-> function returns a class type, the 
  18446.  class type must not be the same as the class declaring the function, and the 
  18447.  class type returned must contain its own definition of an overloaded -> 
  18448.  operator function. 
  18449.  
  18450.  For more information on the standard class member access arrow operator, see 
  18451.  Arrow Operator ->. 
  18452.  
  18453.  
  18454. ΓòÉΓòÉΓòÉ 12.4.5. Overloaded Increment and Decrement ΓòÉΓòÉΓòÉ
  18455.  
  18456. The prefix increment operator ++ can be overloaded for a class type by 
  18457. declaring a nonmember function operator with one argument of class type or a 
  18458. reference to class type, or by declaring a member function operator with no 
  18459. arguments. 
  18460.  
  18461. In the following example, the increment operator is overloaded in both ways: 
  18462.  
  18463. // This example illustrates an overloaded prefix increment operator.
  18464.  
  18465. class X
  18466. {
  18467.    int a;
  18468. public:
  18469.    operator++();    // member prefix increment operator
  18470. };
  18471. class Y { /* ... */ };
  18472. operator++(Y& y);     // nonmember prefix increment operator
  18473.  
  18474. // Definitions of prefix increment operator functions
  18475. // ...
  18476.  
  18477. void main()
  18478. {
  18479.    X x;
  18480.    Y y;
  18481.    ++x;        // x.operator++
  18482.    x.operator++();   // x.operator++
  18483.    operator++(y);   // nonmember operator++
  18484.    ++y;        // nonmember operator++
  18485. }
  18486.  
  18487. The postfix increment operator ++ can be overloaded for a class type by 
  18488. declaring a nonmember function operator operator++() with two arguments, the 
  18489. first having class type and the second having type int. Alternatively, you can 
  18490. declare a member function operator operator++() with one argument having type 
  18491. int. The compiler uses the int argument to distinguish between the prefix and 
  18492. postfix increment operators. For implicit calls, the default value is zero. 
  18493.  
  18494. For example: 
  18495.  
  18496. // This example illustrates an overloaded postfix increment operator.
  18497.  
  18498. class X
  18499. {
  18500.    int a;
  18501. public:
  18502.    operator++(int);  // member postfix increment operator
  18503. };
  18504. operator++(X x, int i);  // nonmember postfix increment operator
  18505.  
  18506. // Definitions of postfix increment operator functions
  18507. // ...
  18508.  
  18509. void main()
  18510. {
  18511.    X x;
  18512.    x++;        // x.operator++
  18513.              // default zero is supplied by compiler
  18514.    x.operator++(0);  // x.operator++
  18515.    operator++(x,0);  // nonmember operator++
  18516. }
  18517.  
  18518. The prefix and postfix decrement operators follow the same rules as their 
  18519. increment counterparts. 
  18520.  
  18521. For more information on the standard postfix and prefix increment operators, 
  18522. see Increment  ++. For more information on the standard postfix and prefix 
  18523. decrement operators, see Decrement  - -. 
  18524.  
  18525.  
  18526. ΓòÉΓòÉΓòÉ 12.4.6. Overloaded new and delete ΓòÉΓòÉΓòÉ
  18527.  
  18528. You can implement your own memory management scheme for a class by overloading 
  18529. the operators new and delete. The overloaded operator new must return a void*, 
  18530. and its first argument must have type size_t. The overloaded operator delete 
  18531. must return a void type, and its first argument must be void*. The second 
  18532. argument for the overloaded delete operator is optional and, if present, it 
  18533. must have type size_t. You can only define one delete operator function for a 
  18534. class. 
  18535.  
  18536. Type size_t is an implementation dependent unsigned integral type defined in 
  18537. <stddef.h>. For more information about size_t, see the IBM VisualAge for C++ 
  18538. for Windows User's Guide. 
  18539.  
  18540. The size argument is required because a class can inherit an overloaded new 
  18541. operator. The derived class can be a different size than the base class. The 
  18542. size argument ensures that the correct amount of storage space is allocated or 
  18543. deallocated for the object. 
  18544.  
  18545. When new and delete are overloaded within a class declaration, they are static 
  18546. member functions whether they are declared with the keyword static or not. They 
  18547. cannot be virtual functions. 
  18548.  
  18549. You can access the standard, nonoverloaded versions of new and delete within a 
  18550. class scope containing the overloading new and delete operators by using the :: 
  18551. (scope resolution) operator to provide global access. 
  18552.  
  18553. For more information on the class member operators new and delete, see Free 
  18554. Store. For more information on the standard new and delete operators, see C++ 
  18555. new Operator and C++ delete Operator. 
  18556.  
  18557.  
  18558. ΓòÉΓòÉΓòÉ 13. Special C++ Member Functions ΓòÉΓòÉΓòÉ
  18559.  
  18560. This chapter introduces the special member functions that are used to create, 
  18561. destroy, convert, initialize, and copy class objects. This chapter discusses: 
  18562.  
  18563.      Constructors 
  18564.      Destructors 
  18565.      Free Store 
  18566.      Temporary Objects 
  18567.      User-Defined Conversions 
  18568.      Initialization by Constructor 
  18569.      Copying Class Objects 
  18570.  
  18571.  Related Information 
  18572.  
  18573.      Functions 
  18574.      C++ Classes 
  18575.      C++ Class Members and Friends 
  18576.      C++ Overloading 
  18577.      C++ Inheritance 
  18578.  
  18579.  
  18580. ΓòÉΓòÉΓòÉ 13.1. Constructors and Destructors Overview ΓòÉΓòÉΓòÉ
  18581.  
  18582. Because classes have complicated internal structures, including data and 
  18583. functions, object initialization and cleanup for classes is much more 
  18584. complicated than it is for simple data structures. Constructors and destructors 
  18585. are special member functions of classes that are used to construct and destroy 
  18586. class objects. Construction may involve memory allocation and initialization 
  18587. for objects. Destruction may involve cleanup and deallocation of memory for 
  18588. objects. 
  18589.  
  18590. Like other member functions, constructors and destructors are declared within a 
  18591. class declaration. They can be defined inline or external to the class 
  18592. declaration. Constructors can have default arguments. Unlike other member 
  18593. functions, constructors can have member initialization lists. The following 
  18594. restrictions apply to constructors and destructors: 
  18595.  
  18596.      Constructors and destructors do not have return types nor can they return 
  18597.       values. 
  18598.      References and pointers cannot be used on constructors and destructors 
  18599.       because their addresses cannot be taken. 
  18600.      Constructors cannot be declared with the keyword virtual. 
  18601.      Constructors and destructors cannot be declared static, const, or 
  18602.       volatile. 
  18603.      Unions cannot contain class objects that have constructors or 
  18604.       destructors. 
  18605.  
  18606.  Constructors and destructors obey the same access rules as member functions. 
  18607.  For example, if a constructor is declared with the keyword protected, only 
  18608.  derived classes and friends can use it to create class objects. Class member 
  18609.  access is described in Member Access. 
  18610.  
  18611.  The compiler automatically calls constructors when defining class objects and 
  18612.  calls destructors when class objects go out of scope. A constructor does not 
  18613.  allocate memory for the class object its this pointer refers to, but may 
  18614.  allocate storage for more objects than its class object refers to. If memory 
  18615.  allocation is required for objects, constructors can explicitly call the new 
  18616.  operator. During cleanup, a destructor may release objects allocated by the 
  18617.  corresponding constructor. To release objects, use the delete operator. 
  18618.  
  18619.  Derived classes do not inherit constructors or destructors from their base 
  18620.  classes, but they do call the constructor and destructor of base classes. 
  18621.  Destructors can be declared with the keyword virtual. 
  18622.  
  18623.  Constructors are also called when local or temporary class objects are 
  18624.  created, and destructors are called when local or temporary objects go out of 
  18625.  scope. 
  18626.  
  18627.  You can call member functions from constructors or destructors. You can call a 
  18628.  virtual function, either directly or indirectly, from a constructor or 
  18629.  destructor. In this case, the function called is the one defined in the class 
  18630.  or base class containing the constructor (or destructor), but not a function 
  18631.  defined in any class derived from the class being constructed. This avoids the 
  18632.  possibility of accessing an unconstructed object from a constructor or 
  18633.  destructor. 
  18634.  
  18635.  The typeid and dynamic_cast operators for runtime type identification (RTTI) 
  18636.  can be used in constructors or destructors, or in functions called from a 
  18637.  constructor or destructor. 
  18638.  
  18639.  If the operand of typeid used refers to an object under construction or 
  18640.  destruction, typeid returns the type_info representing the class of the 
  18641.  constructor or destructor. 
  18642.  
  18643.  If the operand of dynamic_cast refers to an object under construction or 
  18644.  destruction, the object is considered to be a complete object that has the 
  18645.  type of the constructor or destructor's class. 
  18646.  
  18647.  The result of the typeid and dynamic_cast operations is undefined if the 
  18648.  operand refers to an object under construction or destruction, and the static 
  18649.  type of the operand is not an object of the constructor or destructor's class 
  18650.  or one of its bases. 
  18651.  
  18652.  Related Information 
  18653.  
  18654.      Constructors 
  18655.      Destructors 
  18656.      Virtual Functions 
  18657.      Member Access 
  18658.      C++ new Operator 
  18659.      C++ delete Operator 
  18660.      dynamic_cast<>() 
  18661.      typeid() 
  18662.      Inheritance Overview 
  18663.      Virtual Functions 
  18664.      Unary Expressions 
  18665.  
  18666.  
  18667. ΓòÉΓòÉΓòÉ 13.1.1. Constructors ΓòÉΓòÉΓòÉ
  18668.  
  18669. A constructor is a member function with the same name as its class. For 
  18670. example: 
  18671.  
  18672. class X
  18673. {
  18674. public:
  18675.    X();    // constructor for class X
  18676. };
  18677.  
  18678. Constructors are used to create, and can initialize, objects of their class 
  18679. type. Initialization of class objects using constructors is described in 
  18680. Initialization by Constructor. 
  18681.  
  18682. A default constructor is a constructor that either has no arguments, or, if it 
  18683. has arguments, all the arguments have default values. If no user-defined 
  18684. constructor exists for a class and one is needed, the compiler creates a 
  18685. default constructor, with public access, for that class. No default constructor 
  18686. is created for a class that has any constant or reference type members. 
  18687.  
  18688. Like all functions, a constructor can have default arguments. They are used to 
  18689. initialize member objects. If default values are supplied, the trailing 
  18690. arguments can be omitted in the expression list of the constructor. Note that 
  18691. if a constructor has any arguments that do not have default values, it is not a 
  18692. default constructor. 
  18693.  
  18694. A copy constructor is used to make a copy of one class object from another 
  18695. class object of the same class type. A copy constructor is called with a single 
  18696. argument that is a reference to its own class type. You cannot use a copy 
  18697. constructor with an argument of the same type as its class; you must use a 
  18698. reference. You can provide copy constructors with additional default arguments. 
  18699. If a user-defined copy constructor does not exist for a class and one is 
  18700. needed, the compiler creates a copy constructor, with public access, for that 
  18701. class. It is not created for a class if any of its members or base classes have 
  18702. an inaccessible copy constructor. 
  18703.  
  18704. If a class has a base class or members with constructors when it is 
  18705. constructed, the constructor for the base class is called, followed by any 
  18706. constructors for members. The constructor for the derived class is called last. 
  18707. Virtual base classes are constructed before nonvirtual base classes. When more 
  18708. than one base class exists, the base class constructors are called in the order 
  18709. that their classes appear in the base list. For more information, see 
  18710. Construction Order of Derived Class Objects. 
  18711.  
  18712. Examples of Constructors and Construction Order 
  18713.  
  18714. You cannot call constructors directly. You use a function style cast to 
  18715. explicitly construct an object of the specified type. 
  18716.  
  18717. Example of Explicitly Constructing an Object 
  18718.  
  18719. Related Information 
  18720.  
  18721.      Destructors 
  18722.      Constructors and Destructors Overview 
  18723.      Construction Order of Derived Class Objects 
  18724.      Default Arguments in C++ Functions 
  18725.      References 
  18726.  
  18727.  
  18728. ΓòÉΓòÉΓòÉ <hidden> Example of Explicitly Constructing an Object ΓòÉΓòÉΓòÉ
  18729.  
  18730. /************************************************************************
  18731. *
  18732.  
  18733. In the following example, a constructor is used as an initializer to create a 
  18734. named object. 
  18735.  
  18736.                                     *
  18737. ************************************************************************/
  18738.  
  18739. #include <iostream.h>
  18740. class X
  18741. {
  18742. public:
  18743.  
  18744.    X (int, int , int = 0);  // constructor with default argument
  18745. private:
  18746.    int a, b, c;
  18747.    int f();
  18748. };
  18749. X::X (int i, int j, int k) { a = i; b = j; c = k; }
  18750.  
  18751. void main ()
  18752. {
  18753. X xobject = X(1,2,3);   // explicitly create and initialize
  18754.              // named object with constructor call
  18755. }
  18756.  
  18757.  
  18758. ΓòÉΓòÉΓòÉ <hidden> Examples of Constructors and Construction Order ΓòÉΓòÉΓòÉ
  18759.  
  18760. /************************************************************************
  18761. *
  18762.  
  18763. The following code fragment shows two classes with constructors, default 
  18764. constructors, and copy constructors: 
  18765.  
  18766. class X
  18767. {
  18768. public:
  18769.    X();           // default constructor, no arguments
  18770.    X(int, int , int = 0);  // constructor
  18771.    X(const X&);       // copy constructor
  18772.    X(X);           // error, incorrect argument type
  18773. };
  18774. class Y
  18775. {
  18776. public:
  18777.    Y( int = 0);       // default constructor with one
  18778.                // default argument
  18779.    Y(const Y&, int = 0);  // copy constructor
  18780. };
  18781.  
  18782. When more than one base class exists, the base class constructors are called in 
  18783. the order that their classes appear in the base list, as shown in the following 
  18784. example: 
  18785.  
  18786.                                     *
  18787. ************************************************************************/
  18788.  
  18789. class B1 { public: B1(); };
  18790. class B2
  18791. {
  18792. public:
  18793.    B2();
  18794.    B1 b1obj;
  18795. };
  18796. class B3 { public: B3(); };
  18797. // ...
  18798. class D : public B1, public B2, public B3
  18799. {
  18800. public:
  18801.    D();
  18802.    ~D();
  18803. };
  18804.  
  18805. void main ()
  18806. {
  18807.    D object;
  18808. }
  18809.  
  18810. /************************************************************************
  18811. *
  18812.  
  18813. In the above example, the constructors for object are called in the following 
  18814. order: 
  18815.  
  18816. B1();    // first base constructor declared
  18817. B1();    // member constructor for B2::b1obj
  18818. B2();    // second base constructor declared
  18819. B3();    // last base constructor declared
  18820. D();    // derived constructor called last
  18821.  
  18822. Note that the construction of class D involves construction of the base classes 
  18823. B1, B2, and B3. The construction of base class B2 involves the construction of 
  18824. its class B1 member object. When class B2 is constructed, the constructor for 
  18825. class B1 is called in addition to B2's own constructor. 
  18826.  
  18827. As explained above, the second call to the constructor of B1 followed by the 
  18828. call to the constructor of B2 is part of the construction of B2. 
  18829.  
  18830.                                     *
  18831. ************************************************************************/
  18832.  
  18833.  
  18834. ΓòÉΓòÉΓòÉ 13.1.2. Destructors ΓòÉΓòÉΓòÉ
  18835.  
  18836. A destructor is a member function with the same name as its class prefixed by a 
  18837. ~ (tilde). 
  18838.  
  18839. For example: 
  18840.  
  18841. class X
  18842. {
  18843. public:
  18844.    X();    // constructor for class X
  18845.    ~X();    // destructor for class X
  18846. };
  18847.  
  18848. A destructor takes no arguments and has no return type. Its address cannot be 
  18849. taken. Destructors cannot be declared const, volatile, or static. A destructor 
  18850. can be declared virtual or pure virtual. A union cannot have as a member an 
  18851. object of a class with a destructor. 
  18852.  
  18853. Destructors are usually used to deallocate memory and do other cleanup for a 
  18854. class object and its class members when the object is destroyed. A destructor 
  18855. is called for a class object when that object passes out of scope or is 
  18856. explicitly deleted. 
  18857.  
  18858. Class members that are class types can have their own destructors. Both base 
  18859. and derived classes can have destructors, although destructors are not 
  18860. inherited. If a base class or a member of a base class has a destructor and a 
  18861. class derived from that base class does not declare a destructor, a default 
  18862. destructor is generated. The default destructor calls the destructors of the 
  18863. base class and members of the derived class. Default destructors are generated 
  18864. with default public access. 
  18865.  
  18866. Destructors are called in the reverse order to constructors: 
  18867.  
  18868.    1. The destructor for a class object is called before destructors for 
  18869.       members and bases are called. 
  18870.    2. Destructors for nonstatic members are called before destructors for base 
  18871.       classes are called. 
  18872.    3. Destructors for nonvirtual base classes are called before destructors for 
  18873.       virtual base classes are called. 
  18874.  
  18875.  When an exception is thrown for a class object with a destructor, the 
  18876.  destructor for the temporary object thrown is not called until control passes 
  18877.  out of the catch block. For more information, see Constructors and Destructors 
  18878.  in Exception Handling. 
  18879.  
  18880.  Destructors are implicitly called when an automatic or temporary object passes 
  18881.  out of scope. They are implicitly called at program termination for 
  18882.  constructed external and static objects. Destructors are invoked when you use 
  18883.  the delete operator for objects created with the new operator. 
  18884.  
  18885.  Example of Destructors 
  18886.  
  18887.  You can use a destructor explicitly to destroy objects, although this practice 
  18888.  is not recommended. If an object has been placed at a specific address by the 
  18889.  new operator, you can call the destructor of the object explicitly to destroy 
  18890.  it. An explicitly called destructor cannot delete storage. 
  18891.  
  18892.  Note:  You can only call destructors for class types. You cannot call 
  18893.  destructors for simple types. The call to the destructor in the following 
  18894.  example causes the compiler to issue a warning: 
  18895.  
  18896.      int * ptr;
  18897.      ptr -> int::~int(); // warning
  18898.  
  18899.  Related Information 
  18900.  
  18901.      Constructors and Destructors Overview 
  18902.      Constructors 
  18903.      Virtual Functions 
  18904.      Constructors and Destructors in Exception Handling 
  18905.      C++ new Operator 
  18906.      C++ delete Operator 
  18907.  
  18908.  
  18909. ΓòÉΓòÉΓòÉ <hidden> Example of Destructors ΓòÉΓòÉΓòÉ
  18910.  
  18911. /***********************************************************************
  18912. *
  18913.  
  18914. The following example shows the use of destructors: 
  18915.  
  18916.                                     *
  18917. ************************************************************************/
  18918.  
  18919. #include <string.h>
  18920. class Y
  18921. {
  18922. private:
  18923.    char * string;
  18924.    int number;
  18925. public:
  18926.    Y(const char* n,int a);  // constructor
  18927.    ~Y() { delete[] string; } // destructor
  18928. };
  18929. Y::Y(const char* n, int a)    // define class Y constructor
  18930. {
  18931.    string = strcpy(new char[strlen(n) + 1 ], n);
  18932.    number = a;
  18933. }
  18934. void main ()
  18935. {
  18936.    Y yobj = Y("somestring", 10); // create and initialize
  18937.                   // object of class Y
  18938. // ...
  18939. // destructor ~Y is called before control returns from main()
  18940. }
  18941.  
  18942.  
  18943. ΓòÉΓòÉΓòÉ 13.2. Free Store ΓòÉΓòÉΓòÉ
  18944.  
  18945. Free store is used for dynamic allocation of memory. The new and delete 
  18946. operators are used to allocate and deallocate free store, respectively. You can 
  18947. define your own versions of new and delete for a class by overloading them. You 
  18948. can supply the new and delete operators with additional arguments. You can also 
  18949. use the /Tm option to enable the debug versions of these operators. See Debug 
  18950. Versions of new and delete for more information on these versions. When new and 
  18951. delete operate on class objects, the class member operator functions new and 
  18952. delete are called, if they have been declared. 
  18953.  
  18954. If you create a class object with the new operator, one of the operator 
  18955. functions operator new() or operator new[]() (if they have been declared) is 
  18956. called to create the object. An operator new() or operator new[]() for a class 
  18957. is always a static class member, even if it is not declared with the keyword 
  18958. static. It has a return type void* and its first argument must be the size of 
  18959. the object type and have type size_t. It cannot be virtual. 
  18960.  
  18961. Type size_t is an implementation dependent unsigned integral type defined in 
  18962. <stddef.h>. For more information about size_t, see the IBM VisualAge for C++ 
  18963. for Windows User's Guide. 
  18964.  
  18965. When you overload the new operator, you must declare it as a class member, 
  18966. returning type void*, with first argument size_t, as described above. You 
  18967. supply additional arguments in the declaration of operator new() or operator 
  18968. new[](). Use the placement syntax to specify values for these arguments in an 
  18969. allocation expression. 
  18970.  
  18971. The delete operator destroys an object created by the new operator. The operand 
  18972. of delete must be a pointer returned by new. If delete is called for an object 
  18973. with a destructor, the destructor is invoked before the object is deallocated. 
  18974.  
  18975. If you destroy a class object with the delete operator, the operator function 
  18976. operator delete() or operator delete[]() (if they have been declared) is called 
  18977. to destroy the object. An operator delete() or operator delete[]() for a class 
  18978. is always a static member, even if it is not declared with the keyword static. 
  18979. Its first argument must have type void*. Because operator delete() and operator 
  18980. delete[]() have a return type void, they cannot return a value. They cannot be 
  18981. virtual. 
  18982.  
  18983. When you overload the delete operator, you must declare it as class member, 
  18984. returning type void, with first argument having type void*, as described above. 
  18985. You can add a second argument of type size_t to the declaration. You can only 
  18986. have one operator delete() or operator delete[]() for a single class. 
  18987.  
  18988. Examples of operator new() and operator delete() 
  18989.  
  18990. The result of trying to access a deleted object is undefined because the value 
  18991. of the object can change after deletion. 
  18992.  
  18993. If new and delete are called for a class object that does not declare the 
  18994. operator functions new and delete, or they are called for a nonclass object, 
  18995. the global operators new and delete are used. The global operators new and 
  18996. delete are provided in the C++ library. 
  18997.  
  18998. Note:  The C++ operators for allocating and deallocating arrays of class 
  18999. objects are operator new[]() and operator delete[](). 
  19000.  
  19001. Related Information 
  19002.  
  19003.      C++ new Operator 
  19004.      C++ delete Operator 
  19005.      Overloaded new and delete 
  19006.      Debug Versions of new and delete 
  19007.  
  19008.  
  19009. ΓòÉΓòÉΓòÉ <hidden> Examples of operators new() and delete() ΓòÉΓòÉΓòÉ
  19010.  
  19011. /************************************************************************
  19012. *
  19013.  
  19014. The following example shows two overloaded new operator functions. 
  19015.  
  19016.                                     *
  19017. ************************************************************************/
  19018.  
  19019. #include <stddef.h>
  19020. class X
  19021. {
  19022. public:
  19023.    void* operator new(size_t);
  19024.    void* operator new(size_t, int);
  19025. };
  19026.  
  19027. void main ()
  19028. {
  19029.    X* ptr1 = new X;     // calls X::operator new(sizeof(X))
  19030.    X* ptr2 = new(10) X;   // calls X::operator
  19031.                // new(sizeof(X),10)
  19032. }
  19033.  
  19034. /************************************************************************
  19035. *
  19036.  
  19037. The following example shows the declaration and use of the operator functions 
  19038. operator new() and operator delete(): 
  19039.  
  19040.                                     *
  19041. ************************************************************************/
  19042.  
  19043. #include <stddef.h>
  19044. class X
  19045. {
  19046. public:
  19047.    void* operator new(size_t);
  19048.    void operator delete(void*);     // single argument
  19049. };
  19050. class Y
  19051. {
  19052. public:
  19053.    void operator delete(void*, size_t); // two arguments
  19054. };
  19055.  
  19056. void main ()
  19057. {
  19058.    X* ptr = new X;
  19059.    delete ptr;    // call X::operator delete(void*)
  19060.    Y* yptr;
  19061. // ...
  19062.    delete yptr;   // call Y::operator delete(void*, size_t)
  19063.             // with size of Y as second argument
  19064. }
  19065.  
  19066.  
  19067. ΓòÉΓòÉΓòÉ <hidden> Debug Versions of new and delete ΓòÉΓòÉΓòÉ
  19068.  
  19069. VisualAge for C++ provides special versions of new and delete to assist you in 
  19070. debugging memory management problems. These versions can help you find where 
  19071. memory is being incorrectly allocated, written to, or freed. 
  19072.  
  19073. To enable the debug memory management functions, use the /Tm option, which also 
  19074. defines the macro __DEBUG_ALLOC__. The debug versions of new and delete, as 
  19075. well as of the C library functions (malloc and so on), are automatically called 
  19076. in place of the regular functions in your code. Do not parenthesize any calls 
  19077. to these functions, because parentheses disable the definition of the function 
  19078. name to the debug function name. 
  19079.  
  19080. To each call to new, the compiler adds 2 parameters equivalent to the current 
  19081. __FILE__ and __LINE__ macros. They are inserted as the first two parameters in 
  19082. the placement syntax. As a result, the global and class-specific versions of 
  19083. operator new change from: 
  19084.  
  19085.   operator new(size_t);
  19086.   operator new(size_t , additional_parameters );
  19087. to: 
  19088.  
  19089.   operator new(size_t, const char *, size_t);
  19090.   operator new(size_t, const char *, size_t , additional_parameters );
  19091.  
  19092. The compiler adds the same parameters to each delete call, changing all global 
  19093. and class-specific versions of delete from: 
  19094.  
  19095.   operator delete(void *);
  19096.   operator delete(void * , size_t );
  19097. to: 
  19098.  
  19099.   operator delete(void *, const char *, size_t);
  19100.   operator delete(void *, const char *, size_t , size_t );
  19101.  
  19102. The debug versions also automatically call the C library function _heap_check. 
  19103. This function checks all memory blocks allocated or freed by debug memory 
  19104. management functions to make sure that no overwriting has occurred outside the 
  19105. bounds of allocated blocks or in a free memory block. You can also call 
  19106. _heap_check explicitly. 
  19107.  
  19108. You can also call the C library function _dump_allocated to print out 
  19109. information about each memory block currently allocated by the debug memory 
  19110. management functions. Both _heap_check and _dump_allocated are only available 
  19111. when the __DEBUG_ALLOC__ macro is defined. They are described in the IBM 
  19112. VisualAge for C++ for Windows C Library Reference. 
  19113.  
  19114. All output from these functions is sent to stderr. 
  19115.  
  19116. Note:  The information provided by these functions is Diagnosis, Modification, 
  19117.        and Tuning information only. It is not intended to be used as a 
  19118.        programming interface. 
  19119.  
  19120.  You may need to include the <new.h> header file to include the prototypes of 
  19121.  the debug malloc and free code that the debug versions of new and delete use. 
  19122.  
  19123.  Important  The changes described above take place for all occurrences of new 
  19124.  and delete whether global or specific to a class. If you have provided member 
  19125.  new or delete functions, you must make code changes before compiling with /Tm. 
  19126.  You can use the __DEBUG_ALLOC__ macro for conditional compilation. 
  19127.  
  19128.  For more information on debug memory management functions in the C library, 
  19129.  see the IBM VisualAge for C++ for Windows C Library Reference. 
  19130.  
  19131.  
  19132. ΓòÉΓòÉΓòÉ 13.3. Temporary Objects ΓòÉΓòÉΓòÉ
  19133.  
  19134. It is sometimes necessary for the compiler to create temporary objects. They 
  19135. are used during reference initialization and during evaluation of expressions 
  19136. including standard type conversions, argument passing, function returns, and 
  19137. evaluation of the throw expression. 
  19138.  
  19139. When a temporary object is created to initialize a reference variable, the name 
  19140. of the temporary object has the same scope as that of the reference variable. 
  19141. When a temporary object is created during the evaluation of an expression, it 
  19142. exists until there is a break in the flow of control of the program. 
  19143.  
  19144. If a temporary object is created for a class with constructors, the compiler 
  19145. calls the appropriate (matching) constructor to create the temporary object. 
  19146.  
  19147. When a temporary object is destroyed and a destructor exists, the compiler 
  19148. calls the destructor to destroy the temporary object. When you exit from the 
  19149. scope in which the temporary object was created, it is destroyed. If a 
  19150. reference is bound to a temporary object, the temporary object is destroyed 
  19151. when the reference passes out of scope unless it is destroyed earlier by a 
  19152. break in the flow of control. For example, a temporary object created by a 
  19153. constructor initializer for a reference member is destroyed on leaving the 
  19154. contructor. 
  19155.  
  19156. Examples of Temporary Objects 
  19157.  
  19158. Use the /Wgnr option to flag the points where temporary objects are generated. 
  19159.  
  19160. Related Information 
  19161.  
  19162.      Constructors 
  19163.      Destructors 
  19164.      References 
  19165.      Initializing References 
  19166.      Expressions and Operators 
  19167.      Functions 
  19168.      Using Exception Handling 
  19169.  
  19170.  
  19171. ΓòÉΓòÉΓòÉ <hidden> Examples of Temporary Objects ΓòÉΓòÉΓòÉ
  19172.  
  19173. /************************************************************************
  19174. *
  19175.  
  19176. The following example shows two expressions in which temporary objects are 
  19177. constructed: 
  19178.  
  19179.                                     *
  19180. ************************************************************************/
  19181.  
  19182. class Y
  19183. {
  19184. public:
  19185.    Y(int)={ };
  19186.    Y(Y&)={ };
  19187.    ~Y()={ };
  19188. };
  19189. Y add(Y y) { return y; }
  19190.  
  19191. void main ()
  19192. {
  19193.    Y obj1(10);
  19194.    Y obj2 = add(Y(5));    // one temporary created
  19195.    obj1 = add(obj1);     // two temporaries created
  19196. }
  19197.  
  19198. /************************************************************************
  19199. *
  19200.  
  19201. In the above example, a temporary object of class type Y is created to 
  19202. construct Y(5) before it is passed to the function add(). Because obj2 is being 
  19203. constructed, the function add() can construct its return value directly into 
  19204. obj2, so another temporary object is not created. A temporary object of class 
  19205. type Y is created when obj1 is passed to the function add(). Because obj1 has 
  19206. already been constructed, the function add() constructs its return value into a 
  19207. temporary object. This second temporary object is then assigned to obj1 using 
  19208. an assignment operator. 
  19209.  
  19210.                                     *
  19211. ************************************************************************/
  19212.  
  19213.  
  19214. ΓòÉΓòÉΓòÉ 13.4. User-Defined Conversions ΓòÉΓòÉΓòÉ
  19215.  
  19216. User-defined conversions allow you to specify object conversions with 
  19217. constructors or with conversion functions. User-defined conversions are 
  19218. implicitly used in addition to standard conversions for conversion of 
  19219. initializers, functions arguments, function return values, expression operands, 
  19220. expressions controlling iteration, selection statements, and explicit type 
  19221. conversions. 
  19222.  
  19223. There are two types of user-defined conversions: 
  19224.  
  19225.      Conversion by constructor 
  19226.      Conversion functions. 
  19227.  
  19228.  Related Information 
  19229.  
  19230.      Implicit Type Conversions 
  19231.      Constructors and Destructors Overview 
  19232.      Constructors 
  19233.      C++ Classes 
  19234.      Functions 
  19235.  
  19236.  
  19237. ΓòÉΓòÉΓòÉ 13.4.1. Conversion by Constructor ΓòÉΓòÉΓòÉ
  19238.  
  19239. You can call a class constructor with a single argument to convert from the 
  19240. argument type to the type of the class. 
  19241.  
  19242. At most one user-defined conversion, either a constructor or conversion 
  19243. function, is implicitly applied to a class object. When you call a constructor 
  19244. with an argument and you have not defined a constructor accepting that argument 
  19245. type, only standard conversions are used to convert the argument to another 
  19246. argument type acceptable to a constructor for that class. No other constructors 
  19247. or conversions functions are called to convert the argument to a type 
  19248. acceptable to a constructor defined for that class. 
  19249.  
  19250. Example of Conversion by Constructor 
  19251.  
  19252. Related Information 
  19253.  
  19254.      Conversion Functions 
  19255.      Constructors and Destructors Overview 
  19256.      Constructors 
  19257.      User-Defined Conversions 
  19258.      Implicit Type Conversions 
  19259.  
  19260.  
  19261. ΓòÉΓòÉΓòÉ <hidden> Example of Conversion by Constructor ΓòÉΓòÉΓòÉ
  19262.  
  19263. /************************************************************************
  19264. *
  19265.  
  19266. The following example shows conversion by constructor: 
  19267.  
  19268.                                     *
  19269. ************************************************************************/
  19270.  
  19271. class Y
  19272. {
  19273.    int a,b;
  19274.    char* name;
  19275. public:
  19276.    Y(int i);
  19277.    Y(const char* n, int j = 0);
  19278. };
  19279. void add(Y);
  19280. // ...
  19281. void main ()
  19282. {
  19283.    // code           equivalent code
  19284.    Y obj1 = 2;        // obj1 = Y(2)
  19285.    Y obj2 = "somestring";  // obj2 = Y("somestring",0)
  19286.    obj1 = 10;        // obj1 = Y(10)
  19287.    add(5);          // add(Y(5))
  19288. }
  19289.  
  19290.  
  19291. ΓòÉΓòÉΓòÉ 13.4.2. Conversion Functions ΓòÉΓòÉΓòÉ
  19292.  
  19293. You can define a member function of a class, called a conversion function, that 
  19294. converts from the type of its class to another specified type. 
  19295.  
  19296. Syntax of a Conversion Function 
  19297.  
  19298. The conversion function specifies a conversion from the class type the 
  19299. conversion function is a member of, to the type specified by the name of the 
  19300. conversion function. Classes, enumerations, and typedef names cannot be 
  19301. declared or defined as part of the function name. 
  19302.  
  19303. Conversion functions have no arguments, and the return type is implicitly the 
  19304. conversion type. Conversion functions can be inherited. You can have virtual 
  19305. conversion functions but not static ones. 
  19306.  
  19307. Only one user-defined conversion is implicitly applied to a single value. 
  19308. User-defined conversions must be unambiguous, or they are not called. 
  19309.  
  19310. If a conversion function is declared with the keyword const, the keyword has no 
  19311. affect on the function except for acting as a tie-breaker when there is more 
  19312. than one conversion function that could be applied. Specifically, if more than 
  19313. one conversion function could be applied, all of these functions are compared. 
  19314. If any of these functions is declared with the keyword const, const is ignored 
  19315. for the purposes of this comparison. If one of these functions is a best match, 
  19316. this function is applied. If there is no best match, the functions are compared 
  19317. again, but this time const is not ignored. 
  19318.  
  19319. Example of a Conversion Function 
  19320.  
  19321. Related Information 
  19322.  
  19323.      Conversion by Constructor 
  19324.      Functions 
  19325.      Implicit Type Conversions 
  19326.      volatile and const Qualifiers 
  19327.      Virtual Functions 
  19328.  
  19329.  
  19330. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Conversion Function ΓòÉΓòÉΓòÉ
  19331.  
  19332. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇoperatorΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇconversion_typeΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ(ΓöÇΓöÇ)ΓöÇΓöÇ>
  19333.   ΓööΓöÇclass::ΓöÇΓöÿ       Γö£ΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöñ          Γö£ΓöÇ*ΓöÇΓöñ
  19334.               ΓööΓöÇvolatileΓöÇΓöÿ          ΓööΓöÇ&ΓöÇΓöÿ
  19335. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  19336.   ΓööΓöÇ{ΓöÇΓöÇfunction_bodyΓöÇΓöÇ}ΓöÇΓöÿ
  19337.  
  19338.  
  19339. ΓòÉΓòÉΓòÉ <hidden> Example of a Conversion Function ΓòÉΓòÉΓòÉ
  19340.  
  19341. /************************************************************************
  19342. *
  19343.  
  19344. The following code fragment shows a conversion function called operator int(): 
  19345.  
  19346.                                     *
  19347. ************************************************************************/
  19348.  
  19349. class Y
  19350. {
  19351.    int b;
  19352. public:
  19353.    operator int();
  19354. };
  19355. Y::operator int() {return b;}
  19356.  
  19357. void f(Y obj )
  19358. {
  19359.    // each value assigned is converted by Y::operator int()
  19360.    int i = int(obj);
  19361.    int j = (int)obj;
  19362.    int k = i + obj;
  19363. }
  19364.  
  19365.  
  19366. ΓòÉΓòÉΓòÉ 13.5. Initialization by Constructor ΓòÉΓòÉΓòÉ
  19367.  
  19368. A class object with a constructor must be explicitly initialized or have a 
  19369. default constructor. Explicit initialization using a constructor is the only 
  19370. way, except for aggregate initialization, to initialize nonstatic constant and 
  19371. reference class members. 
  19372.  
  19373. A class object that has no constructors, no virtual functions, no private or 
  19374. protected members, and no base classes is called an aggregate. Aggregates are 
  19375. described in Structures and Unions. 
  19376.  
  19377. Class objects with constructors can be initialized with a parenthesized 
  19378. expression list. This list is used as an argument list for the call of a 
  19379. constructor that is used to initialize the class. You can also call a 
  19380. constructor with a single initialization value using the = operator. Because 
  19381. this type of expression is an initialization, not an assignment, the assignment 
  19382. operator function, if one exists, is not called. This value is used as a single 
  19383. argument for the call of a constructor. The type of the single argument must 
  19384. match the type of the first argument to the constructor. If the constructor has 
  19385. remaining arguments, these arguments must have default values. 
  19386.  
  19387. Syntax of an Explicit Initializer by Constructor 
  19388.  
  19389. Constructors can initialize their members in two different ways. A constructor 
  19390. can use the arguments passed to it to initialize member variables in the 
  19391. constructor definition: 
  19392.  
  19393. complx( double r, double i = 0.0) {re = r; im = i;}
  19394.  
  19395. Or a constructor can have an initializer list within the definition but prior 
  19396. to the function body: 
  19397.  
  19398. complx ( double r, double i = 0) : re(r), im(i) { /* ... */ }
  19399.  
  19400. Both methods assign the argument values to the appropriate data members of the 
  19401. class. The second method must be used to initialize base classes from within a 
  19402. derived class to initialize constant and reference members and members with 
  19403. constructors. 
  19404.  
  19405. Example of Explicit Initialization by Constructor 
  19406.  
  19407. Related Information 
  19408.  
  19409.      Initializing Base Classes and Members 
  19410.      Construction Order of Derived Class Objects 
  19411.      Constructors and Destructors Overview 
  19412.      Constructors 
  19413.      C++ Classes 
  19414.  
  19415.  
  19416. ΓòÉΓòÉΓòÉ <hidden> Syntax of an Explicit Initializer by Constructor ΓòÉΓòÉΓòÉ
  19417.  
  19418. The syntax for an initializer that explicitly initializes a class object with a 
  19419. constructor is: 
  19420.  
  19421. >>ΓöÇΓöÇΓö¼ΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  19422.   ΓööΓöÇ=ΓöÇΓöÇΓö¼ΓöÇexpressionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  19423.      Γöé   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ      Γöé
  19424.      Γöé          Γöé      Γöé
  19425.      ΓööΓöÇ{ΓöÇΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ}ΓöÇΓöÿ
  19426.                ΓööΓöÇ,ΓöÇΓöÿ
  19427.  
  19428.  
  19429. ΓòÉΓòÉΓòÉ <hidden> Example of Explicit Initialization by Constructor ΓòÉΓòÉΓòÉ
  19430.  
  19431. /************************************************************************
  19432. *
  19433.  
  19434. The following example shows the declaration and use of several constructors 
  19435. that explicitly initialize class objects: 
  19436.  
  19437.                                     *
  19438. ************************************************************************/
  19439.  
  19440. // This example illustrates explicit initialization
  19441. // by constructor.
  19442.  
  19443. #include <iostream.h>
  19444. class complx
  19445. {
  19446.    double re, im ;
  19447. public:
  19448.    complx();  // default constructor
  19449.    complx(const complx& c) {re = c.re; im = c.im;}
  19450.          // copy constructor
  19451.    complx( double r, double i = 0.0) {re = r; im = i;}
  19452.          // constructor with default trailing argument
  19453.    void display()
  19454.    {
  19455.       cout << "re = "<< re << " im = " << im << endl;
  19456.    }
  19457. };
  19458.  
  19459. void main ()
  19460. {
  19461.    complx one(1);    // initialize with complx(double, double)
  19462.    complx two = one;  // initialize with a copy of one
  19463.              // using complx::complx(const complx&)
  19464.    complx three = complx(3,4);  // construct complx(3,4)
  19465.                   // directly into three
  19466.    complx four;         // initialize with default constructor
  19467.    complx five = 5;       // complx(double, double) & construct
  19468.                   // directly into five
  19469.    one.display();
  19470.    two.display();
  19471.    three.display();
  19472.    four.display();
  19473.    five.display();
  19474. }
  19475.  
  19476. /************************************************************************
  19477. *
  19478.  
  19479. The above example produces the following output: 
  19480.  
  19481. re = 1 im = 0
  19482. re = 1 im = 0
  19483. re = 3 im = 4
  19484. re = 0 im = 0
  19485. re = 5 im = 0
  19486.  
  19487.                                     *
  19488. ************************************************************************/
  19489.  
  19490.  
  19491. ΓòÉΓòÉΓòÉ 13.5.1. Initializing Base Classes and Members ΓòÉΓòÉΓòÉ
  19492.  
  19493. You can initialize immediate base classes and derived class members that are 
  19494. not inherited from base classes by specifying initializers in the constructor 
  19495. definition prior to the function body. 
  19496.  
  19497. Syntax of a Constructor Initializer 
  19498.  
  19499. In a constructor that is not inline, include the initialization list as part of 
  19500. the function definition, not as part of the class declaration. 
  19501.  
  19502. For example: 
  19503.  
  19504. class B1
  19505. {
  19506.    int b;
  19507. public:
  19508.    B1();
  19509.    B1(int i) : b(i) { /* ... */ }    // inline constructor
  19510. };
  19511. class B2
  19512. {
  19513.    int b;
  19514. protected:
  19515.    B2();
  19516.    B2(int i);             // noninline constructor
  19517. };
  19518. // B2 constructor definition including initialization list
  19519. B2::B2(int i) : b(i) { /* ...*/ }
  19520. // ...
  19521. class D : public B1, public B2
  19522. {
  19523.    int d1, d2;
  19524. public:
  19525.    D(int i, int j) : B1(i+1), B2(), d1(i) {d2 = j;}
  19526. };
  19527.  
  19528. If you do not explicitly initialize a base class or member that has 
  19529. constructors by calling a constructor, the compiler automatically initializes 
  19530. the base class or member with a default constructor. In the above example, if 
  19531. you leave out the call B2() in the constructor of class D (as shown below), a 
  19532. constructor initializer with an empty expression list is automatically created 
  19533. to initialize B2. The constructors for class D, shown above and below, result 
  19534. in the same construction of an object of class D. 
  19535.  
  19536. class D : public B1, public B2
  19537. {
  19538.    int d1, d2;
  19539. public:
  19540.    // call B2() generated by compiler
  19541.    D(int i, int j) : B1(i+1), d1(i) {d2 = j;}
  19542. };
  19543.  
  19544. Note:  You must declare base constructors with the access specifiers public or 
  19545. protected to enable a derived class to call them. 
  19546.  
  19547. Example of Base Constructors and Derivation 
  19548.  
  19549. Related Information 
  19550.  
  19551.      Construction Order of Derived Class Objects 
  19552.      Initialization by Constructor 
  19553.      Constructors and Destructors Overview 
  19554.      Constructors 
  19555.      Member Access 
  19556.  
  19557.  
  19558. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Constructor Initializer ΓòÉΓòÉΓòÉ
  19559.  
  19560. The syntax for a constructor initializer is: 
  19561.  
  19562.     ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  19563.     Γöé           ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé
  19564.                             Γöé   Γöé
  19565. >>ΓöÇΓöÇ:ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓö¼ΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓö┤ΓöÇΓöÇ><
  19566.      ΓööΓöÇclass_nameΓöÇΓöÿ    ΓööΓöÇassignment_expressionΓöÇΓöÿ
  19567.  
  19568.  
  19569. ΓòÉΓòÉΓòÉ <hidden> Example of Base Constructors and Derivation ΓòÉΓòÉΓòÉ
  19570.  
  19571. /************************************************************************
  19572. *
  19573.  
  19574. The following example shows how to call base constructors from derived classes: 
  19575.  
  19576.                                     *
  19577. ************************************************************************/
  19578.  
  19579. class B1
  19580. {
  19581.    int b;
  19582. public:
  19583.    B1();
  19584.    B1(int i) : b(i) { /* ... */ }
  19585. };
  19586. class B2
  19587. {
  19588.    int b;
  19589. protected:
  19590.    B2();
  19591.    B2(int i);
  19592. };
  19593. B2::B2(int i) : b(i) { /* ... */ }
  19594. class B4
  19595. {
  19596. public:
  19597.    B4();     // public constructor for B4
  19598.    int b;
  19599. private:
  19600.    B4(int);    // private constructor for B4
  19601. };
  19602. //    .
  19603. //    .
  19604. //    .
  19605.  
  19606. class D : public B1, public B2, public B4
  19607. {
  19608.    int d1, d2;
  19609. public:
  19610.    D(int i, int j) : B1(i+1), B2(i+2) ,
  19611.             B4(i) {d1 = i; d2 = j; }
  19612.       // error, attempt to access private constructor B4()
  19613. };
  19614.  
  19615. To ensure a valid call, you can change the code as follows: 
  19616.  
  19617. public:
  19618.    D(int i, int j) : B1(i+1), B2(i+2) {d1 = i; d2 = j;}
  19619.       // valid, calls public constructor for B4
  19620.  
  19621.  
  19622. ΓòÉΓòÉΓòÉ 13.5.2. Construction Order of Derived Class Objects ΓòÉΓòÉΓòÉ
  19623.  
  19624. When a derived class object is created using constructors, it is created in the 
  19625. following order: 
  19626.  
  19627.    1. Virtual base classes are initialized, in the order they appear in the 
  19628.       base list. 
  19629.    2. Nonvirtual base classes are initialized, in declaration order. 
  19630.    3. Class members are initialized in declaration order (regardless of their 
  19631.       order in the initialization list). 
  19632.    4. The body of the constructor is executed. 
  19633.  
  19634.  In the following code fragment, the constructor for class B1 is called before 
  19635.  the member d1 is initialized. The value passed to the constructor for class B1 
  19636.  is undefined. 
  19637.  
  19638.   class B1
  19639.   {
  19640.      int b;
  19641.   public:
  19642.      B1();
  19643.      B1(int i) {b = i;}
  19644.   };
  19645.   class D : public B1
  19646.   {
  19647.      int d1, d2;
  19648.   public:
  19649.      D(int i, int j) : d1(i), B1(d1) {d2 = j;}
  19650.      // d1 is not initialized in call B1::B1(d1)
  19651.   };
  19652.  
  19653.  Related Information 
  19654.  
  19655.      Initializing Base Classes and Members 
  19656.      Initialization by Constructor 
  19657.      Constructors and Destructors Overview 
  19658.      Constructors 
  19659.      Derivation 
  19660.  
  19661.  
  19662. ΓòÉΓòÉΓòÉ 13.6. Copying Class Objects ΓòÉΓòÉΓòÉ
  19663.  
  19664. You can copy one class object to another object of the same type by either 
  19665. assignment or initialization. 
  19666.  
  19667. Copy by assignment is implemented with an assignment operator function. If you 
  19668. do not define the assignment operator, it is defined as memberwise assignment. 
  19669.  
  19670. Copy by initialization is implemented with a copy constructor. If you do not 
  19671. define a copy constructor, it is defined as  memberwise initialization of 
  19672. members of its class. 
  19673.  
  19674. Memberwise assignment and memberwise initialization mean that, if a class has a 
  19675. member that is a class object, the assignment operator and copy constructor of 
  19676. that class object are used to implement assignment and initialization of the 
  19677. member. 
  19678.  
  19679. Restrictions: 
  19680.  
  19681. A default assignment operator cannot be generated for a class that has: 
  19682.  
  19683.      A nonstatic constant or reference data member 
  19684.      A nonstatic data member or base class whose assignment operator is not 
  19685.       accessible 
  19686.      A nonstatic data member or base class with no assignment operator and for 
  19687.       which a default assignment operator cannot be generated. 
  19688.  
  19689.  A default copy constructor cannot be generated for a class that has: 
  19690.  
  19691.      A nonstatic data member or base class whose copy constructor is not 
  19692.       accessible 
  19693.      A nonstatic data member or base class with no copy constructor and for 
  19694.       which a default copy constructor cannot be generated. 
  19695.  
  19696.  Related Information 
  19697.  
  19698.      Copy by Assignment 
  19699.      Copy by Initialization 
  19700.      Constructors and Destructors Overview 
  19701.      Constructors 
  19702.      Overloaded Assignment 
  19703.  
  19704.  
  19705. ΓòÉΓòÉΓòÉ 13.6.1. Copy by Assignment ΓòÉΓòÉΓòÉ
  19706.  
  19707. If you do not define an assignment operator and one is required, a default 
  19708. assignment operator is defined. If you do not define an assignment operator and 
  19709. one is not required, a default assignment operator is declared but not defined. 
  19710. If an assignment operator that takes a single argument of a class type exists 
  19711. for a class, a default assignment operator is not generated. 
  19712.  
  19713. Copy by assignment is used only in assignment. 
  19714.  
  19715. You can define an assignment operator for a class with a single argument that 
  19716. is a constant reference to that class type, only if all its base classes and 
  19717. members have assignment operators that accept constant arguments. 
  19718.  
  19719. For example: 
  19720.  
  19721. class B1
  19722. {
  19723. public:
  19724.    B1& operator=(const B1&);
  19725. };
  19726. class D: public B1
  19727. {
  19728. public:
  19729.    D& operator=(const D&);
  19730. };
  19731. D& D::operator=(const D& dobj) {D dobj2 = dobj;
  19732.                     return dobj2;}
  19733.  
  19734. Otherwise, you can define an assignment operator for a class with a single 
  19735. argument that is a reference to that class type. For example: 
  19736.  
  19737. class Z
  19738. {
  19739. public:
  19740.    Z& operator=( Z&);
  19741. };
  19742. Z& Z::operator=(Z& zobj) {Z zobj2 = zobj;
  19743.                     return zobj2;}
  19744.  
  19745. The default assignment operator for a class is a public class member. The 
  19746. return type is a reference to the class type it is a member of. 
  19747.  
  19748. Related Information 
  19749.  
  19750.      Assignment Expressions 
  19751.      Overloaded Assignment 
  19752.      Copy by Initialization 
  19753.      C++ Classes 
  19754.  
  19755.  
  19756. ΓòÉΓòÉΓòÉ 13.6.2. Copy by Initialization ΓòÉΓòÉΓòÉ
  19757.  
  19758. You can define a copy constructor for a class. If you do not define a copy 
  19759. constructor and one is required, a default copy constructor is defined. If you 
  19760. do not define a copy constructor, and one is not required, a default copy 
  19761. constructor is declared but not defined. If a class has a copy constructor 
  19762. defined, a default copy constructor is not generated. 
  19763.  
  19764. Copy by initialization is used only in initialization. 
  19765.  
  19766. You can define a copy constructor for a class with a single argument that is a 
  19767. constant reference to a class type only if all its base classes and members 
  19768. have copy constructors that accept constant arguments. For example: 
  19769.  
  19770. class B1
  19771. {
  19772. public:
  19773.    B1(const B1&) { /* ... */ }
  19774. };
  19775.  
  19776. class D: public B1
  19777. {
  19778. public:
  19779.    D(const D&);
  19780. };
  19781. D::D(const D& dobj):B1(dobj) { /* ... */ }
  19782.  
  19783. Otherwise, you can define a copy constructor with a single reference to a class 
  19784. type argument. For example: 
  19785.  
  19786. class Z
  19787. {
  19788. public:
  19789.    Z(Z&);
  19790. };
  19791. Z::Z(Z&) { /* ...*/ }
  19792.  
  19793. The default copy constructor for a class is a public class member. 
  19794.  
  19795. Related Information 
  19796.  
  19797.      Initialization by Constructor 
  19798.      Constructors 
  19799.      Copy by Assignment 
  19800.      C++ Classes 
  19801.  
  19802.  
  19803. ΓòÉΓòÉΓòÉ 14. C++ Inheritance ΓòÉΓòÉΓòÉ
  19804.  
  19805. In C++, you can create classes from existing classes using the object-oriented 
  19806. programming technique called inheritance. Inheritance allows you to define an 
  19807. is a relationship between classes. When members are inherited, they can be used 
  19808. as if they are members of the class that inherits them. 
  19809.  
  19810. This chapter discusses: 
  19811.  
  19812.      Derivation 
  19813.      Inherited Member Access 
  19814.      Multiple Inheritance 
  19815.      Virtual Functions 
  19816.      Abstract Classes 
  19817.  
  19818.  Related Information 
  19819.  
  19820.      Functions 
  19821.      C++ Classes 
  19822.      C++ Class Members and Friends 
  19823.  
  19824.  
  19825. ΓòÉΓòÉΓòÉ 14.1. Inheritance Overview ΓòÉΓòÉΓòÉ
  19826.  
  19827. C++ implements inheritance through the mechanism of derivation. Derivation 
  19828. allows you to reuse code by creating new classes, called derived classes, that 
  19829. inherit properties from one or more existing classes, called base classes. A 
  19830. derived class inherits the properties, including data and function members, of 
  19831. its base class. You can also add new data members and member functions to the 
  19832. derived class. You can modify the implementation of existing member functions 
  19833. or data by overriding base class member functions or data in the newly derived 
  19834. class. 
  19835.  
  19836. Multiple inheritance allows you to create a derived class that inherits 
  19837. properties from more than one base class. 
  19838.  
  19839. Because a derived class inherits members from all its base classes, ambiguities 
  19840. can result. For example, if two base classes have a member with the same name, 
  19841. the derived class cannot implicitly differentiate between the two members. Note 
  19842. that, when you are using multiple inheritance, the access to names of base 
  19843. classes may be ambiguous. 
  19844.  
  19845. Examples of Single and Multiple Inheritance 
  19846.  
  19847. Multiple inheritance allows you to have more than one base class for a single 
  19848. derived class. You can create an interconnected inheritance graph of inherited 
  19849. classes by using derived classes as base classes for other derived classes. You 
  19850. can build an inheritance graph through the process of specialization, in which 
  19851. derived classes are more specialized than their base classes. You can also work 
  19852. in the reverse direction and build an inheritance graph through generalization. 
  19853. If you have a number of related classes that share a group of properties, you 
  19854. can generalize and build a base class to embody them. The group of related 
  19855. classes becomes the derived classes of the new base class. 
  19856.  
  19857. A direct base class is a base class that appears directly as a base specifier 
  19858. in the declaration of its derived class. A direct base class is analogous to a 
  19859. parent in a hierarchical graph. 
  19860.  
  19861. An indirect base class is a base class that does not appear directly in the 
  19862. declaration of the derived class but is available to the derived class through 
  19863. one of its base classes. An indirect base class is analogous to a grandparent 
  19864. or great grandparent or great-great grandparent in a hierarchical graph. For a 
  19865. given class, all base classes that are not direct base classes are indirect 
  19866. base classes. 
  19867.  
  19868. Polymorphic functions are functions that can be applied to objects of more than 
  19869. one type. In C++, polymorphic functions are implemented in two ways: 
  19870.  
  19871.      Overloaded functions are statically bound at compile time, as discussed 
  19872.       in Overloading Functions. 
  19873.      C++ provides virtual functions. A virtual function is a function that can 
  19874.       be called for a number of different user-defined types that are related 
  19875.       through derivation. Virtual functions are bound dynamically at run time. 
  19876.  
  19877.  Typically, a base class has several derived classes, each requiring its own 
  19878.  customized version of a particular operation. It is difficult for a base class 
  19879.  to implement member functions that are useful for all of its derived classes. 
  19880.  A base class would have to determine which derived class an object belonged to 
  19881.  before it could execute the applicable code for that object. When a virtual 
  19882.  function is called, the compiler executes the function implementation 
  19883.  associated with the object that the function is called for. The implementation 
  19884.  of the base class is only a default that is used when the derived class does 
  19885.  not contain its own implementation. 
  19886.  
  19887.  Related Information 
  19888.  
  19889.      Derivation 
  19890.      Multiple Inheritance 
  19891.      Virtual Functions 
  19892.      C++ Classes 
  19893.      C++ Class Members and Friends 
  19894.  
  19895.  
  19896. ΓòÉΓòÉΓòÉ 14.1.1. Examples of Single and Multiple Inheritance ΓòÉΓòÉΓòÉ
  19897.  
  19898. Suppose you have defined a shape class to describe and operate on geometric 
  19899. shapes. Now suppose you want to define a circle class. Because you have 
  19900. existing code that operates on the shape class, you can use inheritance to 
  19901. create the circle class. You can redefine operations in the derived circle 
  19902. class that were originally defined in the shape base class. When you manipulate 
  19903. an object of the circle class, these redefined function implementations are 
  19904. used. 
  19905.  
  19906. For example: 
  19907.  
  19908. class shape
  19909. {
  19910.    char* name;
  19911.    int xpoint, ypoint;
  19912. public:
  19913.    virtual void rotate(int);
  19914.    virtual void draw();
  19915.    void display() const;
  19916. };
  19917.  
  19918. class circle: public shape    // derive class circle from
  19919. class shape
  19920. {
  19921.    int xorigin, yorigin;
  19922.    int radius;
  19923. public:
  19924.    void rotate(int);
  19925.    void draw();
  19926.    void display() const;
  19927. };
  19928.  
  19929. In the above example, class circle inherits the data members name, xpoint and 
  19930. ypoint, as well as the member functions display(), rotate(), and draw() from 
  19931. class shape. Because the member functions rotate() and draw() are declared in 
  19932. class shape with the keyword virtual, you can provide an alternative 
  19933. implementation for them in class circle. 
  19934.  
  19935. You can also provide an alternative implementation for the nonvirtual member 
  19936. function display() in class circle. When you manipulate an argument of type 
  19937. circle using a pointer to shape, and call a virtual member function, the member 
  19938. function defined in the derived class overrides the base-class member function. 
  19939. A similar call to a nonvirtual member function will call the member function 
  19940. defined in the base class. In addition to inheriting the members of class 
  19941. shape, class circle has declared its own data members, xorigin, yorigin, and 
  19942. radius. 
  19943.  
  19944. The key difference between virtual and nonvirtual member functions is that, 
  19945. when you treat the circle class as if it were a shape, the implementations of 
  19946. the virtual functions rotate() and draw() defined in class circle are used, 
  19947. rather than those originally defined in class shape. Because display() is a 
  19948. nonvirtual member function, the original implementation of display() defined in 
  19949. class shape is used. 
  19950.  
  19951. Multiple inheritance allows you to create a derived class that inherits 
  19952. properties from more than one base class. 
  19953.  
  19954. For example, in addition to the shape class, described above, you could also 
  19955. have a symbol class. Because a circle is both a shape and a symbol, you can use 
  19956. multiple inheritance to reflect this relationship. If the circle class is 
  19957. derived from both the shape and symbol classes, the circle class inherits 
  19958. properties from both classes. 
  19959.  
  19960. class symbol
  19961. {
  19962.    char* language;
  19963.    char letter;
  19964.    int number;
  19965. public:
  19966.    virtual void write();
  19967.    virtual void meaning();
  19968. };
  19969. class shape
  19970. {
  19971.    char* name;
  19972.    int xpoint, ypoint;
  19973. public:
  19974.    virtual void rotate(int);
  19975.    virtual void draw();
  19976.    void display() const;
  19977. };
  19978. class circle: public symbol, public shape
  19979. {
  19980.    int xorigin, yorigin;
  19981.    int radius;
  19982. public:
  19983.    void rotate(int);
  19984.    void draw ();
  19985.    void write();
  19986.    void meaning();
  19987.    void display() const;
  19988. };
  19989.  
  19990. In the above example, class circle inherits the members name, xpoint, ypoint, 
  19991. display(), rotate(), and draw() from class shape and also inherits the members 
  19992. language, letter, number, write(), and meaning() from class symbol. 
  19993.  
  19994.  
  19995. ΓòÉΓòÉΓòÉ 14.2. Derivation ΓòÉΓòÉΓòÉ
  19996.  
  19997. Inheritance is implemented in C++ through the mechanism of derivation. 
  19998. Derivation allows you to derive a class, called a derived class, from another 
  19999. class, called a base class. 
  20000.  
  20001. In the declaration of a derived class, you list the base classes of the derived 
  20002. class. The derived class inherits its members from these base classes. All 
  20003. classes that appear in the list of base classes must be previously defined 
  20004. classes. 
  20005.  
  20006. Syntax of a Derived Class 
  20007.  
  20008. Incompletely declared classes are not allowed in base lists. 
  20009.  
  20010. For example: 
  20011.  
  20012. class X; // incomplete declaration of class X
  20013. class Y: public X    // error
  20014. {
  20015. };
  20016.  
  20017. When you derive a class, the derived class inherits class members of the base 
  20018. class. You can refer to inherited members (base class members) as if they were 
  20019. members of the derived class. If you redefine base class members in the derived 
  20020. class, you can still refer to the base class members by using the :: (scope 
  20021. resolution) operator. 
  20022.  
  20023. You can manipulate a derived class object as if it were a base class object. 
  20024. You can use a pointer or a reference to a derived class object in place of a 
  20025. pointer or reference to its base class. For example, you can pass a pointer or 
  20026. reference to a derived class object D to a function expecting a pointer or 
  20027. reference to the base class of D. You do not need to use an explicit cast to 
  20028. achieve this; a standard conversion is performed. You can implicitly convert a 
  20029. pointer to a derived class to point to a base class. You can also implicitly 
  20030. convert a reference to a derived class to a reference to a base class. 
  20031.  
  20032. The reverse case is not allowed. You cannot implicitly convert a pointer or a 
  20033. reference to a base class object to a pointer or reference to a derived class. 
  20034.  
  20035. Examples of Derived Classes 
  20036.  
  20037. If a member of a derived class and a member of a base class have the same name, 
  20038. the base class member is hidden in the derived class. If a member of a derived 
  20039. class has the same name as a base class, the base class name is hidden in the 
  20040. derived class. In both cases, the name of the derived class member is called 
  20041. the dominant name. 
  20042.  
  20043. Related Information 
  20044.  
  20045.      Inheritance Overview 
  20046.      C++ Classes 
  20047.      C++ Scope Resolution Operator :: 
  20048.      Multiple Inheritance 
  20049.  
  20050.  
  20051. ΓòÉΓòÉΓòÉ <hidden> Examples of Derived Classes ΓòÉΓòÉΓòÉ
  20052.  
  20053. /************************************************************************
  20054. *
  20055. You can refer to inherited members (base class members) as if they were members 
  20056. of the derived class: 
  20057.  
  20058.                                     *
  20059. ************************************************************************/
  20060.  
  20061. // This example illustrates references
  20062. // to base class members.
  20063.  
  20064. class base
  20065. {
  20066. public:
  20067.    int a,b;
  20068. };
  20069. class derived : public base
  20070. {
  20071. public:
  20072.    int c;
  20073. };
  20074. void main()
  20075. {
  20076.    derived d;
  20077.    d.a = 1;    // base::a
  20078.    d.b = 2;    // base::b
  20079.    d.c = 3;    // derived::c
  20080. }
  20081.  
  20082. /************************************************************************
  20083. *
  20084.  
  20085. The derived class can also add new class members and redefine existing base 
  20086. class members. In the above example, the two inherited members, a and b, of the 
  20087. derived class d, in addition to the derived class member c, are assigned 
  20088. values. 
  20089.  
  20090. For example: 
  20091.  
  20092.                                     *
  20093. ************************************************************************/
  20094.  
  20095. // This example illustrates references to base class
  20096. // members with the scope resolution (::) operator.
  20097.  
  20098. #include <iostream.h>
  20099. class base
  20100. {
  20101. public:
  20102.    char* name;
  20103.    void display(char* i) {cout << i << endl;}
  20104. };
  20105. class derived : public base
  20106. {
  20107. public:
  20108.    char* name;
  20109.    void display(char* i){cout << i << endl;}
  20110. };
  20111. void main()
  20112. {
  20113.    derived d;           // create derived class object
  20114.    d.name = "Derived Class";   // assignment to derived::name
  20115.    d.base::name = "Base Class";  // assignment to base::name
  20116.  
  20117.    // call derived::display(derived::name)
  20118.    d.display(d.name);
  20119.  
  20120.    // call base::display(base::name)
  20121.    d.base::display(d.base::name);
  20122. }
  20123.  
  20124. /************************************************************************
  20125. *
  20126.  
  20127. In the following example, d, a pointer to a derived class object is assigned to 
  20128. bptr, a pointer to a base class object. A call is made to display() using bptr. 
  20129. Even though bptr has a type of pointer to base, in the body of display() the 
  20130. name member of derived is manipulated: 
  20131.  
  20132.                                     *
  20133. ************************************************************************/
  20134.  
  20135. // This example illustrates how to make a pointer
  20136. // to a derived class point to a base class.
  20137.  
  20138. #include <iostream.h>
  20139. class base
  20140. {
  20141. public:
  20142.    char* name;
  20143.    void display(char* i) {cout << i << endl;}
  20144. };
  20145. class derived : public base
  20146. {
  20147. public:
  20148.    char* name;
  20149.    void display(char* i){cout << i << endl;}
  20150. };
  20151. void main()
  20152. {
  20153.    derived d;
  20154.  
  20155.    // standard conversion from derived* to base*
  20156.    base* bptr = &d;
  20157.  
  20158.    // call base::display(base::name)
  20159.    bptr->display(bptr->name);
  20160. }
  20161.  
  20162.  
  20163. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Derived Class Declaration ΓòÉΓòÉΓòÉ
  20164.  
  20165. The syntax for the list of base classes is: 
  20166.  
  20167. >>ΓöÇΓöÇderived_classΓöÇΓöÇ:ΓöÇΓöÇ>
  20168.   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  20169.                                 Γöé
  20170. >ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇqualified_class_specifierΓöÇΓö┤ΓöÇΓöÇ><
  20171.    Γö£ΓöÇvirtualΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  20172.    Γöé      Γö£ΓöÇpublicΓöÇΓöÇΓöÇΓöÇΓöñ   Γöé
  20173.    Γöé      Γö£ΓöÇprivateΓöÇΓöÇΓöÇΓöñ   Γöé
  20174.    Γöé      ΓööΓöÇprotectedΓöÇΓöÿ   Γöé
  20175.    ΓööΓöÇΓö¼ΓöÇpublicΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  20176.     Γö£ΓöÇprivateΓöÇΓöÇΓöÇΓöñ  ΓööΓöÇvirtualΓöÇΓöÿ
  20177.     ΓööΓöÇprotectedΓöÇΓöÿ
  20178.  
  20179. The qualified class specifier must be a class that has been previously declared 
  20180. in a class declaration as described in Class Names. The access specifiers 
  20181. (public, private, and protected) are described in Member Access. 
  20182.  
  20183. The virtual keyword can be used to declare virtual base classes. 
  20184.  
  20185. The following example shows the declaration of the derived class D and the base 
  20186. classes V, B1, and B2. The class B1 is both a base class and a derived class 
  20187. because it is derived from class V and is a base class for D. 
  20188.  
  20189. class V { /* ... */ };
  20190. class B1 : virtual public V { /* ... */ };
  20191. class B2 { /* ... */ };
  20192. class D : public B1, private B2 { /* ... */ };
  20193.  
  20194.  
  20195. ΓòÉΓòÉΓòÉ 14.3. Inherited Member Access ΓòÉΓòÉΓòÉ
  20196.  
  20197. Access specifiers, as described in Member Access, control the level of access 
  20198. to noninherited class members. The access for an inherited member is controlled 
  20199. in three ways: 
  20200.  
  20201.      When you declare a member in a base class, you can specify a level of 
  20202.       access using the keywords public, private, and protected. 
  20203.      When you derive a class, you can specify the access level for the base 
  20204.       class in the base list. 
  20205.      You can also restore the access level of inherited members. See 
  20206.       Derivation Access of Base Classes for an example. 
  20207.  
  20208.  Resolution of member names does not depend on the level of access associated 
  20209.  with each class member. 
  20210.  
  20211.  Consider the following example: 
  20212.  
  20213.   class A {
  20214.      private:
  20215.         int a;
  20216.   };
  20217.   class B {
  20218.      public:
  20219.         int a;
  20220.   };
  20221.   class C : public A, public B {
  20222.      void f() { a = 0; }  // ambiguous - is it A::a or B::a?
  20223.   };
  20224.  
  20225.  In this example, class A has a private member a, and class B has a public 
  20226.  member a. Class C is derived from both A and B. C does not have access to 
  20227.  A::a, but a in the body of f() can still resolve to either A::a or B::a. For 
  20228.  this reason, a is ambiguous in the body of f(). 
  20229.  
  20230.  If a class is derived publicly from a base class, a protected static base 
  20231.  class member can be accessed by members and friends of any classes derived 
  20232.  from that base class. A protected nonstatic base class member can be accessed 
  20233.  by members and friends of any classes derived from that base class by using 
  20234.  one of the following: 
  20235.  
  20236.      A pointer to a directly or indirectly derived class 
  20237.      A reference to a directly or indirectly derived class 
  20238.      An object of a directly or indirectly derived class 
  20239.  
  20240.  If a class is derived privately from a base class, all protected base class 
  20241.  members become private members of the derived class. 
  20242.  
  20243.  Examples of Inherited Member Access Rules 
  20244.  
  20245.  Related Information 
  20246.  
  20247.      Derivation Access of Base Classes 
  20248.      Access Declarations 
  20249.      Access Resolution 
  20250.      Member Access 
  20251.      Derivation 
  20252.      C++ Classes 
  20253.  
  20254.  
  20255. ΓòÉΓòÉΓòÉ 14.3.1. Derivation Access of Base Classes ΓòÉΓòÉΓòÉ
  20256.  
  20257. When you declare a derived class, an access specifier can precede each base 
  20258. class in the base list of the derived class. This does not alter the access 
  20259. attributes of the individual members of a base class as seen by the base class, 
  20260. but allows the derived class to restore the access attributes of the members of 
  20261. a base class. 
  20262.  
  20263. You can derive classes using any of the three access specifiers: 
  20264.  
  20265.      In a public base class, public and protected members of the base class 
  20266.       remain public and protected members of the derived class. 
  20267.      In a private base class, public and protected members of the base class 
  20268.       become private members of the derived class. 
  20269.      In a protected base class, public and protected members of the base class 
  20270.       are protected members of the derived class. 
  20271.  
  20272.  In all cases, private members of the base class remain private. Private 
  20273.  members of the base class cannot be used by the derived class unless friend 
  20274.  declarations within the base class explicitly grant access to them. 
  20275.  
  20276.  You can use both a structure and a class as base classes in the base list of a 
  20277.  derived class declaration. If the base class is declared with the keyword 
  20278.  class, its default access specifier in the base list of a derived class is 
  20279.  private. If the base class is declared with the keyword struct, its default 
  20280.  access specifier in the base list of a derived class is public. 
  20281.  
  20282.  Examples of Public and Private Derivation 
  20283.  
  20284.  Members and friends of a class can implicitly convert a pointer to an object 
  20285.  of that class to a pointer to either: 
  20286.  
  20287.      A direct private base class 
  20288.      A protected base class (either direct or indirect) 
  20289.  
  20290.  Related Information 
  20291.  
  20292.      Access Declarations 
  20293.      Access Resolution 
  20294.      Member Access 
  20295.      Derivation 
  20296.      C++ Classes 
  20297.  
  20298.  
  20299. ΓòÉΓòÉΓòÉ <hidden> Examples of Public and Private Derivation ΓòÉΓòÉΓòÉ
  20300.  
  20301. In the following example, class d is derived publicly from class b. Class b is 
  20302. declared a public base class by this declaration. 
  20303.  
  20304. class b
  20305. {
  20306. // ...
  20307. };
  20308. class d : public b // public derivation
  20309. {
  20310. // ...
  20311. };
  20312.  
  20313. In the following example, private derivation is used by default because no 
  20314. access specifier is used in the base list: 
  20315.  
  20316. struct bb
  20317. {
  20318. // ...
  20319. };
  20320. class dd : bb // private derivation
  20321. {
  20322. // ...
  20323. };
  20324.  
  20325.  
  20326. ΓòÉΓòÉΓòÉ 14.3.2. Access Declarations ΓòÉΓòÉΓòÉ
  20327.  
  20328. You can restore access to members of a base class using an access declaration. 
  20329. It allows you to change the access of a public member of a private or protected 
  20330. base class back to public. You can also change the access of a protected member 
  20331. of a private base class back to protected. Access is adjusted by using the base 
  20332. class member qualified name in the public or protected declarations of the 
  20333. derived class. 
  20334.  
  20335. You only use access declarations to restore base class access. You cannot 
  20336. change the access to a member to give it more access than it was originally 
  20337. declared with. You cannot change the access of a private member to public or to 
  20338. protected. You cannot change the access of a protected member to public. 
  20339.  
  20340. An access declaration cannot be used to restrict access to a member that is 
  20341. accessible in a base class. 
  20342.  
  20343. It is redundant to use an access declaration to change the access to a public 
  20344. member of a public base class to public, or to change the access to a protected 
  20345. member of a protected base class to protected. 
  20346.  
  20347. Examples of Access Declarations 
  20348.  
  20349. Access declarations can only be used to adjust the access of a member of a base 
  20350. class. The base class that an access declaration appears in can be directly or 
  20351. indirectly inherited by the derived class. 
  20352.  
  20353. You cannot adjust the access to a base class member if a member with the same 
  20354. name exists in a class derived from that base class. 
  20355.  
  20356. If you use an access declaration to adjust the access to an overloaded 
  20357. function, the access is adjusted for all functions with that name in the base 
  20358. class. 
  20359.  
  20360. Related Information 
  20361.  
  20362.      Derivation Access of Base Classes 
  20363.      Access Resolution 
  20364.      Member Access 
  20365.      Derivation 
  20366.      Overloading Functions 
  20367.      C++ Classes 
  20368.  
  20369.  
  20370. ΓòÉΓòÉΓòÉ <hidden> Examples of Access Declarations ΓòÉΓòÉΓòÉ
  20371.  
  20372. /************************************************************************
  20373. *
  20374.  
  20375. In the following example, the member b of the base class base is declared 
  20376. public in its base class declaration. Class derived is derived privately from 
  20377. class base. The access declaration in the public section of class derived 
  20378. restores the access level of the member b back to public. 
  20379.  
  20380.                                     *
  20381. ************************************************************************/
  20382.  
  20383. // This example illustrates using access declarations
  20384. // to restore base class access.
  20385.  
  20386. #include <iostream.h>
  20387. class base
  20388. {
  20389.    char a;
  20390. public:
  20391.    char c, b;
  20392.    void bprint();
  20393. };
  20394.  
  20395. class derived: private base
  20396. {
  20397.    char d;
  20398. public:
  20399.    char e;
  20400.    base::b;       // restore access to b in derived
  20401.    void dprint();
  20402.    derived(char ch) { base::b = ch; }
  20403. };
  20404.  
  20405. void print(derived& d)
  20406. {
  20407.    cout << " Here is d " << d.b << endl;
  20408. }
  20409.  
  20410. void main()
  20411. {
  20412.    derived obj('c');
  20413.    print(obj);
  20414. }
  20415.  
  20416. /************************************************************************
  20417. *
  20418.  
  20419. The external function print(derived&) can use the member b of base because the 
  20420. access of b has been restored to public. The external function print(derived&) 
  20421. can also use the members e and dprint() because they are declared with the 
  20422. keyword public in the derived class. The derived class member dprint() can use 
  20423. the members of its own class, d and e, in addition to the inherited members, b, 
  20424. c, and bprint(), that are declared with the keyword public in the base class. 
  20425. The base class member bprint() can use all the members of its own class, a, b, 
  20426. and c. 
  20427.  
  20428. You can also use an access declaration in a nested class. For example: 
  20429.  
  20430. class B
  20431. {
  20432. public:
  20433.    class N      // nested class
  20434.    {
  20435.    public:
  20436.       int i;   // public member
  20437.    };
  20438. };
  20439. class D: private B::N  // derive privately
  20440. {
  20441. public:
  20442.    B::N::i;     // restores access to public
  20443. };
  20444.  
  20445. You cannot convert a pointer to a derived class object to a pointer to a base 
  20446. class object if the base class is private or protected. For example: 
  20447.  
  20448. class B { /* ... */ };
  20449. class D : private B { /* ... */ };    // private base class
  20450.  
  20451. void main ()
  20452. {
  20453.    D d;
  20454.    B* ptr;
  20455.    ptr = &d;    // error
  20456. }
  20457.  
  20458.                                     *
  20459. ************************************************************************/
  20460.  
  20461.  
  20462. ΓòÉΓòÉΓòÉ 14.3.3. Access Resolution ΓòÉΓòÉΓòÉ
  20463.  
  20464. Access resolution is the process by which the accessibility of a particular 
  20465. class member is determined. Accessibility is dependent on the context. For 
  20466. example, a class member can be accessible in a member function but inaccessible 
  20467. at file scope. The following describes the access resolution procedure used by 
  20468. the compiler. 
  20469.  
  20470. In general, two scopes must be established before access resolution is applied. 
  20471. These scopes reduce an expression or declaration into a simplified construct to 
  20472. which the access rules are applied. Access rules are described in Member 
  20473. Access. These scopes are: 
  20474.  
  20475.  Call scope         The scope that encloses the expression or declaration that 
  20476.                     uses the class member. 
  20477.  
  20478.  Reference scope    The scope that identifies the class. 
  20479.  
  20480.  For example, in the following code: 
  20481.  
  20482.   // This example illustrates access resolution.
  20483.  
  20484.   class B { public: int member; };     // declaration
  20485.   class A : B {}              // declaration
  20486.   void main()
  20487.   {
  20488.      A aobject;             // declaration
  20489.      aobject.member = 10;        // expression
  20490.   }
  20491.  
  20492.  the reference scope for member is the type of aobject, that is class type  A. 
  20493.  
  20494.  Reference scope is chosen by simplifying the expression (or declaration) 
  20495.  containing the member. An expression can be thought of as being reduced to a 
  20496.  simple expression of the form obj.member where obj is the reference scope. 
  20497.  Reference scope is selected as follows: 
  20498.  
  20499.      If the member is qualified with . (dot) or -> (arrow), the reference 
  20500.       scope is the type of the object that is immediately to the left of the . 
  20501.       or -> operator closest to the member. Unqualified members are treated as 
  20502.       if they are qualified with this->. 
  20503.  
  20504.      If the member is a type member or a static member and is qualified with 
  20505.       :: (the scope resolution operator), the reference scope is the type 
  20506.       immediately to the left of the :: operator closest to the member. 
  20507.  
  20508.      Otherwise, the reference scope is the call scope. 
  20509.  
  20510.  The call scope and the reference scope determine the accessibility of a class 
  20511.  member. Once these scopes are resolved, the effective access of the member is 
  20512.  determined. Effective access is the access of the member as it is seen from 
  20513.  the reference scope. It is determined by taking the original access of the 
  20514.  member in its scope as the effective access and changing it as the class 
  20515.  hierarchy is traversed from the member's class to the reference scope. 
  20516.  Effective access is altered as the class hierarchy is traversed for each 
  20517.  derivation by the following: 
  20518.  
  20519.      The derivation access of a base class (see Derivation Access of Base 
  20520.       Classes) 
  20521.      Access declarations that are applied to the members (see Access 
  20522.       Declarations) 
  20523.      Friendships that are granted to the call scope (see Member Access) 
  20524.  
  20525.  After effective access is determined for a member, the access rules are 
  20526.  applied as if the effective access were the original access of the member. A 
  20527.  member is only accessible if the access rules say that it is. 
  20528.  
  20529.  Example of Access Resolution 
  20530.  
  20531.  Related Information 
  20532.  
  20533.      Derivation Access of Base Classes 
  20534.      Access Declarations 
  20535.      Member Access 
  20536.      Derivation 
  20537.      Overloading Functions 
  20538.      C++ Scope Resolution Operator :: 
  20539.      C++ Classes 
  20540.  
  20541.  
  20542. ΓòÉΓòÉΓòÉ <hidden> Example of Access Resolution ΓòÉΓòÉΓòÉ
  20543.  
  20544. The following example demonstrates the access resolution procedure. 
  20545.  
  20546. class A
  20547. {
  20548. public:
  20549.    int a;
  20550. };
  20551. class B : private A
  20552. {
  20553.    friend void f (B*);
  20554. };
  20555. void f(B* b)
  20556. {
  20557.    b->a = 10; // is 'a' accessible to f(B*) ?
  20558. }
  20559. // ...
  20560.  
  20561. The following steps occur to determine the accessibility of A::a in f(B*): 
  20562.  
  20563.    1. The call scope and reference scope of the expression b->a are determined: 
  20564.  
  20565.         a. The call scope is the function f(B*). 
  20566.         b. The reference scope is class B. 
  20567.  
  20568.    2. The effective access of member a is determined: 
  20569.  
  20570.         a. Because the original access of the member a is public in class A, 
  20571.            the initial effective access of a is public. 
  20572.         b. Because B inherits from A privately, the effective access of a 
  20573.            inside class B is private. 
  20574.         c. Because class B is the reference scope, the effective access 
  20575.            procedure stops here. The effective access of a is private. 
  20576.  
  20577.    3. The access rules are applied. The rules state that a private member can 
  20578.       be accessed by a friend or a member of the member's class. Because f(B*) 
  20579.       is a friend of class B, f(B*) can access the private member a. 
  20580.  
  20581.  
  20582. ΓòÉΓòÉΓòÉ <hidden> Examples of Inherited Member Access Rules ΓòÉΓòÉΓòÉ
  20583.  
  20584. /************************************************************************
  20585. *
  20586.  
  20587. The following example demonstrates inherited member access rules. 
  20588.  
  20589.                                     *
  20590. ************************************************************************/
  20591.  
  20592. // This example illustrates inherited member access rules.
  20593.  
  20594. class B
  20595. {
  20596.    int a;
  20597. public:
  20598.    int b,c;
  20599.    void f(int) {}
  20600. protected:
  20601.    int d;
  20602.    void g(int) {}
  20603. };
  20604.  
  20605. class D1 : public B
  20606. {
  20607.    int a;
  20608. public:
  20609.    int b;
  20610.    void h(int i )
  20611.    {
  20612.       g(i);        // valid, protected B::g(int)
  20613.       B::b = 10;     // valid, B::b (not local b)
  20614.       d = 5 ;       // valid, protected B::d
  20615.    }
  20616. };
  20617.  
  20618. class D2 : private B
  20619. {
  20620.    int e;
  20621. public:
  20622.    B::c;             // modify access to B::c
  20623.    void h(int i) { d = 5; }    // valid,protected B::d
  20624. };
  20625.  
  20626. void main( )
  20627. {
  20628.  
  20629.    int i= 1;    // declare and initialize local variable
  20630.    D1 d1;     // create object of class d1
  20631.    D2 d2;     // create object of class d2
  20632.  
  20633.    d1.a = 5;    // error, D1::a is private in class D1
  20634.    d2.b = 10;   // error, B::b is inherited private to
  20635.            // derived class D2
  20636.    d2.c = 5;    // valid, modified access from private to public
  20637.    d2.B::c = 5;  // valid, public B::c
  20638.    d1.c = 5;    // valid, B::c is inherited publicly
  20639.    d1.d = 5;    // error, B::d is protected in base class
  20640.    d2.e = 10;   // error, private D2::e
  20641.    d1.g(i);    // error, g(int) is protected in base class
  20642.    d1.h(i);    // valid
  20643.    d2.h(i);    // valid
  20644. }
  20645.  
  20646. /************************************************************************
  20647. *
  20648.  
  20649.                                     *
  20650. ************************************************************************/
  20651.  
  20652.  
  20653. ΓòÉΓòÉΓòÉ 14.4. Multiple Inheritance ΓòÉΓòÉΓòÉ
  20654.  
  20655. You can derive a class from more than one base class. Deriving a class from 
  20656. more than one direct base class is called multiple inheritance. 
  20657.  
  20658. In the following example, classes A, B, and C are direct base classes for the 
  20659. derived class X: 
  20660.  
  20661. class A { /* ... */ };
  20662. class B { /* ... */ };
  20663. class C { /* ... */ };
  20664. class X : public A, private B, public C { /* ... */ };
  20665.  
  20666. The order of derivation is relevant only to determine the order of default 
  20667. initialization by constructors and cleanup by destructors. For more 
  20668. information, see Initialization by Constructor. 
  20669.  
  20670. A direct base class cannot appear in the base list of a derived class more than 
  20671. once: 
  20672.  
  20673. class B1 { /* ... */ };          // direct base class
  20674. class D : public B1, private B1 { /* ... */ }; // error
  20675.  
  20676. However, a derived class can inherit an indirect base class more than once, as 
  20677. shown in the following example: 
  20678.  
  20679. class L { /* ... */ };          // indirect base class
  20680. class B2 : public L { /* ... */ };
  20681. class B3 : public L { /* ... */ };
  20682. class D : public B2, public B3 { /* ... */ }; // valid
  20683.  
  20684. In the above example, class D inherits the indirect base class L once through 
  20685. class B2 and once through class B3. However, this may lead to ambiguities 
  20686. because two objects of class L exist, and both are accessible through class D. 
  20687. You can avoid this ambiguity by referring to class L using a qualified class 
  20688. name, for example,  B2::L  or  B3::L . 
  20689.  
  20690. You can also avoid this ambiguity by using the base specifier virtual to 
  20691. declare a base class. 
  20692.  
  20693. Examples of Single and Multiple Inheritance 
  20694.  
  20695. Related Information 
  20696.  
  20697.      Virtual Base Classes 
  20698.      Multiple Access 
  20699.      Inheritance Overview 
  20700.      Derivation 
  20701.      Initialization by Constructor 
  20702.      C++ Classes 
  20703.  
  20704.  
  20705. ΓòÉΓòÉΓòÉ 14.4.1. Virtual Base Classes ΓòÉΓòÉΓòÉ
  20706.  
  20707. If you have an inheritance graph in which two or more derived classes have a 
  20708. common base class, you can use a virtual base class to ensure that the two 
  20709. classes share a single instance of the base class. 
  20710.  
  20711. In the following example, an object of class D has two distinct objects of 
  20712. class L, one through class B1 and another through class B2. You can use the 
  20713. keyword virtual in front of the base class specifiers in the base lists of 
  20714. classes B1 and B2 to indicate that only one class L, shared by class B1 and 
  20715. class B2, exists. 
  20716.  
  20717. For example: 
  20718.  
  20719. class L { /* ... */ }; // indirect base class
  20720. class B1 : virtual public L { /* ... */ };
  20721. class B2 : virtual public L { /* ... */ };
  20722. class D : public B1, public B2 { /* ... */ }; // valid
  20723.  
  20724. Using the keyword virtual in this example ensures that an object of class D 
  20725. inherits only one object of class L. 
  20726.  
  20727. A derived class can have both virtual and nonvirtual base classes. For example: 
  20728.  
  20729. class V { /* ... */ };
  20730. class B1 : virtual public V { /* ... */ };
  20731. class B2 : virtual public V { /* ... */ };
  20732. class B3 : public V { /* ... */ };
  20733. class D : public B1, public B2, public B3 { /* ... */
  20734. };
  20735.  
  20736. In the above example, class D has two objects of class V, one that is shared by 
  20737. classes B1 and B2 and one through class B3. 
  20738.  
  20739. Related Information 
  20740.  
  20741.      Multiple Inheritance 
  20742.      Multiple Access 
  20743.      Inheritance Overview 
  20744.      Derivation 
  20745.      C++ Classes 
  20746.  
  20747.  
  20748. ΓòÉΓòÉΓòÉ 14.4.2. Multiple Access ΓòÉΓòÉΓòÉ
  20749.  
  20750. In an inheritance graph containing virtual base classes, a name that can be 
  20751. reached through more than one path is accessed through the path that gives the 
  20752. most access. 
  20753.  
  20754. For example: 
  20755.  
  20756. class L { public: void f(); };
  20757. class B1 : private virtual L { /* ... */ };
  20758. class B2 : public virtual L { /* ... */ };
  20759. class D : public B1, public B2
  20760. {
  20761. public:
  20762.    void f() {L::f();} // L::f() is accessed through B2
  20763.                    // and is public
  20764. };
  20765.  
  20766. In the above example, the function f() is accessed through class B2. Because 
  20767. class B2 is inherited publicly and class B1 is inherited privately, class B2 
  20768. offers more access. 
  20769.  
  20770. An accessible base class is a publicly derived base class that is neither 
  20771. hidden nor ambiguous in the inheritance hierarchy. 
  20772.  
  20773. When you derive classes, ambiguities can result if base and derived classes 
  20774. have members with the same names. Access to a base class member is ambiguous if 
  20775. you use a name or qualified name that does not refer to a unique function, 
  20776. object, type, or enumerator. The declaration of a member with an ambiguous name 
  20777. in a derived class is not an error. The ambiguity is only flagged as an error 
  20778. if you use the ambiguous member name. 
  20779.  
  20780. For example, if two base classes have a member of the same name, an attempt to 
  20781. access the member by the derived class is ambiguous. You can resolve ambiguity 
  20782. by qualifying a member with its class name using the :: (scope resolution) 
  20783. operator. 
  20784.  
  20785. Example of Resolving Ambiguous Access 
  20786.  
  20787. The compiler checks for ambiguities at compile time. Because ambiguity checking 
  20788. occurs before access control or type checking, ambiguities may result even if 
  20789. only one of several members with the same name is accessible from the derived 
  20790. class. 
  20791.  
  20792. Conversions (either implicit or explicit) from a derived class pointer or 
  20793. reference to a base class pointer or reference must refer unambiguously to the 
  20794. same accessible base class object. For example: 
  20795.  
  20796. class W { /* ... */ };
  20797. class X : public W { /* ... */ };
  20798. class Y : public W { /* ... */ };
  20799. class Z : public X, public Y { /* ... */ };
  20800. void main ()
  20801. {
  20802.    Z z;
  20803.    X* xptr = &z;    // valid
  20804.    Y* yptr = &z;    // valid
  20805.    W* wptr = &z;    // error, ambiguous reference to class W
  20806.              // X's W or Y's W ?
  20807. }
  20808.  
  20809. You can use virtual base classes to avoid ambiguous reference. For example: 
  20810.  
  20811. class W { /* ... */ };
  20812. class X : public virtual W { /* ... */ };
  20813. class Y : public virtual W { /* ... */ };
  20814. class Z : public X, public Y { /* ... */ };
  20815. void main ()
  20816. {
  20817.    Z z;
  20818.    X* xptr = &z;    // valid
  20819.    Y* yptr = &z;    // valid
  20820.    W* wptr = &z;    // valid, W is virtual therefore only one
  20821.              // W subobject exists
  20822. }
  20823.  
  20824. Related Information 
  20825.  
  20826.      Virtual Base Classes 
  20827.      Multiple Inheritance 
  20828.      C++ Scope Resolution Operator :: 
  20829.      Inheritance Overview 
  20830.      Derivation 
  20831.      Member Access 
  20832.  
  20833.  
  20834. ΓòÉΓòÉΓòÉ <hidden> Example of Resolving Ambiguous Access ΓòÉΓòÉΓòÉ
  20835.  
  20836. /************************************************************************
  20837. *
  20838.  
  20839. The following example uses the :: (scope resolution) operator to resolve an 
  20840. ambiguous reference. 
  20841.  
  20842.                                     *
  20843. ************************************************************************/
  20844.  
  20845. // This example illustrates ambiguous base classes.
  20846.  
  20847. class B1
  20848. {
  20849. public:
  20850.    int i;
  20851.    int j;
  20852.    int g( );
  20853. };
  20854. class B2
  20855. {
  20856. public:
  20857.    int j;
  20858.    int g( );
  20859. };
  20860. // ...
  20861. class D : public B1, public B2
  20862. {
  20863. public:
  20864.    int i;
  20865. };
  20866. void main ()
  20867. {
  20868.    D dobj;
  20869.    D *dptr = &dobj;
  20870.    dptr -> i = 5;     // valid, D::i
  20871.    dptr -> j = 10;    // error, ambiguous reference to j
  20872.    dptr->B1::j = 10;   // valid, B1::j
  20873.    dobj.g( );       // error, ambiguous reference to g( )
  20874.    dobj.B2::g( );     // valid, B2::g( )
  20875. }
  20876.  
  20877.  
  20878. ΓòÉΓòÉΓòÉ 14.5. Virtual Functions ΓòÉΓòÉΓòÉ
  20879.  
  20880. In C++, dynamic binding is supported by the mechanism of virtual functions. 
  20881. Virtual functions must be members of a class. Use virtual functions when you 
  20882. expect a class to be used as a base class in a derivation and when the 
  20883. implementation of the function may be overridden in the derived class. You can 
  20884. declare a member function with the keyword virtual in its class declaration. 
  20885. For example: 
  20886.  
  20887. class B
  20888. {
  20889.    int a,b,c;
  20890. public:
  20891.    virtual int f();
  20892. };
  20893.  
  20894. You can reimplement a virtual member function, like any member function, in any 
  20895. derived class. The implementation that is executed when you make a call to a 
  20896. virtual function depends on the type of the object for which it is called. If a 
  20897. virtual member function is called for a derived class object and the function 
  20898. is redefined in the derived class, the definition in the derived class is 
  20899. executed. In this case, the redefined derived class function is said to 
  20900. override the base class function. This occurs even if the access to the 
  20901. function is through a pointer or reference to the base class. 
  20902.  
  20903. If you call a virtual function with a pointer that has base class type but 
  20904. points to a derived class object, the member function of the derived class is 
  20905. called. However, if you call a nonvirtual function with a pointer that has base 
  20906. class type, the member function of the base class is called regardless of 
  20907. whether the pointer points to a derived class object. 
  20908.  
  20909. Example of Overriding Virtual Functions 
  20910.  
  20911. If the argument types or the number of arguments of the two functions are 
  20912. different, the functions are considered different, and the function in the 
  20913. derived class does not override the function in the base class. The function in 
  20914. the derived class hides the function in the base class. 
  20915.  
  20916. The return type of an overriding virtual function can differ from the return 
  20917. type of the overridden virtual function provided that: 
  20918.  
  20919.      The overridden function returns a pointer or a reference to a class T 
  20920.  
  20921.       AND 
  20922.  
  20923.      The overriding virtual function returns a pointer or a reference to a 
  20924.       class derived from T. 
  20925.  
  20926.  An error does result when a virtual function that returns D* overrides a 
  20927.  virtual function that returns B* where B is an ambiguous base class of D. The 
  20928.  reason is that two or more instances of class B will exist within class D, and 
  20929.  the compiler will not know which base B to return. For more information, see 
  20930.  Function Return Values. 
  20931.  
  20932.  A virtual function cannot be global or static because, by definition, a 
  20933.  virtual function is a member function of a base class and relies on a specific 
  20934.  object to determine which implementation of the function is called. You can 
  20935.  declare a virtual function to be a friend of another class. 
  20936.  
  20937.  If a function is declared virtual in its base class, it can still be accessed 
  20938.  directly using the :: (scope resolution) operator. In this case, the virtual 
  20939.  function call mechanism is suppressed and the function implementation defined 
  20940.  in the base class is used. In addition, if you do not redefine a virtual 
  20941.  member function in a derived class, a call to that function uses the function 
  20942.  implementation defined in the base class. 
  20943.  
  20944.  A virtual function must be one of the following: 
  20945.  
  20946.      Defined 
  20947.      Declared pure 
  20948.      Defined and declared pure 
  20949.  
  20950.  A base class containing one or more pure virtual member functions is called an 
  20951.  abstract class. 
  20952.  
  20953.  Related Information 
  20954.  
  20955.      Virtual Base Classes 
  20956.      Ambiguous Virtual Function Calls 
  20957.      Virtual Function Access 
  20958.      Abstract Classes 
  20959.      Function Return Values 
  20960.      Friends 
  20961.      C++ Scope Resolution Operator :: 
  20962.      Inheritance Overview 
  20963.      Derivation 
  20964.  
  20965.  
  20966. ΓòÉΓòÉΓòÉ <hidden> Example of Overriding Virtual Functions ΓòÉΓòÉΓòÉ
  20967.  
  20968. /************************************************************************
  20969. *
  20970.  
  20971. The following example shows how virtual functions can be redefined. 
  20972.  
  20973.                                     *
  20974. ************************************************************************/
  20975.  
  20976. class B
  20977. {
  20978. public:
  20979.    virtual int f();
  20980.    virtual int g();
  20981.    int h();
  20982. };
  20983. class D : public B
  20984. {
  20985. public:
  20986.    int f();
  20987.    int g(char*);    // hides B::g()
  20988.    int h();
  20989. };
  20990. // ...
  20991. void main ()
  20992. {
  20993.    D d;
  20994.    B* bptr = &d;
  20995.  
  20996.    bptr->f();     // calls D::f() because f() is virtual
  20997.    bptr->h();     // calls B::h() because h() is nonvirtual
  20998.    bptr->g();     // calls B::g()
  20999.    d.g();       // error, wrong number and type of arguments
  21000.    d.g("string");   // calls D::g(char*)
  21001. }
  21002.  
  21003.  
  21004. ΓòÉΓòÉΓòÉ 14.5.1. Ambiguous Virtual Function Calls ΓòÉΓòÉΓòÉ
  21005.  
  21006. It is an error to override one virtual function with two or more ambiguous 
  21007. virtual functions. This can happen in a derived class that inherits from two 
  21008. nonvirtual bases that are derived from a virtual base class. 
  21009.  
  21010. Example of Ambiguous Virtual Functions 
  21011.  
  21012. A special case occurs when the ambiguous overriding virtual functions come from 
  21013. separate instances of the same class type. In the following example, there are 
  21014. two objects (instances) of class L. There are two data members L::count, one in 
  21015. class A and one in class B. If the declaration of class D is allowed, 
  21016. incrementing L::count in a call to L::f() with a pointer to class V is 
  21017. ambiguous. 
  21018.  
  21019. class V
  21020. {
  21021. public:
  21022.    virtual void f();
  21023. };
  21024. class L : virtual public V
  21025. {
  21026.    int count;
  21027.    void f();
  21028. };
  21029. void L::f() {++count;}
  21030. class A : public L
  21031. { /* ... */ };
  21032. class B : public L
  21033. { /* ... */ };
  21034. class D : public A, public B { /* ... */ }; // error
  21035. void main ()
  21036. {
  21037.    D d;
  21038.    V* vptr = &d;
  21039.    vptr->f();
  21040. }
  21041.  
  21042. In the above example, the function L::f() is expecting a pointer to an L 
  21043. object; that is, the this pointer for class L, as its first implicit argument. 
  21044. Because there are two objects of class L in a D object, there are two this 
  21045. pointers that could be passed to L::f(). Because the compiler cannot decide 
  21046. which this pointer to pass to L::f(), the declaration of class D is flagged as 
  21047. an error. 
  21048.  
  21049. Related Information 
  21050.  
  21051.      Virtual Functions 
  21052.      Virtual Function Access 
  21053.      Multiple Access 
  21054.      C++ Scope Resolution Operator :: 
  21055.      Member Functions 
  21056.  
  21057.  
  21058. ΓòÉΓòÉΓòÉ <hidden> Example of Ambiguous Virtual Functions ΓòÉΓòÉΓòÉ
  21059.  
  21060. /************************************************************************
  21061. *
  21062.  
  21063. The following example shows a class that inherits from two nonvirtual bases 
  21064. that are derived from a virtual base class. 
  21065.  
  21066.                                     *
  21067. ************************************************************************/
  21068.  
  21069. class V
  21070. {
  21071. public:
  21072.    virtual void f() { /* ... */ };
  21073. };
  21074. class A : virtual public V
  21075. {
  21076.    void f() { /* ... */ };
  21077. };
  21078. class B : virtual public V
  21079. {
  21080.    void f() { /* ... */ };
  21081. };
  21082. class D : public B, public A { /* ... */ }; // error
  21083. void main ()
  21084. {
  21085.    D d;
  21086.    V* vptr = &d;
  21087.    vptr->f();       // which f(), A::f() or B::f()?
  21088. }
  21089.  
  21090. /************************************************************************
  21091. *
  21092.  
  21093. In class A, only A::f() will override V::f(). Similarly, in class B, only 
  21094. B::f() will override V::f(). However, in class D, both A::f() and B::f() will 
  21095. try to override V::f(). This attempt is not allowed because it is not possible 
  21096. to decide which function to call if a D object is referenced with a pointer to 
  21097. class V, as shown in the above example. Because only one function can override 
  21098. a virtual function, the compiler flags this situation as an error. 
  21099.  
  21100.                                     *
  21101. ************************************************************************/
  21102.  
  21103.  
  21104. ΓòÉΓòÉΓòÉ 14.5.2. Virtual Function Access ΓòÉΓòÉΓòÉ
  21105.  
  21106. The access for a virtual function is specified when it is declared. The access 
  21107. rules for a virtual function are not affected by the access rules for the 
  21108. function that later overrides the virtual function. In general, the access of 
  21109. the overriding member function is not known. 
  21110.  
  21111. If a virtual function is called with a pointer or reference to a class object, 
  21112. the type of the class object is not used to determine the access of the virtual 
  21113. function. Instead, the type of the pointer or reference to the class object is 
  21114. used. 
  21115.  
  21116. In the following example, when the function f() is called using a pointer 
  21117. having type B*, bptr is used to determine the access to the function f(). 
  21118. Although the definition of f() defined in class D is executed, the access of 
  21119. the member function f() in class B is used. When the function f() is called 
  21120. using a pointer having type D*, dptr is used to determine the access to the 
  21121. function f(). This call produces an error because f() is declared private in 
  21122. class D. 
  21123.  
  21124. class B
  21125. {
  21126. public:
  21127.    virtual void f();
  21128. };
  21129. class D : public B
  21130. {
  21131. private:
  21132.    void f();
  21133. };
  21134. void main ()
  21135. {
  21136.    D dobj;
  21137.    B *bptr = &dobj;
  21138.    D *dptr = &dobj;
  21139.    bptr->f();  // valid, virtual B::f() is public,
  21140.           // D::f() is called
  21141.    dptr->f();  // error, D::f() is private
  21142. }
  21143.  
  21144. Related Information 
  21145.  
  21146.      Virtual Functions 
  21147.      Ambiguous Virtual Function Calls 
  21148.      Inherited Member Access 
  21149.  
  21150.  
  21151. ΓòÉΓòÉΓòÉ 14.6. Abstract Classes ΓòÉΓòÉΓòÉ
  21152.  
  21153. An abstract class is a class that is designed to be specifically used as a base 
  21154. class. An abstract class contains at least one pure virtual function. Pure 
  21155. virtual functions are inherited. You can declare a function to be pure by using 
  21156. a pure specifier in the declaration of the member function in the class 
  21157. declaration. 
  21158.  
  21159. For example: 
  21160.  
  21161. class AB       // abstract class
  21162. {
  21163. public:
  21164.    virtual void f()= 0; // pure virtual member function
  21165. };
  21166.  
  21167. A function that is declared pure typically has no definition and cannot be 
  21168. executed. Attempting to call a pure virtual function that has no implementation 
  21169. is undefined; however, such a call does not cause an error. No objects of an 
  21170. abstract class can be created. 
  21171.  
  21172. Note:  Because destructors are not inherited, a virtual destructor that is 
  21173. declared pure must have a definition. 
  21174.  
  21175. Virtual member functions are inherited. If a base class contains a pure virtual 
  21176. member function and a class derived from that base class does not redefine that 
  21177. pure virtual member function, the derived class itself is an abstract class. 
  21178. Any attempt to create an object of the derived class type produces an error. 
  21179.  
  21180. Examples of Errors using Abstract Classes 
  21181.  
  21182. You cannot use an abstract class as the type of an explicit conversion, as an 
  21183. argument type, or as the return type for a function. You can declare a pointer 
  21184. or reference to an abstract class. 
  21185.  
  21186. Related Information 
  21187.  
  21188.      Virtual Functions 
  21189.      Inheritance Overview 
  21190.      Derivation 
  21191.      C++ Classes 
  21192.  
  21193.  
  21194. ΓòÉΓòÉΓòÉ <hidden> Examples of Errors using Abstract Classes ΓòÉΓòÉΓòÉ
  21195.  
  21196. /************************************************************************
  21197. *
  21198.  
  21199. The following example shows an attempt to create an object of an abstract class 
  21200. type. 
  21201.  
  21202.                                     *
  21203. ************************************************************************/
  21204.  
  21205. class AB       // abstract class
  21206. {
  21207. public:
  21208.    virtual void f()= 0; // pure virtual member function
  21209. };
  21210. class D: public AB
  21211. {
  21212. public:
  21213.    void f();
  21214. };
  21215. // ...
  21216. void main ()
  21217. {
  21218.    D d;
  21219.    d.f() ;   // calls D::f()
  21220.    AB ab;    // error, cannot create an object of an
  21221.          // abstract class type
  21222. }
  21223.  
  21224. /************************************************************************
  21225. *
  21226.  
  21227. The following example shows an attempt to create an object of a class derived 
  21228. from an abstract class, but that does not redefine the pure virtual function of 
  21229. that abstract class. 
  21230.  
  21231.                                     *
  21232. ************************************************************************/
  21233.  
  21234. For example: 
  21235.  
  21236. class AB // abstract class
  21237. {
  21238. public:
  21239.    virtual void f()= 0; // pure virtual member function
  21240. };
  21241. class D2: public AB
  21242. {
  21243.    int a,b,c;
  21244. public:
  21245.    void g();
  21246. };
  21247. // ...
  21248. void main ()
  21249. {
  21250.    D2 d;
  21251.    // error, cannot declare an object of abstract class D2
  21252. }
  21253.  
  21254. To avoid the error in the above example, provide a declaration of D2::f(). 
  21255.  
  21256.  
  21257. ΓòÉΓòÉΓòÉ 14.7. Classes for Runtime Type Identification ΓòÉΓòÉΓòÉ
  21258.  
  21259. To use the typeid operator in Runtime Type Identification (RTTI) you must 
  21260. include the C++ standard header <typeinfo.h> This header defines the following 
  21261. classes: 
  21262.  
  21263.  type_info   Describes the RTTI available to the implementation; it defines the 
  21264.              object returned by the typeid operator. It is a polymorphic type 
  21265.              that supplies comparison and collation operators and provides a 
  21266.              member function that returns the name of the type represented. 
  21267.  
  21268.              The copy constructor and the assignment operator for the class 
  21269.              type_info are private; objects of this type cannot be copied. 
  21270.  
  21271.  bad_cast    Defines the type of objects thrown as exceptions to report dynamic 
  21272.              cast expressions that have failed. 
  21273.  
  21274.  bad_typeid  Defines the type of objects thrown as exceptions to report a null 
  21275.              pointer in a typeid expression. 
  21276.  
  21277.  VisualAge for C++ also defines the extended_type_info class, which provides 
  21278.  support for implementing operations for a persistent object store. It is 
  21279.  described in the IBM VisualAge for C++ for Windows Programming Guide. 
  21280.  
  21281.  Related Information 
  21282.  
  21283.      dynamic_cast<>() 
  21284.      typeid() 
  21285.      Inheritance Overview 
  21286.      Virtual Functions 
  21287.      Unary Expressions 
  21288.  
  21289.  
  21290. ΓòÉΓòÉΓòÉ 15. C++ Templates ΓòÉΓòÉΓòÉ
  21291.  
  21292. This chapter describes the C++ template facility. A template specifies how an 
  21293. individual class, function, or static data member can be constructed by 
  21294. providing a blueprint description of classes or functions within the template. 
  21295.  
  21296. Unlike an ordinary class or function definition, a template definition contains 
  21297. the template keyword, and uses a type argument, instead of a type, in one or 
  21298. more of the constructs used to define the class or function template. 
  21299. Individual classes or functions can then be generated simply by specifying the 
  21300. template name and by naming the type for the particular class or function as 
  21301. the type argument of the template. You can use templates to define a family of 
  21302. types or functions. 
  21303.  
  21304. This chapter discusses: 
  21305.  
  21306.      Template Syntax 
  21307.      Structuring Your Program Using Templates 
  21308.      Class Templates 
  21309.      Function Templates 
  21310.      Differences between Class and Function Templates 
  21311.      Member Function Templates 
  21312.      Friends and Templates 
  21313.      Static Data Members and Templates 
  21314.  
  21315.  Note:  C++ objects with templates can now be linked as a separate step with 
  21316.  the VisualAge for C++ linker command. 
  21317.  
  21318.  Related Information 
  21319.  
  21320.      Functions 
  21321.      C++ Classes 
  21322.      Type Specifiers 
  21323.      define 
  21324.      implementation 
  21325.  
  21326.  See the IBM VisualAge for C++ for Windows Programming Guide for programming 
  21327.  hints on using templates in C++ programs. 
  21328.  
  21329.  
  21330. ΓòÉΓòÉΓòÉ 15.1. Template Syntax ΓòÉΓòÉΓòÉ
  21331.  
  21332. The syntax for a template is: 
  21333.  
  21334.          ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21335. >>ΓöÇΓöÇtemplateΓöÇΓöÇΓöÉΓöÇΓöÇΓö┤Γö¼ΓöÇargument-declarationΓöÇΓö¼Γö┤ΓöÇΓöÇ>ΓöÇΓöÇ><
  21336.        Γöé  Γöé            Γöé
  21337.          ΓööΓöÇtypeΓöÇΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21338.  
  21339. The declaration in a template declaration must define or declare one of the 
  21340. following: 
  21341.  
  21342.      A class 
  21343.      A function 
  21344.      A static member of a template class 
  21345.  
  21346.  The identifier of a type is defined to be a type_name in the scope of the 
  21347.  template declaration. A template declaration can appear as a global 
  21348.  declaration only. 
  21349.  
  21350.  The template arguments (within the < and > delimitiers) specify the types and 
  21351.  the constants within the template that must be specified when the template is 
  21352.  instantiated. 
  21353.  
  21354.  Examples of Templates 
  21355.  
  21356.  Default intializers are permitted in template arguments, under the following 
  21357.  conditions: 
  21358.  
  21359.      They can only be applied to nontype template arguments. 
  21360.      Like functions, they can only be applied to trailing arguments. 
  21361.      Subsequent template declarations can add default initializers but cannot 
  21362.       redefine existing default initializers. 
  21363.      They can only be applied to class template declarations, not to function 
  21364.       template declarations. 
  21365.  
  21366.  Note:  A template that defines a member function of a class template is 
  21367.  treated as a function template. Such a template cannot have default 
  21368.  intializers. 
  21369.  
  21370.  Example of Default Initializers in Templates 
  21371.  
  21372.  Related Information 
  21373.  
  21374.      Structuring Your Program Using Templates 
  21375.      Class Templates 
  21376.      Function Templates 
  21377.      C++ Classes 
  21378.      Functions 
  21379.      Static Members 
  21380.  
  21381.  
  21382. ΓòÉΓòÉΓòÉ <hidden> Examples of Templates ΓòÉΓòÉΓòÉ
  21383.  
  21384. Given the following template: 
  21385.  
  21386. template<class L> class Key
  21387. {
  21388.   L k;
  21389.   L* kptr;
  21390.   int length;
  21391. public:
  21392.   Key(L);
  21393.   // ...
  21394. };
  21395.  
  21396. The following table shows what the classes Key<int>, Key<char*>, and 
  21397. Key<mytype> look like: 
  21398.  
  21399. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21400. Γöé class Key<int> i;    Γöé class Key<char*> c;    Γöé class Key<mytype> m;   Γöé
  21401. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21402. Γöé class Key<int> {     Γöé class Key<char*> {    Γöé class Key<mytype> {   Γöé
  21403. Γöé    int k;       Γöé    char* k;      Γöé    mytype k;     Γöé
  21404. Γöé    int * kptr;    Γöé    char** kptr;    Γöé    mytype* kptr;   Γöé
  21405. Γöé    int length;    Γöé    int length;     Γöé    int length;    Γöé
  21406. Γöé public:         Γöé public:          Γöé public:         Γöé
  21407. Γöé    Key(int);     Γöé    Key(char*);     Γöé    Key(mytype);    Γöé
  21408. Γöé    // ...  };     Γöé    // ...  };     Γöé    // ...  };     Γöé
  21409. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21410.  
  21411. The declarations create the following objects: 
  21412.  
  21413.      i of type Key<int> 
  21414.      c of type Key<char*> 
  21415.      m of type Key<mytype> 
  21416.  
  21417.  Note that these three classes have different names. The types contained within 
  21418.  the angle braces are not arguments to the class names, but part of the class 
  21419.  names themselves. Key<int> and Key<char*> are class names. Within the context 
  21420.  of the example, a class called Key (with no template argument list) is 
  21421.  undefined. 
  21422.  
  21423.  
  21424. ΓòÉΓòÉΓòÉ <hidden> Example of Default Initializers in Templates ΓòÉΓòÉΓòÉ
  21425.  
  21426. /************************************************************************
  21427. *
  21428.  
  21429. The following example shows a valid template declaration with default 
  21430. initializers: 
  21431.  
  21432. *
  21433. ************************************************************************/
  21434.  
  21435. // This example shows a template declaration
  21436. // with default initializers.
  21437.  
  21438. #include <stdio.h>
  21439.  
  21440. template <class T, int i=1> class X
  21441. {
  21442. public:
  21443.    T s;
  21444.    X(int j=4);
  21445.    int val(T&)
  21446.    {
  21447.     return i;
  21448.    };
  21449. };
  21450.  
  21451. template <class T, int i> X<T,i>::X(int j):s(i){
  21452.  printf("i=%d  j=%d\n",i,j);
  21453. }
  21454.  
  21455. void main()
  21456. {
  21457.  X<int>  myX(2);
  21458.  X<int,3> myX2(4);
  21459. }
  21460.  
  21461.  
  21462. ΓòÉΓòÉΓòÉ 15.2. Structuring Your Program Using Templates ΓòÉΓòÉΓòÉ
  21463.  
  21464. You can structure your program three ways using templates: 
  21465.  
  21466.    1. Include the function template definition (both the .h and .c files) in 
  21467.       all files that may reference the corresponding template functions. 
  21468.  
  21469.    2. Include the function template declaration (the .h file only) in all files 
  21470.       that may reference the corresponding template functions, but include the 
  21471.       function definition (both the .h and .c files) in one file only. 
  21472.  
  21473.    3. Include the declaration of the function templates in a header file and 
  21474.       the definition in a source file that has the same name. When you include 
  21475.       the header file in your source, the compiler automatically generates the 
  21476.       template functions. Use the /Ft+ option to enable this method. 
  21477.  
  21478.  The following examples use two files to illustrate all three methods: stack.h 
  21479.  and stackdef.h 
  21480.  
  21481.  To instantiate a stack of 50 ints, you would declare the following in each 
  21482.  source file that requires it: 
  21483.  
  21484.   stack<int> intStack(50);
  21485.  
  21486.  For method 1, each source file using the template should include both stack.h 
  21487.  and stackdef.h. 
  21488.  
  21489.  For method 2, every source file should include stack.h, but only one of the 
  21490.  files needs to include stackdef.h. 
  21491.  
  21492.  For method 3, every source file should include stack.h. The compiler 
  21493.  automatically generates the template functions in the TEMPINC subdirectory 
  21494.  that is created in the current directory. To use this method, copy stackdef.h 
  21495.  to stack.c and use the /Ft+ option, which is the default. 
  21496.  
  21497.  Note:  C++ objects with templates can now be linked as a separate step with 
  21498.  the VisualAge for C++ linker command. 
  21499.  
  21500.  Related Information 
  21501.  
  21502.      Template Syntax 
  21503.      Class Templates 
  21504.      Function Templates 
  21505.      Differences between Class and Function Templates 
  21506.      "Using Templates in C++ Programs" in the IBM VisualAge for C++ for 
  21507.       Windows Programming Guide. 
  21508.  
  21509.  
  21510. ΓòÉΓòÉΓòÉ <hidden> stack.h and stackdef.h ΓòÉΓòÉΓòÉ
  21511.  
  21512. /************************************************************************
  21513. *
  21514.  
  21515. stack.h 
  21516.  
  21517.                                     *
  21518. ************************************************************************/
  21519.  
  21520. #ifndef _STACK_TPL_H
  21521.    #define _STACK_TPL_H
  21522.  
  21523.    template<class T>
  21524.    class stack
  21525.    {
  21526.    private:
  21527.        T*  v;
  21528.        T*  p;
  21529.        int sz;
  21530.  
  21531.    public:
  21532.        stack( int );
  21533.        ~stack();
  21534.        void push( T );
  21535.    };
  21536. #endif
  21537.  
  21538. /************************************************************************
  21539. *
  21540.  
  21541. stackdef.h 
  21542.  
  21543.                                     *
  21544. ************************************************************************/
  21545.  
  21546. #include "stack.h"
  21547.  
  21548. template<class T> stack<T>::stack( int s )
  21549. {
  21550.    v = p = new T[sz=s];
  21551. }
  21552.  
  21553. template<class T> stack<T>::~stack()
  21554. {
  21555.    delete [] v;
  21556. }
  21557.  
  21558. template<class T> void stack<T>::push( T a )
  21559. {
  21560.    *p++ = a;
  21561. }
  21562.  
  21563.  
  21564. ΓòÉΓòÉΓòÉ 15.3. Class Templates ΓòÉΓòÉΓòÉ
  21565.  
  21566. The relationship between a class template and an individual class is like the 
  21567. relationship between a class and an individual object. An individual class 
  21568. defines how a group of objects can be constructed, while a class template 
  21569. defines how a group of classes can be generated. 
  21570.  
  21571. Note the distinction between the terms class template and template class: 
  21572.  
  21573.  Class template    is a template used to generate template classes. A class 
  21574.                    template can be only a declaration, or it can be a 
  21575.                    definition of the class. 
  21576.  
  21577.  Template class    is an instance of a class template. 
  21578.  
  21579.  A template definition is identical to any valid class definition that the 
  21580.  template might generate, except for the following: 
  21581.  
  21582.      The class template definition is preceded by  template < 
  21583.       template-argument-list >  where template-argument-list can include zero 
  21584.       or more arguments of user-defined type and zero or more argument 
  21585.       declarations. The template-argument-list must contain at least one 
  21586.       argument. 
  21587.  
  21588.      Types, variables, constants and objects within the class template can be 
  21589.       declared with arguments of user-defined type as well as with explicit 
  21590.       types (for example, int or char). 
  21591.  
  21592.      The template-argument-list can include argument-declarations (for 
  21593.       example, int a or char* b), which are generally used to define constant 
  21594.       values within the created class. 
  21595.  
  21596.  A class template can declare a class without defining it by using an 
  21597.  elaborated type specifier. For example: 
  21598.  
  21599.   template  <class L,class T> class key;
  21600.  
  21601.  This reserves the name as a class template name. All template declarations for 
  21602.  a class template must have the same types and number of template arguments. 
  21603.  Only one template declaration containing the class definition is allowed. 
  21604.  
  21605.  You can instantiate the class template by declaring a template class. If the 
  21606.  definitions of the member functions of the template class are not inlined, 
  21607.  then you have to define them. When you instantiate a template class, its 
  21608.  argument list must match the argument list in the class template declaration. 
  21609.  
  21610.  Syntax of a Template Class Instantiation 
  21611.  
  21612.  Note:  When you have nested template argument lists, you must have a 
  21613.  separating space between the > at the end of the inner list and the one at the 
  21614.  end of the outer list. Otherwise, there is an ambiguity between the output 
  21615.  operator >> and two template list delimiters >. 
  21616.  
  21617.   template  <class L,class T> class key
  21618.   {
  21619.   // ...
  21620.   };
  21621.   template <class L> class vector
  21622.   {
  21623.   // ...
  21624.   };
  21625.  
  21626.   void main ()
  21627.   {
  21628.   class key <int, vector<int> >; // instantiate template
  21629.   }
  21630.  
  21631.  Objects and functions of individual template classes can be accessed by any of 
  21632.  the techniques used to access ordinary class member objects and functions. 
  21633.  
  21634.  Examples of Accessing Class Template Members 
  21635.  
  21636.  Related Information 
  21637.  
  21638.      Class Template Declarations and Definitions 
  21639.      Nontype Template Arguments 
  21640.      Explicitly Defined Template Classes 
  21641.      Function Templates 
  21642.      Template Syntax 
  21643.      Structuring Your Program Using Templates 
  21644.      C++ Classes 
  21645.      Differences between Class and Function Templates 
  21646.  
  21647.  
  21648. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Template Class Instantiation ΓòÉΓòÉΓòÉ
  21649.  
  21650. The syntax for instantiation of a template class is: 
  21651.  
  21652.            ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21653. >>ΓöÇΓöÇtemplate-nameΓöÇΓöÇΓöÉΓöÇΓöÇΓö┤Γö¼ΓöÇtypeΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>ΓöÇΓöÇ><
  21654.           Γöé  Γöé            Γöé
  21655.             ΓööΓöÇassignment-expressionΓöÇΓöÿ
  21656.  
  21657.  
  21658. ΓòÉΓòÉΓòÉ <hidden> Examples of Accessing Class Template Members ΓòÉΓòÉΓòÉ
  21659.  
  21660. Given a class template: 
  21661.  
  21662. template<class T> class vehicle
  21663. {
  21664. public:
  21665.   vehicle() { /* ... */ }   // constructor
  21666.   ~vehicle() {};       // destructor
  21667.   T kind[16];
  21668.   T* drive();
  21669.   static void roadmap();
  21670.   // ...
  21671. };
  21672.  
  21673. and the declaration: 
  21674.  
  21675. vehicle<char> bicycle; // instantiates the template
  21676.  
  21677. the constructor, the constructed object, and the member function drive() can be 
  21678. accessed with any of the following (assuming the standard header file 
  21679. <string.h> is included in the program file): 
  21680.  
  21681. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21682. Γöé constructor          Γöé "vehicle<char> bicycle;            Γöé
  21683. Γöé                Γöé // constructor called automatically      Γöé
  21684. Γöé                Γöé // object bicycle created"          Γöé
  21685. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21686. Γöé object "bicycle"        Γöé "strcpy (bicycle.kind, "10 speed");      Γöé
  21687. Γöé                Γöé bicycle.kind[0] = '2';"            Γöé
  21688. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21689. Γöé function "drive()"       Γöé "char* n = bicycle.drive();"         Γöé
  21690. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21691. Γöé function "roadmap()"      Γöé "vehicle<char>::roadmap();"          Γöé
  21692. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  21693.  
  21694.  
  21695. ΓòÉΓòÉΓòÉ 15.3.1. Class Template Declarations and Definitions ΓòÉΓòÉΓòÉ
  21696.  
  21697. A class template must be declared before any declaration of a corresponding 
  21698. template class. A class template definition can only appear once in any single 
  21699. compilation unit. A class template must be defined before any use of a template 
  21700. class that requires the size of the class or refers to members of the class. 
  21701.  
  21702. In the following example, the class template key is declared before it is 
  21703. defined. The declaration of the pointer keyiptr is valid because the size of 
  21704. the class is not needed. The declaration of keyi, however, causes an error. 
  21705.  
  21706. template  <class L> class key;    // class template declared,
  21707.                   // not defined yet
  21708.                   //
  21709. class key<int> *keyiptr;       // declaration of pointer
  21710.                   //
  21711. class key<int> keyi;         // error, cannot declare keyi
  21712.                   // without knowing size
  21713.                   //
  21714. template <class L> class key     // now class template defined
  21715. {
  21716. // ...
  21717. };
  21718.  
  21719. If a template class is used before the corresponding class template is defined, 
  21720. the compiler issues an error. A class name with the appearance of a template 
  21721. class name is considered to be a template class. In other words, angle brackets 
  21722. are valid in a class name only if that class is a template class. 
  21723.  
  21724. The definition of a class template is not compiled until the definition of a 
  21725. template class is required. At that point, the class template definition is 
  21726. compiled using the argument list of the template class to instantiate the 
  21727. template arguments. Any errors in the class definition are flagged at this 
  21728. time. If the definition of a class template is never required, it is not 
  21729. compiled. In this case, some errors in the definition might not be flagged by 
  21730. the compiler. The /Wcls option can be used to find errors in class templates 
  21731. that are not compiled. 
  21732.  
  21733. A class template can only be defined once within a compilation unit, and the 
  21734. class template name cannot be declared to refer to any other template, class, 
  21735. object, function, value, or type in the same scope. 
  21736.  
  21737. Related Information 
  21738.  
  21739.      Class Templates 
  21740.      Nontype Template Arguments 
  21741.      Explicitly Defined Template Classes 
  21742.      /Wcls option 
  21743.      C++ Classes 
  21744.      Function Templates 
  21745.      Differences between Class and Function Templates 
  21746.  
  21747.  
  21748. ΓòÉΓòÉΓòÉ 15.3.2. Nontype Template Arguments ΓòÉΓòÉΓòÉ
  21749.  
  21750. A nontype template argument provided within a template argument list is an 
  21751. expression whose value can be determined at compile time. Such arguments must 
  21752. be constant expressions, addresses of functions or objects with external 
  21753. linkage, or addresses of static class members. Nontype template arguments are 
  21754. normally used to initialize a class or to specify the sizes of class members. 
  21755.  
  21756. For nontype integral arguments, the instance argument matches the corresponding 
  21757. template argument as long as the instance argument has a value and sign 
  21758. appropriate to the argument type. 
  21759.  
  21760. For nontype address arguments, the type of the instance argument must be of the 
  21761. form identifier or &identifier, and the type of the instance argument must 
  21762. match the template argument exactly, except that a function name is changed to 
  21763. a pointer to function type before matching. 
  21764.  
  21765. The resulting values of nontype template arguments within a template argument 
  21766. list form part of the template class's type. If two template class names have 
  21767. the same template name and if their arguments have identical values, they are 
  21768. the same class. 
  21769.  
  21770. Example of Nontype Template Arguments 
  21771.  
  21772. Note:  Arguments that contain the < symbol or the > symbol must be enclosed in 
  21773.        parentheses to prevent it from being parsed as a template argument list 
  21774.        delimiter when it is being used as a relational operator or a nested 
  21775.        template delimiter. For example, the arguments in the following 
  21776.        definition are valid: 
  21777.  
  21778.               myfilebuf<double, (20>10)> x;    // valid
  21779.  
  21780. The following definition, however, is not valid because the greater than 
  21781. operator (>) is interpreted as the closing delimiter of the template argument 
  21782. list: 
  21783.  
  21784. myfilebuf<double, 20>10> x;     // error
  21785.  
  21786.  If the template arguments do not evaluate identically, the objects created are 
  21787.  of different types: 
  21788.  
  21789.   myfilebuf<double,200> x;       // create object x of class
  21790.                     // myfilebuf<double,200>
  21791.   myfilebuf<double,200.0> y;      // error, 200.0 is a double,
  21792.                     // not an int
  21793.  
  21794.  The instantiation of y fails because the value 200.0 is of type double, and 
  21795.  the template argument is of type int. 
  21796.  
  21797.  The following two objects: 
  21798.  
  21799.      myfilebuf<double, 128> x
  21800.      myfilebuf<double, 512> y
  21801.  
  21802.  belong to separate template classes, and referencing either of these objects 
  21803.  later with myfilebuf<double> is an error. 
  21804.  
  21805.  A class template does not need to have a type argument if it has nontype 
  21806.  arguments. For example, the following template is a valid class template: 
  21807.  
  21808.   template<int i> class C
  21809.   {
  21810.      public:
  21811.         int k;
  21812.         C() { k = i; }
  21813.   };
  21814.  
  21815.  This class template can be instantiated by declarations such as: 
  21816.  
  21817.   class C<100>;
  21818.   class C<200>;
  21819.  
  21820.  Again, these two declarations refer to distinct classes because the values of 
  21821.  their nontype arguments differ. 
  21822.  
  21823.  Related Information 
  21824.  
  21825.      Class Templates 
  21826.      Class Template Declarations and Definitions 
  21827.      Explicitly Defined Template Classes 
  21828.      C++ Classes 
  21829.      Function Templates 
  21830.      Differences between Class and Function Templates 
  21831.  
  21832.  
  21833. ΓòÉΓòÉΓòÉ <hidden> Example of Nontype Template Arguments ΓòÉΓòÉΓòÉ
  21834.  
  21835. In the following example, a class template is defined that requires a nontype 
  21836. template int argument as well as the type argument: 
  21837.  
  21838. template<class T, int size> class myfilebuf
  21839. {
  21840.    T* filepos;
  21841.    static int array[size];
  21842. public:
  21843.    myfilebuf() { /* ... */ }
  21844.    ~myfilebuf();
  21845.    advance(); // function defined elsewhere in program
  21846. };
  21847.  
  21848. In this example, the template argument size becomes a part of the template 
  21849. class name. An object of such a template class is created with both the type 
  21850. arguments of the class and the values of any additional template arguments. 
  21851.  
  21852. An object x, and its corresponding template class with arguments double and 
  21853. size=200, can be created from this template with a value as its second template 
  21854. argument: 
  21855.  
  21856. myfilebuf<double,200> x;
  21857.  
  21858. x can also be created using an arithmetic expression: 
  21859.  
  21860. myfilebuf<double,10*20> x;
  21861.  
  21862. The objects created by these expressions are identical because the template 
  21863. arguments evaluate identically. The value 200 in the first expression could 
  21864. have been represented by an expression whose result at compile time is known to 
  21865. be equal to 200, as shown in the second construction. 
  21866.  
  21867.  
  21868. ΓòÉΓòÉΓòÉ 15.3.3. Explicitly Defined Template Classes ΓòÉΓòÉΓòÉ
  21869.  
  21870. You can override the definition of a class template of a particular template 
  21871. class by providing a class definition for the type of class required. For 
  21872. example, the following class template creates a class for each type for which 
  21873. it is referenced, but that class may be inappropriate for a particular type: 
  21874.  
  21875. template<class M> class portfolio
  21876. {
  21877.    double capital;
  21878.    M arr;
  21879.    // ...
  21880. } ;
  21881.  
  21882. The type for which the template class is inappropriate can be defined by using 
  21883. the applicable template class name. Assuming the inappropriately defined type 
  21884. is stocks, you can redefine the class portfolio<stocks> as follows: 
  21885.  
  21886. class portfolio<stocks>
  21887. {
  21888.    double capital;
  21889.    stocks yield;
  21890.    // ...
  21891. };
  21892.  
  21893. An explicit specialization of a template class can be defined before the class 
  21894. template is declared. In particular, a template class such as portfolio<stocks> 
  21895. can be defined before its class template has been defined. 
  21896.  
  21897. Related Information 
  21898.  
  21899.      Class Templates 
  21900.      Class Template Declarations and Definitions 
  21901.      Nontype Template Arguments 
  21902.      C++ Classes 
  21903.      Function Templates 
  21904.      Differences between Class and Function Templates 
  21905.  
  21906.  
  21907. ΓòÉΓòÉΓòÉ 15.4. Function Templates ΓòÉΓòÉΓòÉ
  21908.  
  21909. A function template allows you to define a group of functions that are the same 
  21910. except for the types of one or more of their arguments or objects. All type 
  21911. arguments in a function template must be used in the argument list or in the 
  21912. class qualifier for the function name. The type of a template function argument 
  21913. need not be explicitly specified when the template function is called. In this 
  21914. respect, a template function differs from a template class. 
  21915.  
  21916. Note the distinction between the terms function template and template function: 
  21917.  
  21918.  Function template   is a template used to generate template functions. A 
  21919.                      function template can be only a declaration, or it can 
  21920.                      define the function. 
  21921.  
  21922.  Template function   is a function generated by a function template. 
  21923.  
  21924.  Example of a Function Template 
  21925.  
  21926.  Because template functions can be generated in all compilation units that 
  21927.  contain function template definitions, you may want to group function template 
  21928.  definitions into one or two compilation units. Using templates in C++ programs 
  21929.  is described completely in the IBM VisualAge for C++ for Windows Programming 
  21930.  Guide. 
  21931.  
  21932.  Related Information 
  21933.  
  21934.      Overloading Resolution for Template Functions 
  21935.      Explicitly Defined Template Functions 
  21936.      Function Template Declarations and Definitions 
  21937.      Differences between Class and Function Templates 
  21938.      Functions 
  21939.      Class Templates 
  21940.  
  21941.  
  21942. ΓòÉΓòÉΓòÉ <hidden> Example of a Function Template ΓòÉΓòÉΓòÉ
  21943.  
  21944. If you want to create a function approximate(), which determines whether two 
  21945. values are within 5% of each other, you can define the following template: 
  21946.  
  21947.    #include <math.h>
  21948.    template <class T> int approximate (T first, T second)
  21949.    {
  21950.       double aptemp=double(first)/double(second);
  21951.       return int(abs(aptemp-1.0) <= .05);
  21952.    };
  21953.  
  21954. Assuming you have two values of type float you want to compare, you can use the 
  21955. approximate function template: 
  21956.  
  21957.    float a=3.24, b=3.35;
  21958.    if (approximate(a,b))
  21959.       cout << "a and b are pretty close" << endl;
  21960.  
  21961. A template function int approximate(float,float) is generated to resolve the 
  21962. call. 
  21963.  
  21964.  
  21965. ΓòÉΓòÉΓòÉ 15.4.1. Overloading Resolution for Template Functions ΓòÉΓòÉΓòÉ
  21966.  
  21967. Resolution of overloaded template functions is done in the following order: 
  21968.  
  21969.    1. Look for a function with an exact type match. This does not include 
  21970.       template functions, unless such functions were explicitly declared using 
  21971.       a function declaration. Trivial conversions are performed if they produce 
  21972.       an exact type match. 
  21973.  
  21974.    2. Look for a function template that allows generation of a function with an 
  21975.       exact type match. Trivial conversions are performed if they produce an 
  21976.       exact type match. 
  21977.  
  21978.    3. Try ordinary overloading resolution for functions already present. This 
  21979.       does not include template functions, unless such functions were 
  21980.       explicitly declared using a function declaration. 
  21981.  
  21982.  A call to a template function causes an error, and no overloading is done if 
  21983.  the following conditions are true: 
  21984.  
  21985.      The only available functions for a call are template functions. 
  21986.      These functions would require nontrivial conversions for the call to 
  21987.       succeed. 
  21988.      These functions have not been explicitly declared. 
  21989.  
  21990.  Example of Overloading a Template Function 
  21991.  
  21992.  Related Information 
  21993.  
  21994.      Trivial Conversions 
  21995.      Implicit Type Conversions 
  21996.      Function Templates 
  21997.      Explicitly Defined Template Functions 
  21998.      Function Template Declarations and Definitions 
  21999.      Functions 
  22000.      Differences between Class and Function Templates 
  22001.      Class Templates 
  22002.  
  22003.  
  22004. ΓòÉΓòÉΓòÉ <hidden> Example of Overloading a Template Function ΓòÉΓòÉΓòÉ
  22005.  
  22006. In the case of the approximate() function template: 
  22007.  
  22008.    #include <math.h>
  22009.    template <class T> int approximate (T first, T second)
  22010.    {
  22011.       double aptemp=double(first)/double(second);
  22012.       return int(abs(aptemp-1.0) <= .05);
  22013.    };
  22014.  
  22015. if the two input values are of different types, overloading resolution does not 
  22016. take place: 
  22017.  
  22018.    float a=3.24;
  22019.    double b=3.35;
  22020.    if (approximate(a,b))  // error, different types
  22021.    { /* ... */ }
  22022.  
  22023. The solution is to force a conversion to one of the available function types by 
  22024. explicitly declaring the function for the chosen type. To resolve the 
  22025. float/double example, include the following function declaration: 
  22026.  
  22027.    int approximate(double a, double b);
  22028.    // force conversion of the float to double
  22029.  
  22030. This declaration creates a function approximate() that expects two arguments of 
  22031. type double, so that when approximate(a,b) is called, the overloading is 
  22032. resolved by converting variable a to type double. 
  22033.  
  22034.  
  22035. ΓòÉΓòÉΓòÉ 15.4.2. Explicitly Defined Template Functions ΓòÉΓòÉΓòÉ
  22036.  
  22037. In some situations, a function template can define a group of functions in 
  22038. which, for one function type, the function definition would be inappropriate. 
  22039. For instance, the function template: 
  22040.  
  22041.   template<class T> int approximate(T first, T second);
  22042.  
  22043. determines whether two values are within 5% of each other. The algorithm used 
  22044. for this function template is appropriate for numerical values, but for char* 
  22045. values, it would indicate whether the pointers to two character strings are 
  22046. within 5% of one another, not whether the strings themselves are approximately 
  22047. equal. Whether two pointers are within 5% of each other is not useful 
  22048. information. You can define an explicit template function for char* values to 
  22049. compare the two strings themselves, character by character. 
  22050.  
  22051. Example of an Explicitly Defined Template Function 
  22052.  
  22053. Explicit definition has the same effect on template overloading resolution as 
  22054. explicit declaration (See Overloading Resolution for Template Functions for 
  22055. more information.) If a template function is explicitly defined for: 
  22056.  
  22057. int approximate(double a, double b) { /* ... */ }
  22058.  
  22059. then a call of: 
  22060.  
  22061. double a=3.54;
  22062. float b=3.5;
  22063. approximate(a,b);
  22064.  
  22065. resolves in a call to  approximate(double a, double b)  and variable b is 
  22066. converted to type double. 
  22067.  
  22068. Related Information 
  22069.  
  22070.      Function Templates 
  22071.      Overloading Resolution for Template Functions 
  22072.      Function Template Declarations and Definitions 
  22073.      Functions 
  22074.      Differences between Class and Function Templates 
  22075.      Class Templates 
  22076.  
  22077.  
  22078. ΓòÉΓòÉΓòÉ <hidden> Example of an Explicitly Defined Template Function ΓòÉΓòÉΓòÉ
  22079.  
  22080. The following explicitly defined template function compares two strings and 
  22081. returns a value indicating whether more than 5% of the characters differ 
  22082. between the two strings: 
  22083.  
  22084. #include <string.h>
  22085. int approximate(char *first, char *second)
  22086. {
  22087.    if (strcmp(first,second) == 0)
  22088.       return 1; // strings are identical
  22089.  
  22090.    double difct=0;
  22091.    int maxlen=0;
  22092.  
  22093.    if (strlen(first)>strlen(second))
  22094.       maxlen=strlen(first);
  22095.  
  22096.    else maxlen=strlen(second);
  22097.    for (int i=0; i<=maxlen ; ++i)
  22098.       if ( first[i] != second[i] ) difct++;
  22099.    return int((difct / maxlen) <= .05  );
  22100. }
  22101.  
  22102. Given this definition, the function call:  approximate("String A","String B"); 
  22103. invokes the explicitly defined function above, and no template function is 
  22104. generated. 
  22105.  
  22106.  
  22107. ΓòÉΓòÉΓòÉ 15.4.3. Function Template Declarations and Definitions ΓòÉΓòÉΓòÉ
  22108.  
  22109. When a template function is defined explicitly within a compilation unit, this 
  22110. definition is used in preference to any instantiation from the function 
  22111. template. For example, if one compilation unit contains the code: 
  22112.  
  22113. #include <iostream.h>
  22114. template <class T> T f(T i) {return i+1;}
  22115. void main()
  22116. {
  22117.    cout << f(2) << endl;
  22118. }
  22119.  
  22120. and another contains: 
  22121.  
  22122. int f(int i) {return i+2;}
  22123.  
  22124. when compiled and run, the program prints the number 4 to standard output, 
  22125. indicating that the explicitly defined function was used to resolve the call to 
  22126. f(). 
  22127.  
  22128. Each template, whether of a class or of a function, must be defined at most 
  22129. once within a compilation unit. The same applies to an explicitly defined 
  22130. template class or function. Function templates and class templates can be 
  22131. declared many times. 
  22132.  
  22133. A template class is considered declared if its name is used. A template 
  22134. function is considered declared if any of the following applies: 
  22135.  
  22136.      A function whose name matches a function template's name is declared, and 
  22137.       an appropriate template function can be generated. 
  22138.      A function whose name matches a function template's name is called, and 
  22139.       an appropriate template function can be generated. 
  22140.      A function whose name matches a function template's name is called, and 
  22141.       the template function has been explicitly defined. 
  22142.      The address of a template function is taken in such a way that 
  22143.       instantiation can occur. This means the pointer to function must supply a 
  22144.       return type and argument types that can be used to instantiate the 
  22145.       template function. 
  22146.  
  22147.  A template function is instantiated or generated if the function is referenced 
  22148.  in any of the following ways, provided that function is not explicitly defined 
  22149.  elsewhere in the program: 
  22150.  
  22151.      The function is declared. 
  22152.      A call to the function is made. 
  22153.      The address of the function is taken. 
  22154.  
  22155.  When a template function is instantiated, the body of the function template is 
  22156.  compiled using the template argument list of the template class to instantiate 
  22157.  the template arguments. Any errors in the function definition are flagged at 
  22158.  this time. If a template function is never generated from a function template, 
  22159.  it is not compiled. In this case, some errors in the function definition might 
  22160.  not be flagged by the compiler. 
  22161.  
  22162.  Related Information 
  22163.  
  22164.      Function Templates 
  22165.      Overloading Resolution for Template Functions 
  22166.      Explicitly Defined Template Functions 
  22167.      Functions 
  22168.      Differences between Class and Function Templates 
  22169.      Class Templates 
  22170.  
  22171.  
  22172. ΓòÉΓòÉΓòÉ 15.5. Differences between Class and Function Templates ΓòÉΓòÉΓòÉ
  22173.  
  22174. The name of a template class is a compound name consisting of the template name 
  22175. and the full template argument list enclosed in angle braces. Any references to 
  22176. a template class must use this complete name. For example: 
  22177.  
  22178. template <class T, int range> class ex
  22179. {
  22180.    T a;
  22181.     int r;
  22182.    // ...
  22183. };
  22184. //...
  22185. ex<double,20> obj1;   // valid
  22186. ex<double> obj2;     // error
  22187. ex obj3;         // error
  22188.  
  22189. C++ requires this explicit naming convention to ensure that the appropriate 
  22190. class can be generated. 
  22191.  
  22192. A template function, on the other hand, has the name of its function template 
  22193. and the particular function chosen to resolve a given template function call is 
  22194. determined by the type of the calling arguments. In the following example, the 
  22195. call min(a,b) is effectively a call to min(int a, int b), and the call min(af, 
  22196. bf) is effectively a call to min(float a, float b): 
  22197.  
  22198. // This example illustrates a template function.
  22199.  
  22200. template<class T> T min(T a, T b)
  22201. {
  22202.    if (a < b)
  22203.       return a;
  22204.    else
  22205.       return b;
  22206. }
  22207. void main()
  22208. {
  22209.    int a = 0;
  22210.    int b = 2;
  22211.    float af = 3.1;
  22212.    float bf = 2.9;
  22213.    cout << "Here is the smaller int " << min(a,b) << endl;
  22214.    cout << "Here is the smaller float " << min(af, bf) << endl;
  22215. }
  22216.  
  22217. Related Information 
  22218.  
  22219.      Class Templates 
  22220.      Function Templates 
  22221.      C++ Classes 
  22222.      Functions 
  22223.  
  22224.  
  22225. ΓòÉΓòÉΓòÉ 15.6. Member Function Templates ΓòÉΓòÉΓòÉ
  22226.  
  22227. In Function Templates, a function template was defined outside of any template 
  22228. class. However, functions in C++ are often member functions of a class. If you 
  22229. want to create a class template and a set of function templates to go with that 
  22230. class template, you do not have to create the function templates explicitly, as 
  22231. long as the function definitions are contained within the class template. Any 
  22232. member function (inlined or noninlined) declared within a class template is 
  22233. implicitly a function template. When a template class is declared, it 
  22234. implicitly generates template functions for each function defined in the class 
  22235. template. 
  22236.  
  22237. You can define template member functions three ways: 
  22238.  
  22239.    1. Explicitly at file scope for each type used to instantiate the template 
  22240.       class. 
  22241.    2. At file scope with the template arguments. 
  22242.    3. Inlined in the class template itself. 
  22243.  
  22244.  Examples of Defining Template Member Functions 
  22245.  
  22246.  Member function templates are used to instantiate any functions that are not 
  22247.  explicitly generated. If you have both a member function template and an 
  22248.  explicit definition, the explicit definition is used. 
  22249.  
  22250.  The template argument is not used in a constructor name. For example: 
  22251.  
  22252.   template<class L> class Key
  22253.   {
  22254.      Key();       // default constructor
  22255.      Key( L );     // constructor taking L by value
  22256.      Key<L>( L );    // error, <L> implicit within class template
  22257.   };
  22258.  
  22259.  The declaration Key<L>(L) is an error because the constructor does not use the 
  22260.  template argument. Assuming this class template was corrected by removing the 
  22261.  offending line, you can define a function template for the class template's 
  22262.  constructor: 
  22263.  
  22264.   // Constructor contained in function template:
  22265.   template<class L>
  22266.      Key<L>::Key(int) { /* ... */ }
  22267.      // valid, constructor template argument assumed template<class L>
  22268.  
  22269.      Key<L>::Key<L>(int) { /* ... */ }
  22270.      /* error, constructor template argument <L> implicit
  22271.        in class template argument */
  22272.  
  22273.  A template function name does not include the template argument. The template 
  22274.  argument does, however, appear in the template class name if a member function 
  22275.  of a template class is defined or declared outside of the class template. The 
  22276.  definition:   Key<L>::Key(int) { /* ... */ }   is valid because Key<L> (with 
  22277.  template argument) refers to the class, while Key(int) { /* ... */ } refers to 
  22278.  the member function. 
  22279.  
  22280.  Related Information 
  22281.  
  22282.      Class Templates 
  22283.      Function Templates 
  22284.      C++ Class Members and Friends 
  22285.  
  22286.  
  22287. ΓòÉΓòÉΓòÉ <hidden> Examples of Defining Template Member Functions ΓòÉΓòÉΓòÉ
  22288.  
  22289. /************************************************************************
  22290. *
  22291.  
  22292. The following three examples illustrate the three ways to define template 
  22293. member functions: 
  22294.  
  22295. Method 1 
  22296.  
  22297.                                     *
  22298. ************************************************************************/
  22299.  
  22300.    template <class T> class key
  22301.    {
  22302.    public:
  22303.       void f(T);
  22304.    };
  22305.    void key<char>::f(char) { /* ... */ }
  22306.    void key<int>::f(int ) { /* ... */ }
  22307.  
  22308.    void main()
  22309.    {
  22310.       int i = 9;
  22311.       key< int> keyobj;
  22312.       keyobj.f(i);
  22313.    }
  22314.  
  22315. /************************************************************************
  22316. *
  22317.  
  22318. Method 2 
  22319.  
  22320.                                     *
  22321. ************************************************************************/
  22322.  
  22323.    template <class T> class key
  22324.    {
  22325.    public:
  22326.       void f(T);
  22327.    };
  22328.    template <class T> void key <T>::f(T) { /* ... */ }
  22329.  
  22330.    void main()
  22331.    {
  22332.       int i = 9;
  22333.       key< int> keyobj;
  22334.       keyobj.f(i);
  22335.    }
  22336.  
  22337. /************************************************************************
  22338. *
  22339.  
  22340. Method 3 
  22341.  
  22342.                                     *
  22343. ************************************************************************/
  22344.  
  22345.    template <class T> class key
  22346.    {
  22347.    public:
  22348.       void f(T) { /* ... */ }
  22349.    };
  22350.  
  22351.    void main()
  22352.    {
  22353.       int i = 9;
  22354.       key< int> keyobj;
  22355.       keyobj.f(i);
  22356.    }
  22357.  
  22358.  
  22359. ΓòÉΓòÉΓòÉ 15.7. Friends and Templates ΓòÉΓòÉΓòÉ
  22360.  
  22361. A friend function can be declared in a class template either as a single 
  22362. function shared by all classes created by the template or as a template 
  22363. function that varies from class to class within the class template. For 
  22364. example: 
  22365.  
  22366. template<class T> class portfolio
  22367. {
  22368.    //...
  22369.    friend void taxes();
  22370.    friend void transact(T);
  22371.    friend portfolio<T>* invest(portfolio<T>*);
  22372.    friend portfolio* divest(portfolio*);     //error
  22373.    // ...
  22374. };
  22375.  
  22376. In this example, each declaration has the following characteristics: 
  22377.  
  22378.  taxes() 
  22379.      is a single function that can access private and protected members of any 
  22380.      template class generated by the class template. Note that taxes() is not a 
  22381.      template function. 
  22382.  
  22383.  transact(T) 
  22384.      is a function template that declares a distinct function for each class 
  22385.      generated by the class template. The only private and protected members 
  22386.      that can be accessed by functions generated from this template are the 
  22387.      private and protected members of their template class. 
  22388.  
  22389.  invest(portfolio<T>*) 
  22390.      is a function template whose return and argument types are pointers to 
  22391.      objects of type portfolio<T>. Each class generated by the class template 
  22392.      will have a friend function of this name, and each such function will have 
  22393.      a pointer to an object of its own class as both its return type and its 
  22394.      argument type. 
  22395.  
  22396.  divest(portfolio*) 
  22397.      is an error because portfolio* attempts to point to a class template. A 
  22398.      pointer to a class template is undefined and produces an error. This 
  22399.      statement can be corrected by using the syntax of the invest() function 
  22400.      template instead. 
  22401.  
  22402.  Because all friend functions in this example are declared but not defined, you 
  22403.  could create a set of function templates to define those functions that are 
  22404.  implicitly template functions (that is, all the valid functions except 
  22405.  taxes()). The function templates would then be used to instantiate the 
  22406.  template functions as required. 
  22407.  
  22408.  Related Information 
  22409.  
  22410.      Friends 
  22411.      Class Templates 
  22412.      Function Templates 
  22413.      C++ Classes 
  22414.      Functions 
  22415.  
  22416.  
  22417. ΓòÉΓòÉΓòÉ 15.8. Static Data Members and Templates ΓòÉΓòÉΓòÉ
  22418.  
  22419. A static declaration within a class template declares a static data member for 
  22420. each template class generated from the template. The static declaration can be 
  22421. of template argument type or of any defined type. 
  22422.  
  22423. Like member function templates, you can explicitly define a static data member 
  22424. of a template class at file scope for each type used to instantiate a template 
  22425. class. For example: 
  22426.  
  22427. template <class T> class key
  22428. {
  22429. public:
  22430.    static T x;
  22431. };
  22432. int key<int>::x;
  22433. char key<char>::x;
  22434. void main()
  22435. {
  22436.    key<int>::x = 0;
  22437. }
  22438.  
  22439. You can also define a static data member of a template class using a template 
  22440. definition at file scope. For example: 
  22441.  
  22442. template <class T> class key
  22443. {
  22444. public:
  22445.    static T x;
  22446. };
  22447. template <class T> T key<T> ::x; // template definition
  22448. void main()
  22449. {
  22450.    key<int>::x = 0;
  22451. }
  22452.  
  22453. When you instantiate a template class, you must have either an explicit 
  22454. definition or a template definition for each static data member, but not both. 
  22455.  
  22456. Example of Static Data Members in Templates 
  22457.  
  22458. Related Information 
  22459.  
  22460.      Static Members 
  22461.      Class Templates 
  22462.      Explicitly Defined Template Classes 
  22463.      Function Templates 
  22464.      Explicitly Defined Template Functions 
  22465.  
  22466.  
  22467. ΓòÉΓòÉΓòÉ <hidden> Example of Static Data Members in Templates ΓòÉΓòÉΓòÉ
  22468.  
  22469. In the following example: 
  22470.  
  22471. template<class L> class Key
  22472. {
  22473.    static L k;
  22474.    static L* kptr;
  22475.    static int length;
  22476.    // ...
  22477. }
  22478.  
  22479. The definitions of static variables and objects must be instantiated at file 
  22480. scope. If the classes Key<int> and Key<double> are instantiated from this 
  22481. template, and no template definitions exist, the following static data members 
  22482. must be explicitly defined at file scope, or an error occurs: 
  22483.  
  22484. int Key<int>::k, Key<int>::length, Key<double>::length;
  22485. int* Key<int>::kptr;
  22486. double Key<double>::k;
  22487. double* Key<double>::kptr = 0;
  22488.  
  22489.  
  22490. ΓòÉΓòÉΓòÉ 16. C++ Exception Handling ΓòÉΓòÉΓòÉ
  22491.  
  22492. This chapter describes the VisualAge for C++ implementation of C++ exception 
  22493. handling. It discusses: 
  22494.  
  22495.      Formal and Informal Exception Handling 
  22496.      Using Exception Handling 
  22497.      Transferring Control 
  22498.      Constructors and Destructors in Exception Handling 
  22499.      Exception Specifications 
  22500.      unexpected() and terminate() Functions 
  22501.  
  22502.  Note:  C++ exception handling is not the same as Windows exception handling. A 
  22503.         C++ exception exists only within the C++ language. Windows exceptions 
  22504.         are generated by the operating system, and can be used by the VisualAge 
  22505.         for C++ library to generate a signal. In this section, the term 
  22506.         exception refers to a C++ exception. 
  22507.  
  22508.  Windows exception handling is described in detail in the IBM VisualAge for C++ 
  22509.  for Windows Programming Guide. 
  22510.  
  22511.  
  22512. ΓòÉΓòÉΓòÉ 16.1. C++ Exception Handling Overview ΓòÉΓòÉΓòÉ
  22513.  
  22514. Exception handling provides a way for a function that encounters an unusual 
  22515. situation to throw an exception and pass control to a direct or indirect caller 
  22516. of that function. The caller may or may not be able to handle the exception. 
  22517. Code that intercepts an exception is called a handler. Regardless of whether or 
  22518. not the caller can handle an exception, it may rethrow the exception so it can 
  22519. be intercepted by another handler. 
  22520.  
  22521. C++ provides three language constructs to implement exception handling: 
  22522.  
  22523.      Try blocks 
  22524.      Catch blocks 
  22525.      Throw expressions 
  22526.  
  22527.  Within a function, any unusual situation can be flagged with a throw 
  22528.  expression. The throw expression is of type void. Your program can throw an 
  22529.  object to pass information back to the caller. Any object can be thrown, 
  22530.  including the object that caused the exception or an object constructed when 
  22531.  the exception occurred. 
  22532.  
  22533.  A throw expression, or a call to a function that may throw an exception, 
  22534.  should be enclosed within a try block. If the called function throws an 
  22535.  exception and an exception handler is defined to catch the type of the object 
  22536.  thrown, the exception handler is executed. In C++, a catch block implements an 
  22537.  exception handler. A try block must be accompanied by one or more catch 
  22538.  clauses, otherwise the compiler will flag it as an error. 
  22539.  
  22540.  A catch block follows immediately after a try statement or immediately after 
  22541.  another catch block. A catch block includes a parenthesized exception 
  22542.  declaration containing optional qualifiers, a type, and an optional variable 
  22543.  name. The declaration specifies the type of object that the exception handler 
  22544.  may catch. Once an exception is caught, the body of the catch block is 
  22545.  executed. If no handler catches an exception, the program is terminated. 
  22546.  
  22547.  Exception handling is not strictly synonymous with error handling, because the 
  22548.  implementation allows the passing of an exception whether or not an error 
  22549.  actually occurred. You can use exception handlers for things other than 
  22550.  handling errors. For example, you can transfer control back to the original 
  22551.  caller of a function. You might use this if you wanted to process the Quit key 
  22552.  in a program and transfer control back to the driver program when the user 
  22553.  types Quit. To do this exception handlers could be used to throw an object 
  22554.  back to the driver. 
  22555.  
  22556.  Note:  C++ exception handling is not the same as Windows exception handling. A 
  22557.         C++ exception exists only within the C++ language. Windows exceptions 
  22558.         are generated by the operating system, and can be used by the VisualAge 
  22559.         for C++ library to generate a signal. In this section, the term 
  22560.         exception refers to a C++ exception. 
  22561.  
  22562.  Windows exception handling is described in detail in the IBM VisualAge for C++ 
  22563.  for Windows Programming Guide. 
  22564.  
  22565.  Related Information 
  22566.  
  22567.      Formal and Informal Exception Handling 
  22568.      Using Exception Handling 
  22569.      Transferring Control 
  22570.  
  22571.  
  22572. ΓòÉΓòÉΓòÉ 16.2. Formal and Informal Exception Handling ΓòÉΓòÉΓòÉ
  22573.  
  22574. While the exception handling features of C++ offer a formal mechanism for 
  22575. handling exceptions (language implemented), in many situations informal 
  22576. exception handling (logic implemented) is more appropriate. Generally speaking, 
  22577. formal exception handling should be implemented in libraries, classes, and 
  22578. functions likely to be accessed by several programs or programmers. It should 
  22579. also be used in classes and functions that are repeatedly accessed within a 
  22580. program but are not well-suited to handling their exceptions themselves. 
  22581. Because formal exception handling is designed for exceptional circumstances, it 
  22582. is not guaranteed to be efficient. Program performance is usually not affected 
  22583. when you do not invoke formal exception handling, although it can inhibit some 
  22584. optimizations. 
  22585.  
  22586. Informal exception handling, in which an appropriate action is defined if an 
  22587. error or exception occurs, is often more suitable for handling errors. For 
  22588. example, a simple error, such as entering incorrect input, can more easily and 
  22589. clearly be handled by testing the input for validity and by requesting the 
  22590. input again if the original input is incorrect. 
  22591.  
  22592. Related Information 
  22593.  
  22594.      C++ Exception Handling Overview 
  22595.      Using Exception Handling 
  22596.      Transferring Control 
  22597.  
  22598.  
  22599. ΓòÉΓòÉΓòÉ 16.3. Using Exception Handling ΓòÉΓòÉΓòÉ
  22600.  
  22601. The three keywords designed for exception handling in C++ are try, catch, and 
  22602. throw. 
  22603.  
  22604. Syntax of Exception Handling Keywords 
  22605.  
  22606. The steps required to implement an exception handler are: 
  22607.  
  22608.    1. Functions that are expected to be used by many programs are coded so 
  22609.       that, when an error is detected, an exception is thrown. The throw 
  22610.       expression generally throws an object. It may be created explicitly for 
  22611.       purposes of exception handling, or it may be the object that caused the 
  22612.       error to be detected. An example of throwing the problem object: 
  22613.  
  22614.               .
  22615.               .
  22616.               .
  22617.             int input=0;
  22618.             cout << "Enter a number between 1 and 10:";
  22619.             cin >> input;
  22620.  
  22621.             if (input < 1 || input >> 10);
  22622.              throw(input);  //throw the actual problem object
  22623.               .
  22624.               .
  22625.               .
  22626.  
  22627.       The following is an example of throwing an object for the purpose of 
  22628.       exception handling: 
  22629.  
  22630.               .
  22631.               .
  22632.               .
  22633.             int input=0;
  22634.             cout << "Enter a number between 1 and 10:";
  22635.             cin >> input;
  22636.  
  22637.             if (input < 1 || input >> 10)
  22638.               throw(out_of_range_object); //throw object to tell handler
  22639.                             //what happened
  22640.  
  22641.    2. Exceptions are anticipated in a caller by means of a try statement. 
  22642.       Function calls that you anticipate might produce an exception must be 
  22643.       enclosed in braces and preceded by the keyword try. 
  22644.  
  22645.    3. Immediately following the try block, you must code one or more catch 
  22646.       blocks. Each catch block identifies what type or class of objects it can 
  22647.       catch: 
  22648.  
  22649.         a. If the object thrown matches the type of a catch expression, control 
  22650.            passes to that catch block. 
  22651.         b. If the object thrown does not match the first catch block, 
  22652.            subsequent catch blocks are searched for a matching type. 
  22653.         c. If no match is found, the search continues in all enclosing try 
  22654.            blocks and then in the code that called the current function. 
  22655.         d. If no match is found after all try blocks are searched, a call to 
  22656.            terminate() is made. For information on the default handlers of 
  22657.       uncaught exceptions, see unexpected() and terminate() Functions. 
  22658.  
  22659.  Notes: 
  22660.  
  22661.      Any object can be thrown if it can be copied and destroyed in the 
  22662.       function from which the throw occurs. 
  22663.      Exceptions should never be thrown from a C language signal handler. The 
  22664.       result is undefined, and can cause program termination. 
  22665.  
  22666.  A catch argument causes an error if it is a value argument, and a copy of it 
  22667.  cannot be generated. Similarly, a throw expression causes an error if a copy 
  22668.  of the value of the expression being thrown cannot be generated. 
  22669.  
  22670.  Example of an Incorrect catch Argument 
  22671.  
  22672.  Related Information 
  22673.  
  22674.      C++ Exception Handling Overview 
  22675.      Formal and Informal Exception Handling 
  22676.      Transferring Control 
  22677.      Exception Specifications 
  22678.      unexpected() and terminate() Functions 
  22679.  
  22680.  
  22681. ΓòÉΓòÉΓòÉ <hidden> Syntax of Exception Handling Keywords ΓòÉΓòÉΓòÉ
  22682.  
  22683. The syntax for the try and catch keywords is: 
  22684.  
  22685.       ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  22686.             Γöé
  22687. >>ΓöÇΓöÇtryΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇcatchΓöÇΓöÇ(ΓöÇΓöÇ>
  22688.                              ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  22689.                                    Γöé
  22690. >ΓöÇΓöÇΓö¼ΓöÇ. . .ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  22691.   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ              Γöé
  22692.   Γöé          Γöé              Γöé
  22693.   ΓööΓöÇΓöÇΓöÇtype_specifierΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  22694.              Γö£ΓöÇdeclaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  22695.              ΓööΓöÇabstract_declaratorΓöÇΓöÿ
  22696.  
  22697. The syntax for the throw keyword is: 
  22698.  
  22699. >>ΓöÇΓöÇthrowΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  22700.       ΓööΓöÇassignment_expressionΓöÇΓöÿ
  22701.  
  22702.  
  22703. ΓòÉΓòÉΓòÉ <hidden> Example of an Incorrect catch Argument ΓòÉΓòÉΓòÉ
  22704.  
  22705. A catch argument causes an error if it is a value argument, and a copy of it 
  22706. cannot be generated. For example: 
  22707.  
  22708. class B {
  22709. public:
  22710.    B();
  22711.    B(B&);
  22712. };
  22713.        // the following catch block will cause an error
  22714.        //
  22715. catch(const B x)
  22716. {
  22717. // ...
  22718. }
  22719.  
  22720. The catch block causes an error because the compiler does not know the type of 
  22721. the object thrown at compile time. It assumes that the type of the thrown 
  22722. object is the same as the type of the catch argument. In the above example, the 
  22723. thrown object is assumed to be of type const B. The compiler uses a copy 
  22724. constructor on the thrown argument to create the catch argument. Because there 
  22725. is no copy constructor for class B that accepts const B as an input argument, 
  22726. the compiler cannot perform the construction and an error occurs. 
  22727.  
  22728.  
  22729. ΓòÉΓòÉΓòÉ 16.4. Transferring Control ΓòÉΓòÉΓòÉ
  22730.  
  22731. C++ implements the termination model of exception handling. In the termination 
  22732. model, when an exception is thrown, control never returns to the throw point. 
  22733. The throw point is the point in program execution where the exception occurred. 
  22734.  
  22735. C++ exception handling does not implement the resumption model of exception 
  22736. handling, which allows an exception handler to correct the exception and then 
  22737. return to the throw point. 
  22738.  
  22739. When an exception is thrown, control is passed out of the throw expression and 
  22740. out of the try block that anticipated the exception. Control is passed to the 
  22741. catch block whose exception type matches the object thrown. The catch block 
  22742. handles the exception as appropriate. If the catch block ends normally, the 
  22743. flow of control passes over all subsequent catch blocks. 
  22744.  
  22745. When an exception is not thrown from within a try block, the flow of control 
  22746. continues normally through the block, and passes over all catch blocks 
  22747. following the try block. 
  22748.  
  22749. An exception handler cannot return control to the source of the error by using 
  22750. the return statement. A return issued in this context returns from the function 
  22751. containing the catch block. 
  22752.  
  22753. If an exception is thrown and no try block is active, or if a try block is 
  22754. active and no catch block exception declaration matches the object thrown, a 
  22755. call to terminate() is issued. A call to terminate() in turn calls abort() to 
  22756. terminate the program. The abort() C library function is defined in the 
  22757. standard header file <stdlib.h>. 
  22758.  
  22759. Example of Basic Exception Handling 
  22760.  
  22761. Related Information 
  22762.  
  22763.      Catching Exceptions 
  22764.      Nested Try Blocks 
  22765.      Rethrowing an Exception 
  22766.      Using a Conditional Expression in a Throw Expression 
  22767.      C++ Exception Handling Overview 
  22768.      Using Exception Handling 
  22769.      Exception Specifications 
  22770.      unexpected() and terminate() Functions 
  22771.      abort - Stop a Program 
  22772.      return 
  22773.  
  22774.  
  22775. ΓòÉΓòÉΓòÉ <hidden> Example of Basic Exception Handling ΓòÉΓòÉΓòÉ
  22776.  
  22777. /************************************************************************
  22778. *
  22779.  
  22780. The following example illustrates the basic use of try, catch, and throw. The 
  22781. program prompts for numerical input and determines the input's reciprocal. 
  22782. Before it attempts to print the reciprocal to standard output, it checks that 
  22783. the input value is nonzero, to avoid a division by zero. If the input is zero, 
  22784. an exception is thrown, and the catch block catches the exception. If the input 
  22785. is nonzero, the reciprocal is printed to standard output. 
  22786.  
  22787.                                     *
  22788. ************************************************************************/
  22789.  
  22790. // This example illustrates the basic use of
  22791. // try, catch, and throw.
  22792.  
  22793. #include <iostream.h>
  22794. #include <stdlib.h>
  22795. class IsZero { /* ... */ };
  22796. void ZeroCheck( int i )
  22797. {
  22798.      if (i==0)
  22799.         throw IsZero();
  22800. }
  22801. void main()
  22802. {
  22803.      double a;
  22804.  
  22805.      cout << "Enter a number: ";
  22806.      cin >> a;
  22807.      try
  22808.      {
  22809.        ZeroCheck( a );
  22810.        cout << "Reciprocal is " << 1.0/a << endl;
  22811.      }
  22812.      catch ( IsZero )
  22813.      {
  22814.        cout << "Zero input is not valid" << endl;
  22815.        exit(1);
  22816.      }
  22817.      exit(0);
  22818. }
  22819.  
  22820. /************************************************************************
  22821. *
  22822.  
  22823. This example could have been coded more efficiently by using informal exception 
  22824. handling. However, it provides a simple illustration of formal exception 
  22825. handling. 
  22826.  
  22827.                                     *
  22828. ************************************************************************/
  22829.  
  22830.  
  22831. ΓòÉΓòÉΓòÉ 16.4.1. Catching Exceptions ΓòÉΓòÉΓòÉ
  22832.  
  22833. You can declare a handler to catch many types of exceptions. The allowable 
  22834. objects that a function can catch are declared in the parentheses following the 
  22835. catch keyword (the catch argument). You can catch objects of the fundamental 
  22836. types, base and derived class objects, references, and pointers to all of these 
  22837. types. You can also catch const and volatile types. 
  22838.  
  22839. You can also use the catch(...) form of the handler to catch all thrown 
  22840. exceptions that have not been caught by a previous catch block. The ellipsis in 
  22841. the catch argument indicates that any exception thrown can be handled by this 
  22842. handler. 
  22843.  
  22844. If an exception is caught by a catch(...) block, there is no direct way to 
  22845. access the object thrown. Information about an exception caught by catch(...) 
  22846. is very limited. You can declare an optional variable name if you want to 
  22847. access the thrown object in the catch block. 
  22848.  
  22849. A catch block can only catch accessible objects. The object caught must have an 
  22850. accessible copy constructor. For more information on access, see Member Access; 
  22851. on copy constructors, see Copy by Initialization. 
  22852.  
  22853. An argument in the catch argument of a handler matches an argument in the 
  22854. expression of the throw expression (throw argument) if any of the following 
  22855. conditions is met: 
  22856.  
  22857.      The catch argument type matches the type of the thrown object. 
  22858.      The catch argument is a public base class of the thrown class object. 
  22859.      The catch specifies a pointer type, and the thrown object is a pointer 
  22860.       type that can be converted to the pointer type of the catch argument by 
  22861.       standard pointer conversion. Pointer conversion is described on page 
  22862.       Pointer Conversions. 
  22863.  
  22864.  Note:  If the type of the thrown object is const or volatile, the catch 
  22865.  argument must also be a const or volatile for a match to occur. However, a 
  22866.  const, volatile, or reference type catch argument can match a nonconstant, 
  22867.  nonvolatile, or nonreference object type. A nonreference catch argument type 
  22868.  matches a reference to an object of the same type. 
  22869.  
  22870.  Always place a catch block that catches a derived class before a catch block 
  22871.  that catches the base class of that derived class (following a try block). If 
  22872.  a catch block for objects of a base class is followed by a catch block for 
  22873.  objects of a derived class of that base class, the latter block is flagged as 
  22874.  an error. 
  22875.  
  22876.  A catch block of the form catch(...) must be the last catch block following a 
  22877.  try block or an error occurs. This placement ensures that the catch(...) block 
  22878.  does not prevent more specific catch blocks from catching exceptions intended 
  22879.  for them. 
  22880.  
  22881.  Related Information 
  22882.  
  22883.      C++ Exception Handling Overview 
  22884.      Using Exception Handling 
  22885.      Transferring Control 
  22886.      Exception Specifications 
  22887.      volatile and const Qualifiers 
  22888.      Nested Try Blocks 
  22889.      Rethrowing an Exception 
  22890.  
  22891.  
  22892. ΓòÉΓòÉΓòÉ 16.4.2. Nested Try Blocks ΓòÉΓòÉΓòÉ
  22893.  
  22894. When try blocks are nested and a throw occurs in a function called by an inner 
  22895. try block, control is transferred outward through the nested try blocks until 
  22896. the first catch block is found whose argument matches the argument of the throw 
  22897. expression. 
  22898.  
  22899. For example: 
  22900.  
  22901. try
  22902. {
  22903.    func1();
  22904.    try
  22905.    {
  22906.        func2();
  22907.    }
  22908.    catch (spec_err) { /* ... */ }
  22909.    func3();
  22910. }
  22911. catch (type_err) { /* ... */ }
  22912. // if no throw is issued, control resumes here.
  22913.  
  22914. In the above example, if spec_err is thrown within the inner try block (in this 
  22915. case, from func2()), the exception is caught by the inner catch block, and, 
  22916. assuming this catch block does not transfer control, func3() is called. If 
  22917. spec_err is thrown after the inner try block (for instance, by func3()), it is 
  22918. not caught and the function terminate() is called. 
  22919.  
  22920. If the exception thrown from func2() in the inner try block is type_err, the 
  22921. program skips out of both try blocks to the second catch block without invoking 
  22922. func3(), because no appropriate catch block exists following the inner try 
  22923. block. If the entire try block in the example is in a function that has a throw 
  22924. list and does not include spec_err on its throw list, unexpected() is called. 
  22925.  
  22926. You can also nest a try block within a catch block. 
  22927.  
  22928. Related Information 
  22929.  
  22930.      Catching Exceptions 
  22931.      Transferring Control 
  22932.      Using Exception Handling 
  22933.      Rethrowing an Exception 
  22934.      Exception Specifications 
  22935.      unexpected() and terminate() Functions 
  22936.  
  22937.  
  22938. ΓòÉΓòÉΓòÉ 16.4.3. Rethrowing an Exception ΓòÉΓòÉΓòÉ
  22939.  
  22940. If a catch block cannot handle the particular exception it has caught, you can 
  22941. rethrow the exception. The rethrow expression (throw with no argument) causes 
  22942. the originally thrown object to be rethrown. 
  22943.  
  22944. Because the exception has already been caught at the scope in which the rethrow 
  22945. expression occurs, it is rethrown out to the next dynamically enclosing try 
  22946. block. Therefore, it cannot be handled by catch blocks at the scope in which 
  22947. the rethrow expression occurred. Any catch blocks following the dynamically 
  22948. enclosing try block have an opportunity to catch the exception. 
  22949.  
  22950. Example of Rethrowing an Exception 
  22951.  
  22952. The rethrow expression can be caught by any catch whose argument matches the 
  22953. argument of the exception originally thrown. 
  22954.  
  22955. Related Information 
  22956.  
  22957.      Catching Exceptions 
  22958.      Transferring Control 
  22959.      Using Exception Handling 
  22960.      Nested Try Blocks 
  22961.      Using a Conditional Expression in a Throw Expression 
  22962.      Exception Specifications 
  22963.  
  22964.  
  22965. ΓòÉΓòÉΓòÉ <hidden> Example of Rethrowing an Exception ΓòÉΓòÉΓòÉ
  22966.  
  22967. /************************************************************************
  22968. *
  22969.  
  22970. In the following example, catch(FileIO) catches any object of type FileIO and 
  22971. any objects that are public base classes of the FileIO class. It then checks 
  22972. for those exceptions it can handle. For any exception it cannot handle, it 
  22973. issues a rethrow expression to rethrow the exception and allow another handler 
  22974. in a dynamically enclosing try block to handle the exception. 
  22975.  
  22976.                                     *
  22977. ************************************************************************/
  22978.  
  22979. // This example illustrates rethrowing an exception.
  22980.  
  22981. #include <iostream.h>
  22982. class FileIO
  22983. {
  22984. public:
  22985.    int notfound;
  22986.    int endfile;
  22987.    FileIO(); // initialize data members
  22988.    // the following member functions throw an exception
  22989.    // if an input error occurs
  22990.    void advance(int x);
  22991.    void clear();
  22992.    void put(int x, int y);
  22993. };
  22994. //    .
  22995. //    .
  22996. //    .
  22997. void f()
  22998. {
  22999.    FileIO fio;
  23000.    try
  23001.    {
  23002.       // call member functions of FileIO class
  23003.       fio.advance (1);
  23004.       fio.clear();
  23005.       fio.put(1,-1);
  23006.    }
  23007.  
  23008.    catch(FileIO fexc)
  23009.    {
  23010.       if (fexc.notfound)
  23011.          cout << "File not Found" << endl;
  23012.       else if (fexc.endfile)
  23013.          cout << "End of File" << endl;
  23014.       else
  23015.          throw;       // rethrow to outer handler
  23016.    }
  23017.    catch(...) { /* ... */ }    // catch other exceptions
  23018. }
  23019. main()
  23020. {
  23021.    try
  23022.    {
  23023.       f();
  23024.    }
  23025.    catch(FileIO) { cout << "Outer Handler" << endl; }
  23026. }
  23027.  
  23028. /************************************************************************
  23029. *
  23030.  
  23031. The rethrow expression can be caught by any catch whose argument matches the 
  23032. argument of the exception originally thrown. Note that, in this example, the 
  23033. catch(...) will not catch the rethrow expression because, when the rethrow 
  23034. expression is issued, control passes out of the scope of the function f() into 
  23035. the next dynamically enclosing block. 
  23036.  
  23037.                                     *
  23038. ************************************************************************/
  23039.  
  23040.  
  23041. ΓòÉΓòÉΓòÉ 16.4.4. Using a Conditional Expression in a Throw Expression ΓòÉΓòÉΓòÉ
  23042.  
  23043. You can use a conditional expression as a throw expression. as shown in the 
  23044. following example: 
  23045.  
  23046. // This example illustrates a conditional expresion
  23047. // used as a throw expression.
  23048.  
  23049. #include <iostream.h>
  23050. void main() {
  23051.    int doit = 1;
  23052.    int dont = 0;
  23053.    float f = 8.9;
  23054.    int i = 7;
  23055.    int j = 6;
  23056.    try { throw(doit ? i : f); }
  23057.    catch (int x)
  23058.    {
  23059.       cout << "Caught int " << x << endl;
  23060.    }
  23061.    catch (float x)
  23062.    {
  23063.       cout << "Caught float " << x << endl;
  23064.    }
  23065.    catch (double x)
  23066.    {
  23067.       cout << "Caught double " << x << endl;
  23068.    }
  23069.    catch (...)
  23070.    {
  23071.       cout << "Caught something " << endl;
  23072.    }
  23073. }
  23074.  
  23075. This example produces the following output because j is of type int: 
  23076.  
  23077. Caught float 7
  23078.  
  23079. At first glance, it looks as if the block that catches integer values should do 
  23080. the catch, but i is converted to a float value in the try block because it is 
  23081. in a conditional expression with the float value f. If the try block in the 
  23082. example is replaced with the following try block: 
  23083.  
  23084.    try { throw doit ? i : j; }
  23085.  
  23086. The following output is produced: 
  23087.  
  23088. Caught int 7
  23089.  
  23090. Related Information 
  23091.  
  23092.      Catching Exceptions 
  23093.      Transferring Control 
  23094.      Using Exception Handling 
  23095.      Nested Try Blocks 
  23096.      Rethrowing an Exception 
  23097.      Exception Specifications 
  23098.  
  23099.  
  23100. ΓòÉΓòÉΓòÉ 16.5. Constructors and Destructors in Exception Handling ΓòÉΓòÉΓòÉ
  23101.  
  23102. When an exception is thrown and control passes to a catch block following a try 
  23103. block, destructors are called for all automatic objects constructed since the 
  23104. beginning of the try block directly associated with that catch block. If an 
  23105. exception is thrown during construction of an object consisting of subobjects 
  23106. or array elements, destructors are only called for those subobjects or array 
  23107. elements successfully constructed before the exception was thrown. A destructor 
  23108. for a local static object will only be called if the object was successfully 
  23109. constructed. 
  23110.  
  23111. For more information on constructors and destructors, see Constructors and 
  23112. Destructors Overview. 
  23113.  
  23114. If a destructor detects an exception and issues a throw, the exception can be 
  23115. caught if the caller of the destructor was contained within a try block and an 
  23116. appropriate catch is coded. 
  23117.  
  23118. If an exception is thrown by a function called from an inner try block, but 
  23119. caught by an outer try block (because the inner try block did not have an 
  23120. appropriate handler), all objects constructed within both the outer and all 
  23121. inner try blocks are destroyed. If the thrown object has a destructor, the 
  23122. destructor is not called until the exception is caught and handled. 
  23123.  
  23124. Because a throw expression throws an object and a catch statement can catch an 
  23125. object, the object thrown enables error-related information to be transferred 
  23126. from the point at which an exception is detected to the exception's handler. If 
  23127. you throw an object with a constructor, you can construct an object that 
  23128. contains information relevant to the catch expression. The catch block can then 
  23129. access information provided by the thrown object. 
  23130.  
  23131. Example of Using Constructors in Exception Handling 
  23132.  
  23133. Exception handling can be used in conjunction with constructors and destructors 
  23134. to provide resource management that ensures that all locked resources are 
  23135. unlocked when an exception is thrown. 
  23136.  
  23137. Example of Managing Resources with Constructors and Destructors 
  23138.  
  23139. Related Information 
  23140.  
  23141.      Constructors and Destructors Overview 
  23142.      C++ Exception Handling Overview 
  23143.      Using Exception Handling 
  23144.      Transferring Control 
  23145.      Exception Specifications 
  23146.  
  23147.  
  23148. ΓòÉΓòÉΓòÉ <hidden> Managing Resources with Constructors and Destructors ΓòÉΓòÉΓòÉ
  23149.  
  23150. /************************************************************************
  23151. *
  23152.  
  23153. Exception handling can be used in conjunction with constructors and destructors 
  23154. to provide resource management that ensures that all locked resources are 
  23155. unlocked when an exception is thrown. For example: 
  23156.  
  23157.                                     *
  23158. ************************************************************************/
  23159.  
  23160. class data
  23161. {
  23162.    public:
  23163.       void lock();    // prevent other users from
  23164.                // changing the object
  23165.       void unlock();   // allow other users to change
  23166.                // the object
  23167. };
  23168. void q(data&), bar(data&);
  23169. // ...
  23170. main()
  23171. {
  23172.    data important;
  23173.    important.lock();
  23174.    q(important);
  23175.    bar(important);
  23176.    important.unlock();
  23177. }
  23178.  
  23179. /************************************************************************
  23180. *
  23181.  
  23182. If q() or bar() throw an exception, important.unlock() will not be called and 
  23183. the data will stay locked. This problem can be corrected by using a helper 
  23184. class to write an exception-aware program for resource management. 
  23185.  
  23186.                                     *
  23187. ************************************************************************/
  23188.  
  23189. class data
  23190. {
  23191.    public:
  23192.       void lock();    // prevent other users from
  23193.                // changing the object
  23194.       void unlock();   // allow other users to change
  23195.                // the object
  23196. };
  23197. class locked_data       // helper class
  23198. {
  23199.    data& real_data;
  23200.    public:
  23201.       locked_data(data& d) : real_data(d)
  23202.                {real_data.lock();}
  23203.       ~locked_data() {real_data.unlock();}
  23204. };
  23205. void q(data&), bar(data&);
  23206. // ...
  23207. main()
  23208. {
  23209.    data important;
  23210.    locked_data my_lock(important);
  23211.    q(important);
  23212.    bar(important);
  23213. }
  23214.  
  23215. /************************************************************************
  23216. *
  23217.  
  23218. In this case, if q() or bar() throws an exception, the destructor for my_lock 
  23219. will be called, and the data will be unlocked. 
  23220.  
  23221.                                     *
  23222. ************************************************************************/
  23223.  
  23224.  
  23225. ΓòÉΓòÉΓòÉ <hidden> Example of Using Constructors in Exception Handling ΓòÉΓòÉΓòÉ
  23226.  
  23227. /************************************************************************
  23228. *
  23229.  
  23230. In the following example, an object of class DivideByZero is thrown by the 
  23231. function divide(). The constructor copies the string "Division by zero" into 
  23232. the char array errname. Because DivideByZero is a derived class of class 
  23233. Matherr, the catch block for Matherr catches the thrown exception. The catch 
  23234. block can then access information provided by the thrown object, in this case 
  23235. the text of an error message. 
  23236.  
  23237.                                     *
  23238. ************************************************************************/
  23239.  
  23240. // This example illustrates constructors and
  23241. // destructors in exception handling.
  23242.  
  23243. #include <string.h>       // needed for strcpy
  23244. #include <iostream.h>
  23245. class Matherr { public: char errname[30]; };
  23246. class DivideByZero : public Matherr
  23247. {
  23248. public:
  23249.    DivideByZero() {strcpy (errname, "Division by zero");}
  23250. };
  23251. double divide(double a, double b)
  23252. {
  23253.    if (b == 0) throw DivideByZero();
  23254.    return a/b;
  23255. }
  23256.  
  23257. void main()
  23258. {
  23259.    double a=7,b=0;
  23260.    try {divide (a,b);}
  23261.    catch (Matherr xx)
  23262.    {
  23263.       cout << xx.errname << endl;
  23264.    }
  23265. }
  23266.  
  23267.  
  23268. ΓòÉΓòÉΓòÉ 16.6. Exception Specifications ΓòÉΓòÉΓòÉ
  23269.  
  23270. C++ provides a mechanism to ensure that a given function is limited to throwing 
  23271. only a specified list of exceptions. An exception specification at the 
  23272. beginning of any function acts as a guarantee to the function's caller that the 
  23273. function will not directly or indirectly throw any exception not contained in 
  23274. the exception specification. For example, a function: 
  23275.  
  23276. void translate() throw(unknown_word,bad_grammar) { /* ... */ }
  23277.  
  23278. explicitly states that it will not throw any exception other than unknown_word 
  23279. or bad_grammar. The function translate() must handle any exceptions thrown by 
  23280. functions it might call, unless those exceptions are specified in the exception 
  23281. specification of translate(). If an exception is thrown by a function called by 
  23282. translate() and the exception is not handled by translate() or contained in the 
  23283. exception specification of translate(), unexpected() is called. 
  23284.  
  23285. Syntax of an Exception Specification 
  23286.  
  23287. If an exception is thrown from a function that has not specified the thrown 
  23288. exception in its exception specification, the result is a call to the function 
  23289. unexpected(), which is discussed in unexpected() and terminate() Functions. 
  23290.  
  23291. A function with an empty throw() specification guarantees that the function 
  23292. will not throw any exceptions. A function without an exception specification 
  23293. allows any object to be thrown from the function. 
  23294.  
  23295. The compiler does not prevent an exception specification from defining a more 
  23296. limited set of valid exceptions than the set of exceptions the function may 
  23297. actually throw. Such an error is detected only at run time, and only if the 
  23298. unspecified exception is thrown. 
  23299.  
  23300. Example of Throwing an Unspecified Exception 
  23301.  
  23302. If a function with an exception specification calls a subfunction with a less 
  23303. restrictive exception specification (one that contains more objects than the 
  23304. calling function's exception specification), any thrown objects from within the 
  23305. subfunction that are not handled by the subfunction, and that are not part of 
  23306. the outer function's specification list, must be handled within the outer 
  23307. function. If the outer function fails to handle an exception not in its 
  23308. exception specification, a call to unexpected() is made. 
  23309.  
  23310. Related Information 
  23311.  
  23312.      unexpected() and terminate() Functions 
  23313.      C++ Exception Handling Overview 
  23314.      Using Exception Handling 
  23315.      Transferring Control 
  23316.  
  23317.  
  23318. ΓòÉΓòÉΓòÉ <hidden> Syntax of an Exception Specification ΓòÉΓòÉΓòÉ
  23319.  
  23320. The syntax of the exception specification is: 
  23321.  
  23322.        ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23323.             Γöé
  23324. >>ΓöÇΓöÇthrowΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  23325.         ΓööΓöÇtypeΓöÇΓöÿ
  23326.  
  23327. The syntax of a function definition that includes an exception specification 
  23328. is: 
  23329.  
  23330.                   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ        ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23331.                          Γöé             Γöé
  23332. >>ΓöÇΓöÇreturn_typeΓöÇΓöÇfunction_nameΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÇthrowΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>
  23333.                   ΓööΓöÇargumentΓöÇΓöÿ         ΓööΓöÇtypeΓöÇΓöÿ
  23334. >ΓöÇΓöÇ)ΓöÇΓöÇ{ΓöÇΓöÇfunction_bodyΓöÇΓöÇ}ΓöÇΓöÇ><
  23335.  
  23336.  
  23337. ΓòÉΓòÉΓòÉ <hidden> Example of Throwing an Unspecified Exception ΓòÉΓòÉΓòÉ
  23338.  
  23339. In the following example, NameTooShort is thrown from within a function that 
  23340. explicitly states that it will only throw NameTooLong. This is a valid 
  23341. function, although at run time, if NameTooShort is thrown, a call to 
  23342. unexpected() will be made. 
  23343.  
  23344. #include <string.h>       // needed for strlen
  23345. class NameTooLong {};
  23346. class NameTooShort {};
  23347.  
  23348. void check(char* fname) throw (NameTooLong)
  23349. {
  23350.     if ( strlen(fname)<4 ) throw NameTooShort();
  23351. }
  23352.  
  23353.  
  23354. ΓòÉΓòÉΓòÉ 16.7. unexpected() and terminate() Functions ΓòÉΓòÉΓòÉ
  23355.  
  23356. Not all thrown errors can be caught and successfully dealt with by a catch 
  23357. block. In some situations, the best way to handle an exception is to terminate 
  23358. the program. Two special library functions are implemented in C++ to process 
  23359. exceptions not properly handled by catch blocks or exceptions thrown outside of 
  23360. a valid try block. These functions are unexpected() and terminate(). 
  23361.  
  23362. When a function with an exception specification throws an exception that is not 
  23363. listed in its exception specification, the function void unexpected() is 
  23364. called. Next, unexpected() calls a function specified by the set_unexpected() 
  23365. function. By default, unexpected() calls the function terminate(). 
  23366.  
  23367. In some cases, the exception handling mechanism fails and a call to void 
  23368. terminate() is made. This terminate() call occurs in any of the following 
  23369. situations: 
  23370.  
  23371.      When terminate() is explicitly called 
  23372.      When no catch can be matched to a thrown object 
  23373.      When the stack becomes corrupted during the exception-handling process 
  23374.      When a system defined unexpected() is called 
  23375.  
  23376.  The terminate() function calls a function specified by the set_terminate() 
  23377.  function. By default, terminate calls abort(), which exits from the program. 
  23378.  
  23379.  A terminate function cannot return to its caller, either by using return or by 
  23380.  throwing an exception. 
  23381.  
  23382.  Example of Using the Exception Handling Functions 
  23383.  
  23384.  Related Information 
  23385.  
  23386.      set_unexpected() and set_terminate() Functions 
  23387.      C++ Exception Handling Overview 
  23388.      Exception Specifications 
  23389.      Using Exception Handling 
  23390.      Transferring Control 
  23391.      abort - Stop a Program 
  23392.  
  23393.  
  23394. ΓòÉΓòÉΓòÉ 16.8. set_unexpected() and set_terminate() Functions ΓòÉΓòÉΓòÉ
  23395.  
  23396. The function unexpected(), when invoked, calls the function most recently 
  23397. supplied as an argument to set_unexpected(). If set_unexpected() has not yet 
  23398. been called, unexpected() calls terminate(). 
  23399.  
  23400. The function terminate(), when invoked, calls the function most recently 
  23401. supplied as an argument to set_terminate(). If set_terminate() has not yet been 
  23402. called, terminate() calls abort(), which ends the program. 
  23403.  
  23404. You can use set_unexpected() and set_terminate() to register functions you 
  23405. define to be called by unexpected() and terminate(). set_unexpected() and 
  23406. set_terminate() are included in the standard header files <unexpect.h>. and 
  23407. <terminat.h>. Each of these functions has as its return type and its argument 
  23408. type a pointer to function with a void return type and no arguments. The 
  23409. pointer to function you supply as the argument becomes the function called by 
  23410. the corresponding special function: the argument to set_unexpected() becomes 
  23411. the function called by unexpected(), and the argument to set_terminate() 
  23412. becomes the function called by terminate(). Both set_unexpected() and 
  23413. set_terminate() return a pointer to the function that was previously called by 
  23414. their respective special functions (unexpected() and terminate()). By saving 
  23415. the return values, you can restore the original special functions later so that 
  23416. unexpected() and terminate() will once again call terminate() and abort(). 
  23417.  
  23418. If you use set_terminate() to register your own function, the final action of 
  23419. that program should be to exit from the program. If you attempt to return from 
  23420. the function called by terminate(), abort() is called instead and the program 
  23421. ends. 
  23422.  
  23423. Note:  Providing a call to longjmp() inside a user-defined terminate function 
  23424. can transfer execution control to some other desired point. When you call 
  23425. longjmp, objects existing at the time of a setjmp call will still exist, but 
  23426. some objects constructed after the call to setjmp might not be destructed. 
  23427.  
  23428. Example of Using the Exception Handling Functions 
  23429.  
  23430. Related Information 
  23431.  
  23432.      unexpected() and terminate() Functions 
  23433.      C++ Exception Handling Overview 
  23434.      Using Exception Handling 
  23435.      Transferring Control 
  23436.      abort - Stop a Program 
  23437.      setjmp - Preserve Stack Environment 
  23438.      longjmp - Restore Stack Environment 
  23439.  
  23440.  
  23441. ΓòÉΓòÉΓòÉ 16.9. _set_mt_unexpected() and _set_mt_terminate() Functions ΓòÉΓòÉΓòÉ
  23442.  
  23443. The function _set_mt_terminate() registers a terminate handler exactly the same 
  23444. way set_terminate() does, except that it only affects the current thread. When 
  23445. a terminate function needs to be called, the code first checks to see if a 
  23446. thread terminate handler has been registered. If so, the thread terminate 
  23447. handler is called. If not, the global terminate handler (the one registered 
  23448. with set_terminate()) is called. 
  23449.  
  23450. The function _set_mt_unexpected() registers an unexpected handler exactly the 
  23451. same way set_unexpected() does, except that it only affects the current thread. 
  23452. When an unexpected handler needs to be called, the code first checks to see if 
  23453. a thread unexpected handler has been registered. If so, the thread unexpected 
  23454. handler is called. If not, the global unexpected handler (the one registered 
  23455. with set_unexpected()) is called. 
  23456.  
  23457. Related Information 
  23458.  
  23459.      unexpected() and terminate() Functions 
  23460.      set_unexpected() and set_terminate() Functions 
  23461.      C++ Exception Handling Overview 
  23462.      Using Exception Handling 
  23463.      Transferring Control 
  23464.      Exception Specifications 
  23465.  
  23466.  
  23467. ΓòÉΓòÉΓòÉ 16.10. Example of Using the Exception Handling Functions ΓòÉΓòÉΓòÉ
  23468.  
  23469. /************************************************************************
  23470. *
  23471.  
  23472. The following example shows the flow of control and special functions used in 
  23473. exception handling: 
  23474.  
  23475.                                     *
  23476. ************************************************************************/
  23477.  
  23478. #include <terminat.h>
  23479. #include <unexpect.h>
  23480. #include <iostream.h>
  23481. class X { /* ... */ };
  23482. class Y { /* ... */ };
  23483. class A { /* ... */ };
  23484. // pfv type is pointer to function returning void
  23485. typedef void (*pfv)();
  23486. void my_terminate()
  23487. {    cout << "Call to my terminate" << endl; }
  23488. void my_unexpected()
  23489. {    cout << "Call to my unexpected" << endl; }
  23490. void f() throw(X,Y)    // f() is permitted to throw objects of class
  23491.              // types X and Y only
  23492. {
  23493.    A aobj;
  23494.    throw(aobj); // error, f() throws a class A object
  23495. }
  23496. main()
  23497. {
  23498.    pfv old_term = set_terminate(my_terminate);
  23499.    pfv old_unex = set_unexpected(my_unexpected);
  23500.    try{ f(); }
  23501.    catch(X)    { /* ... */ }
  23502.    catch(Y)    { /* ... */ }
  23503.    catch (...)   { /* ... */ }
  23504.  
  23505.    set_unexpected(old_unex);
  23506.    try { f();}
  23507.    catch(X)    { /* ... */ }
  23508.    catch(Y)    { /* ... */ }
  23509.    catch (...)   { /* ... */ }
  23510. }
  23511.  
  23512. /************************************************************************
  23513. *
  23514.  
  23515. At run time, this program behaves as follows: 
  23516.  
  23517.    1. The call to set_terminate() assigns to old_term the address of the 
  23518.       function last passed to set_terminate() when set_terminate() was 
  23519.       previously called. 
  23520.  
  23521.    2. The call to set_unexpected() assigns to old_unex the address of the 
  23522.       function last passed to set_unexpected() when set_unexpected() was 
  23523.       previously called. 
  23524.  
  23525.    3. Within a try block, function f() is called. Because f() throws an 
  23526.       unexpected exception, a call to unexpected() is made. unexpected() in 
  23527.       turn calls my_unexpected(), which prints a message to standard output and 
  23528.       returns. 
  23529.  
  23530.    4. The second call to set_unexpected() replaces the user-defined function 
  23531.       my_unexpected() with the saved pointer to the original function 
  23532.       (terminate()) called by unexpected(). 
  23533.  
  23534.    5. Within a second try block, function f() is called once more. Because f() 
  23535.       throws an unexpected exception, a call to unexpected() is again made. 
  23536.       unexpected() automatically calls terminate(), which calls the function 
  23537.       my_terminate(). 
  23538.  
  23539.    6. my_terminate() displays a message. It returns, and the system calls 
  23540.       abort(), which terminates the program. 
  23541.  
  23542.  At run time, the following information is displayed, and the program ends: 
  23543.  
  23544.   Call to my_unexpected
  23545.   Call to my_terminate
  23546.  
  23547.  Note:  The catch blocks following the try block are not entered, because the 
  23548.  exception was handled by my_unexpected() as an unexpected throw, not as a 
  23549.  valid exception. 
  23550.  
  23551.                                       *
  23552.   ************************************************************************/
  23553.  
  23554.  
  23555. ΓòÉΓòÉΓòÉ 17. C and C++ Compatibility ΓòÉΓòÉΓòÉ
  23556.  
  23557. The differences between ANSI/ISO C and C++ fall into two categories: 
  23558.  
  23559.      Constructs found in C++ but not in ANSI/ISO C 
  23560.      Constructs found in both C++ and ANSI/ISO C, but treated differently in 
  23561.       the two languages 
  23562.  
  23563.  C++ contains many constructs that are not found in ANSI/ISO C: 
  23564.  
  23565.      Single line comments beginning with // 
  23566.      Scope operator (::) 
  23567.      Free store management using the operators new and delete 
  23568.      Linkage specification for functions 
  23569.      Reference types 
  23570.      Default arguments for functions 
  23571.      Inline functions 
  23572.      Classes 
  23573.      Anonymous unions 
  23574.      Overloaded operators and functions 
  23575.      Class templates and function templates 
  23576.      Exception handling 
  23577.  
  23578.  Note:  The VisualAge for C++ compiler also supports anonymous unions in C, but 
  23579.  the implementation is slightly different from C++.  For more information, see 
  23580.  Anonymous Unions in C. 
  23581.  
  23582.  
  23583. ΓòÉΓòÉΓòÉ 17.1. Constructs Treated Differently in C and C++ ΓòÉΓòÉΓòÉ
  23584.  
  23585. Because C++ is based on ANSI/ISO C, the two languages have many constructs in 
  23586. common. The use of some of these shared constructs differs, as shown here. 
  23587.  
  23588.      Character Array Initialization 
  23589.      Character Constants 
  23590.      Class and typedef Names 
  23591.      Class and Scope Declarations 
  23592.      const Object Initialization 
  23593.      Definitions 
  23594.      Definitions within Return or Argument Types 
  23595.      Enumerator Type 
  23596.      Enumeration Type 
  23597.      Function Declarations 
  23598.      Functions with an Empty Argument List 
  23599.      Global Constant Linkage 
  23600.      Jump Statements 
  23601.      Keywords 
  23602.      main() Recursion 
  23603.      Names of Nested Classes 
  23604.      Pointers to void 
  23605.      Prototype Declarations 
  23606.      Return without Declared Value 
  23607.      __STDC__ Macro 
  23608.      typedefs in Class Declarations 
  23609.  
  23610.  Related Information 
  23611.  
  23612.      C and C++ Compatibility 
  23613.  
  23614.  
  23615. ΓòÉΓòÉΓòÉ 17.1.1. Character Array Initialization ΓòÉΓòÉΓòÉ
  23616.  
  23617. In C++, when you initialize character arrays, a trailing '\0' (zero of type 
  23618. char) is appended to the string initializer. You cannot initialize a character 
  23619. array with more initializers than there are array elements. 
  23620.  
  23621. In ANSI/ISO C, space for the trailing '\0' can be omitted in this type of 
  23622. initialization. 
  23623.  
  23624. The following initialization, for instance, is not valid in C++: 
  23625.  
  23626. char v[3] = "asd"; // not valid in C++, valid in ANSI/ISO C
  23627.  
  23628. because four elements are required. This initialization produces an error 
  23629. because there is no space for the implied trailing '\0' (zero of type char). 
  23630.  
  23631. For more information, see Arrays. 
  23632.  
  23633.  
  23634. ΓòÉΓòÉΓòÉ 17.1.2. Character Constants ΓòÉΓòÉΓòÉ
  23635.  
  23636. A character constant has type char in C++ and int in ANSI/ISO C. 
  23637.  
  23638. For more information, see Character Constants. 
  23639.  
  23640.  
  23641. ΓòÉΓòÉΓòÉ 17.1.3. Class and typedef Names ΓòÉΓòÉΓòÉ
  23642.  
  23643. In C++, a class and a typedef cannot both use the same name to refer to a 
  23644. different type within the same scope (unless the typedef is a synonym for the 
  23645. class name). In C, a typedef name and a struct tag name declared in the same 
  23646. scope can have the same name because they have different name spaces. For 
  23647. example: 
  23648.  
  23649. void main ()
  23650. {
  23651.    typedef double db;
  23652.    struct db; // error in C++, valid in ANSI/ISO C
  23653.  
  23654.    typedef struct st st; // valid ANSI/ISO C and C++
  23655. }
  23656.  
  23657. For more information on typedef, see typedef. For information on class types, 
  23658. see C++ Classes. For information on structures, see Structures. 
  23659.  
  23660.  
  23661. ΓòÉΓòÉΓòÉ 17.1.4. Class and Scope Declarations ΓòÉΓòÉΓòÉ
  23662.  
  23663. In C++, a class declaration introduces the class name into the scope where it 
  23664. is declared and hides any object, function, or other declaration of that name 
  23665. in an enclosing scope. In ANSI/ISO C, an inner scope declaration of a struct 
  23666. name does not hide an object or function of that name in an outer scope. For 
  23667. example: 
  23668.  
  23669. double db;
  23670. void main ()
  23671. {
  23672.    struct db        // hides double object db in C++
  23673.    { char* str; };
  23674.    int x = sizeof(db);   // size of struct in C++
  23675.                // size of double in ANSI/ISO C
  23676. }
  23677.  
  23678. For more information, see Scope of Class Names. For general information about 
  23679. scope, see Scope in C++. 
  23680.  
  23681.  
  23682. ΓòÉΓòÉΓòÉ 17.1.5. const Object Initialization ΓòÉΓòÉΓòÉ
  23683.  
  23684. In C++, const objects must be initialized. In ANSI/ISO C, they can be left 
  23685. uninitialized. 
  23686.  
  23687. For more information, see volatile and const Qualifiers. 
  23688.  
  23689.  
  23690. ΓòÉΓòÉΓòÉ 17.1.6. Definitions ΓòÉΓòÉΓòÉ
  23691.  
  23692. An object declaration, for example: 
  23693.  
  23694. int i;
  23695.  
  23696. is a definition in C++. In ANSI/ISO C, it is a tentative definition. 
  23697.  
  23698. In C++, a global data object must be defined only once. In ANSI/ISO C, a global 
  23699. data object can be declared several times without using the extern keyword. 
  23700.  
  23701. In C++, multiple definitions for a single variable cause an error. A C 
  23702. compilation unit can contain many identical tentative definitions for a 
  23703. variable. 
  23704.  
  23705. For more information, see Declarations. 
  23706.  
  23707.  
  23708. ΓòÉΓòÉΓòÉ 17.1.7. Definitions within Return or Argument Types ΓòÉΓòÉΓòÉ
  23709.  
  23710. In C++, types may not be defined in return or argument types. ANSI/ISO C allows 
  23711. such definitions. For example, the declarations: 
  23712.  
  23713. void print(struct X { int i;} x);    // error in C++
  23714. enum count{one, two, three} counter(); // error in C++
  23715.  
  23716. produce errors in C++, but are valid declarations in ANSI/ISO C. 
  23717.  
  23718. For more information, see Function Declarations and Calling Functions and 
  23719. Passing Arguments. 
  23720.  
  23721.  
  23722. ΓòÉΓòÉΓòÉ 17.1.8. Enumerator Type ΓòÉΓòÉΓòÉ
  23723.  
  23724. An enumerator has the same type as its enumeration in C++. In ANSI/ISO C, an 
  23725. enumeration has type int. 
  23726.  
  23727. For more information on enumerators, see Enumerations. 
  23728.  
  23729.  
  23730. ΓòÉΓòÉΓòÉ 17.1.9. Enumeration Type ΓòÉΓòÉΓòÉ
  23731.  
  23732. The assignment to an object of enumeration type with a value that is not of 
  23733. that enumeration type produces an error in C++. In ANSI/ISO C, an object of 
  23734. enumeration type can be assigned values of any integral type. 
  23735.  
  23736. For more information, see Enumerations. 
  23737.  
  23738.  
  23739. ΓòÉΓòÉΓòÉ 17.1.10. Function Declarations ΓòÉΓòÉΓòÉ
  23740.  
  23741. In C++, all declarations of a function must match the unique definition of a 
  23742. function. ANSI/ISO C has no such restriction. 
  23743.  
  23744. For more information, see Function Declarations. 
  23745.  
  23746.  
  23747. ΓòÉΓòÉΓòÉ 17.1.11. Functions with an Empty Argument List ΓòÉΓòÉΓòÉ
  23748.  
  23749. Consider the following function declaration: 
  23750.  
  23751.  int f();
  23752.  
  23753. In C++, this function declaration means that the function takes no arguments. 
  23754. In ANSI/ISO C, it could take any number of arguments, of any type. 
  23755.  
  23756. For more information, see Function Declarations. 
  23757.  
  23758.  
  23759. ΓòÉΓòÉΓòÉ 17.1.12. Global Constant Linkage ΓòÉΓòÉΓòÉ
  23760.  
  23761. In C++, an object declared const has internal linkage, unless it has previously 
  23762. been given external linkage. In ANSI/ISO C, it has external linkage. 
  23763.  
  23764. For more information, see Program Linkage. 
  23765.  
  23766.  
  23767. ΓòÉΓòÉΓòÉ 17.1.13. Jump Statements ΓòÉΓòÉΓòÉ
  23768.  
  23769. C++ does not allow you to jump over declarations containing initializations. 
  23770. ANSI/ISO C does allow you to use jump statements for this purpose. 
  23771.  
  23772. For more information, see Initializers. 
  23773.  
  23774.  
  23775. ΓòÉΓòÉΓòÉ 17.1.14. Keywords ΓòÉΓòÉΓòÉ
  23776.  
  23777. C++ contains some additional keywords not found in ANSI/ISO C. C programs that 
  23778. use these keywords as identifiers are not valid C++ programs: 
  23779.  
  23780. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23781. Γöé Table 8. C++ Keywords                             Γöé
  23782. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23783. Γöé asm        Γöé friend       Γöé protected     Γöé try        Γöé
  23784. Γöé catch       Γöé inline       Γöé public       Γöé typeid      Γöé
  23785. Γöé class       Γöé new        Γöé template      Γöé virtual      Γöé
  23786. Γöé delete       Γöé operator      Γöé this        Γöé wchar_t      Γöé
  23787. Γöé dynamic_cast    Γöé private      Γöé throw       Γöé          Γöé
  23788. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  23789.  
  23790. Although they are documented in the ANSI/ISO C++ Working Paper, and are 
  23791. reserved by the compiler, the following keywords are not yet supported by 
  23792. VisualAge for C++: 
  23793.  
  23794. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23795. Γöé Table 9. C++ Keywords Not Supported by VisualAge for C++           Γöé
  23796. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23797. Γöé bool        Γöé false       Γöé reinterpret_cast  Γöé typename     Γöé
  23798. Γöé const_cast     Γöé mutable      Γöé static_cast    Γöé using       Γöé
  23799. Γöé explicit      Γöé namespace     Γöé true        Γöé          Γöé
  23800. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  23801.  
  23802. If you include the <iso646.h> header, you can represent unavailable characters 
  23803. in a source program using the following keywords: 
  23804.  
  23805. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  23806. Γöé AND        Γöé BITOR       Γöé NOT_EQ       Γöé XOR        Γöé
  23807. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23808. Γöé AND_EQ       Γöé COMPL       Γöé OR         Γöé XOR_EQ      Γöé
  23809. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  23810. Γöé BITAND       Γöé NOT        Γöé OR_EQ       Γöé          Γöé
  23811. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  23812.  
  23813. For more information, see Keywords. 
  23814.  
  23815.  
  23816. ΓòÉΓòÉΓòÉ 17.1.15. main() Recursion ΓòÉΓòÉΓòÉ
  23817.  
  23818. In C++, main() cannot be called recursively and cannot have its address taken. 
  23819. ANSI/ISO C allows recursive calls and allows pointers to hold the address of 
  23820. main(). 
  23821.  
  23822. For more information, see The main() Function. 
  23823.  
  23824.  
  23825. ΓòÉΓòÉΓòÉ 17.1.16. Names of Nested Classes ΓòÉΓòÉΓòÉ
  23826.  
  23827. In C++, the name of a nested class is local to its enclosing class. In ANSI/ISO 
  23828. C, the name of the nested structure belongs to the same scope as the name of 
  23829. the outermost enclosing structure. 
  23830.  
  23831. For more information, see Nested Classes. 
  23832.  
  23833.  
  23834. ΓòÉΓòÉΓòÉ 17.1.17. Pointers to void ΓòÉΓòÉΓòÉ
  23835.  
  23836. C++ allows void pointers to be assigned only to other void pointers. In 
  23837. ANSI/ISO C, a pointer to void can be assigned to a pointer of any other type 
  23838. without an explicit cast. 
  23839.  
  23840. For more information, see void Type and Pointers. 
  23841.  
  23842.  
  23843. ΓòÉΓòÉΓòÉ 17.1.18. Prototype Declarations ΓòÉΓòÉΓòÉ
  23844.  
  23845. C++ requires full prototype declarations. ANSI/ISO C allows nonprototyped 
  23846. functions. 
  23847.  
  23848. For more information, see Function Declarator. 
  23849.  
  23850.  
  23851. ΓòÉΓòÉΓòÉ 17.1.19. Return without Declared Value ΓòÉΓòÉΓòÉ
  23852.  
  23853. In C++, a return (either explicit or implicit) from main() that is declared to 
  23854. return a value results in an error if no value is returned. A return (either 
  23855. explicit or implicit) from all other functions that is declared to return a 
  23856. value must return a value. In ANSI/ISO C, a function that is declared to return 
  23857. a value can return with no value, with unspecified results. 
  23858.  
  23859. For more information, see Function Return Values. 
  23860.  
  23861.  
  23862. ΓòÉΓòÉΓòÉ 17.1.20. __STDC__ Macro ΓòÉΓòÉΓòÉ
  23863.  
  23864. The predefined macro variable __STDC__ is not defined for C++. It has the 
  23865. integer value 0 when used in a #if statement, indicating that the C++ language 
  23866. is not a proper superset of C, and that the compiler does not conform to 
  23867. ANSI/ISO C. In ANSI/ISO C, __STDC__ has the integer value 1. 
  23868.  
  23869. For more information on macros, see Predefined Macro Names. 
  23870.  
  23871.  
  23872. ΓòÉΓòÉΓòÉ 17.1.21. typedefs in Class Declarations ΓòÉΓòÉΓòÉ
  23873.  
  23874. In C++, a typedef name may not be redefined in a class declaration after being 
  23875. used in the declaration. ANSI/ISO C allows such a declaration. For example: 
  23876.  
  23877. void main ()
  23878. {
  23879.    typedef double db;
  23880.    struct st
  23881.    {
  23882.      db x;
  23883.      double db; // error in C++, valid in ANSI/ISO C
  23884.    };
  23885. }
  23886.  
  23887. For more information, see typedef. 
  23888.  
  23889.  
  23890. ΓòÉΓòÉΓòÉ 18. Glossary ΓòÉΓòÉΓòÉ
  23891.  
  23892. This glossary defines terms and abbreviations that are used in this book. 
  23893. Included are terms and definitions from the following sources: 
  23894.  
  23895.      American National Standard Dictionary for Information Systems, American 
  23896.       National Standard for Information Systems X3.172-1990, copyright 1990 by 
  23897.       the American National Standards Institute (American National Standard for 
  23898.       Information Systems). Copies may be purchased from the American National 
  23899.       Standards Institute, 1430 Broadway, New York, New York 10018. Such 
  23900.       definitions are indicated by the symbol American National Standard for 
  23901.       Information Systems after the definition. 
  23902.  
  23903.      IBM Dictionary of Computing, SC20-1699. These definitions are indicated 
  23904.       by the registered trademark IBM after the definition. 
  23905.  
  23906.      X/Open CAE Specification.  Commands and Utilities, Issue 4.  July, 1992. 
  23907.       These definitions are indicated by the symbol X/Open after the 
  23908.       definition. 
  23909.  
  23910.      ISO/IEC 9945-1:1990/IEEE POSIX 1003.1-1990. These definitions are 
  23911.       indicated by the symbol ISO.1 after the definition. 
  23912.  
  23913.      The Information Technology Vocabulary, developed by Subcommittee 1, Joint 
  23914.       Technical Committee 1, of the International Organization for 
  23915.       Standardization and the International Electrotechnical Commission 
  23916.       (ISO/IEC JTC1/SC1). Definitions of published parts of this vocabulary are 
  23917.       identified by the symbol ISO-JTC1 after the definition; definitions taken 
  23918.       from draft international standards, committee drafts, and working papers 
  23919.       being developed by ISO/IEC JTC1/SC1 are identified by the symbol ISO 
  23920.       Draft after the definition, indicating that final agreement has not yet 
  23921.       been reached among the participating National Bodies of SC1. 
  23922.  
  23923.   A            J            S
  23924.   B             K            T
  23925.   C             L            U
  23926.   D             M            V
  23927.   E             N            W
  23928.   F             O            X
  23929.   G             P            Y
  23930.   H             Q            Z
  23931.   I             R
  23932.  
  23933.  
  23934. ΓòÉΓòÉΓòÉ <hidden> A ΓòÉΓòÉΓòÉ
  23935.  
  23936.  abstract class 
  23937.  
  23938.              1. A class with at least one pure virtual function that is used as 
  23939.                 a base class for other classes. The abstract class represents a 
  23940.                 concept; classes derived from it represent implementations of 
  23941.                 the concept. You cannot construct an object of an abstract 
  23942.                 class. See also base class. 
  23943.  
  23944.              2. A class that allows polymorphism. 
  23945.  
  23946.  abstract data type A mathematical model that includes a structure for storing 
  23947.            data and operations that can be performed on that data. Common 
  23948.            abstract data types include sets, trees, and heaps. 
  23949.  
  23950.  abstraction (data) See data abstraction. 
  23951.  
  23952.  access    An attribute that determines whether or not a class member is 
  23953.            accessible in an expression or declaration. It can be public, 
  23954.            protected, or private. 
  23955.  
  23956.  access declaration A declaration used to adjust access to members of a base 
  23957.            class. 
  23958.  
  23959.  access resolution The process by which the accessibility of a particular class 
  23960.            member is determined. 
  23961.  
  23962.  access specifier One of the C++ keywords public, private, or protected. 
  23963.  
  23964.  aggregate 
  23965.  
  23966.              1. An array or a structure. 
  23967.  
  23968.              2. A compile-time option to show the layout of a structure or 
  23969.                 union in the listing. 
  23970.  
  23971.              3. An array or a class object with no private or protected 
  23972.                 members, no constructors, no base classes, and no virtual 
  23973.                 functions. 
  23974.  
  23975.              4. In programming languages, a structured collection of data items 
  23976.                 that form a data type. ISO-JTC1. 
  23977.  
  23978.  alignment The storing of data in relation to certain machine-dependent 
  23979.            boundaries. IBM. 
  23980.  
  23981.  ambiguous derivation A derivation where the class is derived from two or more 
  23982.            base classes that have members with the same name. 
  23983.  
  23984.  American National Standards Institute See American National Standard for 
  23985.            Information Systems. 
  23986.  
  23987.  angle brackets The characters < (left angle bracket) and > (right angle 
  23988.            bracket). When used in the phrase "enclosed in angle brackets", the 
  23989.            symbol < immediately precedes the object to be enclosed, and > 
  23990.            immediately follows it. 
  23991.  
  23992.  anonymous union A union that is declared within a structure or class and that 
  23993.            does not have a name. 
  23994.  
  23995.  American National Standard for Information Systems (American National 
  23996.  Standards Institute) An organization consisting of producers, consumers, and 
  23997.            general interest groups, that establishes the procedures by which 
  23998.            accredited organizations create and maintain voluntary industry 
  23999.            standards in the United States. American National Standard for 
  24000.            Information Systems. 
  24001.  
  24002.  array     An aggregate that consists of data objects, with identical 
  24003.            attributes, each of which may be uniquely referenced by 
  24004.            subscripting. 
  24005.  
  24006.  array element A data element in an array. 
  24007.  
  24008.  ASCII (American National Standard Code for Information Interchange) The 
  24009.            standard code, using a coded character set consisting of 7-bit coded 
  24010.            characters (8 bits including parity check), that is used for 
  24011.            information interchange among data processing systems, data 
  24012.            communication systems, and associated equipment. The ASCII set 
  24013.            consists of control characters and graphic characters. 
  24014.  
  24015.            Note:  IBM has defined an extension to ASCII code (characters 
  24016.            128-255). 
  24017.  
  24018.  assignment expression An operation that stores the value of the right operand 
  24019.            in the storage location specified by the left operand. 
  24020.  
  24021.  automatic data Data that does not persist after a routine has finished 
  24022.            executing. Automatic data may be automatically initialized to a 
  24023.            certain value upon entry and reentry to a routine. 
  24024.  
  24025.  automatic storage Storage that is allocated on entry to a routine or block and 
  24026.            is freed on the subsequent return. Sometimes referred to as stack 
  24027.            storage or dynamic storage. 
  24028.  
  24029.  
  24030. ΓòÉΓòÉΓòÉ <hidden> B ΓòÉΓòÉΓòÉ
  24031.  
  24032.  backslash The character \. 
  24033.  
  24034.  base class A class from which other classes are derived. A base class may 
  24035.            itself be derived from another base class. See also abstract class. 
  24036.  
  24037.  binary expression An operation containing two operands and one operator. 
  24038.  
  24039.  bit field A member of a structure or union that contains a specified number of 
  24040.            bits. 
  24041.  
  24042.  block 
  24043.  
  24044.              1. In programming languages, a compound statement that coincides 
  24045.                 with the scope of at least one of the declarations contained 
  24046.                 within it. A block may also specify storage allocation or 
  24047.                 segment programs for other purposes. ISO-JTC1. 
  24048.  
  24049.              2. A string of data elements recorded or transmitted as a unit. 
  24050.                 The elements may be characters, words, or physical records. ISO 
  24051.                 Draft. 
  24052.  
  24053.              3. The unit of data transmitted to and from a device. Each block 
  24054.                 contains one record, part of a record, or several records. 
  24055.  
  24056.  boundary alignment The position in main storage of a fixed-length field (such 
  24057.            as byte or doubleword) on an integral boundary for that unit of 
  24058.            information. 
  24059.  
  24060.            For the Class Library example, a word boundary is a storage address 
  24061.            evenly divisible by two. 
  24062.  
  24063.  brackets  The characters [ (left bracket) and ] (right bracket), also known as 
  24064.            square brackets. When used in the phrase "enclosed in (square) 
  24065.            brackets" the symbol [ immediately precedes the object to be 
  24066.            enclosed, and ] immediately follows it. 
  24067.  
  24068.  built-in  A function that the compiler automatically puts inline instead of 
  24069.            generating a call to the function. Synonymous with predefined. IBM. 
  24070.  
  24071.  
  24072. ΓòÉΓòÉΓòÉ <hidden> C ΓòÉΓòÉΓòÉ
  24073.  
  24074.  C++ class library See class library. 
  24075.  
  24076.  C++ library A system library that contains common C++ language subroutines for 
  24077.            file access, memory allocation, and other functions. 
  24078.  
  24079.  call      To transfer control to a procedure, program, routine, or subroutine. 
  24080.            IBM. 
  24081.  
  24082.  caller    A routine that calls another routine. 
  24083.  
  24084.  cast      A notation used to express the conversion of one type to another. 
  24085.  
  24086.  catch block A block associated with a try block that receives control when a 
  24087.            C++ exception matching its argument is thrown. 
  24088.  
  24089.  character 
  24090.  
  24091.              1. A letter, digit, or other symbol that is used as part of the 
  24092.                 organization, control, or representation of data. A character 
  24093.                 is often in the form of a spatial arrangement of adjacent or 
  24094.                 connected strokes. American National Standard for Information 
  24095.                 Systems. 
  24096.  
  24097.              2. A sequence of one or more bytes representing a single graphic 
  24098.                 symbol or control code. This term corresponds to the ISO C 
  24099.                 standard term multibyte character (multi-byte character), where 
  24100.                 a single-byte character is a special case of the multi-byte 
  24101.                 character. Unlike the usage in the ISO C standard, character 
  24102.                 here has no necessary relationship with storage space, and byte 
  24103.                 is used when storage space is discussed. X/Open. ISO.1. 
  24104.  
  24105.  character array An array of type char. X/Open. 
  24106.  
  24107.  character constant 
  24108.  
  24109.              1. A constant with a character value. IBM. 
  24110.  
  24111.              2. A string of any of the characters that can be represented, 
  24112.                 usually enclosed in apostrophes. IBM. 
  24113.  
  24114.              3. In some languages, a character enclosed in apostrophes. IBM. 
  24115.  
  24116.  character set 
  24117.  
  24118.              1. A finite set of different characters that is complete for a 
  24119.                 given purpose; for example, the character set in ISO Standard 
  24120.                 646, 7-bit Coded Character Set for Information Processing 
  24121.                 Interchange. ISO Draft. 
  24122.  
  24123.              2. All the valid characters for a programming language or for a 
  24124.                 computer system. IBM. 
  24125.  
  24126.              3. A group of characters used for a specific reason; for example, 
  24127.                 the set of characters a printer can print. IBM. 
  24128.  
  24129.  character string A contiguous sequence of characters terminated by and 
  24130.            including the first null byte. X/Open. 
  24131.  
  24132.  class 
  24133.  
  24134.              1. A group of objects that share a common definition and that 
  24135.                 therefore share common properties, operations, and behavior. 
  24136.  
  24137.              2. A C++ aggregate that may contain functions, types, and 
  24138.                 user-defined operators in addition to data. Classes can be 
  24139.                 defined hierarchically, allowing one class to be an expansion 
  24140.                 of another, and classes can restrict access to their members. 
  24141.  
  24142.  class key Any of the three C++ keywords: class, struct, or union. 
  24143.  
  24144.  class hierarchy A tree-like structure showing relationships among classes. It 
  24145.            places one abstract class at the top (a base class) and one or more 
  24146.            layers of derived classes below it. 
  24147.  
  24148.  class identifier (CLSID) In Windows 95, the globally unique identifier for an 
  24149.            object. The Win32 Registry uses the CLSID to distinguish all OLE 
  24150.            objects available on a system. A CLSID is a 16-bit value that 
  24151.            contains 32 hexadecimal digits. 
  24152.  
  24153.            Also commonly referred to as a globally unique identifier (GUID). 
  24154.  
  24155.  class library A collection of classes. 
  24156.  
  24157.  class template A blueprint describing how a set of related classes can be 
  24158.            constructed. 
  24159.  
  24160.  class name A unique identifier of a class type that becomes a reserved word 
  24161.            within its scope. 
  24162.  
  24163.  class scope The scope of class member names. 
  24164.  
  24165.  class tag See class name. 
  24166.  
  24167.  C library A system library that contains common C language subroutines for 
  24168.            file access, string operators, character operations, memory 
  24169.            allocation, and other functions. IBM. 
  24170.  
  24171.  code page 
  24172.  
  24173.              1. An assignment of graphic characters and control function 
  24174.                 meanings to all code points; for example, assignment of 
  24175.                 characters and meanings to 256 code points for an 8-bit code, 
  24176.                 or assignment of characters and meanings to 128 code points for 
  24177.                 a 7-bit code. 
  24178.  
  24179.              2. A particular assignment of hexadecimal identifiers to graphic 
  24180.                 characters. 
  24181.  
  24182.  collating sequence 
  24183.  
  24184.              1. A specified arrangement used in sequencing. ISO-JTC1. American 
  24185.                 National Standard for Information Systems. 
  24186.  
  24187.              2. An ordering assigned to a set of items, such that any two sets 
  24188.                 in that assigned order can be collated. American National 
  24189.                 Standard for Information Systems. 
  24190.  
  24191.              3. The relative ordering of collating elements as determined by 
  24192.                 the setting of the LC_COLLATE category in the current locale. 
  24193.                 The character order, as defined for the LC_COLLATE category in 
  24194.                 the current locale, defines the relative order of all collating 
  24195.                 elements, such that each element occupies a unique position in 
  24196.                 the order. This is the order used in ranges of characters and 
  24197.                 collating elements in regular expressions and pattern matching. 
  24198.                 In addition, the definition of the collating weights of 
  24199.                 characters and collating elements uses collating elements to 
  24200.                 represent their respective positions within the collation 
  24201.                 sequence. 
  24202.  
  24203.  collation The logical ordering of character or wide-character strings 
  24204.            according to defined precedence rules. These rules identify a 
  24205.            collation sequence between the collating elements, and such 
  24206.            additional rules that can be used to order strings consisting or 
  24207.            multiple collating elements. X/Open. 
  24208.  
  24209.  comma expression An expression that contains two operands separated by a 
  24210.            comma.  Although the compiler evaluates both operands, the value of 
  24211.            the expression is the value of the right operand. If the left 
  24212.            operand produces a value, the compiler discards this value. 
  24213.            Typically, the left operand of a comma expression is used to produce 
  24214.            side effects. 
  24215.  
  24216.  compilation unit 
  24217.  
  24218.              1. A portion of a computer program sufficiently complete to be 
  24219.                 compiled correctly. IBM. 
  24220.  
  24221.              2. A single compiled file and all its associated include files. 
  24222.  
  24223.              3. An independently compilable sequence of high-level language 
  24224.                 statements. Each high-level language product has different 
  24225.                 rules for what makes up a compilation unit. 
  24226.  
  24227.  complete class name The complete qualification of a nested class name 
  24228.            including all enclosing class names. 
  24229.  
  24230.  Compound Object Model (COM) The underlying model for all OLE services. It 
  24231.            consists of a variety of APIs and object interfaces that allow 
  24232.            container components to communicate and interact with one another. 
  24233.  
  24234.  condition 
  24235.  
  24236.              1. A relational expression that can be evaluated to a value of 
  24237.                 either true or false. IBM. 
  24238.  
  24239.              2. An exception that has been enabled, or recognized, by the 
  24240.                 Language Environment and thus is eligible to activate user and 
  24241.                 language condition handlers. Any alteration to the normal 
  24242.                 programmed flow of an application. Conditions can be detected 
  24243.                 by the hardware/operating system and result in an interrupt. 
  24244.                 They can also be detected by language-specific generated code 
  24245.                 or language library code. 
  24246.  
  24247.  conditional expression A compound expression that contains a condition (the 
  24248.            first expression), an expression to be evaluated if the condition 
  24249.            has a nonzero value (the second expression), and an expression to be 
  24250.            evaluated if the condition has the value zero (the third 
  24251.            expression). 
  24252.  
  24253.  const 
  24254.  
  24255.              1. An attribute of a data object that declares that the object 
  24256.                 cannot be changed. 
  24257.  
  24258.              2. An attribute of a function that declares that the function will 
  24259.                 not modify data members of its class. 
  24260.  
  24261.  constant 
  24262.  
  24263.              1. In programming languages, a language object that takes only one 
  24264.                 specific value. ISO-JTC1. 
  24265.  
  24266.              2. A data item with a value that does not change. IBM. 
  24267.  
  24268.  constant expression An expression having a value that can be determined during 
  24269.            compilation and that does not change during the running of the 
  24270.            program. IBM. 
  24271.  
  24272.  constructor A special class member function that has the same name as the 
  24273.            class and is used to construct and, possibly, initialize objects of 
  24274.            its class type. A return type is not specified. 
  24275.  
  24276.  control character 
  24277.  
  24278.              1. A character whose occurrence in a particular context specifies 
  24279.                 a control function. ISO Draft. 
  24280.  
  24281.              2. Synonymous with nonprinting character. IBM. 
  24282.  
  24283.              3. A character, other than a graphic character, that affects the 
  24284.                 recording, processing, transmission, or interpretation of text. 
  24285.                 X/Open. 
  24286.  
  24287.  conversion 
  24288.  
  24289.              1. In programming languages, the transformation between values 
  24290.                 that represent the same data item but belong to different data 
  24291.                 types. Information may be lost because of conversion since 
  24292.                 accuracy of data representation varies among different data 
  24293.                 types. ISO-JTC1. 
  24294.  
  24295.              2. The process of changing from one method of data processing to 
  24296.                 another or from one data processing system to another. IBM. 
  24297.  
  24298.              3. The process of changing from one form of representation to 
  24299.                 another; for example to change from decimal representation to 
  24300.                 binary representation. IBM. 
  24301.  
  24302.              4. A change in the type of a value. For example, when you add 
  24303.                 values having different data types, the compiler converts both 
  24304.                 values to a common form before adding the values. 
  24305.  
  24306.  conversion function A member function that specifies a conversion from its 
  24307.            class type to another type. 
  24308.  
  24309.  copy constructor A constructor used to make a copy of an object from another 
  24310.            object of the same type. 
  24311.  
  24312.  
  24313. ΓòÉΓòÉΓòÉ <hidden> D ΓòÉΓòÉΓòÉ
  24314.  
  24315.  data abstraction A data type with a private representation and a public set of 
  24316.            operations. The C++ language uses the concept of classes to 
  24317.            implement data abstraction. 
  24318.  
  24319.  data member The smallest possible piece of complete data. Elements are 
  24320.            composed of data members. 
  24321.  
  24322.  data structure The internal data representation of an implementation. 
  24323.  
  24324.  data type The properties and internal representation that characterize data. 
  24325.  
  24326.  DBCS (Double-Byte Character Set) See double-byte character set. 
  24327.  
  24328.  decimal constant 
  24329.  
  24330.              1. A numerical data type used in standard arithmetic operations. 
  24331.  
  24332.              2. A number containing any of the digits 0 through 9. IBM. 
  24333.  
  24334.  declaration Introduces a name to a program and specifies how the name is to be 
  24335.            interpreted. 
  24336.  
  24337.  declare   To specify the interpetation that C++ gives to each identifier. 
  24338.  
  24339.  default argument An argument that is declared with a default value in a 
  24340.            function prototype or declaration. If a call to the function omits 
  24341.            this argument, the default value is used. Arguments with default 
  24342.            values must be the trailing arguments in a function prototype 
  24343.            argument list. 
  24344.  
  24345.  default constructor A constructor that takes no arguments, or a constructor 
  24346.            for which all the arguments have default values. 
  24347.  
  24348.  default initialization The initial value assigned to a data object by the 
  24349.            compiler if no initial value is specified by the programmer. extern 
  24350.            and static variables receive a default initialization of zero, while 
  24351.            the default initial value for auto and register variables is 
  24352.            undefined. 
  24353.  
  24354.  define directive A preprocessor statement that directs the preprocessor to 
  24355.            replace an identifier or macro invocation with special code. 
  24356.  
  24357.  definition 
  24358.  
  24359.              1. A data description that reserves storage and may provide an 
  24360.                 initial value. 
  24361.  
  24362.              2. A declaration that allocates storage, and may initialize a data 
  24363.                 object or specify the body of a function. 
  24364.  
  24365.  delete 
  24366.  
  24367.              1. A C++ keyword that identifies a free-storage deallocation 
  24368.                 operator. 
  24369.  
  24370.              2. A C++ operator used to destroy objects created by operator new. 
  24371.  
  24372.  demangling The conversion of mangled names back to their original source code 
  24373.            names. During C++ compilation, identifiers such as function and 
  24374.            static class member names are mangled (encoded) with type and 
  24375.            scoping information to ensure type-safe linkage. These mangled names 
  24376.            appear in the object file and the final executable file. Demangling 
  24377.            (decoding) converts these names back to their original names to make 
  24378.            program debugging easier. See also mangling. 
  24379.  
  24380.  derivation 
  24381.  
  24382.              1. The creation of a new or derived class from an existing base 
  24383.                 class. 
  24384.  
  24385.              2. The relationship between a class and the classes above or below 
  24386.                 it in a class hierarchy. 
  24387.  
  24388.  derived class A class that inherits from a base class. You can add new data 
  24389.            members and member functions to the derived class. You can 
  24390.            manipulate a derived class object as if it were a base class object. 
  24391.            The derived class can override virtual functions of the base class. 
  24392.  
  24393.            Synonym for child class and subclass. 
  24394.  
  24395.  destructor A special member function that has the same name as its class, 
  24396.            preceded by a tilde (~), and that "cleans up" after an object of 
  24397.            that class, for example, by freeing storage that was allocated when 
  24398.            the object was created. A destructor has no arguments, and no return 
  24399.            type is specified. 
  24400.  
  24401.  double-byte character set (DBCS) A set of characters in which each character 
  24402.            is represented by 2 bytes. Languages such as Japanese, Chinese, and 
  24403.            Korean, which contain more symbols than can be represented by 256 
  24404.            code points, require double-byte character sets. 
  24405.  
  24406.            Because each character requires 2 bytes, you need hardware and 
  24407.            supporting software that are DBCS-enabled to enter, display, and 
  24408.            print DBCS characters. 
  24409.  
  24410.  double-precision Pertaining to the use of two computer words to represent a 
  24411.            number in accordance with the required precision. ISO-JTC1. American 
  24412.            National Standard for Information Systems. 
  24413.  
  24414.  doubleword A contiguous sequence of bits or characters that comprises two 
  24415.            computer words and can be addressed as a unit. For the C Set++ for 
  24416.            AIX compiler, a doubleword is 32 bits (4 bytes). 
  24417.  
  24418.  dynamic   Pertaining to an operation that occurs at the time it is needed 
  24419.            rather than at a predetermined or fixed time. IBM. 
  24420.  
  24421.  dynamic binding Resolution of a call to a virtual member function at run time. 
  24422.  
  24423.  dynamic link library (DLL) A file containing executable code and data bound to 
  24424.            a program at load time or run time. The code and data in a dynamic 
  24425.            link library can be shared by several applications simultaneously. 
  24426.  
  24427.  dynamic storage Synonym for automatic storage. 
  24428.  
  24429.  
  24430. ΓòÉΓòÉΓòÉ <hidden> E ΓòÉΓòÉΓòÉ
  24431.  
  24432.  element   The component of an array, subrange, enumeration, or set. 
  24433.  
  24434.  encapsulation The hiding of the internal representation of objects and 
  24435.            implementation details from the client program. 
  24436.  
  24437.  enumeration constant An identifier that is defined in an enumeration and that 
  24438.            has an associated constant integer value. You can use an enumeration 
  24439.            constant anywhere an integer constant is allowed. 
  24440.  
  24441.  entry point In assembler language, the address or label of the first 
  24442.            instruction that is executed when a routine is entered for 
  24443.            execution. 
  24444.  
  24445.  enumeration constant An identifier that is defined in an enumeration and that 
  24446.            has an associated constant integer value. You can use an enumeration 
  24447.            constant anywhere an integer constant is allowed. 
  24448.  
  24449.  enumeration data type A type that represents integers and a set of enumeration 
  24450.            constants. Each enumeration constant has an associated integer 
  24451.            value. 
  24452.  
  24453.  enumeration tag The identifier that names an enumeration data type. 
  24454.  
  24455.  enumerator In the C and C++ language, an enumeration constant and its 
  24456.            associated value. IBM. 
  24457.  
  24458.  environment variable Any of a number of variables that describe the way an 
  24459.            operating system is going to run and the devices it is going to 
  24460.            recognize. 
  24461.  
  24462.  escape sequence 
  24463.  
  24464.              1. A representation of a character. An escape sequence contains 
  24465.                 the \ symbol followed by one of the characters: a, b, f, n, r, 
  24466.                 t, v, ', ", x, \, or followed by one or more octal or 
  24467.                 hexadecimal digits. 
  24468.  
  24469.              2. A sequence of characters that represent, for example, 
  24470.                 nonprinting characters, or the exact code point value to be 
  24471.                 used to represent variant and nonvariant characters regardless 
  24472.                 of code page. 
  24473.  
  24474.              3. In the C and C++ language, an escape character followed by one 
  24475.                 or more characters. The escape character indicates that a 
  24476.                 different code, or a different coded character set, is used to 
  24477.                 interpret the characters that follow. Any member of the 
  24478.                 character set used at runtime can be represented using an 
  24479.                 escape sequence. 
  24480.  
  24481.              4. A character that is preceded by a backslash character and is 
  24482.                 interpreted to have a special meaning to the operating system. 
  24483.  
  24484.              5. A sequence sent to a terminal to perform actions such as moving 
  24485.                 the cursor, changing from normal to reverse video, and clearing 
  24486.                 the screen. Synonymous with multibyte control. IBM. 
  24487.  
  24488.  exception 
  24489.  
  24490.              1. A user or system error detected by the system and passed to an 
  24491.                 operating system or user exception handler. 
  24492.  
  24493.              2. For C++, any user, logic, or system error detected by a 
  24494.                 function that does not itself deal with the error but passes 
  24495.                 the error on to a handling routine (also called "throwing the 
  24496.                 exception"). 
  24497.  
  24498.  exception handler 
  24499.  
  24500.              1. A function that is invoked when an exception is detected, and 
  24501.                 that either corrects the problem and returns execution to the 
  24502.                 program, or terminates the program. 
  24503.  
  24504.              2. In C++, a catch block that catches a C++ exception when it is 
  24505.                 thrown from a function in a try block. 
  24506.  
  24507.  exception handling A type of error handling that allows control and 
  24508.            information to be passed to an exception handler when an exception 
  24509.            occurs. Under the Windows operating system, exceptions are generated 
  24510.            by the system and handled by user code. In C++, try, catch, and 
  24511.            throw expressions are the constructs used to implement C++ exception 
  24512.            handling. 
  24513.  
  24514.  executable file A regular file acceptable as a new process image file by the 
  24515.            equivalent of the exec family of functions, and thus usable as one 
  24516.            form of a utility. The standard utilities described as compilers can 
  24517.            produce executable files, but other unspecified methods of producing 
  24518.            executable files may also be provided. The internal format of an 
  24519.            executable file is unspecified, but a conforming application cannot 
  24520.            assume an executable file is a text file. X/Open. 
  24521.  
  24522.  external data definition A definition appearing outside a function. The 
  24523.            defined object is accessible to all functions that follow the 
  24524.            definition and are located within the same source file as the 
  24525.            definition. 
  24526.  
  24527.  
  24528. ΓòÉΓòÉΓòÉ <hidden> F ΓòÉΓòÉΓòÉ
  24529.  
  24530.  file scope A name declared outside all blocks and classes has file scope and 
  24531.            can be used after the point of declaration in a source file. 
  24532.  
  24533.  filter    A command whose operation consists of reading data from standard 
  24534.            input or a list of input files and writing data to standard output. 
  24535.            Typically, its function is to perform some transformation on the 
  24536.            data stream. 
  24537.  
  24538.  for statement A looping statement that contains the word for followed by a 
  24539.            list of expressions enclosed in parentheses (the condition) and a 
  24540.            statement (the action). Each expression in the parenthesized list is 
  24541.            separated by a semicolon. You can omit any of the expressions, but 
  24542.            you cannot omit the semicolons. 
  24543.  
  24544.  free store Dynamically allocated memory.  New and delete are used to allocate 
  24545.            and deallocate free store. 
  24546.  
  24547.  friend class A class in which all the member functions are granted access to 
  24548.            the private and protected members of another class. It is named in 
  24549.            the declaration of the other class with the prefix friend. 
  24550.  
  24551.  friend function A function that is granted access to the private and protected 
  24552.            parts of a class. It is named in the declaration of the class with 
  24553.            the prefix friend. 
  24554.  
  24555.  function  A named group of statements that can be called and evaluated and can 
  24556.            return a value to the calling statement. IBM. 
  24557.  
  24558.  function call An expression that moves the path of execution from the current 
  24559.            function to a specified function and evaluates to the return value 
  24560.            provided by the called function. A function call contains the name 
  24561.            of the function to which control moves and a parenthesized list of 
  24562.            values. IBM. 
  24563.  
  24564.  function declarator The part of a function definition that names the function, 
  24565.            provides additional information about the return value of the 
  24566.            function, and lists the function parameters. 
  24567.  
  24568.  function definition The complete description of a function. A function 
  24569.            definition contains an optional storage class specifier, an optional 
  24570.            type specifier, a function declarator, optional parameter 
  24571.            declarations, and a block statement (the function body). 
  24572.  
  24573.  function prototype A function declaration that provides type information for 
  24574.            each parameter. It is the first line of the function (header) 
  24575.            followed by a ; (semicolon). The declaration is required by the 
  24576.            compiler at the time that the function is declared, so that the 
  24577.            compiler can check the type. 
  24578.  
  24579.  function scope The capacity to be used anywhere in a function. Labels that are 
  24580.            declared in a function have function scope. 
  24581.  
  24582.  function template Provides a blueprint describing how a set of related 
  24583.            individual functions can be constructed. 
  24584.  
  24585.  
  24586. ΓòÉΓòÉΓòÉ <hidden> G ΓòÉΓòÉΓòÉ
  24587.  
  24588.  generic class See class templates. 
  24589.  
  24590.  global    Pertaining to information available to more than one program or 
  24591.            subroutine. IBM. 
  24592.  
  24593.  global scope See file scope. 
  24594.  
  24595.  global variable A symbol defined in one program module that is used in other 
  24596.            independently compiled program modules. 
  24597.  
  24598.  
  24599. ΓòÉΓòÉΓòÉ <hidden> H ΓòÉΓòÉΓòÉ
  24600.  
  24601.  header file A file that can contain system-defined control information or user 
  24602.            data and generally consists of declarations. 
  24603.  
  24604.  heap      An unordered flat collection that allows duplicate elements. 
  24605.  
  24606.  heap storage An area of storage used for allocation of storage whose lifetime 
  24607.            is not related to the execution of the current routine. The heap 
  24608.            consists of the initial heap segment and zero or more increments. 
  24609.  
  24610.  hexadecimal constant A constant, usually starting with special characters, 
  24611.            that contains only hexadecimal digits. Three examples for the 
  24612.            hexadecimal constant with value 0 would be '\x00', '0x0', or '0X00'. 
  24613.  
  24614.  
  24615. ΓòÉΓòÉΓòÉ <hidden> I ΓòÉΓòÉΓòÉ
  24616.  
  24617.  identifier 
  24618.  
  24619.              1. One or more characters used to identify or name a data element 
  24620.                 and possibly to indicate certain properties of that data 
  24621.                 element. American National Standard for Information Systems. 
  24622.  
  24623.              2. In programming languages, a token that names a data object such 
  24624.                 as a variable, an array, a record, a subprogram, or a function. 
  24625.                 American National Standard for Information Systems. 
  24626.  
  24627.              3. A sequence of letters, digits, and underscores used to identify 
  24628.                 a data object or function. IBM. 
  24629.  
  24630.  if statement A conditional statement that contains the keyword if, followed by 
  24631.            an expression in parentheses (the condition), a statement (the 
  24632.            action), and an optional else clause (the alternative action). IBM. 
  24633.  
  24634.  include directive A preprocessor directive that causes the preprocessor to 
  24635.            replace the statement with the contents of a specified file. 
  24636.  
  24637.  include file See header file. 
  24638.  
  24639.  incomplete class declaration A class declaration that does not define any 
  24640.            members of a class. Typically, you use an incomplete class 
  24641.            declaration as a forward declaration. 
  24642.  
  24643.  incomplete type A type that has no value or meaning when it is first declared. 
  24644.            There are three incomplete types: void, arrays of unknown size and 
  24645.            structures and unions of unspecified content. A void type can never 
  24646.            be completed. Arrays of unknown size and structures or unions of 
  24647.            unspecified content can be completed in further declarations. 
  24648.  
  24649.  indirection 
  24650.  
  24651.              1. A mechanism for connecting objects by storing, in one object, a 
  24652.                 reference to another object. 
  24653.  
  24654.              2. In the C and C++ languages, the application of the unary 
  24655.                 operator * to a pointer to access the object the pointer points 
  24656.                 to. 
  24657.  
  24658.  inheritance 
  24659.  
  24660.              1. An object-oriented programming technique that allows you to use 
  24661.                 existing classes as bases for creating other classes. 
  24662.  
  24663.              2. A mechanism by which a derived class can use the attributes, 
  24664.                 relationships, and member functions defined in more abstract 
  24665.                 classes related to it (its base classes). See also multiple 
  24666.                 inheritance. 
  24667.  
  24668.  initializer An expression used to initialize objects. In the C++ language, 
  24669.            there are three types of initializers: 
  24670.  
  24671.              1. An expression followed by an assignment operator is used to 
  24672.                 initialize fundamental data type objects or class objects that 
  24673.                 have copy constructors. 
  24674.              2. An expression enclosed in braces ( { } ) is used to initialize 
  24675.                 aggregates. 
  24676.              3. A parenthesized expression list is used to initialize base 
  24677.                 classes and members using constructors. 
  24678.  
  24679.  inlined function A function call that the compiler replaces with the actual 
  24680.            code for the function. You can direct the compiler to inline a 
  24681.            function with the inline keyword. 
  24682.  
  24683.  instance (of a class) An object that is a member of that class. An object 
  24684.            created according to the definition of that class. 
  24685.  
  24686.  instantiate To create or generate a particular instance or object of a data 
  24687.            type. For example, an instance box1 of class box could be 
  24688.            instantiated with the declaration: 
  24689.  
  24690.                       box box1;
  24691.  
  24692.  integer constant A decimal, octal, or hexadecimal constant. 
  24693.  
  24694.  integral object A character object, an object having an enumeration type, an 
  24695.            object having variations of the type int, or an object that is a bit 
  24696.            field. 
  24697.  
  24698.  iteration The process of repeatedly applying a function to a series of 
  24699.            elements in a collection until some condition is satisfied. 
  24700.  
  24701.  
  24702. ΓòÉΓòÉΓòÉ <hidden> K ΓòÉΓòÉΓòÉ
  24703.  
  24704.  keyword 
  24705.  
  24706.              1. A predefined word reserved for the C or C++ language that you 
  24707.                 cannot use as an identifier. 
  24708.  
  24709.              2. A symbol that identifies a parameter. 
  24710.  
  24711.  
  24712. ΓòÉΓòÉΓòÉ <hidden> L ΓòÉΓòÉΓòÉ
  24713.  
  24714.  label     An identifier within or attached to a set of data elements. 
  24715.  
  24716.                        ISO Draft.
  24717.  
  24718.  late binding See dynamic binding. 
  24719.  
  24720.  library 
  24721.  
  24722.              1. A collection of functions, function calls, subroutines, or 
  24723.                 other data. 
  24724.  
  24725.              2. A set of object modules that can be specified in a link 
  24726.                 command. 
  24727.  
  24728.  link      To interconnect items of data or portions of one or more computer 
  24729.            programs; for example, linking of object programs by a linkage 
  24730.            editor to produce an executable file. 
  24731.  
  24732.  linkage editor Synonym for linker. 
  24733.  
  24734.  linker    A program that resolves cross-references between separately compiled 
  24735.            object modules and then assigns final addresses to create a single 
  24736.            executable program. 
  24737.  
  24738.  literal 
  24739.  
  24740.              1. In programming languages, a lexical unit that directly 
  24741.                 represents a value; for example, 14 represents the integer 
  24742.                 fourteen, "APRIL" represents the string of characters APRIL, 
  24743.                 3.0005E2 represents the number 300.05. ISO-JTC1. 
  24744.  
  24745.              2. A symbol or a quantity in a source program that is itself data, 
  24746.                 rather than a reference to data. IBM. 
  24747.  
  24748.              3. A character string whose value is given by the characters 
  24749.                 themselves; for example, the numeric literal 7 has the value 7, 
  24750.                 and the character literal CHARACTERS has the value CHARACTERS. 
  24751.                 IBM. 
  24752.  
  24753.  local 
  24754.  
  24755.              1. In programming languages, pertaining to the relationship 
  24756.                 between a language object and a block such that the language 
  24757.                 object has a scope contained in that block. ISO-JTC1. 
  24758.  
  24759.              2. Pertaining to that which is defined and used only in one 
  24760.                 subdivision of a computer program. American National Standard 
  24761.                 for Information Systems. 
  24762.  
  24763.  local scope A name declared in a block, which can only be used in that block. 
  24764.  
  24765.  locale    The definition of the subset of a user's environment that depends on 
  24766.            language and cultural conventions. 
  24767.  
  24768.  lvalue    An expression that represents an object that can be both examined 
  24769.            and altered. 
  24770.  
  24771.  
  24772. ΓòÉΓòÉΓòÉ <hidden> M ΓòÉΓòÉΓòÉ
  24773.  
  24774.  macro     An identifier followed by arguments (may be a parenthesized list of 
  24775.            arguments) that the preprocessor replaces with the replacement code 
  24776.            located in a preprocessor #define directive. 
  24777.  
  24778.  main function An external function with the identifier main that is the first 
  24779.            user function-aside from exit routines and C++ static object 
  24780.            constructors-to get control when program execution begins. Each C 
  24781.            and C++ program must have exactly one function named main. 
  24782.  
  24783.  mangling  The encoding during compilation of identifiers such as function and 
  24784.            variable names to include type and scope information.  The prelinker 
  24785.            uses these mangled names to ensure type-safe linkage. See also 
  24786.            demangling. 
  24787.  
  24788.  member function 
  24789.  
  24790.              1. An operator or function that is declared as a member of a 
  24791.                 class. A member function has access to the private and 
  24792.                 protected data members and member functions of objects of its 
  24793.                 class. Member functions are also called methods. 
  24794.  
  24795.              2. A function that performs operations on a class. 
  24796.  
  24797.  message   A request from one object that the receiving object implement a 
  24798.            method. Because data is encapsulated and not directly accessible, a 
  24799.            message is the only way to send data from one object to another. 
  24800.            Each message specifies the name of the receiving object, the method 
  24801.            to be implemented, and any parameters the method needs for 
  24802.            implementation. 
  24803.  
  24804.  method    Synonym for member function. 
  24805.  
  24806.  module    A program unit that usually performs a particular function or 
  24807.            related functions, and that is distinct and identifiable with 
  24808.            respect to compiling, combining with other units, and loading. 
  24809.  
  24810.  multibyte character A mixture of single-byte characters from a single-byte 
  24811.            character set and double-byte characters from a double-byte 
  24812.            character set. 
  24813.  
  24814.  multiple inheritance 
  24815.  
  24816.              1. An object-oriented programming technique implemented in C++ 
  24817.                 through derivation, in which the derived class inherits members 
  24818.                 from more than one base class. 
  24819.  
  24820.              2. The structuring of inheritance relationships among classes so a 
  24821.                 derived class can use the attributes, relationships, and 
  24822.                 functions used by more than one base class. 
  24823.  
  24824.                 See also inheritance. 
  24825.  
  24826.  multithread Pertaining to concurrent operation of more than one path of 
  24827.            execution within a computer. 
  24828.  
  24829.  
  24830. ΓòÉΓòÉΓòÉ <hidden> N ΓòÉΓòÉΓòÉ
  24831.  
  24832.  name      In the C++ language, a name is commonly referred to as an 
  24833.            identifier. However, syntactically, a name can be an identifier, 
  24834.            operator function name, conversion function name, destructor name, 
  24835.            or qualified name. 
  24836.  
  24837.  nested class A class defined within the scope of another class. 
  24838.  
  24839.  new 
  24840.  
  24841.              1. A C++ keyword identifying a free storage allocation operator. 
  24842.  
  24843.              2. A C++ operator used to create class objects. 
  24844.  
  24845.  new-line character A control character that causes the print or display 
  24846.            position to move to the first position on the next line. This 
  24847.            control character is represented by \n in the C language. 
  24848.  
  24849.  nonreentrant The state of 16-bit code in the kernel where two threads cannot 
  24850.            access it at the same time without risking a system crash. 
  24851.  
  24852.            In Windows 95, processes are preempted and any thread is likely to 
  24853.            be interrupted at any point in its execution. 
  24854.  
  24855.  NULL      In the C and C++ languages, a pointer that does not point to a data 
  24856.            object. IBM. 
  24857.  
  24858.  null character (\0) The character with the hex value 00 (all bits turned off). 
  24859.            It is used to represent the absence of a printed or displayed 
  24860.            character. 
  24861.  
  24862.  null pointer The value that is obtained by converting the number 0 into a 
  24863.            pointer; for example, (void *) 0. The C and C++ languages guarantee 
  24864.            that this value will not match that of any legitimate pointer, so it 
  24865.            is used by many functions that return pointers to indicate an error. 
  24866.            X/Open. 
  24867.  
  24868.  number sign The character #, also known as pound sign and hash sign. 
  24869.  
  24870.  
  24871. ΓòÉΓòÉΓòÉ <hidden> O ΓòÉΓòÉΓòÉ
  24872.  
  24873.  object 
  24874.  
  24875.              1. A computer representation of something that a user can work 
  24876.                 with to perform a task. An object can appear as text or an 
  24877.                 icon. 
  24878.  
  24879.              2. A collection of data and member functions that operate on that 
  24880.                 data, which together represent a logical entity in the system. 
  24881.                 In object-oriented programming, objects are grouped into 
  24882.                 classes that share common data definitions and member 
  24883.                 functions. Each object in the class is said to be an instance 
  24884.                 of the class. 
  24885.  
  24886.              3. In Visual Builder, an instance of an object class consisting of 
  24887.                 attributes, a data structure, and operational member functions. 
  24888.                 It can represent a person, place, thing, event, or concept. 
  24889.                 Each instance has the same properties, attributes, and member 
  24890.                 functions as other instances of the object class, though it has 
  24891.                 unique values assigned to its attributes. 
  24892.  
  24893.              4. In Windows, any item that is or can be linked into another 
  24894.                 Windows application, such as a sound, graphic, piece of text, 
  24895.                 or portion of a spreadsheet. An object must be from an 
  24896.                 application that supports OLE. See object linking and embedding 
  24897.                 (OLE). 
  24898.  
  24899.  object code Machine-executable instructions, usually generated by a compiler 
  24900.            from source code written in a higher level language (such as the C++ 
  24901.            language). For programs that must be linked, object code consists of 
  24902.            relocatable machine code. 
  24903.  
  24904.  object linking and embedding (OLE) 
  24905.  
  24906.              1. An API that supports compound documents, cross-application 
  24907.                 macro control, and common object registration. OLE defines 
  24908.                 protocols for in-place editing, drag-and-drop data transfers, 
  24909.                 structured storage, custom controls, and more. 
  24910.  
  24911.              2. A data-sharing scheme that allows dissimilar applications to 
  24912.                 create single complex documents cooperatively. The documents 
  24913.                 can consist of material that a single application could not 
  24914.                 have created on its own. 
  24915.  
  24916.  OLE       See object linking and embedding. 
  24917.  
  24918.  operation class A class that defines all required element and key operations 
  24919.            required by a specific collection implementation. 
  24920.  
  24921.  object module 
  24922.  
  24923.              1. All or part of an object program sufficiently complete for 
  24924.                 linking.  Assemblers and compilers usually produce object 
  24925.                 modules. ISO Draft. 
  24926.  
  24927.              2. A set of instructions in machine language produced by a 
  24928.                 compiler from a source program. IBM. 
  24929.  
  24930.  object-oriented programming A programming approach based on the concepts of 
  24931.            data abstraction and inheritance. Unlike procedural programming 
  24932.            techniques, object-oriented programming concentrates on what data 
  24933.            objects comprise the problem and how they are manipulated, not on 
  24934.            how something is accomplished. 
  24935.  
  24936.  octal constant The digit 0 (zero) followed by any digits 0 through 7. 
  24937.  
  24938.  operator function An overloaded operator that is either a member of a class or 
  24939.            that takes at least one argument that is a class type or a reference 
  24940.            to a class type. See overloading. 
  24941.  
  24942.  operator precedence In programming languages, an order relation defining the 
  24943.            sequence of the application of operators within an expression. 
  24944.            ISO-JTC1. 
  24945.  
  24946.  overflow  A condition that occurs when a portion of the result of an operation 
  24947.            exceeds the capacity of the intended unit of storage. 
  24948.  
  24949.  overloading An object-oriented programming technique where one or more 
  24950.            function declarations are specified for a single name in the same 
  24951.            scope. 
  24952.  
  24953.  
  24954. ΓòÉΓòÉΓòÉ <hidden> P ΓòÉΓòÉΓòÉ
  24955.  
  24956.  pack      To store data in a compact form in such a way that the original form 
  24957.            can be recovered. 
  24958.  
  24959.  pad       To fill unused positions in a field with data, usually 0's, 1's, or 
  24960.            blanks. 
  24961.  
  24962.  parameter 
  24963.  
  24964.              1. In the C and C++ languages, an object declared as part of a 
  24965.                 function declaration or definition that acquires a value on 
  24966.                 entry to the function, or an identifier following the macro 
  24967.                 name in a function-like macro definition. X/Open. 
  24968.  
  24969.              2. Data passed between programs or procedures. IBM. 
  24970.  
  24971.  parameter declaration A description of a value that a function receives. A 
  24972.            parameter declaration determines the storage class and the data type 
  24973.            of the value. 
  24974.  
  24975.  pointer   A variable that holds the address of a data object or function. 
  24976.  
  24977.  pointer class A class that implements pointers. 
  24978.  
  24979.  pointer to member An operator used to access the address of nonstatic members 
  24980.            of a class. 
  24981.  
  24982.  polymorphism The technique of taking an abstract view of an object or function 
  24983.            and using any concrete objects or arguments that are derived from 
  24984.            this abstract view. 
  24985.  
  24986.  precedence The priority system for grouping different types of operators with 
  24987.            their operands. 
  24988.  
  24989.  predefined macros Frequently used routines provided by an application or 
  24990.            language for the programmer. 
  24991.  
  24992.  preprocessor A phase of the compiler that examines the source program for 
  24993.            preprocessor statements, which are then executed, resulting in the 
  24994.            alteration of the source program. 
  24995.  
  24996.  primary expression Literals, names, and names qualified by the :: (scope 
  24997.            resolution) operator. 
  24998.  
  24999.  private   Pertaining to a class member that is accessible only to member 
  25000.            functions and friends of that class. 
  25001.  
  25002.  profiling The process of generating a statistical analysis of a program that 
  25003.            shows processor time and the percentage of program execution time 
  25004.            used by each procedure in the program. 
  25005.  
  25006.  protected Pertaining to a class member that is only accessible to member 
  25007.            functions and friends of that class, or to member functions and 
  25008.            friends of classes derived from that class. 
  25009.  
  25010.  prototype A function declaration or definition that includes both the return 
  25011.            type of the function and the types of its arguments. 
  25012.  
  25013.  public    Pertaining to a class member that is accessible to all functions. 
  25014.  
  25015.  pure virtual function A virtual function that has a function initializer of 
  25016.            the form = 0;. 
  25017.  
  25018.  
  25019. ΓòÉΓòÉΓòÉ <hidden> Q ΓòÉΓòÉΓòÉ
  25020.  
  25021.  qualified name Used to qualify a nonclass type name such as a member by its 
  25022.            class name. 
  25023.  
  25024.  
  25025. ΓòÉΓòÉΓòÉ <hidden> R ΓòÉΓòÉΓòÉ
  25026.  
  25027.  reference class A class that links a concrete class to an abstract class. 
  25028.            Reference classes make polymorphism possible with the Collection 
  25029.            Classes. 
  25030.  
  25031.  register storage class specifier A specifier that indicates to the compiler 
  25032.            within a block scope data definition, or a parameter declaration, 
  25033.            that the object being described will be heavily used. 
  25034.  
  25035.  reentrant The attribute of a program or routine that allows the same copy of a 
  25036.            program or routine to be used concurrently by two or more tasks. 
  25037.  
  25038.  return    A language construct that ends an execution sequence in a procedure. 
  25039.  
  25040.  
  25041. ΓòÉΓòÉΓòÉ <hidden> S ΓòÉΓòÉΓòÉ
  25042.  
  25043.  scalar    An arithmetic object, or a pointer to an object of any type. 
  25044.  
  25045.  scope     That part of a source program in which an object is defined and 
  25046.            recognized. 
  25047.  
  25048.  scope operator (::) An operator that defines the scope for the argument on the 
  25049.            right. If the left argument is blank, the scope is global; if the 
  25050.            left argument is a class name, the scope is within that class. Also 
  25051.            called a scope resolution operator. 
  25052.  
  25053.  signal 
  25054.  
  25055.              1. A condition that may or may not be reported during program 
  25056.                 execution. For example, SIGFPE is the signal used to represent 
  25057.                 erroneous arithmetic operations such as a division by zero. 
  25058.  
  25059.              2. A mechanism by which a process may be notified of, or affected 
  25060.                 by, an event occurring in the system. Examples of such events 
  25061.                 include hardware exceptions and specific actions by processes. 
  25062.                 The term signal is also used to refer to the event itself. 
  25063.                 X/Open. ISO.1. 
  25064.  
  25065.              3. In AIX operating system operations, a method of interprocess 
  25066.                 communication that simulates software interrupts. IBM. 
  25067.  
  25068.  signal handler A function to be called when the signal is reported. 
  25069.  
  25070.  source file A file that contains source statements for such items as 
  25071.            high-level language programs and data description specifications. 
  25072.            IBM. 
  25073.  
  25074.  source program A set of instructions written in a programming language that 
  25075.            must be translated to machine language before the program can be 
  25076.            run. IBM. 
  25077.  
  25078.  specifiers Used in declarations to indicate storage class, fundamental data 
  25079.            type and other properties of the object or function being declared. 
  25080.  
  25081.  stack     A data structure in which new elements are added to and removed from 
  25082.            the top of the structure.  A stack is characterized by 
  25083.            Last-In-First-Out (LIFO) behavior. 
  25084.  
  25085.  stack storage Synonym for automatic storage. 
  25086.  
  25087.  standard error An output stream usually intended to be used for diagnostic 
  25088.            messages. 
  25089.  
  25090.  standard input An input stream usually intended to be used for primary data 
  25091.            input. Standard input comes from the keyboard unless redirection or 
  25092.            piping is used, in which case standard input can be from a file or 
  25093.            the output from another command. 
  25094.  
  25095.  standard output An output stream usually intended to be used for primary data 
  25096.            output. X/Open.  When programs are run interactively, standard 
  25097.            output usually goes to the display unless redirection or piping is 
  25098.            used, in which case standard output can go to a file or to another 
  25099.            command. 
  25100.  
  25101.  statement An instruction that ends with the character ; (semicolon) or several 
  25102.            instructions that are surrounded by the characters { and }. 
  25103.  
  25104.  static    A keyword used for defining the scope and linkage of variables and 
  25105.            functions. For internal variables, the variable has block scope and 
  25106.            retains its value between function calls. For external values, the 
  25107.            variable has file scope and retains its value within the source 
  25108.            file. For class variables, the variable is shared by all objects of 
  25109.            the class and retains its value within the entire program. 
  25110.  
  25111.  storage class specifier One of: auto, register, static, or extern. 
  25112.  
  25113.  stream 
  25114.  
  25115.              1. A continuous stream of data elements being transmitted, or 
  25116.                 intended for transmission, in character or binary-digit form, 
  25117.                 using a defined format. 
  25118.  
  25119.              2. A file access object that allows access to an ordered sequence 
  25120.                 of characters, as described by the ISO C standard. A stream 
  25121.                 provides the additional services of user-selectable buffering 
  25122.                 and formatted input and output. 
  25123.  
  25124.  stream buffer A stream buffer is a buffer between the ultimate consumer, 
  25125.            ultimate producer, and the I/O Stream Library functions that format 
  25126.            data. It is implemented in the I/O Stream Library by the streambuf 
  25127.            class and the classes derived from streambuf. 
  25128.  
  25129.  string    A contiguous sequence of characters. 
  25130.  
  25131.  string literal Zero or more characters enclosed in double quotation marks. 
  25132.  
  25133.  structure A construct that contains an ordered group of data objects. Unlike 
  25134.            an array, the data objects within a structure can have varied data 
  25135.            types. 
  25136.  
  25137.  structure tag The identifier that names a structure data type. 
  25138.  
  25139.  subscript One or more expressions, each enclosed in brackets, that follow an 
  25140.            array name. A subscript refers to an element in an array. 
  25141.  
  25142.  subsystem A secondary or subordinate system, usually capable of operating 
  25143.            independently of or asynchronously with, a controlling system. ISO 
  25144.            Draft. 
  25145.  
  25146.  switch statement A C or C++ language statement that causes control to be 
  25147.            transferred to one of several statements depending on the value of 
  25148.            an expression. 
  25149.  
  25150.  
  25151. ΓòÉΓòÉΓòÉ <hidden> T ΓòÉΓòÉΓòÉ
  25152.  
  25153.  template  A family of classes or functions where the code remains invariant 
  25154.            but operates with variable types. 
  25155.  
  25156.  template class A class instance generated by a class template. 
  25157.  
  25158.  template function A function generated by a function template. 
  25159.  
  25160.  this      A C++ keyword that identifies a special type of pointer in a member 
  25161.            function, one that references the class object with which the member 
  25162.            function was invoked. 
  25163.  
  25164.  thread 
  25165.  
  25166.              1. The smallest unit or path of execution within a process. IBM. 
  25167.  
  25168.              2. A piece of executing code. 
  25169.  
  25170.              3. In Windows, each thread is allocated its own stack from the 
  25171.                 owning process' 4-GB address space, and each one has its own 
  25172.                 set of processor registers, called the thread's context. 
  25173.  
  25174.  throw expression An argument to the C++ exception being thrown. 
  25175.  
  25176.  token     The smallest independent unit of meaning of a program as defined 
  25177.            either by a parser or a lexical analyzer. A token can contain data, 
  25178.            a language keyword, an identifier, or other parts of language 
  25179.            syntax. 
  25180.  
  25181.  try block 
  25182.  
  25183.              1. A block in which a known C++ exception is passed to a handler. 
  25184.  
  25185.               2.
  25186.  
  25187.  type      The description of the data and the operations that can be performed 
  25188.            on or by the data. See also data type. 
  25189.  
  25190.  type definition A definition of a name for a data type. IBM. 
  25191.  
  25192.  type balancing A conversion that makes both operands have the same data type. 
  25193.            If the operands do not have the same size data type, the compiler 
  25194.            converts the value of the operand with the smaller type to a value 
  25195.            having the larger type. 
  25196.  
  25197.  type specifier Used to indicate the data type of an object or function being 
  25198.            declared. 
  25199.  
  25200.  
  25201. ΓòÉΓòÉΓòÉ <hidden> U ΓòÉΓòÉΓòÉ
  25202.  
  25203.  unary expression An expression that contains one operand. 
  25204.  
  25205.  undefined behavior Referring to a program or function that may produce 
  25206.            erroneous results without warning because of its use of an 
  25207.            indeterminate value, or because of erroneous program constructs or 
  25208.            erroneous data. 
  25209.  
  25210.  union 
  25211.  
  25212.              1. Structures that can contain different types of objects at 
  25213.                 different times. Only one of the member objects can be stored 
  25214.                 in a union at any time. IBM. 
  25215.  
  25216.              2. Given the sets A and B, all elements of A, B, or both A and B. 
  25217.  
  25218.  union tag The identifier that names a union data type. 
  25219.  
  25220.  
  25221. ΓòÉΓòÉΓòÉ <hidden> V ΓòÉΓòÉΓòÉ
  25222.  
  25223.  variable  In programming languages, a language object that may take different 
  25224.            values, one at a time. The values of a variable are usually 
  25225.            restricted to a certain data type. ISO-JTC1. 
  25226.  
  25227.  virtual function A function of a class that is declared with the keyword 
  25228.            virtual. The implementation that is executed when you make a call to 
  25229.            a virtual function depends on the type of the object for which it is 
  25230.            called. This is determined at run time. 
  25231.  
  25232.  visible   Visibility of identifiers is based on scoping rules and is 
  25233.            independent of access. 
  25234.  
  25235.  volatile  An attribute of a data object that indicates the object is 
  25236.            changeable beyond the control or detection of  the compiler. Any 
  25237.            expression referring to a volatile object is evaluated immediately, 
  25238.            for example, assignments. 
  25239.  
  25240.  
  25241. ΓòÉΓòÉΓòÉ <hidden> W ΓòÉΓòÉΓòÉ
  25242.  
  25243.  white space Space characters, tab characters, form feed characters, and 
  25244.            new-line characters. 
  25245.  
  25246.  wide character A character whose range of values can represent distinct codes 
  25247.            for all members of the largest extended character set specified 
  25248.            among the supporting locales. 
  25249.  
  25250.  Win32     The name of a 32-bit application programming interface (API). 
  25251.  
  25252.            See also Win32 API. 
  25253.  
  25254.  Win32 API 
  25255.  
  25256.              1. A set of Win32 functions that can be called from source code. 
  25257.  
  25258.              2. A 32-bit version of the 16-bit Windows 3.1 API (native to 
  25259.                 Windows NT). 
  25260.  
  25261.                 See also Win32. 
  25262.  
  25263.  Windows NT A platform that the Win32 API is implemented on. It is a portable, 
  25264.            high-end operating system, which can run several different types of 
  25265.            applications simultaneously. It is the only Win32 platform for 
  25266.            machine architectures based on processors other than the x86, and it 
  25267.            supports multiple processors. 
  25268.  
  25269.            See also Win32 API. 
  25270.  
  25271.  word boundary Any storage position at which data must be aligned for certain 
  25272.            processing operations. The halfword boundary must be divisible by 2; 
  25273.            the fullword boundary by 4; and the doubleword boundary by 8. IBM. 
  25274.  
  25275.  working directory 
  25276.  
  25277.              1. Synonym for current working directory. 
  25278.  
  25279.              2. The directory where files that are copied or dragged into the 
  25280.                 project are stored.  Actions are also executed in this 
  25281.                 directory, so this directory is where many output files are 
  25282.                 placed. 
  25283.  
  25284.  write 
  25285.  
  25286.              1. To output characters to a file, such as standard output or 
  25287.                 standard error. Unless otherwise stated, standard output is the 
  25288.                 default output destination for all uses of the term write. 
  25289.                 X/Open. 
  25290.  
  25291.              2. To make a permanent or transient recording of data in a storage 
  25292.                 device or on a data medium. ISO-JTC1. American National 
  25293.                 Standard for Information Systems. 
  25294.