home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv4.zip / VACPP / IBMCPP / HELP / CPPLNG.INF (.txt) < prev    next >
OS/2 Help File  |  1995-04-27  |  602KB  |  23,790 lines

  1.  
  2. ΓòÉΓòÉΓòÉ 1. How to Use the Online Language Reference ΓòÉΓòÉΓòÉ
  3.  
  4. The VisualAge C++ Online Language Reference is a language reference guide for C 
  5. and C++ programmers. It provides information about the VisualAge 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 (which you can customize using the 
  22. OS/2 Scheme Palette). For example, here is a link to another panel: 
  23. Communicating Your Comments to IBM. By double-clicking on the text of the link 
  24. or by pressing Enter on a highlighted link, you will open a panel of related 
  25. information. When you open a panel, the first link has the focus; to shift the 
  26. focus to other links, use the Tab key. 
  27.  
  28. You should also understand: 
  29.  
  30.      How to Use the Contents 
  31.      How to Get More Information on a Topic 
  32.      How to Use Action Bar Choices 
  33.      How to Cut and Paste Examples 
  34.  
  35.  
  36. ΓòÉΓòÉΓòÉ 1.1. How to Use the Contents ΓòÉΓòÉΓòÉ
  37.  
  38. When the Contents window first appears, some topics have a plus (+) sign beside 
  39. them. The plus sign indicates that additional topics are available. 
  40.  
  41. To expand the Contents if you are using a mouse, click on the plus sign. If you 
  42. are using the keyboard, use the Up or Down Arrow key to highlight the topic, 
  43. and press the plus (+) key. For example, Preprocessor Directives has a plus 
  44. sign beside it. To see additional topics for that heading, click on the plus 
  45. sign or highlight that topic and press the plus (+) key. 
  46.  
  47. To view a topic, double-click on the topic (or press the Up or Down Arrow key 
  48. to highlight the topic, and then press the Enter key). 
  49.  
  50.  
  51. ΓòÉΓòÉΓòÉ 1.2. How to Get More Information on a Topic ΓòÉΓòÉΓòÉ
  52.  
  53. After you select a topic, the information for that topic appears in a window. 
  54. Highlighted words or phrases indicate that additional information is available. 
  55. Words and phrases highlighted in a different color from the surrounding text 
  56. are called hypertext terms. 
  57.  
  58. If you are using a mouse, double-click on the highlighted word. If you are 
  59. using a keyboard, press the Tab key to move to the highlighted word, and then 
  60. press the Enter key. Additional information then appears in a window. 
  61.  
  62.  
  63. ΓòÉΓòÉΓòÉ 1.3. How to Use Action Bar Choices ΓòÉΓòÉΓòÉ
  64.  
  65. Several choices are available for managing information presented in the 
  66. VisualAge C++ Online Language Reference. There are three pull-down menus on the 
  67. action bar: the Services menu, the Options menu, and the Help menu. 
  68.  
  69. The actions that are selectable from the Services menu operate on the active 
  70. window currently displayed on the screen. These actions include the following: 
  71.  
  72.  Bookmark 
  73.    You can set a placeholder so you can retrieve information of interest to 
  74.    you. 
  75.  
  76.  Search 
  77.    You can find occurrences of a word or phrase in the current topic, selected 
  78.    topics, or all topics. 
  79.  
  80.  Print 
  81.    You can print one or more topics. You can also print a set of topics by 
  82.    first marking the topics in the Contents list. 
  83.  
  84.  Copy 
  85.    You can copy a topic that you are viewing to the System Clipboard or to a 
  86.    file that you can edit. This method is particularly useful for copying 
  87.    syntax definitions and program samples into the application that you are 
  88.    developing. 
  89.  
  90.  Using the actions that are selectable from the Options menu, you can change 
  91.  the way your Contents list is displayed. To expand the Contents and show all 
  92.  levels for all topics, choose Expand all from the Options pull-down. You can 
  93.  also press the Ctrl, Shift, and * keys together. 
  94.  
  95.  The actions that are selectable from the Help menu allow you to select 
  96.  different types of help information. 
  97.  
  98.  For information about any of the menu choices, highlight the choice in the 
  99.  menu and press F1. 
  100.  
  101.  
  102. ΓòÉΓòÉΓòÉ <hidden> Placing Bookmarks ΓòÉΓòÉΓòÉ
  103.  
  104. When you place a bookmark on a topic, it is added to a list of bookmarks you 
  105. have previously set. You can view the list, and you can remove one or all 
  106. bookmarks from the list. If you have not set any bookmarks, the list is empty. 
  107.  
  108. To set a bookmark, do the following: 
  109.  
  110.    1. Select a topic from the Contents. 
  111.    2. When that topic appears, select the Bookmark option from the Services 
  112.       menu. 
  113.    3. If you want to change the name used for the bookmark, type the new name 
  114.       in the field. 
  115.    4. Click on the Place radio button (or press the Up or Down Arrow key to 
  116.       select it). 
  117.    5. Click on OK (or select it and press Enter). The bookmark is then added to 
  118.       the bookmark list. 
  119.  
  120.  
  121. ΓòÉΓòÉΓòÉ <hidden> Searching for Information ΓòÉΓòÉΓòÉ
  122.  
  123. You can specify a word or phrase to be searched. You can also limit the search 
  124. to a set of topics by first marking the topics in the Contents list. 
  125.  
  126. To search for a word or phrase in all topics, do the following: 
  127.  
  128.    1. Select the Search option from the Services menu. 
  129.    2. Type the word or words to be searched for. 
  130.    3. Click on All sections (or press the Up or Down Arrow keys to select it). 
  131.    4. Click on Search (or select it and press Enter) to begin the search. 
  132.    5. The list of topics where the word or phrase appears is displayed. 
  133.  
  134.  
  135. ΓòÉΓòÉΓòÉ <hidden> Printing Information ΓòÉΓòÉΓòÉ
  136.  
  137. You can print one or more topics, the index, or the table of contents. Make 
  138. sure that your printer is connected to the serial port, configured correctly, 
  139. and ready for input. To print: 
  140.  
  141.    1. Select Print from the Services pull-down. 
  142.    2. Select what you want to print. Note that the This section and Marked 
  143.       sections choices are only available if you are viewing a topic or if you 
  144.       have marked topics, respectively. To mark topics in the table of 
  145.       contents, press the Ctrl key and click on the topics, or use the arrow 
  146.       keys. 
  147.    3. Select Print to print what you've chosen on your printer. 
  148.  
  149.  
  150. ΓòÉΓòÉΓòÉ <hidden> Copying Information to a File ΓòÉΓòÉΓòÉ
  151.  
  152. You can copy a topic that you are viewing in two ways: 
  153.  
  154.      Copy copies the topic that you are viewing into the System Clipboard. If 
  155.       you are using a Presentation Manager (PM) editor (for example, the 
  156.       Enhanced Editor) that copies or cuts (or both) to the System Clipboard, 
  157.       and pastes to the System Clipboard, you can easily add the copied 
  158.       information to your program source module. 
  159.  
  160.      Copy to file copies the topic that you are viewing into a temporary file 
  161.       named TEXT.TMP. You can later edit that file by using any editor. 
  162.       TEXT.TMP is placed in the directory where your viewable document resides. 
  163.  
  164.  To copy a topic, do the following: 
  165.  
  166.    1. Expand the Contents list and select a topic. 
  167.    2. When the topic appears, select Copy to file from the Services menu. 
  168.    3. The system puts the text pertaining to that topic into the temporary file 
  169.       TEXT.TMP. 
  170.  
  171.  
  172. ΓòÉΓòÉΓòÉ 1.4. How to Cut and Paste Examples ΓòÉΓòÉΓòÉ
  173.  
  174. You can copy examples (or information) from this reference/guide/book to 
  175. compile, link, and run them, or to paste them into your own code. 
  176.  
  177. To copy an example or information: 
  178.  
  179.    1. Make the topic you want to copy the active window. 
  180.  
  181.    2. From the Services menu, select Copy to file. The text in that topic is 
  182.       placed in the temporary file TEXT.TMP, in the same directory as this 
  183.       reference. 
  184.  
  185.    3. You can then modify or use TEXT.TMP as you want. 
  186.  
  187.  Note:  Because the system copies the entire contents of the topic to the file, 
  188.  you may need to edit it to remove additional text. Most examples in this 
  189.  reference are ready to compile, link, and run as they appear, and do not 
  190.  require any editing. 
  191.  
  192.  
  193. ΓòÉΓòÉΓòÉ 1.5. Other Information You Might Find Helpful ΓòÉΓòÉΓòÉ
  194.  
  195. This product provides a number of online guides and references that we hope 
  196. you'll find helpful as you develop applications. This information includes 
  197. User's Guides, References, and How Do I help that gives you specific 
  198. instructions for performing common tasks. You can get to this online 
  199. information from the Information folder inside the main product folder. You can 
  200. also get to it from the Help menu in any of the components of the product. You 
  201. can get help in four ways: 
  202.  
  203.      Inside VisualAge C++ 
  204.      From the Command Line 
  205.      For a Keyword or Construct 
  206.      BookManager Books 
  207.  
  208.  For a list of VisualAge C++ documents that are available online, see Online 
  209.  Documents Available in VisualAge C++. 
  210.  
  211.  
  212. ΓòÉΓòÉΓòÉ <hidden> Getting Help Inside VisualAge C++ ΓòÉΓòÉΓòÉ
  213.  
  214. Three kinds of help are available directly within the VisualAge C++ interface: 
  215.  
  216.      To get general contextual help for the component of VisualAge C++ that 
  217.       you are using, press F1 anywhere in the window. 
  218.      To get contextual help on a particular menu, menu item, or button, 
  219.       highlight the element and press F1. 
  220.      To get access to all of the help information that is available to you in 
  221.       a particular window, click on Help in the menu bar at the top of the 
  222.       window. 
  223.  
  224.  The Help menu includes the following selections: 
  225.  
  226.  Help Index  An alphabetical list of all of the help topics that are available 
  227.              from this window 
  228.  
  229.  General Help Overall help for the window 
  230.  
  231.  Using Help  General information about the help facility 
  232.  
  233.  How Do I... The How Do I help for the component 
  234.  
  235.  Product Information A dialog that shows the level of VisualAge C++ being used 
  236.  
  237.  In addition, there are selections that let you open all of online documents 
  238.  that are available in VisualAge C++. 
  239.  
  240.  To get detailed information, open the Information folder in the VisualAge C++ 
  241.  folder. In this folder you will find icons for a variety of online documents 
  242.  that describe, in detail, the different aspects of VisualAge C++. To open a 
  243.  particular online document, double click on its icon. 
  244.  
  245.  
  246. ΓòÉΓòÉΓòÉ <hidden> Getting Help from the Command Line ΓòÉΓòÉΓòÉ
  247.  
  248. You can look at the online documents by issuing the view command. The 
  249. installation routine stores the online document files in the \IBMCPP\HELP 
  250. directory. To view the Language Reference, for example, make C:\IBMCPP\HELP 
  251. your current directory (substituting the drive where you installed VisualAge 
  252. C++ for C:) and enter the following command: 
  253.  
  254.      VIEW CPPLNG.INF
  255.  
  256. If you want to get information on a specific topic, you can specify a word or a 
  257. series of words after the file name. If the words appear in an entry in the 
  258. table of contents or the index, the online document is opened to the associated 
  259. section. For example, if you want to read the section on operator precedence in 
  260. the Language Reference, you can enter the following command: 
  261.  
  262.      VIEW CPPLNG.INF OPERATOR PRECEDENCE
  263.  
  264.  
  265. ΓòÉΓòÉΓòÉ <hidden> Getting Help for a Keyword or Construct ΓòÉΓòÉΓòÉ
  266.  
  267. If you are editing a file using Editor, you can get help for a keyword or 
  268. construct by highlighting the word and pressing F1. In the other tools, you can 
  269. get help for a keyword or construct by highlighting the word and pressing 
  270. Ctrl-H. 
  271.  
  272.  
  273. ΓòÉΓòÉΓòÉ <hidden> BookManager Books ΓòÉΓòÉΓòÉ
  274.  
  275. The online documents for VisualAge C++ are also available in BookManager format 
  276. in the CD-ROM version of VisualAge C++. You can read this information using 
  277. either the IBM Library Reader/2 or IBM Library Reader/DOS. For details on 
  278. installing and using the IBM Library Reader and BookManager books, see the 
  279. README.ENG file in the root directory of the CD-ROM. 
  280.  
  281.  
  282. ΓòÉΓòÉΓòÉ 1.6. Online Documents Available in VisualAge C++ ΓòÉΓòÉΓòÉ
  283.  
  284. The following documents are available in standard format (.INF files): 
  285.  
  286. Building VisualAge C++    Multimedia Subsystem    SOM Programming Reference
  287. Parts for Fun and Profit   Programming Guide
  288. C Library Reference     Open Class Library Ref-   User's Guide and Refer-
  289.               erence           ence
  290. Control Program Guide and  Open Class Library     Visual Builder User's
  291. Reference          User's Guide        Guide
  292. Graphics Programming     OS/2 Bidirectional Lan-   Visual Builder Parts Ref-
  293. Guide and Reference     guage Support Develop-   erence
  294.               ment Guide
  295. IPF Guide and Reference   OS/2 Tools Reference    Editor Command Reference
  296. Kernel Debug Reference    Presentation Manager    Welcome to VisualAge C++
  297.               Guide and Reference
  298. Language Reference      Programming Guide      Workplace Shell Program-
  299.                             ming Guide
  300. Multimedia Application    REXX Reference       Workplace Shell Program-
  301. Programming Guide                    ming Reference
  302. Multimedia Programming    SOM Programming Guide
  303. Reference
  304.  
  305.  
  306. ΓòÉΓòÉΓòÉ 1.7. Communicating Your Comments to IBM ΓòÉΓòÉΓòÉ
  307.  
  308. If there is something you like, or dislike, about this book, please let us 
  309. know. You can use one of the methods listed below to send your comments to IBM. 
  310. Please be sure to include the complete title of the publication that you are 
  311. commenting on. 
  312.  
  313. The comments you send should only pertain to the information in this document 
  314. and its presentation. To request additional publications or to ask questions or 
  315. make comments about the functions of IBM products or systems, you should talk 
  316. to your IBM representative or your authorized IBM remarketer. 
  317.  
  318. When you send comments to IBM, you grant IBM a nonexclusive right to use or 
  319. distribute your comments in any way it believes appropriate without incurring 
  320. any obligation to you. 
  321.  
  322. You can send your comments to IBM in the following ways: 
  323.  
  324.      By mail to the following address: 
  325.  
  326.             IBM Canada Ltd. Laboratory
  327.             Information Development
  328.             2G/345/1150/TOR
  329.             1150 EGLINTON AVENUE EAST
  330.             NORTH YORK, ONTARIO
  331.             CANADA M3C 1H7
  332.  
  333.      By FAX to the following number: 
  334.  
  335.         -  United States and Canada: (416) 448-6161 
  336.         -  Other countries (+1) 416-448-6161 
  337.  
  338.      By electronic mail to one of the following IDs. Be sure to include your 
  339.       entire network address if you wish to get a reply. 
  340.  
  341.         -  Internet: torrcf@vnet.ibm.com 
  342.         -  IBMLink: toribm(torrcf) 
  343.         -  IBM/PROFS: torolab4(torrcf) 
  344.         -  IBMMAIL: ibmmail(caibmwt9) 
  345.  
  346.  
  347. ΓòÉΓòÉΓòÉ <hidden> Related Information ΓòÉΓòÉΓòÉ
  348.  
  349.      Copyright 
  350.      Edition Notice 
  351.      Notices 
  352.      Trademarks and Service Marks 
  353.  
  354.  
  355. ΓòÉΓòÉΓòÉ 1.8. Copyright ΓòÉΓòÉΓòÉ
  356.  
  357. Copyright International Business Machines Corporation, 1995. All rights 
  358. reserved. 
  359.  
  360. Note to U.S. Government Users - Documentation related to restricted rights - 
  361. Use, duplication, or disclosure is subject to restrictions set forth in GSA ADP 
  362. Schedule Contract with IBM Corp. 
  363.  
  364.  
  365. ΓòÉΓòÉΓòÉ 1.9. Edition Notice ΓòÉΓòÉΓòÉ
  366.  
  367. First Edition, May 1995. 
  368.  
  369. This edition applies to Version 3.0 of IBM VisualAge C ++ for OS/2 (30H1664, 
  370. 30H1665, 30H1666) and to all subsequent releases and modifications until 
  371. otherwise indicated in new editions. Make sure you are using the correct 
  372. edition for the level of the product. 
  373.  
  374. This publication could include technical inaccuracies or typographical errors. 
  375. Changes are periodically made to the information herein; any such changes will 
  376. be reported in subsequent revisions. 
  377.  
  378. Requests for publications and for technical information about IBM products 
  379. should be made to your IBM Authorized Dealer or your IBM Marketing 
  380. Representative. 
  381.  
  382. When you send information to IBM, you grant IBM a nonexclusive right to use or 
  383. distribute the information in any ways it believes appropriate without 
  384. incurring any obligation to you. 
  385.  
  386.  
  387. ΓòÉΓòÉΓòÉ 1.10. Notices ΓòÉΓòÉΓòÉ
  388.  
  389. Any reference to an IBM licensed program in this publication is not intended to 
  390. state or imply that only IBM's licensed program may be used. Any functionally 
  391. equivalent product, program, or service that does not infringe any of IBM's 
  392. intellectual property rights may be used instead of the IBM product, program, 
  393. or service. Evaluation and verification of operation in conjunction with other 
  394. products, except those expressly designated by IBM, is the user's 
  395. responsibility. 
  396.  
  397. IBM may have patents or pending patent applications covering subject matter in 
  398. this document. The furnishing of this document does not give you any license to 
  399. these patents. You can send license inquiries, in writing, to the IBM Director 
  400. of Licensing, IBM Corporation, 500 Columbus Avenue, Thornwood, NY, 10594, USA. 
  401.  
  402. This publication contains examples of data and reports used in daily business 
  403. operations. To illustrate them as completely as possible, the examples include 
  404. the names of individuals, companies, brands, and products. All of these names 
  405. are fictitious and any similarity to the names and addresses used by an actual 
  406. business enterprise is entirely coincidental. 
  407.  
  408.  
  409. ΓòÉΓòÉΓòÉ 1.11. Trademarks and Service Marks ΓòÉΓòÉΓòÉ
  410.  
  411. The following terms are trademarks of IBM Corporation in the United States or 
  412. other countries or both: 
  413.  
  414.       BookManager 
  415.       C/2 
  416.       C Set/2 
  417.       C Set ++ 
  418.       Common User Access 
  419.       CUA 
  420.       IBM 
  421.       IBMLink 
  422.       Library Reader 
  423.       Operating System/2 
  424.       OS/2 
  425.       Personal System/2 
  426.       Presentation Manager 
  427.       PS/2 
  428.       VisualAge 
  429.       WorkFrame 
  430.  
  431.  Other company, product, and service names, which may be denoted by a double 
  432.  asterisk(**), may be trademarks or service marks of others. 
  433.  
  434.  
  435. ΓòÉΓòÉΓòÉ <hidden> signed/unsigned types ΓòÉΓòÉΓòÉ
  436.  
  437. The signed and unsigned types can be used with either a character (char) or an 
  438. integer (int, short, long). The unsigned prefix indicates that the value of the 
  439. object is to be a nonnegative value. 
  440.  
  441. For more information on conversions between signed and unsigned types, see 
  442. Implicit Type Conversions. 
  443.  
  444.  
  445. ΓòÉΓòÉΓòÉ <hidden> \ Character ΓòÉΓòÉΓòÉ
  446.  
  447. The backslash can appear in string literals or comments as a punctuator.  A 
  448. backslash followed by a single character in C code indicates an escape 
  449. sequence. A backslash by itself at the end of a line of C code is a 
  450. continuation character. 
  451.  
  452. Escape Sequences provides help on escape sequences and the continuation 
  453. character. 
  454.  
  455.  
  456. ΓòÉΓòÉΓòÉ <hidden> ( ) ΓòÉΓòÉΓòÉ
  457.  
  458. Parentheses are used to group expressions to force a particular order of 
  459. evaluation. A parenthesized expression usually contains one or more operators 
  460. and operands (variables or constants), and is often part of an assignment 
  461. expression. For example, ((x + y) * g) is a parenthesized expression. 
  462.  
  463. Parentheses are also used in function calls to group the argument list for the 
  464. function. The opening parenthesis appears directly after the function name, and 
  465. may be followed by any number of arguments (or no arguments), followed by the 
  466. closing parenthesis and a semicolon. For example, fgets(line, 100, stream); is 
  467. a function call. 
  468.  
  469. For help on parenthesized expressions, see Parenthesized Expressions ( ). 
  470.  
  471. For help on function calls, see Function Calls ( ). 
  472.  
  473.  
  474. ΓòÉΓòÉΓòÉ <hidden> + ΓòÉΓòÉΓòÉ
  475.  
  476. The plus (+) sign can be used as a unary operator to maintain the value of an 
  477. operand, for example, +quality. The unary plus sign is the opposite of the 
  478. unary minus (-) sign, which negates the value of an operand, for example, 
  479. -quality. 
  480.  
  481. The plus sign can also be used as a binary operator in an arithmetic expression 
  482. to represent the addition operation. For example, x + y indicates that the 
  483. variables x and y are to be added together. 
  484.  
  485. For more information on the unary plus operator, see Unary Plus  +. 
  486.  
  487. For more information on the addition operator, see Addition  +. 
  488.  
  489.  
  490. ΓòÉΓòÉΓòÉ <hidden> - ΓòÉΓòÉΓòÉ
  491.  
  492. The minus (-) sign can be used as a unary operator to negate the value of an 
  493. operand, for example -quality. 
  494.  
  495. It can also be used as a binary operator in an arithmetic expression to 
  496. represent the subtraction operation. For example, x - y indicates that the 
  497. variable y is to be subtracted from the variable x. 
  498.  
  499. For more information on the unary minus operator, see Unary Minus  -. 
  500.  
  501. For more information on the subtraction operator, see Subtraction  -. 
  502.  
  503.  
  504. ΓòÉΓòÉΓòÉ <hidden> & ΓòÉΓòÉΓòÉ
  505.  
  506. The ampersand (&) sign can be used as a unary operator to indicate the address 
  507. of its operand. For example, &anyvar represents the address of the variable 
  508. anyvar. 
  509.  
  510. The ampersand can also be used as a binary operator to represent the bitwise 
  511. AND operation. For example, in the expression x & y, the corresponding bits of 
  512. the x and y values are compared to see if the bits are both 1. 
  513.  
  514. A double ampersand (&&) is the logical AND operator. which indicate For 
  515. example, in the expression x && y, the values of x and y are checked to see if 
  516. both are nonzero values. 
  517.  
  518. For more information on the address operator, see Address  &. 
  519.  
  520. For more information on the bitwise AND operator, see Bitwise AND  &. 
  521.  
  522. For more information on the logical AND operator, see Logical AND  &&. 
  523.  
  524.  
  525. ΓòÉΓòÉΓòÉ <hidden> * ΓòÉΓòÉΓòÉ
  526.  
  527. The asterisk (*) can be used as a unary operator to indicate indirection. For 
  528. example, int *anyvar; declares anyvar as a pointer to int, that points to the 
  529. value of *anyvar. 
  530.  
  531. The asterisk can also be used as a binary operator in an arithmetic expression 
  532. to represent the multiplication operation. For example, x * y indicates that 
  533. the variable x is to be multiplied by y. 
  534.  
  535. For more information on the indirection operator, see Indirection  *. 
  536.  
  537. For more information on the multiplication operator, see Multiplication  *. 
  538.  
  539.  
  540. ΓòÉΓòÉΓòÉ <hidden> % ΓòÉΓòÉΓòÉ
  541.  
  542. The percent (%) sign can be used simply to indicate percentage in a string 
  543. literal.  For example, "More than 50% agree". 
  544.  
  545. The percent sign is also used as part of the format specifier for the printf 
  546. and scanf functions.  For example, in the statement printf("The value is %d", 
  547. anyint); the integer value of anyint is printed in the place of the %d 
  548. specifier. 
  549.  
  550. The percent sign can also be used as a binary operator to represent the modulus 
  551. (or remainder) operation. For example, the expression x % y indicates that x is 
  552. divided by y, and the result of the expression is the remainder of the 
  553. division. 
  554.  
  555. For more information on string literals, see String Literals. 
  556.  
  557. For more information on format specifiers, see the printf function or the scanf 
  558. function in the IBM VisualAge C++ for OS/2 C Library Reference. 
  559.  
  560. For more information on the remainder operator, see Remainder  %. 
  561.  
  562.  
  563. ΓòÉΓòÉΓòÉ <hidden> : ΓòÉΓòÉΓòÉ
  564.  
  565. The colon (:) is used to indicate the end of a label and separate it from the 
  566. following statement. For example, in the expression anylabl: x = y;, anylabl is 
  567. a label that could be part of a switch statement or the target of a goto 
  568. statement. 
  569.  
  570. The colon is also used in bit-field declarations to separate the identifier of 
  571. the bit field and the storage it is given. For example, in the structure 
  572.  
  573. struct {
  574.         unsigned x : 4
  575.         unsigned y : 1
  576.        }
  577.  
  578. the bit fields x and y are assigned 4 bits and 1 bit of storage, respectively. 
  579.  
  580. The colon can also be used as part of the compound conditional expression (?:) 
  581. to separate the two action expressions. For example, in the expression x = (y < 
  582. z) ? y : z;, if y is less than z, the value of y is assigned to x; if y is not 
  583. less than z, the value of z is assigned to x. 
  584.  
  585. For more information on labels, see Labels. 
  586.  
  587. For more information on bit fields, see the section Declaring and Using Bit 
  588. Fields under Structures. 
  589.  
  590. For more information on the compound conditional expression, see Conditional 
  591. Expressions. 
  592.  
  593.  
  594. ΓòÉΓòÉΓòÉ <hidden> ? ΓòÉΓòÉΓòÉ
  595.  
  596. The question mark (?) is used for both trigraphs (three characters starting 
  597. with ??) and as the first part of the operator for the conditional expression. 
  598.  
  599. For more information on the compound conditional expression, see Conditional 
  600. Expressions. 
  601.  
  602.  
  603. ΓòÉΓòÉΓòÉ <hidden> , ΓòÉΓòÉΓòÉ
  604.  
  605. The comma (,) can be used to separate items such as parameters in a function 
  606. call. 
  607.  
  608. The comma is also used in the comma expression to separate two operands.  For 
  609. example, in the expression x = (y++, z * 4);, the left operand is evaluated 
  610. then discarded, and the value of the right operand is assigned to x. 
  611.  
  612. For more information on the comma expression, see Comma Expression  ,. 
  613.  
  614.  
  615. ΓòÉΓòÉΓòÉ <hidden> ; ΓòÉΓòÉΓòÉ
  616.  
  617. The semicolon (;) is used to indicate the end of a C expression, for example, 
  618. int x = 4;. 
  619.  
  620. The semicolon can also be used by itself as a null statement to show a 
  621. nonexistent action. 
  622.  
  623. For more information on expressions, see Expression. 
  624.  
  625. For more information on null statements, see Null Statement. 
  626.  
  627.  
  628. ΓòÉΓòÉΓòÉ 2. Introduction to the C and C++ Languages ΓòÉΓòÉΓòÉ
  629.  
  630. This chapter describes the C and C++ programming languages implemented by 
  631. VisualAge C++ and shows you how to structure C and C++ source programs. It also 
  632. briefly summarizes the differences between C and C++, and discusses the 
  633. principles of object-oriented programming. 
  634.  
  635. This section discusses: 
  636.  
  637.      Overview of the C Language 
  638.      C Source Programs 
  639.      C Source Files 
  640.      Program Execution 
  641.      Scope in C 
  642.      Program Linkage 
  643.      Storage Duration 
  644.      Name Spaces 
  645.  
  646.  Related Information 
  647.  
  648.      Overview of the C++ Language 
  649.  
  650.  
  651. ΓòÉΓòÉΓòÉ 2.1. Overview of the C Language ΓòÉΓòÉΓòÉ
  652.  
  653. C is a programming language designed for a wide variety of programming tasks. 
  654. It is used for system-level code, text processing, graphics, and in many other 
  655. application areas. 
  656.  
  657. C supports several data types, including characters, integers, floating-point 
  658. numbers and pointers - each in a variety of forms. In addition, C also supports 
  659. arrays, structures (records), unions, and enumerations. 
  660.  
  661. The C language contains a concise set of statements, with functionality added 
  662. through its library. This division enables C to be both flexible and efficient. 
  663. An additional benefit is that the language is highly consistent across 
  664. different systems. 
  665.  
  666. The C library contains functions for input and output, mathematics, exception 
  667. handling, string and character manipulation, dynamic memory management, as well 
  668. as date and time manipulation. Use of this library helps to maintain program 
  669. portability, because the underlying implementation details for the various 
  670. operations need not concern the programmer. 
  671.  
  672. Related Information 
  673.  
  674.      Lexical Elements of C and C++ 
  675.      Functions 
  676.      Type Specifiers 
  677.      Overview of the C++ Language 
  678.  
  679.  
  680. ΓòÉΓòÉΓòÉ 2.2. C Source Programs ΓòÉΓòÉΓòÉ
  681.  
  682. A C source program is a collection of one or more directives, declarations, and 
  683. statements contained in one or more source files. 
  684.  
  685.  Statements      Specify the action to be performed. 
  686.  
  687.  Directives      Instruct the preprocessor to act on the text of the program. 
  688.                  Pragma directives affect compiler behavior. 
  689.  
  690.  Declarations    Establish names and define characteristics such as scope, data 
  691.                  type and linkage. 
  692.  
  693.  Definitions     Are declarations that allocate storage for data objects or 
  694.                  define a body for functions. An object definition allocates 
  695.                  storage and may optionally initialize the object. 
  696.  
  697.  A function declaration precedes the function body. The function body is a 
  698.  compound statement that can contain declarations and statements that define 
  699.  what the function does. The function declaration declares the function name, 
  700.  its parameters, and the data type of the value it returns. 
  701.  
  702.  A program must contain one, and only one, function called main. The main 
  703.  function is the first function called when a program is run. 
  704.  
  705.  C++ Note:  This is not the case for C++ programs. If a C++ program 
  706.  instantiates an object in file scope, the constructor for that object is 
  707.  executed first. 
  708.  
  709.  By convention, main is the starting point for running a program. It can call 
  710.  other functions. A program usually stops running at 
  711.  
  712.      the end of the main function 
  713.      a return statement in the main function 
  714.      an exit function call. 
  715.  
  716.  Source for a Simple C Program 
  717.  
  718.  Related Information 
  719.  
  720.      C Source Files 
  721.      Overview of the C Language 
  722.      C++ Programs 
  723.  
  724.  
  725. ΓòÉΓòÉΓòÉ <hidden> Source for a Simple C Program ΓòÉΓòÉΓòÉ
  726.  
  727. /************************************************************************
  728. *
  729.  
  730. This is the source code of a simple C program: 
  731.  
  732.                                                                         *
  733. ************************************************************************/
  734.  
  735. #include <stdio.h>              /* standard I/O library header that
  736.                                    contains macros and function declarations
  737.                                    such as printf used below          */
  738.  
  739. #include <math.h>               /* standard math library header that
  740.                                    contains macros and function declarations
  741.                                    such as cos used below             */
  742.  
  743. #define NUM 46.0                /* Preprocessor directive             */
  744.  
  745. double x = 45.0;                /* External variable definitions      */
  746.  
  747. double y = NUM;
  748.  
  749.  
  750. int main(void)                  /* Function definition
  751.                                    for main function                  */
  752. {
  753.    double z;                    /* Local variable definitions         */
  754.    double w;
  755.  
  756.    z = cos(x);                  /* cos is declared in math.h as
  757.                                          double cos(double arg)       */
  758.    w = cos(y);
  759.    printf ("cosine of x is %f\n", z);  /* Print cosine of x           */
  760.    printf ("cosine of y is %f\n", w);  /* Print cosine of y           */
  761.  
  762. return 0;
  763. }
  764.  
  765. /************************************************************************
  766. *
  767.  
  768. This source program defines main and declares a reference to the function cos. 
  769. The program defines the global variables x and y, initializes them, and 
  770. declares two local variables z and w. 
  771.  
  772.                                                                         *
  773. ************************************************************************/
  774.  
  775.  
  776. ΓòÉΓòÉΓòÉ 2.3. C Source Files ΓòÉΓòÉΓòÉ
  777.  
  778. A C source file is a text file that contains all or part of a C source program. 
  779. It can include any of the functions that the program needs. To create an 
  780. executable module, you compile the separate source files individually and then 
  781. link them as one program. With the #include directive, you can combine source 
  782. files into larger source files. 
  783.  
  784. A source file contains any combination of directives, declarations, and 
  785. definitions. You can split items such as function definitions and large data 
  786. structures between text files, but you cannot split them between compiled 
  787. files. Before the source file is compiled, the preprocessor alters the source 
  788. file in a predictable way. The preprocessor directives determine what changes 
  789. are made to the source text. As a result of the preprocessing stage, 
  790. preprocessor directives are completed, macros are expanded, and a source file 
  791. is created containing C statements, completed directives, declarations, and 
  792. definitions. 
  793.  
  794. It is sometimes useful to gather variable definitions into one source file and 
  795. declare references to those variables in any source files that use them. This 
  796. procedure makes definitions easy to find and change, if necessary. You can also 
  797. organize constants and macros into separate files and include them into source 
  798. files as required. 
  799.  
  800. Directives in a source file apply to that source file and its included files 
  801. only. Each directive applies only to the part of the file following the 
  802. directive. 
  803.  
  804. Example of C Source Files 
  805.  
  806. Related Information 
  807.  
  808.      C Source Programs 
  809.      Overview of the C Language 
  810.      Declarations 
  811.      Statements 
  812.      Functions 
  813.      Preprocessor Directives 
  814.      C++ Programs 
  815.  
  816.  
  817. ΓòÉΓòÉΓòÉ <hidden> Example of C Source Files ΓòÉΓòÉΓòÉ
  818.  
  819. /************************************************************************
  820. *
  821.  
  822. The following example is a C program in two source files. The main and max 
  823. functions are in separate files. The program starts running with the main 
  824. function. 
  825.  
  826. Source file 1 
  827.  
  828.                                                                         *
  829. ************************************************************************/
  830.  
  831. /************************************************************************
  832. *  Source file 1 - main function                                        *
  833. ************************************************************************/
  834.  
  835. #define ONE     1
  836. #define TWO     2
  837. #define THREE   3
  838.  
  839. extern int max(int, int);              /* Function declaration */
  840.  
  841. int main(int argc, char * argv[])      /* Function definition  */
  842. {
  843.    int u, w, x, y, z;
  844.  
  845.    u = 5;
  846.    z = 2;
  847.    w = max(u, ONE);
  848.    x = max(w,TWO);
  849.    y = max(x,THREE);
  850.    z = max(y,z);
  851. return 0;
  852. }
  853.  
  854. /************************************************************************
  855. *
  856.  
  857. Source file 2 
  858.  
  859.                                                                         *
  860. ************************************************************************/
  861.  
  862. /************************************************************************
  863. *  Source file 2 - max function                                         *
  864. ************************************************************************/
  865. int max (int a,int b)                 /* Function  definition          */
  866.  
  867. {
  868.    if ( a > b )
  869.        return (a);
  870.    else
  871.        return (b);
  872. }
  873.  
  874. /************************************************************************
  875. *
  876.  
  877. The first source file declares the function max, but does not define it. This 
  878. is an external declaration, a declaration of a function defined in source file 
  879. 2. Four statements in main are function calls of max. 
  880.  
  881. The lines beginning with a number sign (#) are preprocessor directives that 
  882. direct the preprocessor to replace the identifiers ONE, TWO, and THREE with the 
  883. digits 1, 2, and 3. The directives do not apply to the second source file. 
  884.  
  885. The second source file contains the function definition for max, which is 
  886. called four times in main. After you compile the source files, you can link and 
  887. run them as a single program. 
  888.  
  889. /************************************************************************
  890. *
  891.  
  892.  
  893. ΓòÉΓòÉΓòÉ 2.4. Program Execution ΓòÉΓòÉΓòÉ
  894.  
  895. Every program must have a function called main and usually contains other 
  896. functions. 
  897.  
  898. The main function is the starting point for running a program. The statements 
  899. within the main function are executed sequentially. There may be calls to other 
  900. functions. A program usually stops running at the end of the main function, 
  901. although it can stop at other points in the program. 
  902.  
  903. You can make your program more modular by creating separate functions to 
  904. perform a specific task or set of tasks. The main function calls these 
  905. functions to perform the tasks. Whenever a function call is made, the 
  906. statements are executed sequentially starting with the first statement in the 
  907. function. The function returns control to the calling function at the return 
  908. statement or at the end of the function. 
  909.  
  910. You can declare any function to have parameters. When functions are called, 
  911. they receive values for their parameters from the arguments passed by the 
  912. calling functions. You can declare parameters for the main function so you can 
  913. pass values to main from the command line. The command function that starts the 
  914. program can pass such values as described in The main() Function. 
  915.  
  916. Related Information 
  917.  
  918.      Functions 
  919.      The main() Function 
  920.      Calling Functions and Passing Arguments 
  921.      C Source Files 
  922.      Overview of the C Language 
  923.      C++ Programs 
  924.  
  925.  
  926. ΓòÉΓòÉΓòÉ 2.5. Scope in C ΓòÉΓòÉΓòÉ
  927.  
  928. An identifier becomes visible with its declaration. The region where an 
  929. identifier is visible is referred to as the identifier's scope. The four kinds 
  930. of scope are: 
  931.  
  932.      Block 
  933.      Function 
  934.      File 
  935.      Function prototype 
  936.  
  937.  The scope of an identifier is determined by where the identifier is declared. 
  938.  See Identifiers for more information on identifiers. 
  939.  
  940.  In the following example, the variable x, which is defined on line 1, is 
  941.  different from the x defined on line 2. The variable defined on line 2 has 
  942.  function prototype scope and is visible only up to the closing parenthesis of 
  943.  the prototype declaration. Visibility of the variable x defined on line 2 
  944.  resumes after the end of the prototype declaration. 
  945.  
  946.   1   int x = 4;             /* variable x defined with file scope */
  947.   2   long myfunc(int x, long y); /* variable x has function       */
  948.   3                               /* prototype scope               */
  949.   4   int main(void)
  950.   5   {
  951.   6      /* . . . */
  952.   7   }
  953.  
  954.  Functions with static storage class are visible only in the source file they 
  955.  are defined in. All other functions can be globally visible. 
  956.  
  957.  Example of Scope 
  958.  
  959.  Related Information 
  960.  
  961.      Block 
  962.      Labels 
  963.      goto 
  964.      Functions 
  965.      static Storage Class Specifier 
  966.      C Source Files 
  967.      Scope in C++ 
  968.  
  969.  
  970. ΓòÉΓòÉΓòÉ <hidden> Block Scope ΓòÉΓòÉΓòÉ
  971.  
  972. The identifier's declaration is located inside a statement block. A block 
  973. starts with an opening brace ({) and ends with a closing brace (}). An 
  974. identifier with block scope is visible from the point where it is declared to 
  975. the closing brace that ends the block. Block scope is sometimes referred to as 
  976. local scope. 
  977.  
  978. You can nest block visibility. A block nested inside a block can contain 
  979. declarations that redeclare variables declared in the outer block. The new 
  980. declaration of the variable applies to the inner block. The original 
  981. declaration is restored when program control returns to the outer block. A 
  982. variable from the outer block is visible inside inner blocks that do not 
  983. redefine the variable. 
  984.  
  985.  
  986. ΓòÉΓòÉΓòÉ <hidden> Function Scope ΓòÉΓòÉΓòÉ
  987.  
  988. The only type of identifier with function scope is a label name. A label is 
  989. implicitly declared by its appearance in the program text and is visible 
  990. throughout the function that declares it. 
  991.  
  992.  
  993. ΓòÉΓòÉΓòÉ <hidden> File Scope ΓòÉΓòÉΓòÉ
  994.  
  995. The identifier's declaration appears outside of any block. It is visible from 
  996. the point where it is declared to the end of the source file. If source files 
  997. are included by #include preprocessor directives, those files are considered to 
  998. be part of the source and the identifier will be visible to all included files 
  999. that appear after the declaration of the identifier. The identifier can be 
  1000. declared again as a block scope variable. The new declaration replaces the 
  1001. file-scope declaration until the end of the block. 
  1002.  
  1003.  
  1004. ΓòÉΓòÉΓòÉ <hidden> Function Prototype Scope ΓòÉΓòÉΓòÉ
  1005.  
  1006. The identifier's declaration appears within the list of parameters in a 
  1007. function prototype. It is visible from the point where it is declared to the 
  1008. closing parenthesis of the prototype declaration. 
  1009.  
  1010.  
  1011. ΓòÉΓòÉΓòÉ <hidden> Example of Scope ΓòÉΓòÉΓòÉ
  1012.  
  1013. /************************************************************************
  1014. *
  1015.  
  1016. The following program illustrates blocks, nesting, and scope. The example shows 
  1017. two kinds of scope: file and block. The main function prints the values 1, 2, 
  1018. 3, 0, 3, 2, 1 on separate lines. Each instance of i represents a different 
  1019. variable. 
  1020.  
  1021.                                                                         *
  1022. ************************************************************************/
  1023.  
  1024.      #include <stdio.h>
  1025.      int i = 1;             /* i defined at file scope */
  1026.  
  1027.      int main(int argc, char * argv[])
  1028.  ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ  {
  1029.  Γöé
  1030.  Γöé      printf("%d\n", i);        /* Prints 1 */
  1031.  Γöé
  1032.  Γöé ΓöîΓöÇΓöÇΓöÇΓöÇ   {
  1033.  Γöé Γöé       int i = 2, j = 3;       /* i and j defined at
  1034.  Γöé Γöé                       block scope */
  1035.  Γöé Γöé       printf("%d\n%d\n", i, j);   /* Prints 2, 3 */
  1036.  Γöé Γöé
  1037.  Γöé Γöé ΓöîΓöÇΓöÇ     {
  1038.  Γöé Γöé Γöé       int i = 0;         /* i is redefined in a nested block   */
  1039.  Γöé Γöé Γöé                    /* previous definitions of i are hidden */
  1040.  Γöé Γöé Γöé       printf("%d\n%d\n", i, j); /* Prints 0, 3 */
  1041.  Γöé Γöé ΓööΓöÇΓöÇ     }
  1042.  Γöé Γöé
  1043.  Γöé Γöé       printf("%d\n", i);      /* Prints 2 */
  1044.  Γöé Γöé
  1045.  Γöé ΓööΓöÇΓöÇΓöÇΓöÇ   }
  1046.  Γöé
  1047.  Γöé      printf("%d\n", i);        /* Prints 1 */
  1048.  Γöé
  1049.  Γöé      return 0;
  1050.  Γöé
  1051.  ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ  }
  1052.  
  1053.  
  1054. ΓòÉΓòÉΓòÉ 2.6. Program Linkage ΓòÉΓòÉΓòÉ
  1055.  
  1056. The association, or lack of association, between two identical identifiers is 
  1057. known as linkage. The kind of linkage that an identifier has depends on the way 
  1058. that it is declared. 
  1059.  
  1060. A file scope identifier has one of the following kinds of linkage: 
  1061.  
  1062.  Internal        Identical identifiers within a single source file refer to the 
  1063.                  same data object or function. 
  1064.  
  1065.  External        Identical identifiers in separately compiled files refer to 
  1066.                  the same data object or function. 
  1067.  
  1068.  No linkage      Each identical identifier refers to a unique object. 
  1069.  
  1070.  Note:  Program linkage is not the same as a function calling convention, which 
  1071.  is also commonly referred to as linkage. While it is related to program 
  1072.  linkage, a calling convention concerns itself with linkage specifications and 
  1073.  the use of certain keywords. This section discusses only program linkage. 
  1074.  Function calling conventions are described in the IBM VisualAge C++ for OS/2 
  1075.  User's Guide and Reference. 
  1076.  
  1077.  C++ Notes: 
  1078.  
  1079.      Linkage specifications are used to link to non-C++ declarations. 
  1080.  
  1081.      During compilation, the compiler encodes all function names and certain 
  1082.       other identifiers to include type and scope information. This encoding 
  1083.       process is called mangling, and the mangled names are used in the object 
  1084.       files and final executable file. Tools that use these files must use the 
  1085.       mangled names and not the original names used in the source code. 
  1086.  
  1087.       VisualAge C++ provides two methods of converting mangled names to the 
  1088.       original source code names, demangling functions and the CPPFILT utility. 
  1089.       The demangling functions are described in the appendix on Mapping in the 
  1090.       IBM VisualAge C++ for OS/2 User's Guide and Reference and in the 
  1091.       <demangle.h> header file. The CPPFILT utility is described in the online 
  1092.       VisualAge C++ Compiler Utilities Reference. 
  1093.  
  1094.  Related Information 
  1095.  
  1096.      Internal Linkage 
  1097.      External Linkage 
  1098.      No Linkage 
  1099.      Scope in C 
  1100.      Declarations 
  1101.  
  1102.  
  1103. ΓòÉΓòÉΓòÉ <hidden> Internal Linkage ΓòÉΓòÉΓòÉ
  1104.  
  1105. The following kinds of identifiers have internal linkage: 
  1106.  
  1107.      All identifiers with file or block scope that have the keyword static in 
  1108.       their declarations. Functions with static storage class are visible only 
  1109.       in the source file in which you define them. 
  1110.      Functions qualified with _Inline and C++ inline functions. 
  1111.      C++ identifiers declared at file scope with the specifier const and not 
  1112.       explicitly declared extern. In C, const objects have external linkage by 
  1113.       default 
  1114.  
  1115.  A variable that has static storage class can be defined within a block or 
  1116.  outside a function. If the definition occurs within a block, the variable has 
  1117.  internal linkage and is only visible within the block after its declaration is 
  1118.  seen. If the definition occurs outside a function, the variable has internal 
  1119.  linkage and is available from the point where it is defined to the end of the 
  1120.  current source file. 
  1121.  
  1122.  A class that has no static members or noninline member functions, and that has 
  1123.  not been used in the declaration of an object or function or class is local to 
  1124.  its translation unit. 
  1125.  
  1126.  If the declaration of an identifier has the keyword extern and if a previous 
  1127.  declaration of the identifier is visible at file scope, the identifier has the 
  1128.  same linkage as the first declaration. 
  1129.  
  1130.  
  1131. ΓòÉΓòÉΓòÉ <hidden> External Linkage ΓòÉΓòÉΓòÉ
  1132.  
  1133. The following kinds of identifiers have external linkage: 
  1134.  
  1135.      Identifiers with file or block scope that have the keyword extern in 
  1136.       their declarations. 
  1137.  
  1138.       If a previous declaration of the identifier is visible at file scope, the 
  1139.       identifier has the same linkage as the first declaration. For example, a 
  1140.       variable or function that is first declared with the keyword static and 
  1141.       later declared with the keyword extern has internal linkage. 
  1142.      Function identifiers declared without storage-class specifiers. 
  1143.      Object identifiers that have file scope declarations without a 
  1144.       storage-class specified.  Storage is allocated for such object 
  1145.       identifiers. 
  1146.      Static class members and noninline member functions. 
  1147.  
  1148.  Identifiers declared with the keyword extern can be defined in other 
  1149.  translation units. 
  1150.  
  1151.  Related Information 
  1152.  
  1153.      Program Linkage 
  1154.      Internal Linkage 
  1155.      No Linkage 
  1156.      Storage Class Specifiers 
  1157.  
  1158.  
  1159. ΓòÉΓòÉΓòÉ <hidden> No Linkage ΓòÉΓòÉΓòÉ
  1160.  
  1161. The following kinds of identifiers have no linkage: 
  1162.  
  1163.      Identifiers that do not represent an object or a function, including 
  1164.       labels, enumerators, typedef names, type names, and template names 
  1165.      Identifiers that represent a function argument 
  1166.      Identifiers declared inside a block without the keyword extern 
  1167.  
  1168.  Related Information 
  1169.  
  1170.      Program Linkage 
  1171.      Internal Linkage 
  1172.      External Linkage 
  1173.      extern Storage Class Specifier 
  1174.      Identifiers 
  1175.  
  1176.  
  1177. ΓòÉΓòÉΓòÉ 2.7. Storage Duration ΓòÉΓòÉΓòÉ
  1178.  
  1179. Storage duration determines how long storage for an object exists. An object 
  1180. has either static storage duration or automatic storage class depending on its 
  1181. declaration. 
  1182.  
  1183.  Static storage      Is allocated at initialization and remains available until 
  1184.                      the program ends. Objects have static storage duration if 
  1185.                      they: 
  1186.  
  1187.                          Have file scope 
  1188.                          Have external or internal linkage 
  1189.  
  1190.                           OR 
  1191.                          Contain the static storage class specifier. 
  1192.  
  1193.  Automatic storage   Is allocated and removed according to the scope of the 
  1194.                      identifier. Objects have automatic storage duration if 
  1195.                      they are: 
  1196.  
  1197.                          Parameters in a function definition. 
  1198.                          Declared at block scope and do not have any storage 
  1199.                           class specifier. 
  1200.  
  1201.                           OR 
  1202.                          Declared at block scope and have the register or auto 
  1203.                           storage class specifier. 
  1204.  
  1205.                      For example, storage for an object declared at block scope 
  1206.                      is allocated when the identifier is declared and removed 
  1207.                      when the closing brace (}) is reached. 
  1208.  
  1209.  Note:  Objects can also have heap storage duration. Heap objects are declared 
  1210.  at runtime by calling a function such as malloc(). 
  1211.  
  1212.  Related Information 
  1213.  
  1214.      Storage Class Specifiers 
  1215.      Scope in C 
  1216.      Program Linkage 
  1217.  
  1218.  
  1219. ΓòÉΓòÉΓòÉ 2.8. Name Spaces ΓòÉΓòÉΓòÉ
  1220.  
  1221. The compiler sets up name spaces to distinguish among identifiers referring to 
  1222. different kinds of entities. Identical identifiers in different name spaces do 
  1223. not interfere with each other, even if they are in the same scope. 
  1224.  
  1225. You must assign unique names within each name space to avoid conflict. The same 
  1226. identifier can be used to declare different objects as long as each identifier 
  1227. is unique within its name space. The syntactic context of an identifier within 
  1228. a program lets the compiler resolve its name space without ambiguity. 
  1229.  
  1230. Identifiers in the same name space can be redefined within enclosed program 
  1231. blocks as described in Scope in C. 
  1232.  
  1233. Within each of the following four name spaces, the identifiers must be unique. 
  1234.  
  1235.      Tags of these types must be unique within a single scope: 
  1236.  
  1237.         -  Enumerations 
  1238.         -  Structures and unions 
  1239.  
  1240.      Members of structures, unions, and classes must be unique within a single 
  1241.       structure, union or class type. 
  1242.  
  1243.      Statement labels have function scope and must be unique within a 
  1244.       function. 
  1245.  
  1246.      All other ordinary identifiers must be unique within a single scope: 
  1247.  
  1248.         -  Function names 
  1249.         -  Variable names 
  1250.         -  Names of function parameters 
  1251.         -  Enumeration constants 
  1252.         -  typedef names. 
  1253.  
  1254.  Structure tags, structure members, variable names, and statement labels are in 
  1255.  four different name spaces; no conflict occurs among the four items named 
  1256.  student in the following example: 
  1257.  
  1258.   int get_item()
  1259.   {
  1260.      struct student        /*  structure tag        */
  1261.      {
  1262.         char student[20];  /*  structure member     */
  1263.         int section;
  1264.         int id;
  1265.      } student;            /*  structure variable   */
  1266.  
  1267.      goto student;
  1268.      student: ;            /*  null statement label */
  1269.      return (0);
  1270.   }
  1271.  
  1272.  Each occurrence of student is interpreted by its context in the program. For 
  1273.  example, when student appears after the keyword struct, it is a structure tag. 
  1274.  When student appears after either of the member selection operators . or ->, 
  1275.  the name refers to the structure member. When student appears after the goto 
  1276.  statement, control is passed to the null statement label. In other contexts, 
  1277.  the identifier student refers to the structure variable. 
  1278.  
  1279.  Related Information 
  1280.  
  1281.      Scope in C 
  1282.      Identifiers 
  1283.      Type Specifiers 
  1284.      Expressions and Operators 
  1285.  
  1286.  
  1287. ΓòÉΓòÉΓòÉ 2.9. Overview of the C++ Language ΓòÉΓòÉΓòÉ
  1288.  
  1289. C++ is an object-oriented language based on the C programming language. It can 
  1290. be viewed as a superset of C. Almost all of the features and constructs 
  1291. available in C are also available in C++. However, C++ is more than just an 
  1292. extension of C. Its additional features support the programming style known as 
  1293. object-oriented programming. Several features that are already available in C, 
  1294. such as input and output may be implemented differently in C++. In C++ you may 
  1295. use the conventional C input and output routines or you may use object oriented 
  1296. input and output by using the I/O Stream class library. 
  1297.  
  1298. C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories. It was 
  1299. originally based on the definition of the C language stated in The C 
  1300. Programming Language by Brian W. Kernighan and Dennis M. Ritchie. This C 
  1301. language definition is commonly called K&R C. Since then, the International 
  1302. Standards Organization C language definition (referred to here as ISO/ANSI C) 
  1303. has been approved. It specifies many of the features that K&R left unspecified. 
  1304. Some features of ISO/ANSI C have been incorporated into the current definition 
  1305. of C++, and some parts of the ISO/ANSI C definition have been motivated by C++. 
  1306.  
  1307. While there is currently no C++ standard comparable to the ISO/ANSI C 
  1308. definition, an ISO committee is working on such a definition. The draft of the 
  1309. Working Paper for Draft Proposed American National Standard for Information 
  1310. Systems - Programming Language C++, X3J16/92-0091, is the base document for the 
  1311. ongoing standardization of C++. The VisualAge C++ compiler adheres to the 
  1312. version of the ISO/ANSI working paper dated September 17, 1992. 
  1313.  
  1314.  
  1315. ΓòÉΓòÉΓòÉ 2.10. C++ Support for Object-Oriented Programming ΓòÉΓòÉΓòÉ
  1316.  
  1317. Object-oriented programming is based on the concepts of data abstraction, 
  1318. inheritance, and polymorphism. Unlike procedural programming, it concentrates 
  1319. on the data objects that are involved in a problem and how they are 
  1320. manipulated, not on how something is accomplished. Based on the foundation of 
  1321. data abstraction, object-oriented programming allows you to reuse existing code 
  1322. more efficiently and increase your productivity. 
  1323.  
  1324.      Data Abstraction 
  1325.      Encapsulation 
  1326.      Inheritance 
  1327.      Dynamic Binding and Polymorphism 
  1328.      Other Features of C++ 
  1329.  
  1330.  Related Information 
  1331.  
  1332.      C++ Classes 
  1333.      Member Access 
  1334.      Inheritance Overview 
  1335.      Derivation 
  1336.      Overview of the C++ Language 
  1337.  
  1338.  
  1339. ΓòÉΓòÉΓòÉ <hidden> Data Abstraction ΓòÉΓòÉΓòÉ
  1340.  
  1341. Data abstraction provides the foundation for object-oriented programming. In 
  1342. addition to providing fundamental data types, object-oriented programming 
  1343. languages allow you to define your own data types, called user-defined or 
  1344. abstract data types. In the C programming language, related data items can be 
  1345. organized into structures. These structures can then be manipulated as units of 
  1346. data. In addition to providing this type of data structure, object-oriented 
  1347. programming languages allow you to implement a set of operations that can be 
  1348. applied to the data elements. The data elements and the set of operations 
  1349. applicable to the data elements together form the abstract data type. 
  1350.  
  1351. To support data abstraction, a programming language must provide a construct 
  1352. that can be used to encapsulate the data elements and operations that make up 
  1353. an abstract data type. In C++, this construct is called a class. An instance of 
  1354. a class is called an object. Classes are composed of data elements called data 
  1355. members and member functions that define the operations that can be carried out 
  1356. on the data members. 
  1357.  
  1358.  
  1359. ΓòÉΓòÉΓòÉ <hidden> Encapsulation ΓòÉΓòÉΓòÉ
  1360.  
  1361. Another key feature of object-oriented programming is encapsulation. 
  1362. Encapsulation means a class can hide the details of: 
  1363.  
  1364.      The representation of its data members 
  1365.      The implementation of the operations that can be performed on these data 
  1366.       members 
  1367.  
  1368.  Application programs manipulate objects of a class using a clearly defined 
  1369.  interface. As long as this interface does not change, you can change the 
  1370.  implementation of a class without having to change the application programs 
  1371.  that use the class. Encapsulation provides the following advantages: 
  1372.  
  1373.      Users of a class do not have to deal with unnecessary implementation 
  1374.       details. 
  1375.      Programs are easier to debug and maintain. 
  1376.      Permitted alterations are clearly specified. 
  1377.  
  1378.  In C++, encapsulation is accomplished by specifying the level of access for 
  1379.  each member of a class. Both the data members and member functions of a class 
  1380.  can be declared public, protected, or private depending on the kind of access 
  1381.  required. 
  1382.  
  1383.  Note:  C++ encapsulation is not a true security mechanism. It is possible to 
  1384.  circumvent the class access controls that make encapsulation possible. The 
  1385.  language is not designed to prevent such misuse. 
  1386.  
  1387.  
  1388. ΓòÉΓòÉΓòÉ <hidden> Inheritance ΓòÉΓòÉΓòÉ
  1389.  
  1390. Inheritance lets you reuse existing code and data structures in new 
  1391. applications. In C++, inheritance is implemented through class derivation. You 
  1392. can extend a library of existing classes by adding data elements and operations 
  1393. to existing classes to form derived classes. A derived class has all the 
  1394. members of its parent or base class, as well as extensions that can provide 
  1395. additional features. When you create a new derived class, you only have to 
  1396. write the code for the additional features. The existing features of the base 
  1397. class are already available. 
  1398.  
  1399. A base class can have more than one class derived from it. In addition, a 
  1400. derived class can serve as a base class for other derived classes in a 
  1401. hierarchy. Typically, a derived class is more specialized than its base class. 
  1402.  
  1403. A derived class can inherit data members and member functions from more than 
  1404. one base class. Inheritance from more than one base class is called multiple 
  1405. inheritance. 
  1406.  
  1407.  
  1408. ΓòÉΓòÉΓòÉ <hidden> Dynamic Binding and Polymorphism ΓòÉΓòÉΓòÉ
  1409.  
  1410. Another key concept that allows you to write generic programs is dynamic or 
  1411. late binding. Dynamic binding allows a member function call to be resolved at 
  1412. run time, according to the run-time type of an object reference. This permits 
  1413. each user-defined class in an inheritance hierarchy to have a different 
  1414. implementation of a particular function. Application programs can then apply 
  1415. that function to an object without needing to know the specifics of the class 
  1416. that the object belongs to. 
  1417.  
  1418. In C++, dynamic binding hides the differences between a group of classes in an 
  1419. inheritance hierarchy from the application program. At run time, the system 
  1420. determines the specific class of the object and invokes the appropriate 
  1421. function implementation for that class. 
  1422.  
  1423. Dynamic binding is distinguished from static or compile-time binding, which 
  1424. involves compile-time member function resolution according to the static type 
  1425. of an object reference. 
  1426.  
  1427.  
  1428. ΓòÉΓòÉΓòÉ <hidden> Other Features of C++ ΓòÉΓòÉΓòÉ
  1429.  
  1430. C++ provides several other powerful extensions to the C programming language. 
  1431. Among these are: 
  1432.  
  1433.      Constructors and destructors, which are used to create, initialize and 
  1434.       destroy class objects 
  1435.      Overloaded functions and operators, which lets you extend the operations 
  1436.       a function or operator can perform on different data types 
  1437.      Inline functions, which make programs more efficient 
  1438.      References, which allow a function to modify its arguments in the calling 
  1439.       function 
  1440.      Template functions and classes, which allow the definition of generic 
  1441.       classes and functions 
  1442.      Object-Oriented Exception handling, which provides transfer of control 
  1443.       and recovery from errors and other exceptional circumstances 
  1444.  
  1445.  
  1446. ΓòÉΓòÉΓòÉ 2.11. C++ Programs ΓòÉΓòÉΓòÉ
  1447.  
  1448. C++ programs contain many of the same programming statements and constructs as 
  1449. C programs: 
  1450.  
  1451.      C++ has the same fundamental types (built-in) data types as C, as well as 
  1452.       some types that are not built-in to C. 
  1453.      Like ISO/ANSI C, C++ allows you to declare new type names by using the 
  1454.       typedef construct. These new type names are not new types. 
  1455.      In general, the scope and storage class rules for C also apply in C++. 
  1456.      C and C++ have the same set of arithmetic and logical operators. 
  1457.  
  1458.  A C++ name can identify any of the following: 
  1459.  
  1460.      an object 
  1461.      a function 
  1462.      a set of functions 
  1463.      an enumerator 
  1464.      a type 
  1465.      a class member 
  1466.      a template 
  1467.      a value 
  1468.      a label 
  1469.  
  1470.  A declaration introduces a name into a program and can define an area of 
  1471.  storage associated with that name. 
  1472.  
  1473.  An expression can be evaluated and is composed of operations and operands. An 
  1474.  expression ending with a ; (semicolon) is called a statement. A statement is 
  1475.  the smallest independent computational unit. Functions are composed of groups 
  1476.  of one or more statements. 
  1477.  
  1478.  A C++ program is composed of one or more functions. These functions can all 
  1479.  reside in a single file or can be placed in different files that are linked to 
  1480.  each other. In C++, a program must have one and only one non-member function 
  1481.  called main(). 
  1482.  
  1483.  Source for a Simple C++ Program 
  1484.  
  1485.  Related Information 
  1486.  
  1487.      C++ Support for Object-Oriented Programming 
  1488.      Overview of the C Language 
  1489.      C Source Files 
  1490.      C Source Programs 
  1491.  
  1492.  
  1493. ΓòÉΓòÉΓòÉ <hidden> Source for a Simple C++ Program ΓòÉΓòÉΓòÉ
  1494.  
  1495. /************************************************************************
  1496. *
  1497.  
  1498. The following is a simple C++ program containing declarations, expressions, 
  1499. statements, and two functions: 
  1500.  
  1501.                                                                         *
  1502. ************************************************************************/
  1503.  
  1504. /**
  1505.  ** A simple C++ program containing declarations,
  1506.  ** expressions, statements, and two functions:
  1507.  **/
  1508.  
  1509. #include <math.h>                         // contains definition of abs()
  1510. double multiplier, common_ratio;          // variable declarations
  1511. double geo_series(double a, double r)     // function definition
  1512. {
  1513.       if (r == 1)                         // if statement
  1514.             return -1.0;                  // return statement
  1515.       else if (abs(r) < 1.0)              // else if statement
  1516.             return (a / (1 - r));         // statement containing
  1517.                                           // expression
  1518.       else return -2.0;
  1519. }
  1520. void main()                // program execution begins here
  1521. {
  1522.       double sum;          // variable declaration
  1523.       multiplier = 2.2;    // initialization of external variable
  1524.       common_ratio = 3.1;  // initialization of external variable
  1525.       sum = geo_series(multiplier, common_ratio); // function call
  1526.       // ..
  1527. }
  1528.  
  1529.  
  1530. ΓòÉΓòÉΓòÉ 2.12. Scope in C++ ΓòÉΓòÉΓòÉ
  1531.  
  1532. The area of the code where an identifier is visible is referred to as the scope 
  1533. of the identifier. The four kinds of scope are: 
  1534.  
  1535.      Local 
  1536.      Function 
  1537.      File 
  1538.      Class 
  1539.  
  1540.  The scope of a name is determined by the location of the name's declaration. 
  1541.  
  1542.  A type name first declared in a function return type has file scope. A type 
  1543.  name first declared in a function argument list has local scope. 
  1544.  
  1545.  A function name that is first declared as a friend of a class is in the first 
  1546.  nonclass scope that encloses the class. 
  1547.  
  1548.  If the friend function is a member of another class, it has the scope of that 
  1549.  class. The scope of a class name first declared as a friend of a class is the 
  1550.  first nonclass enclosing scope. 
  1551.  
  1552.  Related Information 
  1553.  
  1554.      Scope in C 
  1555.      Friend Scope 
  1556.      Scope of Class Names 
  1557.      Member Scope 
  1558.  
  1559.  
  1560. ΓòÉΓòÉΓòÉ <hidden> Local Scope ΓòÉΓòÉΓòÉ
  1561.  
  1562. A name has local scope if it is declared in a block. A name with local scope 
  1563. can be used in that block and in blocks enclosed within that block, but the 
  1564. name must be declared before it is used. When the block is exited, the names 
  1565. declared in the block are no longer available. 
  1566.  
  1567. Formal argument names for a function have the scope of the outermost block of 
  1568. that function. 
  1569.  
  1570. If a local variable is a class object with a destructor, the destructor is 
  1571. called when control passes out of the block in which the class object was 
  1572. constructed. 
  1573.  
  1574. When one block is nested inside another, the variables from the outer block are 
  1575. usually visible in the nested block. However, if an outer block variable is 
  1576. redefined in a nested block, the new declaration is in effect in the inner 
  1577. block. The original declaration is restored when program control returns to the 
  1578. outer block. This is called block visibility. 
  1579.  
  1580.  
  1581. ΓòÉΓòÉΓòÉ <hidden> Function Scope ΓòÉΓòÉΓòÉ
  1582.  
  1583. The only type of identifier with function scope is a label name. A label is 
  1584. implicitly declared by its appearance in the program text and is visible 
  1585. throughout the function that declares it. 
  1586.  
  1587.  
  1588. ΓòÉΓòÉΓòÉ <hidden> File Scope ΓòÉΓòÉΓòÉ
  1589.  
  1590. A name has file scope if its declaration appears outside of all blocks and 
  1591. classes. A name with file scope is visible from the point where it is declared 
  1592. to the end of the source file. The name is also made accessible for the 
  1593. initialization of global variables. If a name is declared extern, it is also 
  1594. visible, at linkage time, in all object files being linked. Global names are 
  1595. names declared with file scope. 
  1596.  
  1597.  
  1598. ΓòÉΓòÉΓòÉ <hidden> Class Scope ΓòÉΓòÉΓòÉ
  1599.  
  1600. The name of a class member has class scope and can only be used in the 
  1601. following cases: 
  1602.  
  1603.      In a  member function of that class 
  1604.      In a member function of a class derived from that class 
  1605.      After the . (dot) operator applied to an instance of that class 
  1606.      After the . (dot) operator applied to an instance of a class derived from 
  1607.       that class 
  1608.      After the -> (arrow) operator applied to a pointer to an instance of that 
  1609.       class 
  1610.      After the -> (arrow) operator applied to a pointer to an instance of a 
  1611.       class derived from that class 
  1612.      After the :: (scope resolution) operator applied to the name of a class 
  1613.      After the :: (scope resolution) operator applied to a class derived from 
  1614.       that class. 
  1615.  
  1616.  For more information on class scope, see Scope of Class Names. 
  1617.  
  1618.  
  1619. ΓòÉΓòÉΓòÉ 2.13. Simple C++ Input and Output ΓòÉΓòÉΓòÉ
  1620.  
  1621. Like C, the C++ language has no built-in input and output facilities. Instead, 
  1622. input and output facilities for C++ are provided by the I/O Stream Library. For 
  1623. compatibility with C, C++ also supports the standard I/O functions of C. The 
  1624. I/O Stream Library supports a set of I/O operations, written in the C++ 
  1625. language, for the built-in types. You can extend these facilities to provide 
  1626. input and output functions for user-defined data types. For a complete 
  1627. description of the I/O Stream Library, see the Standard Class Library Guide. 
  1628.  
  1629. There are four predefined I/O stream objects that you can use to perform 
  1630. standard I/O: 
  1631.  
  1632.      cout 
  1633.      cin 
  1634.      cerr 
  1635.      clog 
  1636.  
  1637.  You can use these in conjunction with the overloaded << (insertion or output) 
  1638.  and >> (extraction or input) operators. To use these streams and operators, 
  1639.  you must include the header file iostream.h. The following example prints 
  1640.  Hello World! to standard output: 
  1641.  
  1642.   /**
  1643.    ** Hello World
  1644.    **/
  1645.  
  1646.   #include <iostream.h>
  1647.   void main()
  1648.   {
  1649.         cout << "Hello World!" << endl;
  1650.   }
  1651.  
  1652.  The manipulator endl acts as a newline character, causing any output following 
  1653.  it to be directed to the next line. Because it also causes any buffered output 
  1654.  to be flushed, endl is preferred over \n to end lines. 
  1655.  
  1656.  Related Information 
  1657.  
  1658.      Overview of the C++ Language 
  1659.      Overview of the C Language 
  1660.      Overloading Operators 
  1661.  
  1662.  
  1663. ΓòÉΓòÉΓòÉ <hidden> cout ΓòÉΓòÉΓòÉ
  1664.  
  1665. The cout stream is associated with standard output. You can use the output 
  1666. operator in conjunction with cout to direct a value to standard output. 
  1667. Successive output operators are concatenated when applied to cout. The 
  1668. following example prints out three strings in a row and produces the same 
  1669. result as the previous example, printing Hello World! to standard output. 
  1670.  
  1671. /**
  1672.  ** Another Hello World, illustrating concatenation with cout
  1673.  **/
  1674.  
  1675. #include <iostream.h>
  1676. void main()
  1677. {
  1678.       cout << "Hello "
  1679.            << "World"
  1680.            << "!"
  1681.            << endl;
  1682. }
  1683.  
  1684. Output operators are defined to accept arguments of any of the fundamental data 
  1685. types, as well as pointers, references, and array types. You can also overload 
  1686. the output operator to define output for your own class types. 
  1687.  
  1688.  
  1689. ΓòÉΓòÉΓòÉ <hidden> cerr and clog ΓòÉΓòÉΓòÉ
  1690.  
  1691. The cerr and clog streams direct output to standard error. cerr provides 
  1692. unbuffered output, while clog provides buffered output. The following example 
  1693. checks for a division by zero condition. If one occurs, a message is sent to 
  1694. standard error. 
  1695.  
  1696. /**
  1697.  ** Check for a division by zero condition.
  1698.  ** If one occurs, a message is sent to standard error.
  1699.  **/
  1700.  
  1701. #include <iostream.h>
  1702. void main()
  1703. {
  1704.       double val1, val2;
  1705.       cout << "Divide Two Values" << endl;
  1706.       cout << "Enter two numeric values: " << endl;
  1707.       cin >> val1 >> val2;
  1708.       if (val2 == 0 )
  1709.       {
  1710.              cerr << "The second value must be non-zero" << endl;
  1711.       } else
  1712.              cout << "The answer is " << val1 / val2 << endl;
  1713. }
  1714.  
  1715.  
  1716. ΓòÉΓòÉΓòÉ <hidden> cin ΓòÉΓòÉΓòÉ
  1717.  
  1718. The cin class object is associated with standard input. You can use the input 
  1719. operator in conjunction with cin to read a value from standard input. By 
  1720. default, white space (including blanks, tabs, and new lines) is disregarded by 
  1721. the input operator. For example: 
  1722.  
  1723. /**
  1724.  ** This example illustrates the cin operator
  1725.  **/
  1726.  
  1727. #include <iostream.h>
  1728. main()
  1729. {
  1730.       double val1, val2;
  1731.       cout << "Enter two numeric values:" << endl;
  1732.       cin >> val1 >> val2;
  1733.       cout   << "The first value entered is " << val1
  1734.              << " and the second value is "
  1735.              << val2 << "." << endl;
  1736. }
  1737.  
  1738. If the values 1.2 and 3.4 are entered through standard input, the above program 
  1739. prints the following to standard output: 
  1740.  
  1741. Enter two numeric values:
  1742. 1.2
  1743. 3.4
  1744. The first value entered is 1.2 and the second value is 3.4.
  1745.  
  1746. Any white space entered between the two numeric values is disregarded by the 
  1747. input operator. 
  1748.  
  1749. The input operator is defined to accept arguments of any of the fundamental 
  1750. data types, as well as pointers, references and array types. You can also 
  1751. overload the input operator to define input for your own class types. 
  1752.  
  1753.  
  1754. ΓòÉΓòÉΓòÉ 2.14. Linkage Specifications - Linking to non-C++ Programs ΓòÉΓòÉΓòÉ
  1755.  
  1756. You can link C++ object modules to object modules produced using other source 
  1757. languages such as C and Fortran by using a linkage specification. 
  1758.  
  1759. The syntax is: 
  1760.  
  1761. >>ΓöÇΓöÇexternΓöÇΓöÇstring-literalΓöÇΓöÇΓö¼ΓöÇdeclarationΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  1762.               Γöé   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé
  1763.               Γöé           Γöé   Γöé
  1764.               ΓööΓöÇ{ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ}ΓöÇΓöÿ
  1765.                  ΓööΓöÇdeclarationΓöÇΓöÿ
  1766.  
  1767. The string-literal is used to specify the linkage associated with a particular 
  1768. function. For example: 
  1769.  
  1770. /**
  1771.  ** This example illustrates linkage specifications
  1772.  **/
  1773.  
  1774. extern "C" int printf(const char*,...);
  1775. void main()
  1776. {
  1777.       printf("hello\n");
  1778. }
  1779.  
  1780. Here the string-literal, "C", tells the compiler that the routine 
  1781. printf(char*,...) has C linkage. Note that string literals used in linkage 
  1782. specifications are not case sensitive. 
  1783.  
  1784. Some valid values for string-literal are: 
  1785.  
  1786.  "C++"               Default 
  1787.  
  1788.  "C"                 C type linkage 
  1789.  
  1790.  If the value of string-literal is not recognized, C type linkage is used. For 
  1791.  more information on linkage specifications, see Chapter 13, "Calling 
  1792.  Conventions" in the IBM VisualAge C++ for OS/2 User's Guide and Reference. 
  1793.  
  1794.  Related Information 
  1795.  
  1796.      Overview of the C++ Language 
  1797.      Overview of the C Language 
  1798.  
  1799.  
  1800. ΓòÉΓòÉΓòÉ 3. Lexical Elements of C and C++ ΓòÉΓòÉΓòÉ
  1801.  
  1802. This section describes the following lexical elements of C and C++: 
  1803.  
  1804.      Tokens 
  1805.      Source Program Character Set 
  1806.      Trigraph Sequences 
  1807.      Escape Sequences 
  1808.      Comments 
  1809.      Identifiers 
  1810.      Keywords 
  1811.      Constants 
  1812.  
  1813.  
  1814. ΓòÉΓòÉΓòÉ 3.1. Tokens ΓòÉΓòÉΓòÉ
  1815.  
  1816. Source code is treated during preprocessing and compilation as a sequence of 
  1817. tokens. There are five different types of tokens: 
  1818.  
  1819.      Identifiers 
  1820.      Keywords 
  1821.      Literals 
  1822.      Operators 
  1823.      Other separators 
  1824.  
  1825.  Adjacent identifiers, keywords and literals must be separated with white 
  1826.  space. Other tokens should be separated by white space to make the source code 
  1827.  more readable. White space includes blanks, horizontal and vertical tabs, new 
  1828.  lines, form feeds and comments. 
  1829.  
  1830.  
  1831. ΓòÉΓòÉΓòÉ 3.2. Source Program Character Set ΓòÉΓòÉΓòÉ
  1832.  
  1833. The following lists the basic character set that must be available at both 
  1834. compile and run time: 
  1835.  
  1836.      The uppercase and lowercase letters of the English alphabet 
  1837.      The decimal digits 0 through 9 
  1838.      The following graphic characters: 
  1839.  
  1840.                ! " # % & ' ( ) * + , - . / :
  1841.                ; < = > ? [ \ ] _ { } ~
  1842.  
  1843.      The caret (^) character 
  1844.      The split vertical bar (Γûî) character 
  1845.      The space character 
  1846.      The control characters representing new-line, horizontal tab, vertical 
  1847.       tab, and form feed, and end of string (NULL character). 
  1848.  
  1849.  where the # (number sign) character is used for preprocessing only, and the _ 
  1850.  (underscore) character is treated as a normal letter. 
  1851.  
  1852.  In extended and compatible language levels, the compiler allows the $ (dollar 
  1853.  sign) character in C++ identifiers to facilitate calls between different 
  1854.  languages and porting code. In ansi language level, the $ (dollar sign) 
  1855.  character is not permitted in C++ identifiers. The default language level for 
  1856.  the compiler is extended. Language level is set with the #pragma langlvl or 
  1857.  the /S option. 
  1858.  
  1859.  For the keyboards that do not support the entire character set, you can use 
  1860.  trigraphs as alternative symbols to represent some characters. 
  1861.  
  1862.  Related Information 
  1863.  
  1864.      Trigraph Sequences 
  1865.      /Ss option 
  1866.  
  1867.  
  1868. ΓòÉΓòÉΓòÉ <hidden> Trigraph Sequences ΓòÉΓòÉΓòÉ
  1869.  
  1870. Some characters from the C character set are not available in all environments. 
  1871. You can enter these characters into a C source program using a sequence of 
  1872. three characters called a trigraph. The trigraph sequences are: 
  1873.  
  1874. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  1875. Γöé "??="   Γöé "#"      Γöé pound sign      Γöé
  1876. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1877. Γöé "??("   Γöé "["      Γöé left bracket     Γöé
  1878. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1879. Γöé "??)"   Γöé "]"      Γöé right bracket     Γöé
  1880. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1881. Γöé "??<"   Γöé "{"      Γöé left brace      Γöé
  1882. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1883. Γöé "??>"   Γöé "}"      Γöé right brace      Γöé
  1884. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1885. Γöé "??/"   Γöé "\"      Γöé backslash       Γöé
  1886. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1887. Γöé "??'"   Γöé "^"      Γöé caret         Γöé
  1888. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1889. Γöé "??!"   Γöé "|"      Γöé pipe         Γöé
  1890. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  1891. Γöé "??-"   Γöé "~"      Γöé tilde         Γöé
  1892. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  1893.  
  1894. The preprocessor replaces trigraph sequences with the corresponding 
  1895. single-character representation. 
  1896.  
  1897. Related Information 
  1898.  
  1899.      Source Program Character Set 
  1900.  
  1901.  
  1902. ΓòÉΓòÉΓòÉ 3.3. Comments ΓòÉΓòÉΓòÉ
  1903.  
  1904. Comments begin with the /* characters, end with the */ characters, and can span 
  1905. more than one line. You can put comments anywhere the language allows white 
  1906. space. 
  1907.  
  1908. Comments are replaced during preprocessing by a single space character. 
  1909.  
  1910. Multibyte characters can also be included within a comment. 
  1911.  
  1912. Note:  The /* or */ characters found in a character constant or string literal 
  1913. do not start or end comments. 
  1914.  
  1915. In the following program, line 6 is a comment: 
  1916.  
  1917.  1   #include <stdio.h>
  1918.  2
  1919.  3   int main(void)
  1920.  4   {
  1921.  5      printf("This program has a comment.\n");
  1922.  6      /* printf("This is a comment line and will not print.\n"); */
  1923.  7   return 0;
  1924.  8   }
  1925.  
  1926. Because the comment on line 6 is equivalent to a space, the output of this 
  1927. program is: 
  1928.  
  1929. This program has a comment.
  1930.  
  1931. Because the comment delimiters are inside a string literal, line 5 in the 
  1932. following program is not a comment. 
  1933.  
  1934.  1   #include <stdio.h>
  1935.  2
  1936.  3   int main(void)
  1937.  4   {
  1938.  5      printf("This program does not have \
  1939.  6   /* NOT A COMMENT */ a comment.\n");
  1940.  7   return 0;
  1941.  8   }
  1942.  
  1943. The output of the program is: 
  1944.  
  1945. This program does not have /* NOT A COMMENT */ a comment.
  1946.  
  1947. You cannot nest comments. Each comment ends at the first occurrence of */. 
  1948.  
  1949. Related Information 
  1950.  
  1951.      C++ Comments 
  1952.      /Ss option 
  1953.  
  1954.  
  1955. ΓòÉΓòÉΓòÉ <hidden> C++ Comments ΓòÉΓòÉΓòÉ
  1956.  
  1957. If the /Ss compiler option is in effect when you compile a C program, double 
  1958. slashes (//) also specify the beginning of a comment. The comment ends at the 
  1959. next new line character. C++ also permits double-slash comments as part of the 
  1960. language definition. 
  1961.  
  1962. A C++ comment can span more than one physical source line if it is joined into 
  1963. one logical source line with line-continuation (\) characters. The backslash 
  1964. character can also be represented by a trigraph. 
  1965.  
  1966.  
  1967. ΓòÉΓòÉΓòÉ 3.4. Identifiers ΓòÉΓòÉΓòÉ
  1968.  
  1969. Identifiers consist of an arbitrary number of letters or digits. They provide 
  1970. names for the following language elements: 
  1971.  
  1972.      Functions 
  1973.      Data objects 
  1974.      Labels 
  1975.      Tags 
  1976.      Parameters 
  1977.      Macros 
  1978.      Typedefs 
  1979.      Structure and union members. 
  1980.  
  1981.  
  1982. ΓòÉΓòÉΓòÉ 3.4.1. Significant Characters in Identifiers ΓòÉΓòÉΓòÉ
  1983.  
  1984. There is no limit for the number of characters in an identifier. However, only 
  1985. the first several characters of identifiers may be significant. The following 
  1986. table shows the number of significant characters for several kinds of 
  1987. identifiers. 
  1988.  
  1989.  Identifier                  Maximum Number of Significant Characters 
  1990.  Static data objects         255 characters 
  1991.  Static function names       255 characters 
  1992.  External data objects       255 characters 
  1993.  External function names     255 characters 
  1994.  
  1995.  
  1996. ΓòÉΓòÉΓòÉ 3.4.2. Case Sensitivity and Special Characters in Identifiers ΓòÉΓòÉΓòÉ
  1997.  
  1998. The compiler distinguishes between uppercase and lowercase letters in 
  1999. identifiers. For example, PROFIT and profit represent different data objects. 
  2000.  
  2001. Note:  By default, the VisualAge C++ linker linker is case sensitive. To force 
  2002. it to be case insensitive, use the /IGNORECASE linker option, though you 
  2003. typically should note need to use this option. For complete portability, never 
  2004. use different case representations to refer to the same object. 
  2005.  
  2006. Avoid creating identifiers that begin with an underscore (_) for function names 
  2007. and variable names. 
  2008.  
  2009. The first character in an identifier must be a letter. The _ (underscore) 
  2010. character is considered a letter; however, identifiers beginning with an 
  2011. underscore are reserved by the compiler for identifiers at file scope. 
  2012.  
  2013. Identifiers that begin with two underscores or an underscore followed by a 
  2014. capital letter, are reserved in all contexts. 
  2015.  
  2016. Although the names of system calls and library functions are not reserved words 
  2017. if you do not include the appropriate headers, avoid using them as identifiers. 
  2018. Duplication of a predefined name can lead to confusion for the maintainers of 
  2019. your code and can cause errors at link time or run time. If you include a 
  2020. library in a program, be aware of the function names in that library to avoid 
  2021. name duplications. 
  2022.  
  2023. You should always include the appropriate headers when using standard library 
  2024. functions. At the extended and compatible language levels, C++ identifiers can 
  2025. contain the $ character. 
  2026.  
  2027. Related Information 
  2028.  
  2029.      Name Spaces 
  2030.      Overview of the C Language 
  2031.      File Inclusion (#include) 
  2032.  
  2033.  
  2034. ΓòÉΓòÉΓòÉ 3.4.3. Keywords ΓòÉΓòÉΓòÉ
  2035.  
  2036. Keywords are identifiers reserved by the language for special use. Although you 
  2037. can use them for preprocessor macro names, it is poor programming style. Only 
  2038. the exact spelling of keywords is reserved. For example, auto is reserved but 
  2039. AUTO is not. The following lists the keywords common to both the C and C++ 
  2040. languages. These keywords are also included in the ISO/ANSI C language 
  2041. definition: 
  2042.  
  2043. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2044. Γöé Table 1. Keywords Common to C and C++                     Γöé
  2045. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2046. Γöé auto        Γöé double       Γöé int        Γöé struct      Γöé
  2047. Γöé break       Γöé else        Γöé long        Γöé switch      Γöé
  2048. Γöé case        Γöé enum        Γöé register      Γöé typedef      Γöé
  2049. Γöé char        Γöé extern       Γöé return       Γöé union       Γöé
  2050. Γöé const       Γöé float       Γöé short       Γöé unsigned     Γöé
  2051. Γöé continue      Γöé for        Γöé signed       Γöé void       Γöé
  2052. Γöé default      Γöé goto        Γöé sizeof       Γöé volatile     Γöé
  2053. Γöé do         Γöé if         Γöé static       Γöé while       Γöé
  2054. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2055.  
  2056. The C++ language also reserves the following keywords: 
  2057.  
  2058. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2059. Γöé Table 2. C++ Keywords                             Γöé
  2060. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2061. Γöé asm        Γöé inline       Γöé protected     Γöé throw       Γöé
  2062. Γöé catch       Γöé new        Γöé public       Γöé try        Γöé
  2063. Γöé class       Γöé operator      Γöé template      Γöé virtual      Γöé
  2064. Γöé delete       Γöé private      Γöé this        Γöé wchar_t      Γöé
  2065. Γöé friend       Γöé          Γöé          Γöé          Γöé
  2066. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2067.  
  2068. The VisualAge C++ compiler also reserves the following keywords. They are 
  2069. considered to be VisualAge C++ extensions to the existing language standards. 
  2070. Except for the keywords _Far32 and _Inline, the following keywords are 
  2071. supported in both C and C++. 
  2072.  
  2073. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2074. Γöé Table 3. Additional VisualAge C++ Keywords                  Γöé
  2075. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2076. Γöé _Cdecl       Γöé _Far32       Γöé _Pascal      Γöé __stdcall     Γöé
  2077. Γöé __cdecl      Γöé _Fastcall     Γöé _Packed      Γöé _System      Γöé
  2078. Γöé _Export      Γöé _Inline      Γöé _Seg16       Γöé __unaligned    Γöé
  2079. Γöé _Far16       Γöé _Optlink      Γöé          Γöé          Γöé
  2080. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2081.  
  2082. The keyword _Packed is reserved only for C programs. _Packed is an extension to 
  2083. the ISO/ANSI C standard, and is not supported by C++. 
  2084.  
  2085.  
  2086. ΓòÉΓòÉΓòÉ 3.5. Constants ΓòÉΓòÉΓòÉ
  2087.  
  2088. A constant does not change its value while the program is running. The value of 
  2089. any constant must be in the range of representable values for its type. 
  2090.  
  2091. The C language contains the following types of constants (also called 
  2092. literals): 
  2093.  
  2094.      Integer Constants 
  2095.      Floating-Point Constants 
  2096.      Character Constants 
  2097.      String Literals 
  2098.  
  2099.  Enumeration constants, which belong to the lexical class of identifiers, are 
  2100.  discussed in Enumerations. For more information on data types, see Type 
  2101.  Specifiers. 
  2102.  
  2103.  
  2104. ΓòÉΓòÉΓòÉ 3.5.1. Integer Constants ΓòÉΓòÉΓòÉ
  2105.  
  2106. Integer constants can represent decimal, octal, or hexadecimal values. The data 
  2107. type of an integer constant is determined by the form, value, and suffix of the 
  2108. constant. The following lists the integer constants and shows the possible data 
  2109. types for each constant. The smallest data type can represent the constant 
  2110. value is used to store the constant. 
  2111.  
  2112.  Constant                    Data Type 
  2113.  unsuffixed decimal          int, long int, unsigned long int 
  2114.  unsuffixed octal            int, unsigned int, long int, unsigned long int 
  2115.  unsuffixed hexadecimal      int, unsigned int, long int, unsigned long int 
  2116.  suffixed by u or U          unsigned int, unsigned long int 
  2117.  suffixed by l or L          long int, unsigned long int 
  2118.  suffixed by both u or U, and l or L unsigned long int 
  2119.  
  2120.  A plus (+) or minus (-) symbol can precede the constant. It is treated as a 
  2121.  unary operator rather than as part of the constant value. 
  2122.  
  2123.  Related Information 
  2124.  
  2125.      Decimal Constants 
  2126.      Octal Constants 
  2127.      Hexadecimal Constants 
  2128.      Integer Variables 
  2129.  
  2130.  
  2131. ΓòÉΓòÉΓòÉ 3.5.1.1. Decimal Constants ΓòÉΓòÉΓòÉ
  2132.  
  2133. A decimal constant contains any of the digits 0 through 9. The first digit 
  2134. cannot be 0. Integer constants beginning with the digit 0 are interpreted as an 
  2135. octal constant, rather than as a decimal constant. 
  2136.  
  2137. Related Information 
  2138.  
  2139.      Integer Constants 
  2140.      Octal Constants 
  2141.      Hexadecimal Constants 
  2142.      Integer Variables 
  2143.  
  2144.  
  2145. ΓòÉΓòÉΓòÉ 3.5.1.2. Hexadecimal Constants ΓòÉΓòÉΓòÉ
  2146.  
  2147. A hexadecimal constant begins with the 0 digit followed by either an x or X, 
  2148. followed by any combination of the digits 0 through 9 and the letters a through 
  2149. f or A through F. The letters A (or a) through F (or f) represent the values 10 
  2150. through 15, respectively. 
  2151.  
  2152. The following are examples of hexadecimal constants: 
  2153.  
  2154. 0x3b24
  2155. 0XF96
  2156. 0x21
  2157. 0x3AA
  2158. 0X29b
  2159. 0X4bD
  2160.  
  2161. Related Information 
  2162.  
  2163.      Integer Constants 
  2164.      Decimal Constants 
  2165.      Octal Constants 
  2166.      Integer Variables 
  2167.  
  2168.  
  2169. ΓòÉΓòÉΓòÉ 3.5.1.3. Octal Constants ΓòÉΓòÉΓòÉ
  2170.  
  2171. An octal constant begins with the digit 0 and contains any of the digits 0 
  2172. through 7. 
  2173.  
  2174. The following are examples of octal constants: 
  2175.  
  2176. 0
  2177. 0125
  2178. 034673
  2179. 03245
  2180.  
  2181. Related Information 
  2182.  
  2183.      Integer Constants 
  2184.      Decimal Constants 
  2185.      Hexadecimal Constants 
  2186.      Integer Variables 
  2187.  
  2188.  
  2189. ΓòÉΓòÉΓòÉ 3.5.2. Floating-Point Constants ΓòÉΓòÉΓòÉ
  2190.  
  2191. A floating-point constant consists of: 
  2192.  
  2193.      An integral part 
  2194.      A decimal point 
  2195.      A fractional part 
  2196.      An exponent part 
  2197.      An optional suffix. 
  2198.  
  2199.  Both the integral and fractional parts are made up of decimal digits. You can 
  2200.  omit either the integral part or the fractional part, but not both. You can 
  2201.  omit either the decimal point or the exponent part, but not both. 
  2202.  
  2203.  The representation of a floating-point number on a system is unspecified. If a 
  2204.  floating-point constant is too large or too small, the result is undefined by 
  2205.  the language. VisualAge C++, represents floating-point numbers according to 
  2206.  IEEE rules. For C, if a floating-point constant is too large, it is set to the 
  2207.  largest value representable by the type. If it is too small, it is set to 
  2208.  zero. For C++, constant values that are too large or too small cause a 
  2209.  compile-time error. 
  2210.  
  2211.  The suffix f or F indicates a type of float, and the suffix l or L indicates a 
  2212.  type of long double. If a suffix is not specified, the floating-point constant 
  2213.  has a type double. 
  2214.  
  2215.  A plus (+) or minus (-) symbol can precede a floating-point constant. However, 
  2216.  it is not part of the constant; it is interpreted as a unary operator. 
  2217.  
  2218.  The following are examples of floating-point constants: 
  2219.  
  2220.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2221.   Γöé FLOATING-POINT CON-   Γöé VALUE          Γöé
  2222.   Γöé STANT          Γöé             Γöé
  2223.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2224.   Γöé "5.3876e4"       Γöé "53,876"        Γöé
  2225.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2226.   Γöé "4e-11"         Γöé "0.00000000004"     Γöé
  2227.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2228.   Γöé "1e+5"         Γöé "100000"        Γöé
  2229.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2230.   Γöé "7.321E-3"       Γöé "0.007321"       Γöé
  2231.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2232.   Γöé "3.2E+4"        Γöé "32000"         Γöé
  2233.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2234.   Γöé "0.5e-6"        Γöé "0.0000005"       Γöé
  2235.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2236.   Γöé "0.45"         Γöé "0.45"         Γöé
  2237.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2238.   Γöé "6.e10"         Γöé "60000000000"      Γöé
  2239.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2240.  
  2241.  Related Information 
  2242.  
  2243.      Floating-Point Variables 
  2244.  
  2245.  
  2246. ΓòÉΓòÉΓòÉ 3.5.3. Character Constants ΓòÉΓòÉΓòÉ
  2247.  
  2248. A character constant contains a sequence of characters or escape sequences 
  2249. enclosed in single quotation mark symbols. 
  2250.  
  2251. At least one character or escape sequence must appear in the character 
  2252. constant. The characters can be any from the source program character set, 
  2253. excluding the single quotation mark, backslash and new-line symbols. The prefix 
  2254. L indicates a wide character constant. A character constant must appear on a 
  2255. single logical source line. 
  2256.  
  2257. The value of a character constant containing a single character is the numeric 
  2258. representation of the character in the character set used at run time. The 
  2259. value of a wide character constant containing a single multibyte character is 
  2260. the code for that character, as defined by the mbtowc function. If the 
  2261. character constant contains more than one character, the last 4 bytes represent 
  2262. the character constant. In C++, a character constant can contain only one 
  2263. character. 
  2264.  
  2265. In C, a character constant has type int. In C++, a character constant hast type 
  2266. char. 
  2267.  
  2268. A wide character constant is represented by a double-byte character of type 
  2269. wchar_t. Multibyte characters represent character sets that use more than one 
  2270. byte in their representation. In OS/2, each multibyte character can contain up 
  2271. to 2 bytes. 
  2272.  
  2273. Restrictions 
  2274.  
  2275. To represent the single quotation symbol, backslash, and new-line characters, 
  2276. you must use the corresponding escape sequence. For more information on escape 
  2277. sequences, see Escape Sequences. 
  2278.  
  2279. The following are examples of character constants: 
  2280.  
  2281.  'a'    '\'' 
  2282.  '0'    '(' 
  2283.  'x'    '\n' 
  2284.  '7'    '\117' 
  2285.  'C' 
  2286.  
  2287.  Related Information 
  2288.  
  2289.      String Literals 
  2290.      Escape Sequences 
  2291.      Integer Variables 
  2292.  
  2293.  
  2294. ΓòÉΓòÉΓòÉ 3.5.4. String Literals ΓòÉΓòÉΓòÉ
  2295.  
  2296. A string constant or literal contains a sequence of characters or escape 
  2297. sequences enclosed in double quotation mark symbols. 
  2298.  
  2299. The prefix L indicates a wide-character string literal. 
  2300.  
  2301. A null ('\0') character is appended to each string. For a wide character string 
  2302. (a string prefixed by the letter L), the value '\0' of type wchar_t is 
  2303. appended. By convention, programs recognize the end of a string by finding the 
  2304. null character. 
  2305.  
  2306. Multiple spaces contained within a string constant are retained. 
  2307.  
  2308. To continue a string on the next line, use the line continuation sequence (\ 
  2309. symbol immediately followed by a new-line character). A carriage return must 
  2310. immediately follow the backslash. In the following example, the string literal 
  2311. second causes a compile-time error. 
  2312.  
  2313. char *first = "This string continues onto the next\
  2314.   line, where it ends.";                /* compiles successfully.   */
  2315. char *second = "The comment makes the \ /* continuation symbol      */
  2316.   invisible to the compiler.";          /* compilation error.       */
  2317.  
  2318. Another way to continue a string is to have two or more consecutive strings. 
  2319. Adjacent string literals are concatenated to produce a single string. You 
  2320. cannot concatenate a wide string constant with a character string constant. For 
  2321. example: 
  2322.  
  2323. "hello " "there"     /* is equivalent to "hello there"   */
  2324. "hello " L"there"    /* is not valid                     */
  2325. "hello" "there"      /* is equivalent to "hellothere"    */
  2326.  
  2327. Characters in concatenated strings remain distinct. For example, the strings 
  2328. "\xab" and "3" are concatenated to form "\xab3". However, the characters \xab 
  2329. and 3 remain distinct and are not merged to form the hexadecimal character 
  2330. \xab3. 
  2331.  
  2332. Following any concatenation, '\0' of type char is appended at the end of each 
  2333. string. C++ programs find the end of a string by scanning for this value. For a 
  2334. wide-character string literal, '\0' of type wchar_t is appended. For example: 
  2335.  
  2336. char *first = "Hello ";            /* stored as "Hello \0"       */
  2337. char *second = "there";            /* stored as "there\0"        */
  2338. char *third = "Hello " "there";    /* stored as "Hello there\0"  */
  2339.  
  2340. A character string constant has type array of char and static storage duration. 
  2341. A wide character constant has type array of wchar_t and static storage 
  2342. duration. 
  2343.  
  2344. Use the escape sequence \n to represent a new-line character as part of the 
  2345. string. Use the escape sequence \\ to represent a backslash character as part 
  2346. of the string. You can represent the single quotation mark symbol by itself ', 
  2347. but you use the escape sequence \" to represent the double quotation mark 
  2348. symbol. 
  2349.  
  2350. For example: 
  2351.  
  2352. /**
  2353.  ** This example illustrates escape sequences in string literals
  2354.  **/
  2355.  
  2356. #include <iostream.h>
  2357. void main ()
  2358. {
  2359.       char *s ="Hi there! \n";
  2360.       cout << s;
  2361.       char *p = "The backslash character \\.";
  2362.       cout << p << endl;
  2363.       char *q = "The double quotation mark \".\n";
  2364.       cout << q ;
  2365. }
  2366.  
  2367. This program produces the following output: 
  2368.  
  2369. Hi there!
  2370. The backslash character \.
  2371. The double quotation mark ".
  2372.  
  2373. You should be careful when modifying string literals because the resulting 
  2374. behavior depends on whether your strings are stored in read/write static 
  2375. memory. String literals are stored read/write by default. Use the #pragma 
  2376. strings preprocessor directive, to specify the storage type for strings. 
  2377.  
  2378. The following are examples of string literals: 
  2379.  
  2380. char titles[ ] = "Handel's \"Water Music\"";
  2381. char *mail_addr = "Last Name    First Name    MI   Street Address   \
  2382.    City     Province   Postal code ";
  2383. char *temp_string = "abc" "def" "ghi";  /* *temp_string = "abcdefghi\0" */
  2384. wchar_t *wide_string = L"longstring";
  2385.  
  2386. Related Information 
  2387.  
  2388.      Character Constants 
  2389.      Escape Sequences 
  2390.      Characters 
  2391.      Arrays 
  2392.      Pragma Directives (#pragma) 
  2393.      #pragma strings 
  2394.  
  2395.  
  2396. ΓòÉΓòÉΓòÉ 3.5.5. Escape Sequences ΓòÉΓòÉΓòÉ
  2397.  
  2398. An escape sequence contains a backslash (\) symbol followed by one of the 
  2399. escape sequence characters or an octal or hexadecimal number. A hexadecimal 
  2400. escape sequence contains an x followed by one or more hexadecimal digits (0-9, 
  2401. A-F, a-f). An octal escape sequence uses up to three octal digits (0-7). 
  2402.  
  2403. Note:  The line continuation sequence (\ followed by a new-line character) is 
  2404. not an escape sequence. It is used in character strings to indicate that the 
  2405. current line continues on the next line. 
  2406.  
  2407. The escape sequences and the characters they represent are: 
  2408.  
  2409. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2410. Γöé ESCAPE   Γöé CHARACTER REPRES-   Γöé
  2411. Γöé SEQUENCE  Γöé ENTED         Γöé
  2412. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2413. Γöé "\a"    Γöé Alert (bell, alarm)  Γöé
  2414. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2415. Γöé "\b"    Γöé Backspace       Γöé
  2416. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2417. Γöé "\f"    Γöé Form feed (new page) Γöé
  2418. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2419. Γöé "\n"    Γöé New-line       Γöé
  2420. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2421. Γöé "\r"    Γöé Carriage return    Γöé
  2422. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2423. Γöé "\t"    Γöé Horizontal tab    Γöé
  2424. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2425. Γöé "\v"    Γöé Vertical tab     Γöé
  2426. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2427. Γöé "\'"    Γöé Single quotation   Γöé
  2428. Γöé       Γöé mark         Γöé
  2429. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2430. Γöé "\""    Γöé Double quotation   Γöé
  2431. Γöé       Γöé mark         Γöé
  2432. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2433. Γöé "\?"    Γöé Question mark     Γöé
  2434. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2435. Γöé "\\"    Γöé Backslash       Γöé
  2436. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2437.  
  2438. The value of an escape sequence represents the member of the character set used 
  2439. at run time. For example, on a system uses the ASCII character codes, the 
  2440. letter V is represented by the escape sequence \x56. 
  2441.  
  2442. Use escape sequences only in character constants or in string literals. 
  2443.  
  2444. If an escape sequence is not recognized, the compiler uses the character 
  2445. following the backslash and a message is issued. Note that this behavior is 
  2446. implementation-defined. 
  2447.  
  2448. In string and character sequences, when you want the backslash to represent 
  2449. itself (rather than the beginning of an escape sequence), you must use a \\ 
  2450. backslash escape sequence. For example: 
  2451.  
  2452.       cout << "The escape sequence \\n." << endl;
  2453.  
  2454. This statement results in the following output: 
  2455.  
  2456.       The escape sequence \n.
  2457.  
  2458. The following program prints the character 'a' four times to standard output, 
  2459. and then prints a new line: 
  2460.  
  2461. #include <iostream.h>
  2462. void main()
  2463. {
  2464.       char a,b,c,d,e;
  2465.       a='a';
  2466.       b=97;       // ASCII integer value
  2467.       c='\141';   // ASCII octal value
  2468.       d='\x61';   // ASCII hexadecimal value
  2469.       e='\n';
  2470.       cout << a << b << c << d << e;
  2471. }
  2472.  
  2473. Related Information 
  2474.  
  2475.      Character Constants 
  2476.      String Literals 
  2477.  
  2478.  
  2479. ΓòÉΓòÉΓòÉ 4. Declarations ΓòÉΓòÉΓòÉ
  2480.  
  2481. A declaration establishes the names and characteristics of data objects and 
  2482. functions used in a program. A definition allocates storage for data objects or 
  2483. specifies the body for a function. When you define a type, no storage is 
  2484. allocated. 
  2485.  
  2486. Declarations determine the following properties of data objects and their 
  2487. identifiers: 
  2488.  
  2489.      Scope, which describes the visibility of an identifier in a block or 
  2490.       source file. For a complete description of scope, see Scope in C. 
  2491.      Linkage, which describes the association between two identical 
  2492.       identifiers. See Program Linkage for more information. 
  2493.      Storage duration, which describes when the system allocates and frees 
  2494.       storage for a data object. See Storage Duration for more information. 
  2495.      Type, which describes the kind of data the object is to represent. 
  2496.  
  2497.  The declaration for a data object includes one or more of: 
  2498.  
  2499.      Qualifier and declarator, described on page Storage Class Specifiers 
  2500.      Storage class, described on page Storage Class Specifiers 
  2501.      Initializer, described on page Initializers 
  2502.      Type specifier, described on page Type Specifiers 
  2503.  
  2504.  Function declarations are described in Functions. 
  2505.  
  2506.  Syntax of a Data Declaration 
  2507.  
  2508.  Note: 
  2509.  
  2510.    1. One of the fundamental differences between C++ and C is the placement of 
  2511.       variable declarations. Although variables are declared in the same way, 
  2512.       in C++, variable declarations can be put anywhere in the program. In C, 
  2513.       declarations must come before any statements in a block. 
  2514.  
  2515.       In the following C++ example, the variable d is declared in the middle of 
  2516.       the main() function: 
  2517.  
  2518.             #include <iostream.h>
  2519.             void main()
  2520.             {
  2521.                   int a, b;
  2522.                   cout << "Please enter two integers" << endl;
  2523.                   cin >> a >> b;
  2524.                   int d = a + b;
  2525.                   cout << "Here is the sum of your two integers:" << d << endl;
  2526.             }
  2527.  
  2528.    2. A given function, object, or type can have only one definition. It can 
  2529.       have more than one declaration as long as all of the declarations match. 
  2530.       If a function is never called and its address is never taken, then you do 
  2531.       not have to define it. If an object is declared but never used, or is 
  2532.       only used as the operand of sizeof, you do not have to define it. You can 
  2533.       declare a given class or enumerator more than once. 
  2534.  
  2535.  The following table shows examples of declarations and definitions. 
  2536.  
  2537.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2538.   Γöé Table 4. Examples of Declarations and Definitions               Γöé
  2539.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2540.   Γöé DECLARATIONS          Γöé DECLARATIONS AND DEFINITIONS         Γöé
  2541.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2542.   Γöé "extern double pi;"      Γöé "double pi = 3.14159265;"           Γöé
  2543.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2544.   Γöé "float square(float x);"    Γöé "float square(float x) { return x*x; }"    Γöé
  2545.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2546.   Γöé "struct payroll;"       Γöé  struct payroll {              Γöé
  2547.   Γöé                Γöé           char *name;        Γöé
  2548.   Γöé                Γöé           float salary;       Γöé
  2549.   Γöé                Γöé          } employee;         Γöé
  2550.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2551.  
  2552.  Related Information 
  2553.  
  2554.      Block Scope Data Declarations 
  2555.      File Scope Data Declarations 
  2556.      Declarators 
  2557.      Storage Class Specifiers 
  2558.      Initializers 
  2559.      Type Specifiers 
  2560.  
  2561.  
  2562. ΓòÉΓòÉΓòÉ <hidden> Data Declaration Syntax ΓòÉΓòÉΓòÉ
  2563.  
  2564.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2565.                 Γöé                 Γöé
  2566. >>ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓöÇdeclaratorΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ;ΓöÇΓöÇ><
  2567.    Γö£ΓöÇstorage_class_specifierΓöÇΓöñ         ΓööΓöÇinitializerΓöÇΓöÿ
  2568.    Γö£ΓöÇtype_specifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2569.    ΓööΓöÇtype_qualifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2570.  
  2571.  
  2572. ΓòÉΓòÉΓòÉ 4.1. Block Scope Data Declarations ΓòÉΓòÉΓòÉ
  2573.  
  2574. A block scope data declaration can only be put at the beginning of a block. It 
  2575. describes a variable and makes that variable accessible to the current block. 
  2576. All block scope declarations that do not have the extern storage class 
  2577. specifier are definitions and allocate storage for that object. 
  2578.  
  2579. You can declare a data object with block scope with any of the storage class 
  2580. specifiers described in Storage Class Specifiers. If you do not specify a 
  2581. storage class specifier in a block-scope data declaration, the default storage 
  2582. class specifier auto is used. If you specify a storage class specifier, you can 
  2583. omit the type specifier. If you omit the type specifier, all variables in that 
  2584. declaration receive type int. 
  2585.  
  2586. Initialization 
  2587. You cannot initialize a variable declared in a block scope data declaration 
  2588. that has the extern storage class specifier. 
  2589.  
  2590. The types of variables you can initialize and the values that uninitialized 
  2591. variables receive vary for that storage class specifier. See Storage Class 
  2592. Specifiers for details on the different storage classes. 
  2593.  
  2594. Storage 
  2595.  
  2596. The duration and type of storage varies for each storage class specifier. 
  2597.  
  2598. Declarations with the auto or register storage class specifier result in 
  2599. automatic storage duration. Declarations with the extern or static storage 
  2600. class specifier result in static storage duration. 
  2601.  
  2602. Related Information 
  2603.  
  2604.      Declarators 
  2605.      Storage Class Specifiers 
  2606.      auto Storage Class Specifier 
  2607.      extern Storage Class Specifier 
  2608.      register Storage Class Specifier 
  2609.      static Storage Class Specifier 
  2610.      Declarations 
  2611.      Initializers 
  2612.      Type Specifiers 
  2613.  
  2614.  
  2615. ΓòÉΓòÉΓòÉ 4.2. File Scope Data Declarations ΓòÉΓòÉΓòÉ
  2616.  
  2617. A file scope data declaration appears outside any function definition. It 
  2618. describes a variable and makes that variable accessible to all functions that 
  2619. are in the same file and whose definitions appear after the declaration. 
  2620.  
  2621. A file scope data definition is a data declaration at file scope that also 
  2622. causes storage to be allocated for that variable. All objects whose identifiers 
  2623. are declared at file scope have static storage duration. 
  2624.  
  2625. Use a file scope data declaration to declare variables that you want to have 
  2626. external linkage. 
  2627.  
  2628. The only storage class specifiers you can put in a file scope data declaration 
  2629. are static, extern, and typedef. If you specify static, all variables defined 
  2630. in it have internal linkage. If you do not specify static, all variables 
  2631. defined in it have external linkage. If you specify the storage class you can 
  2632. omit the type specifier. If you omit the type specifier, all variables defined 
  2633. in that declaration receive the type int. 
  2634.  
  2635. Initialization 
  2636. You can initialize any object with file scope. If you do not initialize a file 
  2637. scope variable, its initial value is zero of the appropriate type. If you do 
  2638. initialize it, the initializer must be described by a constant expression, or 
  2639. it must reduce to the address of a previously declared variable at file scope, 
  2640. possibly modified by a constant expression. Initialization of all variables at 
  2641. file scope takes place before the main function begins running. 
  2642.  
  2643. Storage 
  2644. All objects with file scope data declarations have static storage duration. 
  2645. Storage is allocated at runtime and freed when the program stops running. 
  2646.  
  2647. Related Information 
  2648.  
  2649.      extern Storage Class Specifier 
  2650.      static Storage Class Specifier 
  2651.      Declarations 
  2652.      Declarators 
  2653.      Initializers 
  2654.      Type Specifiers 
  2655.  
  2656.  
  2657. ΓòÉΓòÉΓòÉ 4.3. Objects ΓòÉΓòÉΓòÉ
  2658.  
  2659. An object is a region of storage that contains a value or group of values. Each 
  2660. value can be accessed using its identifier or a more complex expression that 
  2661. refers to the object. In addition, each object has a unique data type. Both the 
  2662. identifier and data type of an object are established in the object 
  2663. declaration. 
  2664.  
  2665. The data type of an object determines the initial storage allocation for that 
  2666. object and the interpretation of the values during subsequent access. It is 
  2667. also used in any type-checking operations. 
  2668.  
  2669. C++ has built-in, or standard, data types and user-defined data types. Standard 
  2670. data types include signed and unsigned integers, floating-point numbers, and 
  2671. characters. User-defined types include enumerations, structures, unions, and 
  2672. classes. 
  2673.  
  2674. In C++ code, objects are represented by variables. A variable also represents 
  2675. the location in storage that contains the value of an object. 
  2676.  
  2677. An instance of a class type is commonly called a class object. The individual 
  2678. class members are also called objects. The set of all member objects comprises 
  2679. a class object. 
  2680.  
  2681. Related Information 
  2682.  
  2683.      Type Specifiers 
  2684.      C++ Classes 
  2685.      Declarations 
  2686.  
  2687.  
  2688. ΓòÉΓòÉΓòÉ 4.4. Declarators ΓòÉΓòÉΓòÉ
  2689.  
  2690. A declarator designates a data object or function. Declarators appear in all 
  2691. data definitions and declarations and in some type definitions. 
  2692.  
  2693. In a declarator, you can specify the type of an object to be an array, a 
  2694. pointer, or a reference. You can specify that the return type of a function is 
  2695. a pointer or a reference. You can also perform initialization in a declarator. 
  2696.  
  2697. Syntax of a Declarator VisualAge C++ also implements the following qualifiers: 
  2698.  
  2699.      _Packed 
  2700.      __unaligned 
  2701.      _Seg16 
  2702.      _Export 
  2703.      _Inline 
  2704.  
  2705.  In C, you cannot declare or define a volatile or const function. C++ class 
  2706.  member functions can be qualified with const or volatile. 
  2707.  
  2708.  A simple declarator consists of an identifier, which names a data object. For 
  2709.  example, the following block scope data declaration uses initial as the 
  2710.  declarator: 
  2711.  
  2712.   auto char initial;
  2713.  
  2714.  The data object initial has the storage class auto and the data type char. 
  2715.  
  2716.  You can define or declare a structure, union, or array. by using a declarator 
  2717.  that contains an identifier, which names the data object, and some combination 
  2718.  of symbols and identifiers, which describes the type of data that the object 
  2719.  represents. 
  2720.  
  2721.  The following declaration uses compute[5] as the declarator: 
  2722.  
  2723.   extern long int compute[5];
  2724.  
  2725.  Examples of Declarators 
  2726.  
  2727.  Related Information 
  2728.  
  2729.      volatile and const Qualifiers 
  2730.      _Packed Qualifier 
  2731.      _Seg16 Type Qualifier 
  2732.      _Export Qualifier 
  2733.      Declarations 
  2734.      Arrays 
  2735.      Enumerations 
  2736.      Pointers 
  2737.      Structures 
  2738.      Unions 
  2739.  
  2740.  
  2741. ΓòÉΓòÉΓòÉ <hidden> Declarator Syntax ΓòÉΓòÉΓòÉ
  2742.  
  2743. A declarator has the form: 
  2744.  
  2745.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2746.              Γöé
  2747. >>ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ>
  2748.    ΓööΓöÇ*ΓöÇΓöÿ  Γö£ΓöÇvolatileΓöÇΓöñ
  2749.        ΓööΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöÿ
  2750.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  2751.                              Γöé
  2752. >ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇ><
  2753.    ΓööΓöÇ(ΓöÇΓöÇdeclaratorΓöÇΓöÇ)ΓöÇΓöÿ  Γö£ΓöÇsubscript_declaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  2754.               Γö£ΓöÇ(ΓöÇΓöÇparameter_type_listΓöÇΓöÇ)ΓöÇΓöñ
  2755.               ΓööΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  2756.                 ΓööΓöÇidentifierΓöÇΓöÿ
  2757.  
  2758. A qualifier is one of:  const, volatile or _Packed. The VisualAge C++ compiler 
  2759. also implements the _Seg16, _Export, and _Inline qualifiers. 
  2760.  
  2761. C++ Note:  C++ does not support the _Packed keyword. 
  2762.  
  2763. A declarator can contain a subdeclarator. A subdeclarator has the form: 
  2764.  
  2765. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>
  2766.   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé  ΓööΓöÇ(ΓöÇΓöÇsubdeclaratorΓöÇΓöÇ)ΓöÇΓöÿ
  2767.   Γöé          Γöé Γöé
  2768.   ΓööΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ*ΓöÇΓö┤ΓöÇΓöÿ
  2769.     Γö£ΓöÇvolatileΓöÇΓöñ
  2770.     ΓööΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöÿ
  2771. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  2772.   ΓööΓöÇsubscript_declaratorΓöÇΓöÿ
  2773.  
  2774. A subscript declarator describes the number of dimensions in an array and the 
  2775. number of elements in each dimension. A subscript declarator has the form: 
  2776.  
  2777. >>ΓöÇΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  2778.     ΓööΓöÇconstant_expressionΓöÇΓöÿ   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  2779.                   Γöé               Γöé Γöé
  2780.                   ΓööΓöÇΓöÇΓöÇ[ΓöÇΓöÇconstant_expressionΓöÇΓöÇ]ΓöÇΓö┤ΓöÇΓöÿ
  2781.  
  2782.  
  2783. ΓòÉΓòÉΓòÉ 4.4.1. volatile and const Qualifiers ΓòÉΓòÉΓòÉ
  2784.  
  2785. The volatile qualifier maintains consistency in memory access to data objects. 
  2786. Volatile objects are read from memory each time their value is needed, and 
  2787. written back to memory each time they are changed. The volatile qualifier is 
  2788. useful for data objects having values that may be changed in ways unknown to 
  2789. your program (such as the system clock). Objects referenced by multiple threads 
  2790. or by signal handlers should also be qualified as volatile. Portions of an 
  2791. expression that reference volatile objects are not to be changed or removed. 
  2792.  
  2793. The const qualifier explicitly declares a data object as a data item that 
  2794. cannot be changed. Its value is set at initialization. You cannot use const 
  2795. data objects in expressions requiring a modifiable lvalue. For example, a const 
  2796. data object cannot appear on the left-hand side of an assignment statement. 
  2797.  
  2798. These type qualifiers are only meaningful in expressions that are lvalues. 
  2799.  
  2800. For a volatile or const pointer, you must put the keyword between the * and the 
  2801. identifier. For example: 
  2802.  
  2803. int * volatile x;        /* x is a volatile pointer to an int */
  2804. int * const y = &z;      /* y is a const pointer to the int variable z */
  2805.  
  2806. For a pointer to a volatile or const data object, the type specifier, 
  2807. qualifier, and storage class specifier can be in any order. For example: 
  2808.  
  2809. volatile int *x;         /* x is a pointer to a volatile int  */
  2810.   or
  2811. int volatile *x;         /* x is a pointer to a volatile int  */
  2812.  
  2813. const int *y;            /* y is a pointer to a const int  */
  2814.   or
  2815. int const *y;            /* y is a pointer to a const int  */
  2816.  
  2817. In the following example, the pointer to y is a constant. You can change the 
  2818. value that y points to, but you cannot change the value of y: 
  2819.  
  2820. int * const y
  2821.  
  2822. In the following example, the value that y points to is a constant integer and 
  2823. cannot be changed. However, you can change the content of y: 
  2824.  
  2825. const int * y
  2826.  
  2827. For other types of volatile and const variables, the position of the keyword 
  2828. within the definition (or declaration) is less important. For example: 
  2829.  
  2830. volatile struct omega {
  2831.                          int limit;
  2832.                          char code;
  2833.                       } group;
  2834.  
  2835. provides the same storage as: 
  2836.  
  2837. struct omega {
  2838.                 int limit;
  2839.                 char code;
  2840.              } volatile group;
  2841.  
  2842. In both examples, only the structure variable group receives the volatile 
  2843. qualifier. Similarly, if you specified the const keyword instead of volatile, 
  2844. only the structure variable group receives the const qualifier. The const and 
  2845. volatile qualifiers when applied to a structure, union, or class also apply to 
  2846. the members of the structure, union, or class. 
  2847.  
  2848. Although enumeration, structure, and union variables can receive the volatile 
  2849. or const qualifier, enumeration, structure, and union tags do not carry the 
  2850. volatile or const qualifier. For example, the blue structure does not carry the 
  2851. volatile qualifier: 
  2852.  
  2853. volatile struct whale {
  2854.                            int weight;
  2855.                            char name[8];
  2856.                       } beluga;
  2857. struct whale blue;
  2858.  
  2859. The keywords volatile and const cannot separate the keywords enum, struct, and 
  2860. union from their tags. 
  2861.  
  2862. You can declare or define a volatile or const function only if it is a C++ 
  2863. member function. You can define or declare any function to return a pointer to 
  2864. a volatile or const function. 
  2865.  
  2866. You can put more than one qualifier on a declaration but you cannot specify the 
  2867. same qualifier more than once on a declaration. 
  2868.  
  2869. Related Information 
  2870.  
  2871.      Declarators 
  2872.      _Packed Qualifier 
  2873.      _Seg16 Type Qualifier 
  2874.      _Export Qualifier 
  2875.      Type Specifiers 
  2876.      Structures 
  2877.      Unions 
  2878.      Enumerations 
  2879.      Pointers 
  2880.      lvalues 
  2881.  
  2882.  
  2883. ΓòÉΓòÉΓòÉ 4.4.2. _Packed Qualifier ΓòÉΓòÉΓòÉ
  2884.  
  2885. The _Packed qualifier removes padding between members of structures and unions, 
  2886. whenever possible. However, the storage saved using packed structures and 
  2887. unions may come at the expense of runtime performance. Most machines access 
  2888. data more efficiently if it is aligned on appropriate boundaries. With packed 
  2889. structures and unions, members are generally not aligned on natural boundaries, 
  2890. and the result is that member-accessing operations (using the . and -> 
  2891. operators) are slower. 
  2892.  
  2893. _Packed can only be used with structures or unions. If you use _Packed with 
  2894. other types, an error message is generated and the qualifier has no effect on 
  2895. the declarator it qualifies. Packed and nonpacked structures and unions have 
  2896. different storage layouts. Comparisons between packed and nonpacked structures 
  2897. or unions of the same type are prohibited. 
  2898.  
  2899. If you specify the _Packed qualifier on a structure or union that contains a 
  2900. structure or union as a member, the qualifier is not passed on to the contained 
  2901. structure or union. 
  2902.  
  2903. The VisualAge C++ compiler also lets you pack structures using the #pragma pack 
  2904. directive or the /Sp option. 
  2905.  
  2906. C++ Note:  C++ does not support the _Packed keyword. Use the #pragma pack 
  2907. directive or the /Sp compiler option to control the alignment of structures and 
  2908. unions. 
  2909.  
  2910. Related Information 
  2911.  
  2912.      #pragma pack 
  2913.      /Sp option 
  2914.      Declarators 
  2915.      volatile and const Qualifiers 
  2916.      _Seg16 Type Qualifier 
  2917.      _Export Qualifier 
  2918.      Type Specifiers 
  2919.      Structures 
  2920.      Unions 
  2921.  
  2922.  
  2923. ΓòÉΓòÉΓòÉ <hidden> Examples of Declarators ΓòÉΓòÉΓòÉ
  2924.  
  2925. The following table describes some declarators: 
  2926.  
  2927.  Example         Description 
  2928.  
  2929.  int owner       owner is an int data object. 
  2930.  
  2931.  int *node       node is a pointer to an int data object. 
  2932.  
  2933.  int names[126]  names is an array of 126 int elements. 
  2934.  
  2935.  int *action( )  action is a function returning a pointer to an int. 
  2936.  
  2937.  volatile int min min is an int that has the volatile 
  2938.  
  2939.  int * volatile volume volume is a volatile pointer to an int. 
  2940.  
  2941.  volatile int * next next is a pointer to a volatile int 
  2942.  
  2943.  volatile int * sequence[5] sequence is an array of five pointers to volatile 
  2944.                  int objects. 
  2945.  
  2946.  extern const volatile int op_system_clock op_system_clock is an extern int 
  2947.                  that has the volatile attribute. 
  2948.  
  2949.  
  2950. ΓòÉΓòÉΓòÉ 4.4.3. _Seg16 Type Qualifier ΓòÉΓòÉΓòÉ
  2951.  
  2952. Because pointers are interpreted differently in 16-bit programs than in 32-bit 
  2953. programs, they cannot be shared between the two types of program.  Use the 
  2954. _Seg16 type qualifier when calling 16-bit code to ensure correct mapping of 
  2955. pointers between the different types of code. For example: 
  2956.  
  2957.    char * _Seg16 p16;
  2958.  
  2959. declares p16 to be a segmented pointer that can be addressed by a 16-bit 
  2960. program. The pointer can also be used in a 32-bit program, because the compiler 
  2961. converts it to 32-bit form when it is used in an expression. The _Seg16 
  2962. qualifier can only be used with pointers. Note that _Seg16 comes after the 
  2963. asterisk in the declaration, as required by ISO/ANSI C syntax rules. 
  2964.  
  2965. All pointers shared between 32-bit and 16-bit code must be qualified with 
  2966. _Seg16. These include pointers passed indirectly to 16-bit code, such as 
  2967. pointers in structures and pointers that are referenced by pointers passed 
  2968. directly to 16-bit code. 
  2969.  
  2970. While it is possible to write a program where all the pointers are qualified 
  2971. with _Seg16, it is not recommended. Every time a segmented pointer is used in a 
  2972. 32-bit program, it must be converted to a 32-bit pointer and then back to 
  2973. segmented pointer to be stored. This process will cause a noticeable 
  2974. performance degradation in your program. Pointers that are not shared with 
  2975. 16-bit code and those that are passed by value to 16-bit code (that is, as a 
  2976. parameter to a function) do not need to be qualified with _Seg16. 
  2977.  
  2978. For more information on using _Seg16 and calling 16-bit programs from 32-bit 
  2979. code, see the IBM VisualAge C++ for OS/2 Programming Guide. 
  2980.  
  2981. Related Information 
  2982.  
  2983.      Pointers 
  2984.      #pragma seg16 
  2985.      Declarators 
  2986.      volatile and const Qualifiers 
  2987.      _Packed Qualifier 
  2988.      _Export Qualifier 
  2989.  
  2990.  
  2991. ΓòÉΓòÉΓòÉ 4.5. Storage Class Specifiers ΓòÉΓòÉΓòÉ
  2992.  
  2993. The storage class specifier used within the declaration determines whether: 
  2994.  
  2995.      The object has internal, external, or no linkage. 
  2996.  
  2997.      The object is to be stored in memory or in a register, if available. 
  2998.  
  2999.      The object receives the default initial value 0 or an indeterminate 
  3000.       default initial value. 
  3001.  
  3002.      The object can be referenced throughout a program or only within the 
  3003.       function, block, or source file where the variable is defined. 
  3004.  
  3005.      Storage duration for the object is static (storage is maintained 
  3006.       throughout program run time) or automatic (storage is maintained only 
  3007.       during the execution of the block where the object is defined). 
  3008.  
  3009.  For a function, the storage class specifier determines the linkage of the 
  3010.  function. 
  3011.  
  3012.  The VisualAge C++ compiler implements an additional storage class specifier 
  3013.  for functions, inline. The _Inline and inline specifiers determine whether the 
  3014.  function code will be inlined or called. Note that _Inline and inline are 
  3015.  ignored if the /Oi- compiler option is specified. 
  3016.  
  3017.  The following sections describe the storage class specifiers: 
  3018.  
  3019.      auto Storage Class Specifier 
  3020.      extern Storage Class Specifier 
  3021.      register Storage Class Specifier 
  3022.      static Storage Class Specifier 
  3023.      Inline Specifiers 
  3024.  
  3025.  Related Information 
  3026.  
  3027.      Program Linkage 
  3028.      C++ Inline Functions 
  3029.      Declarations 
  3030.      Inline Specifiers 
  3031.      /Oi option 
  3032.  
  3033.  
  3034. ΓòÉΓòÉΓòÉ 4.5.1. auto Storage Class Specifier ΓòÉΓòÉΓòÉ
  3035.  
  3036. The auto storage class specifier lets you define a variable with automatic 
  3037. storage; its use and storage is restricted to the current block. The storage 
  3038. class keyword auto is optional in a data declaration. It is not permitted in a 
  3039. parameter declaration. A variable having the auto storage class specifier must 
  3040. be declared within a block. It cannot be used for file scope declarations. 
  3041.  
  3042. Because automatic variables require storage only while they are actually being 
  3043. used, defining variables with the auto storage class can decrease the amount of 
  3044. memory required to run a program. However, having many large automatic objects 
  3045. is likely to cause you to run out of stack space. 
  3046.  
  3047. Declaring variables with the auto storage class can also make code easier to 
  3048. maintain, because a change to an auto variable in one function never affects 
  3049. another function (unless it is passed as an argument). 
  3050.  
  3051. You can initialize any auto variable except parameters. If you do not 
  3052. initialize an automatic object, its value is indeterminate. If you provide an 
  3053. initial value, the expression representing the initial value can be any valid C 
  3054. or C++ expression. For structure and union members, the initial value must be a 
  3055. valid constant expression if an initializer list is used. The object is then 
  3056. set to that initial value each time the program block that contains the 
  3057. object's definition is entered. 
  3058.  
  3059. Note:  If you use the goto statement to jump into the middle of a block, 
  3060. automatic variables within that block are not initialized. 
  3061.  
  3062. Objects with the auto storage class specifier have automatic storage duration. 
  3063. Each time a block is entered, storage for auto objects defined in that block is 
  3064. made available. When the block is exited, the objects are no longer available 
  3065. for use. 
  3066.  
  3067. If an auto object is defined within a function that is recursively invoked, 
  3068. memory is allocated for the object at each invocation of the block. 
  3069.  
  3070. Examples of auto Storage Class 
  3071.  
  3072. Related Information 
  3073.  
  3074.      Storage Class Specifiers 
  3075.      register Storage Class Specifier 
  3076.      Block Scope Data Declarations 
  3077.      Function Declarator 
  3078.      Address  & 
  3079.  
  3080.  
  3081. ΓòÉΓòÉΓòÉ <hidden> Examples of auto Storage Class ΓòÉΓòÉΓòÉ
  3082.  
  3083. /************************************************************************
  3084. *
  3085.  
  3086. The following program shows the scope and initialization of auto variables. The 
  3087. function main defines two variables, each named auto_var. The first definition 
  3088. occurs on line 8. The second definition occurs in a nested block on line 11. 
  3089. While the nested block is running, only the auto_var created by the second 
  3090. definition is available. During the rest of the program, only the auto_var 
  3091. created by the first definition is available. 
  3092.  
  3093.                                                                         *
  3094. ************************************************************************/
  3095.  
  3096.  1   /****************************************************
  3097.  2    ** Example illustrating the use of auto variables **
  3098.  3    ****************************************************/
  3099.  4
  3100.  5   #include <stdio.h>
  3101.  6
  3102.  7   int main(void)
  3103.  8   {
  3104.  9      void call_func(int passed_var);
  3105. 10      auto int auto_var = 1;  /* first definition of auto_var  */
  3106. 11
  3107. 12      {
  3108. 13         int auto_var = 2;    /* second definition of auto_var */
  3109. 14         printf("inner auto_var = %d\n", auto_var);
  3110. 15      }
  3111. 16      call_func(auto_var);
  3112. 17      printf("outer auto_var = %d\n", auto_var);
  3113. 18      return(0);
  3114. 19   }
  3115. 20
  3116. 21   void call_func(int passed_var)
  3117. 22   {
  3118. 23      printf("passed_var = %d\n", passed_var);
  3119. 24      passed_var = 3;
  3120. 25      printf("passed_var = %d\n", passed_var);
  3121. 26   }
  3122.  
  3123. /************************************************************************
  3124. *
  3125. This program produces the following output: 
  3126.  
  3127. inner auto_var = 2
  3128. passed_var = 1
  3129. passed_var = 3
  3130. outer auto_var = 1
  3131.  
  3132. The following example uses an array that has the storage class auto to pass a 
  3133. character string to the function sort. The function sort receives the address 
  3134. of the character string, rather than the contents of the array. The address 
  3135. enables sort to change the values of the elements in the array. 
  3136.  
  3137.                                                                         *
  3138. ************************************************************************/
  3139.  
  3140. /*****************************************************************
  3141.  ** Sorted string program -- this example passes an array name  **
  3142.  ** to a function                                               **
  3143.  *****************************************************************/
  3144.  
  3145. #include <stdio.h>
  3146. #include <string.h>
  3147.  
  3148. int main(void)
  3149. {
  3150.    void sort(char *array, int n);
  3151.    char string[75];
  3152.    int length;
  3153.  
  3154.    printf("Enter letters:\n");
  3155.    scanf("%74s", string);
  3156.    length = strlen(string);
  3157.    sort(string,length);
  3158.    printf("The sorted string is: %s\n", string);
  3159.  
  3160.    return(0);
  3161. }
  3162.  
  3163. void sort(char *array, int n)
  3164. {
  3165.    int gap, i, j, temp;
  3166.  
  3167.    for (gap = n / 2; gap > 0; gap /= 2)
  3168.       for (i = gap; i < n; i++)
  3169.          for (j = i - gap; j >= 0 && array[j] > array[j + gap];
  3170.             j -= gap)
  3171.          {
  3172.             temp = array[j];
  3173.             array[j] = array[j + gap];
  3174.             array[j + gap] = temp;
  3175.          }
  3176. }
  3177.  
  3178. /**********************************************************************************
  3179. *
  3180.  
  3181. When the program is run, interaction with the program could produce: 
  3182.  
  3183.  Output    Enter letters: 
  3184.  
  3185.  Input     zyfab 
  3186.  
  3187.  Output    The sorted string is:  abfyz 
  3188.  
  3189.                                                                           *
  3190.   ************************************************************************/
  3191.  
  3192.  
  3193. ΓòÉΓòÉΓòÉ 4.5.2. extern Storage Class Specifier ΓòÉΓòÉΓòÉ
  3194.  
  3195. The extern storage class specifier lets you declare objects and functions that 
  3196. several source files can use. All object declarations that occur outside a 
  3197. function and that do not contain a storage class specifier declare identifiers 
  3198. with external linkage. All function definitions that do not specify a storage 
  3199. class define functions with external linkage. 
  3200.  
  3201. You can distinguish an extern declaration from an extern definition by the 
  3202. presence of the keyword extern and the absence of an initial value. If the 
  3203. keyword extern is absent or if there is an initial value, the declaration is 
  3204. also a definition; otherwise, it is just a declaration. An extern definition 
  3205. can appear only at file scope. 
  3206.  
  3207. An extern variable, function definition, or declaration also makes the 
  3208. described variable or function usable by the succeeding part of the current 
  3209. source file. This declaration does not replace the definition. The declaration 
  3210. is used to describe the variable that is externally defined. 
  3211.  
  3212. If a declaration for an identifier already exists at file scope, any extern 
  3213. declaration of the same identifier found within a block refers to that same 
  3214. object. If no other declaration for the identifier exists at file scope, the 
  3215. identifier has external linkage. 
  3216.  
  3217. An extern declaration can appear outside a function or at the beginning of a 
  3218. block. If the declaration describes a function or appears outside a function 
  3219. and describes an object with external linkage, the keyword extern is optional. 
  3220.  
  3221. C++ Note:  In C++, an extern declaration cannot appear in class scope. 
  3222.  
  3223. You can initialize any object with the extern storage class specifier at file 
  3224. scope. You can initialize an extern object with an initializer that must 
  3225. either: 
  3226.  
  3227.      Appear as part of the definition and the initial value must be described 
  3228.       by a constant expression. 
  3229.  
  3230.       OR 
  3231.      Reduce to the address of a previously declared object with static storage 
  3232.       duration. This object may be modified by adding or subtracting an 
  3233.       integral constant expression. 
  3234.  
  3235.  If you do not explicitly initialize an extern variable, its initial value is 
  3236.  zero of the appropriate type. Initialization of an extern object is completed 
  3237.  by the time the program starts running. 
  3238.  
  3239.  extern objects have static storage duration. Memory is allocated for extern 
  3240.  objects before the main function begins running. When the program finishes 
  3241.  running, the storage is freed. 
  3242.  
  3243.  Examples of extern Storage Class 
  3244.  
  3245.  Related Information 
  3246.  
  3247.      Storage Class Specifiers 
  3248.      File Scope Data Declarations 
  3249.      Function Definitions 
  3250.      Function Declarator 
  3251.      Constant Expressions 
  3252.  
  3253.  
  3254. ΓòÉΓòÉΓòÉ <hidden> Examples of extern Storage Class ΓòÉΓòÉΓòÉ
  3255.  
  3256. /************************************************************************
  3257. *
  3258.  
  3259. The following program shows the linkage of extern objects and functions. The 
  3260. extern object total is declared on line 12 of File 1 and on line 11 of File 2. 
  3261. The definition of the external object total appears in File 3. The extern 
  3262. function tally is defined in File 2. The function tally can be in the same file 
  3263. as main or in a different file. Because main precedes these definitions and 
  3264. main uses both total and tally, main declares tally on line 11 and total on 
  3265. line 12. 
  3266.  
  3267. File 1 
  3268.  
  3269.  
  3270. ************************************************************************/
  3271.  
  3272.  1   /**************************************************************
  3273.  2    ** The program receives the price of an item, adds the      **
  3274.  3    ** tax, and prints the total cost of the item.              **
  3275.  5    **************************************************************/
  3276.  6
  3277.  7   #include <stdio.h>
  3278.  8
  3279.  9   int main(void)
  3280. 10   {                               /* begin main                    */
  3281. 11      void tally(void);            /* declaration of function tally */
  3282. 12      extern float total;          /* first declaration of total    */
  3283. 13
  3284. 14      printf("Enter the purchase amount: \n");
  3285. 15      tally();
  3286. 16      printf("\nWith tax, the total is:  %.2f\n", total);
  3287. 17
  3288. 18      return(0);
  3289. 19   }                               /* end main                      */
  3290.  
  3291. /************************************************************************
  3292. *
  3293.  
  3294. File 2 
  3295.  
  3296.                                                                         *
  3297. ************************************************************************/
  3298.  
  3299.  1   /**************************************************************
  3300.  2    ** This file defines the function tally                     **
  3301.  3    **************************************************************/
  3302.  4   #include <stdio.h>
  3303.  6   #define  tax_rate  0.05
  3304.  7
  3305.  8   void tally(void)
  3306.  9   {                                           /* begin tally */
  3307. 10      float tax;
  3308. 11      extern float total;     /* second declaration of total  */
  3309. 12
  3310. 13      scanf("%f", &total);
  3311. 14      tax = tax_rate * total;
  3312. 15      total += tax;
  3313. 16   }                                            /* end tally */
  3314.  
  3315. /************************************************************************
  3316. *
  3317.  
  3318. File 3 
  3319.  
  3320.                                                                         *
  3321. ************************************************************************/
  3322.  
  3323.  1   float total;
  3324.  
  3325. /************************************************************************
  3326. *
  3327.  
  3328. When this program is run, interaction with it could produce: 
  3329.  
  3330.  Output    Enter the purchase amount: 
  3331.  
  3332.  Input     99.95 
  3333.  
  3334.  Output    With tax, the total is:  104.95 
  3335.  
  3336.  The following program shows extern variables used by two functions. Because 
  3337.  both functions main and sort can access and change the values of the extern 
  3338.  variables string and length, main does not have to pass parameters to sort. 
  3339.  
  3340.                                                                           *
  3341.   ************************************************************************/
  3342.  
  3343.   /*****************************************************************
  3344.    ** Sorted string program -- this example shows extern          **
  3345.    ** used by two functions                                       **
  3346.    *****************************************************************/
  3347.  
  3348.   #include <stdio.h>
  3349.   #include <string.h>
  3350.  
  3351.   char string[75];
  3352.   int length;
  3353.  
  3354.   int main(void)
  3355.   {
  3356.      void sort(void);
  3357.  
  3358.      printf("Enter letters:\n");
  3359.      scanf("%s", string);
  3360.      length = strlen(string);
  3361.      sort();
  3362.      printf("The sorted string is: %s\n", string);
  3363.  
  3364.      return(0);
  3365.   }
  3366.  
  3367.   void sort(void)
  3368.   {
  3369.      int gap, i, j, temp;
  3370.  
  3371.      for (gap = length / 2; gap > 0; gap /= 2)
  3372.         for (i = gap; i < length; i++)
  3373.            for (j = i - gap;
  3374.                 j >= 0 && string[j] > string[j + gap];
  3375.                 j -= gap)
  3376.            {
  3377.               temp = string[j];
  3378.               string[j] = string[j + gap];
  3379.               string[j + gap] = temp;
  3380.            }
  3381.   }
  3382.  
  3383.   /************************************************************************
  3384.   *
  3385.  
  3386.  When this program is run, interaction with it could produce: 
  3387.  
  3388.  Output    Enter letters: 
  3389.  
  3390.  Input     zyfab 
  3391.  
  3392.  Output    The sorted string is:  abfyz 
  3393.  
  3394.  The following program shows a static variable var1, which is defined at file 
  3395.  scope and then declared with the storage class specifier extern. The second 
  3396.  declaration refers to the first definition of var1 and so it has internal 
  3397.  linkage. 
  3398.  
  3399.   static int var1;
  3400.      .
  3401.      .
  3402.      .
  3403.   extern int var1;
  3404.  
  3405.                                                                           *
  3406.   ************************************************************************/
  3407.  
  3408.  
  3409. ΓòÉΓòÉΓòÉ 4.5.3. register Storage Class Specifier ΓòÉΓòÉΓòÉ
  3410.  
  3411. The register storage class specifier indicates to the compiler that a heavily 
  3412. used variable (such as a loop control variable) within a block scope data 
  3413. definition or a parameter declaration should be allocated a register to 
  3414. minimize access time. 
  3415.  
  3416. It is equivalent to the auto storage class except that the compiler places the 
  3417. object, if possible, into a machine register for faster access. 
  3418.  
  3419. Note:  Because the VisualAge C++ compiler optimizes register use, it ignores 
  3420. the register keyword. 
  3421.  
  3422. Most heavily used entities are generated by the compiler itself; therefore, 
  3423. register variables are given no special priority for placement in machine 
  3424. registers. The register storage class keyword is required in a data definition 
  3425. and in a parameter declaration that describes an object having the register 
  3426. storage class. An object having the register storage class specifier must be 
  3427. defined within a block or declared as a parameter to a function. 
  3428.  
  3429. You can initialize any register object except parameters. If you do not 
  3430. initialize an automatic object, its value is indeterminate. If you provide an 
  3431. initial value, the expression representing the initial value can be any valid C 
  3432. or C++ expression. For structure and union members, the initial value must be a 
  3433. valid constant expression if an initializer list is used. The object is then 
  3434. set to that initial value each time the program block that contains the 
  3435. object's definition is entered. 
  3436.  
  3437. Objects with the register storage class specifier have automatic storage 
  3438. duration. Each time a block is entered, storage for register objects defined in 
  3439. that block are made available. When the block is exited, the objects are no 
  3440. longer available for use. 
  3441.  
  3442. If a register object is defined within a function that is recursively invoked, 
  3443. the memory is allocated for the variable at each invocation of the block. 
  3444.  
  3445. The register storage class specifier indicates that the object is heavily used 
  3446. and indicates to the compiler that the value of the object should reside in a 
  3447. machine register. Because of the limited size and number of registers available 
  3448. on most systems, few variables can actually be put in registers. 
  3449.  
  3450. If the compiler does not allocate a machine register for a register object, the 
  3451. object is treated as having the storage class specifier auto. 
  3452.  
  3453. Using register definitions for variables that are heavily used may make your 
  3454. object files smaller and make them run faster. In object code, a reference to a 
  3455. register can require less code and time than a reference to memory. 
  3456.  
  3457. Restrictions 
  3458.  
  3459. You cannot use the register storage class specifier in file scope data 
  3460. declarations. 
  3461.  
  3462. C++ Note: 
  3463.  
  3464. In C programs, you cannot apply the address (&) operator to register variables. 
  3465. However, C++ lets you take the address of an object with the register storage 
  3466. class. For example: 
  3467.  
  3468.    register i;
  3469.    int* b = &i;      // valid in C++, but not in C
  3470.  
  3471. Related Information 
  3472.  
  3473.      Storage Class Specifiers 
  3474.      Block Scope Data Declarations 
  3475.      auto Storage Class Specifier 
  3476.      Address  & 
  3477.  
  3478.  
  3479. ΓòÉΓòÉΓòÉ 4.5.4. static Storage Class Specifier ΓòÉΓòÉΓòÉ
  3480.  
  3481. The static storage class specifier lets you define objects with static storage 
  3482. duration and internal linkage, or to define functions with internal linkage. 
  3483.  
  3484. An object having the static storage class specifier can be defined within a 
  3485. block or at file scope. If the definition occurs within a block, the object has 
  3486. no linkage. If the definition occurs at file scope, the object has internal 
  3487. linkage. 
  3488.  
  3489. You can initialize any static object with a constant expression or an 
  3490. expression that reduces to the address of a previously declared extern or 
  3491. static object, possibly modified by a constant expression. If you do not 
  3492. provide an initial value, the object receives the value of zero of the 
  3493. appropriate type. 
  3494.  
  3495. Storage is allocated at compile time for static variables that are initialized. 
  3496. Uninitialized static variables are mapped at compile time and initialized to 0 
  3497. (zero) at load time. This storage is freed when the program finishes running. 
  3498. Beyond this, the language does not define the order of initialization of 
  3499. objects from different files. 
  3500.  
  3501. Use static variables to declare objects that retain their value from one 
  3502. execution of a block to the next execution of that block. The static storage 
  3503. class specifier keeps the variable from being reinitialized each time the block 
  3504. where the variable is defined runs. For example: 
  3505.  
  3506. static float rate = 10.5;
  3507.  
  3508. Initialization of a static array is performed only once at compile time. The 
  3509. following examples show the initialization of an array of characters and an 
  3510. array of integers: 
  3511.  
  3512. static char message[] = "startup completed";
  3513. static int integers[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  3514.  
  3515. The static storage class specifier causes the variable to be visible only in 
  3516. the file where it is declared. Files, therefore, cannot access file scope 
  3517. static variables declared in other files. 
  3518.  
  3519. C++ Note:  If a local static variable is a class object with constructors and 
  3520. destructors, the object is constructed when control passes through its 
  3521. definition for the first time. If a local class object is created by a 
  3522. constructor, its destructor is called immediately before or as part of the 
  3523. calls of the atexit function. 
  3524.  
  3525. You cannot declare a static function at block scope. 
  3526.  
  3527. Examples of static Storage Class 
  3528.  
  3529. Related Information 
  3530.  
  3531.      Storage Class Specifiers 
  3532.      Block Scope Data Declarations 
  3533.      File Scope Data Declarations 
  3534.      Function Definitions 
  3535.      Function Declarator 
  3536.  
  3537.  
  3538. ΓòÉΓòÉΓòÉ <hidden> Examples of static Storage Class ΓòÉΓòÉΓòÉ
  3539.  
  3540. /************************************************************************
  3541. *
  3542.  
  3543. The following program shows the linkage of static identifiers at file scope. 
  3544. This program uses two different external static identifiers named stat_var. The 
  3545. first definition occurs in file 1. The second definition occurs in file 2. The 
  3546. main function references the object defined in file 1. The var_print function 
  3547. references the object defined in file 2: 
  3548.  
  3549. File 1 
  3550.  
  3551.                                                                         *
  3552. ************************************************************************/
  3553.  
  3554. /************************************************************************
  3555. ** Program to illustrate file scope static variables                   **
  3556. ************************************************************************/
  3557.  
  3558. #include <stdio.h>
  3559.  
  3560. extern void var_print(void);
  3561. static stat_var = 1;
  3562.  
  3563. int main(void)
  3564. {
  3565.    printf("file1 stat_var = %d\n", stat_var);
  3566.    var_print();
  3567.    printf("FILE1 stat_var = %d\n", stat_var);
  3568.  
  3569.    return(0);
  3570. }
  3571.  
  3572. /************************************************************************
  3573. *
  3574.  
  3575. File 2 
  3576.  
  3577.                                                                         *
  3578. ************************************************************************/
  3579.  
  3580. /************************************************************************
  3581. ** This file contains the second definition of stat_var             **
  3582. ************************************************************************/
  3583.  
  3584. #include <stdio.h>
  3585.  
  3586. static int stat_var = 2;
  3587.  
  3588. void var_print(void)
  3589. {
  3590.     printf("file2 stat_var = %d\n", stat_var);
  3591. }
  3592.  
  3593. /************************************************************************
  3594. *
  3595.  
  3596. This program produces the following output: 
  3597.  
  3598. file1 stat_var = 1
  3599. file2 stat_var = 2
  3600. FILE1 stat_var = 1
  3601.  
  3602. The following program shows the linkage of static identifiers with block scope. 
  3603. The function test defines the static variable stat_var, which retains its 
  3604. storage throughout the program, even though test is the only function that can 
  3605. refer to stat_var. 
  3606.  
  3607.                                                                         *
  3608. ************************************************************************/
  3609.  
  3610. /************************************************************************
  3611. ** Program to illustrate block scope static variables                  **
  3612. ************************************************************************/
  3613.  
  3614. #include <stdio.h>
  3615.  
  3616. int main(void)
  3617. {
  3618.    void test(void);
  3619.    int counter;
  3620.    for (counter = 1; counter <= 4; ++counter)
  3621.       test();
  3622.  
  3623.    return(0);
  3624. }
  3625.  
  3626. void test(void)
  3627. {
  3628.    static int stat_var = 0;
  3629.    auto int auto_var = 0;
  3630.    stat_var++;
  3631.    auto_var++;
  3632.    printf("stat_var = %d auto_var = %d\n", stat_var, auto_var);
  3633. }
  3634.  
  3635. /************************************************************************
  3636. *
  3637.  
  3638. This program produces the following output: 
  3639.  
  3640. stat_var = 1 auto_var = 1
  3641. stat_var = 2 auto_var = 1
  3642. stat_var = 3 auto_var = 1
  3643. stat_var = 4 auto_var = 1
  3644.  
  3645.                                                                         *
  3646. ************************************************************************/
  3647.  
  3648.  
  3649. ΓòÉΓòÉΓòÉ 4.6. Function Specifiers ΓòÉΓòÉΓòÉ
  3650.  
  3651. The function specifiers inline and virtual are used only in function 
  3652. declarations, which are described in Function Declarations. 
  3653.  
  3654. The function specifier inline is used to make a suggestion to the compiler to 
  3655. incorporate the code of a function into the code at the point of the call. For 
  3656. more information, see C++ Inline Functions. 
  3657.  
  3658. The function specifier virtual can only be used in nonstatic member function 
  3659. declarations. For more information, see Virtual Functions. 
  3660.  
  3661.  
  3662. ΓòÉΓòÉΓòÉ 4.7. References ΓòÉΓòÉΓòÉ
  3663.  
  3664. A C++ reference is an alias or an alternative name for an object. All 
  3665. operations applied to a reference act on the object the reference refers to. 
  3666. The address of a reference is the address of the aliased object. 
  3667.  
  3668. A reference type is defined by placing the & after the type specifier. You must 
  3669. initialize all references except function parameters when they are defined. 
  3670.  
  3671. Because arguments of a function are passed by value, a function call does not 
  3672. modify the actual values of the arguments. If a function needs to modify the 
  3673. actual value of an argument, the argument must be passed by reference (as 
  3674. opposed to being passed by value). Passing arguments by reference can be done 
  3675. using either references or pointers. In C++, this is accomplished 
  3676. transparently. Unlike C, C++ does not force you to use pointers if you want to 
  3677. pass arguments by reference. For example: 
  3678.  
  3679. int f(int&);
  3680. void main()
  3681. {
  3682.       extern int i;
  3683.       f(i);
  3684. }
  3685.  
  3686. You cannot tell from the function call f(i) that the argument is being passed 
  3687. by reference. 
  3688.  
  3689. References to NULL are not allowed. 
  3690.  
  3691. Additional information is provided on Initializing References. 
  3692.  
  3693. Related Information 
  3694.  
  3695.      Passing Arguments by Reference 
  3696.      Pointers 
  3697.      Declarators 
  3698.      Initializers 
  3699.  
  3700.  
  3701. ΓòÉΓòÉΓòÉ <hidden> Initializing References ΓòÉΓòÉΓòÉ
  3702.  
  3703. The object that you use to initialize a reference must be of the same type as 
  3704. the reference, or it must be of a type that is convertible to the reference 
  3705. type. If you initialize a reference to a constant using an object that requires 
  3706. conversion, a temporary object is created. In the following example, a 
  3707. temporary object of type float is created: 
  3708.  
  3709. int i;
  3710. const float& f = i; // reference to a constant float
  3711.  
  3712. Attempting to initialize a nonconstant reference with an object that requires a 
  3713. conversion is an error. 
  3714.  
  3715. Once a reference has been initialized, it cannot be modified to refer to 
  3716. another object. For example: 
  3717.  
  3718. int num1 = 10;
  3719. int num2 = 20;
  3720.  
  3721. int &RefOne = num1;         // valid
  3722. int &RefOne = num2;         // error, two definitions of RefOne
  3723. RefOne = num2;              // assign num2 to num1
  3724. int &RefTwo;                // error, uninitialized reference
  3725. int &RefTwo = num2;         // valid
  3726.  
  3727. Note that the initialization of a reference is not the same as an assignment to 
  3728. a reference. Initialization operates on the actual reference by initializing 
  3729. the reference with the object it is an alias for. Assignment operates through 
  3730. the reference on the object referred to. 
  3731.  
  3732. A reference can be declared without an initializer: 
  3733.  
  3734.      When it is used in an argument declaration 
  3735.      In the declaration of a return type for a function call 
  3736.      In the declaration of class member within its class declaration 
  3737.      When the extern specifier is explicitly used. 
  3738.  
  3739.  You cannot have references to references, references to bit fields, arrays of 
  3740.  references, or pointers to references. Additional information is provided on 
  3741.  Initializing References. 
  3742.  
  3743.  Related Information 
  3744.  
  3745.      Passing Arguments by Reference 
  3746.      Pointers 
  3747.      Declarators 
  3748.      Initializers 
  3749.      Temporary Objects 
  3750.  
  3751.  
  3752. ΓòÉΓòÉΓòÉ 4.8. Initializers ΓòÉΓòÉΓòÉ
  3753.  
  3754. An initializer is an optional part of a data declaration that specifies an 
  3755. initial value of a data object. 
  3756.  
  3757. Syntax of an Initializer 
  3758.  
  3759. The initializer consists of the = symbol followed by an initial expression or a 
  3760. braced list of initial expressions separated by commas. The number of 
  3761. initializers must not be more than the number of elements to be initialized. An 
  3762. initializer list with fewer initializers than elements, can end with a comma, 
  3763. indicating that the rest of the uninitialized elements are initialized to zero. 
  3764. The initial expression evaluates to the first value of the data object. 
  3765.  
  3766. To assign a value to a scalar object, use the simple initializer: = expression. 
  3767. For example, the following data definition uses the initializer = 3 to set the 
  3768. initial value of group to 3: 
  3769.  
  3770. int group = 3;
  3771.  
  3772. For unions, structures, and aggregate classes (classes with no constructors, 
  3773. base classes, virtual functions, or private or protected members), the set of 
  3774. initial expressions must be enclosed in { } (braces) unless the initializer is 
  3775. a string literal. 
  3776.  
  3777. If the initializer of a character string is a string literal, the { } are 
  3778. optional. Individual expressions must be separated by commas, and groups of 
  3779. expressions can be enclosed in braces and separated by commas. 
  3780.  
  3781. In an array, structure, or union initialized using a brace-enclosed initializer 
  3782. list, any members or subscripts that are not initialized are implicitly 
  3783. initialized to zero of the appropriate type. 
  3784.  
  3785. The initialization properties of each data type are described in the section 
  3786. for that data type. 
  3787.  
  3788. Note: 
  3789.  
  3790.    1. An initializer of the form (expression) can be used to initialize 
  3791.       fundamental types in C++. For example, the following two initializations 
  3792.       are identical: 
  3793.  
  3794.             int group = 3;
  3795.             int group(3);
  3796.  
  3797.    2. You can also use the (expression) form to initialize C++ classes. For 
  3798.       more information on initializing classes, see Initialization by 
  3799.       Constructor. 
  3800.  
  3801.    3. You can initialize variables at file scope with nonconstant expressions. 
  3802.       This is not allowed in ISO/ANSI C. 
  3803.  
  3804.    4. If your code jumps over declarations that contain initializations, the 
  3805.       compiler generates an error. For example, the following code is not valid 
  3806.       in C++: 
  3807.  
  3808.             goto skiplabel;    // error - jumped over declaration
  3809.             int i = 3;         //   and initialization of i
  3810.  
  3811.             skiplabel: i = 4;
  3812.  
  3813.    5. You can initialize classes in external, static, and automatic 
  3814.       definitions. The initializer contains an = (equal sign) followed by a 
  3815.       brace-enclosed, comma-separated list of values. You do not need to 
  3816.       initialize all members of a class. 
  3817.  
  3818.  In the following example, only the first eight elements of the array grid are 
  3819.  explicitly initialized. The remaining four elements that are not explicitly 
  3820.  initialized are initialized as if they were explicitly initialized to zero. 
  3821.  
  3822.   static short grid[3] [4] = {0, 0, 0, 1, 0, 0, 1, 1};
  3823.  
  3824.  The initial values of grid are: 
  3825.  
  3826.  Element               Value 
  3827.  grid[0][0]            0 
  3828.  grid[0][1]            0 
  3829.  grid[0][2]            0 
  3830.  grid[0][3]            1 
  3831.  grid[1][0]            0 
  3832.  grid[1][1]            0 
  3833.  grid[1][2]            1 
  3834.  grid[1][3]            1 
  3835.  grid[2][0]            0 
  3836.  grid[2][1]            0 
  3837.  grid[2][2]            0 
  3838.  grid[2][3]            0 
  3839.  
  3840.  Related Information 
  3841.  
  3842.      Block Scope Data Declarations 
  3843.      File Scope Data Declarations 
  3844.      Arrays 
  3845.      Characters 
  3846.      Enumerations 
  3847.      Floating-Point Variables 
  3848.      Integer Variables 
  3849.      Pointers 
  3850.      Structures 
  3851.      Unions 
  3852.  
  3853.  
  3854. ΓòÉΓòÉΓòÉ <hidden> Initializer Syntax ΓòÉΓòÉΓòÉ
  3855.  
  3856. An initializer has the form: 
  3857.  
  3858.     ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  3859.            Γöé
  3860. >>ΓöÇΓöÇΓö¼ΓöÇ(ΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  3861.   ΓööΓöÇ=ΓöÇΓöÇΓö¼ΓöÇexpressionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  3862.      Γöé    ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ         Γöé
  3863.      Γöé           Γöé         Γöé
  3864.      ΓööΓöÇ{ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ}ΓöÇΓöÿ
  3865.        Γöé ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  3866.        Γöé Γöé   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé Γöé
  3867.        Γöé           Γöé   Γöé Γöé
  3868.        ΓööΓöÇΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓö┤ΓöÇΓöÿ
  3869.  
  3870. The form (expression) is allowed in C++ only. 
  3871.  
  3872.  
  3873. ΓòÉΓòÉΓòÉ 4.9. Type Specifiers ΓòÉΓòÉΓòÉ
  3874.  
  3875. Type specifiers indicate the type of the object or function being declared. The 
  3876. fundamental data types are: 
  3877.  
  3878.      Characters 
  3879.      Floating-Point Variables 
  3880.      Integer Variables 
  3881.      Enumerations 
  3882.      void Type 
  3883.  
  3884.  From these types, you can derive: 
  3885.  
  3886.      Pointers 
  3887.      Arrays 
  3888.      Structures 
  3889.      Unions 
  3890.      Functions 
  3891.  
  3892.  The integral types are char, wchar_t (C++ only), and int of all sizes. 
  3893.  Floating-point numbers can have types float, double, or long double. Integral 
  3894.  and floating-point types are collectively called arithmetic types. In C++ 
  3895.  only, you can also derive the following: 
  3896.  
  3897.      References 
  3898.      Classes 
  3899.      Pointers to Members 
  3900.  
  3901.  In C++, enumerations are not an integral type, but they can be subject to 
  3902.  integral promotion, as described in Integral Promotions. 
  3903.  
  3904.  You can give names to both fundamental and derived types by using the typedef 
  3905.  specifier. 
  3906.  
  3907.  
  3908. ΓòÉΓòÉΓòÉ 4.9.1. Characters ΓòÉΓòÉΓòÉ
  3909.  
  3910. There are three character data types: char, signed char, and unsigned char. 
  3911. These three data types are not compatible. 
  3912.  
  3913. The character data types provide enough storage to hold any member of the 
  3914. character set used at run time. The amount of storage allocated for a char is 
  3915. implementation-dependent. The VisualAge C++ compiler represents a character by 
  3916. 8 bits, as defined in the CHAR_BIT macro in the <limits.h> header. 
  3917.  
  3918. The default character type behaves like an unsigned char. To change this 
  3919. default, use #pragma chars or the /J compiler option. 
  3920.  
  3921. If it does not matter whether a char data object is signed or unsigned, you can 
  3922. declare the object as having the data type char;  otherwise, explicitly declare 
  3923. signed char or unsigned char. When a char (signed or unsigned) is widened to an 
  3924. int, its value is preserved. 
  3925.  
  3926. To declare a data object having a character type, use a char type specifier. 
  3927.  
  3928. The declarator for a simple character declaration is an identifier. You can 
  3929. initialize a simple character with a character constant or with an expression 
  3930. that evaluates to an integer. 
  3931.  
  3932. Use the char specifier in variable definitions to define such variables as: 
  3933. arrays of characters, pointers to characters, and arrays of pointers to 
  3934. characters. Use signed char or unsigned char to declare numeric variables that 
  3935. occupy a single byte. 
  3936.  
  3937. C++ Note:  For the purposes of distinguishing overloaded functions, a C++ char 
  3938. is a distinct type from signed char and unsigned char. 
  3939.  
  3940. Examples of Character Data Types 
  3941.  
  3942. Related Information 
  3943.  
  3944.      Arrays 
  3945.      Pointers 
  3946.      Character Constants 
  3947.      Assignment Expressions 
  3948.      Declarators 
  3949.      Initializers 
  3950.  
  3951.  
  3952. ΓòÉΓòÉΓòÉ <hidden> Examples of Character Data Types ΓòÉΓòÉΓòÉ
  3953.  
  3954. The following example defines the identifier end_of_string as a constant object 
  3955. of type char having the initial value \0 (the null character): 
  3956.  
  3957. const char end_of_string = '\0';
  3958.  
  3959. The following example defines the unsigned char variable switches as having the 
  3960. initial value 3: 
  3961.  
  3962. unsigned char switches = 3;
  3963.  
  3964. The following example defines string_pointer as a pointer to a character: 
  3965.  
  3966. char *string_pointer;
  3967.  
  3968. The following example defines name as a pointer to a character.  After 
  3969. initialization, name points to the first letter in the character string 
  3970. "Johnny": 
  3971.  
  3972. char *name = "Johnny";
  3973.  
  3974. The following example defines a one-dimensional array of pointers to 
  3975. characters.  The array has three elements.  Initially they are a pointer to the 
  3976. string "Venus", a pointer to "Jupiter", and a pointer to "Saturn": 
  3977.  
  3978. static char *planets[ ] = { "Venus", "Jupiter", "Saturn" };
  3979.  
  3980.  
  3981. ΓòÉΓòÉΓòÉ 4.9.2. Floating-Point Variables ΓòÉΓòÉΓòÉ
  3982.  
  3983. There are three types of floating-point variables: float, double, and long 
  3984. double. 
  3985.  
  3986. The amount of storage allocated for a float, a double, or a long double is 
  3987. implementation-dependent. On all compilers, the storage size of a float 
  3988. variable is less than or equal to the storage size of a double variable. 
  3989.  
  3990. The VisualAge C++ compiler allocates the following storage for floating-point 
  3991. types: 
  3992.  
  3993.      4 bytes for a float 
  3994.      8 bytes for a double 
  3995.      16 bytes for a long double, of which only the first 10 bytes are 
  3996.       significant. 
  3997.  
  3998.  For more information about compiler options and the VisualAge C++ 
  3999.  implementation of floating-point types, see the IBM VisualAge C++ for OS/2 
  4000.  User's Guide and Reference. 
  4001.  
  4002.  To declare a data object having a floating-point type, use the float 
  4003.  specifier. 
  4004.  
  4005.  The declarator for a simple floating-point declaration is an identifier. 
  4006.  Initialize a simple floating-point variable with a float constant or with a 
  4007.  variable or expression that evaluates to an integer or floating-point number. 
  4008.  The storage class of a variable determines how you initialize the variable. 
  4009.  
  4010.  Examples of Floating-Point Data Types 
  4011.  
  4012.  Related Information 
  4013.  
  4014.      Floating-Point Constants 
  4015.      <float.h> 
  4016.      Assignment Expressions 
  4017.      Integer Variables 
  4018.      Declarators 
  4019.      Initializers 
  4020.  
  4021.  
  4022. ΓòÉΓòÉΓòÉ <hidden> Examples of Floating-Point Data Types ΓòÉΓòÉΓòÉ
  4023.  
  4024. The following example defines the identifier pi as an object of type double: 
  4025.  
  4026. double pi;
  4027.  
  4028. The following example defines the float variable real_number with the initial 
  4029. value 100.55: 
  4030.  
  4031. static float real_number = 100.55f;
  4032.  
  4033. The following example defines the float variable float_var with the initial 
  4034. value 0.0143: 
  4035.  
  4036. float float_var = 1.43e-2f;
  4037.  
  4038. The following example declares the long double variable maximum: 
  4039.  
  4040. extern long double maximum;
  4041.  
  4042. The following example defines the array table with 20 elements of type double: 
  4043.  
  4044. double table[20];
  4045.  
  4046.  
  4047. ΓòÉΓòÉΓòÉ 4.9.3. Integer Variables ΓòÉΓòÉΓòÉ
  4048.  
  4049. There are six categories of integer variables: 
  4050.  
  4051.      short int or short or signed short int or signed short 
  4052.      signed int or int 
  4053.      long int or long or signed long int or signed long 
  4054.      unsigned short int or unsigned short 
  4055.      unsigned or unsigned int 
  4056.      unsigned long int or unsigned long 
  4057.  
  4058.  The default integer type for a bit field is unsigned. 
  4059.  
  4060.  The amount of storage allocated for an int, a short, or a long is 
  4061.  implementation-dependent. 
  4062.  
  4063.  Two sizes of integer data types are provided. Objects having type short are 2 
  4064.  bytes of storage long. Objects having type long are 4 bytes of storage long. 
  4065.  An int represents the most efficient data storage size on the system (the 
  4066.  word-size of the machine) and receives 4 bytes of storage. 
  4067.  
  4068.  For more information about the VisualAge C++ implementation of integer types, 
  4069.  see the IBM VisualAge C++ for OS/2 User's Guide and Reference. 
  4070.  
  4071.  The unsigned prefix indicates that the object is a nonnegative integer. Each 
  4072.  unsigned type provides the same size storage as its signed equivalent. For 
  4073.  example, int reserves the same storage as unsigned int. Because a signed type 
  4074.  reserves a sign bit, an unsigned type can hold a larger positive integer than 
  4075.  the equivalent signed type. 
  4076.  
  4077.  To declare a data object having an integer data type, use an int type 
  4078.  specifier. 
  4079.  
  4080.  The declarator for a simple integer definition or declaration is an 
  4081.  identifier. You can initialize a simple integer definition with an integer 
  4082.  constant or with an expression that evaluates to a value that can be assigned 
  4083.  to an integer. The storage class of a variable determines how you can 
  4084.  initialize the variable. 
  4085.  
  4086.  C++ Note:  When the arguments in overloaded functions and overloaded operators 
  4087.  are integer types, two integer types that both come from the same group are 
  4088.  not treated as distinct types. For example, you cannot overload an int 
  4089.  argument against a signed int argument. Overloading and argument matching is 
  4090.  described in C++ Overloading. 
  4091.  
  4092.  Examples of Integer Data Types 
  4093.  
  4094.  Related Information 
  4095.  
  4096.      Integer Constants 
  4097.      Decimal Constants 
  4098.      Octal Constants 
  4099.      Hexadecimal Constants 
  4100.      Declarators 
  4101.      Initializers 
  4102.  
  4103.  
  4104. ΓòÉΓòÉΓòÉ <hidden> Examples of Integer Data Types ΓòÉΓòÉΓòÉ
  4105.  
  4106. The following example defines the short int variable flag: 
  4107.  
  4108. short int flag;
  4109.  
  4110. The following example defines the int variable result: 
  4111.  
  4112. int result;
  4113.  
  4114. The following example defines the unsigned long int variable ss_number as 
  4115. having the initial value 438888834: 
  4116.  
  4117. unsigned long ss_number = 438888834ul;
  4118.  
  4119. The following example defines the identifier sum as an object of type int. The 
  4120. initial value of sum is the result of the expression a + b: 
  4121.  
  4122. extern int a, b;
  4123. auto sum  = a + b;
  4124.  
  4125.  
  4126. ΓòÉΓòÉΓòÉ 4.9.4. Enumerations ΓòÉΓòÉΓòÉ
  4127.  
  4128. An enumeration data type represents a set of values that you declare. You can 
  4129. define an enumeration data type and all variables that have that enumeration 
  4130. type in one statement, or you can declare an enumeration type separately from 
  4131. the definition of variables of that type. The identifier associated with the 
  4132. data type (not an object) is called an enumeration tag. 
  4133.  
  4134. C++ Note:  In C, an enumeration has an implementation-defined integral type. 
  4135. This restriction does not apply to C++. In C++, an enumeration has a distinct 
  4136. type that does not have to be integral. 
  4137.  
  4138. An enumeration type declaration contains the enum keyword followed by an 
  4139. optional identifier (the enumeration tag) and a brace-enclosed list of 
  4140. enumerators. Commas separate each enumerator. 
  4141.  
  4142. Syntax of an Enumeration 
  4143.  
  4144. The keyword enum, followed by the identifier, names the data type (like the tag 
  4145. on a struct data type). The list of enumerators provides the data type with a 
  4146. set of values. 
  4147.  
  4148. C++ Note:  In C, each enumerator represents an integer value. In C++, each 
  4149. enumerator represents a value that can be converted to an integral value. 
  4150.  
  4151. To conserve space, enumerations may be stored in spaces smaller than that of an 
  4152. int. By default, the type of the enum variable is the size of the smallest 
  4153. integral type that can contain all enumerator values. You can change the 
  4154. default using the /Su option, described in the IBM VisualAge C++ for OS/2 
  4155. User's Guide and Reference. 
  4156.  
  4157. When you define an enumeration data type, you specify a set of identifiers that 
  4158. the data type represents. Each identifier in this set is an enumeration 
  4159. constant. 
  4160.  
  4161. The value of the constant is determined in the following way: 
  4162.  
  4163.    1. An equal sign (=) and a constant expression after the enumeration 
  4164.       constant gives an explicit value to the constant. The identifier 
  4165.       represents the value of the constant expression. 
  4166.  
  4167.    2. If no explicit value is assigned, the leftmost constant in the list 
  4168.       receives the value zero (0). 
  4169.  
  4170.    3. Identifiers with no explicitly assigned values receive the integer value 
  4171.       that is one greater than the value represented by the previous 
  4172.       identifier. 
  4173.  
  4174.  In C, enumeration constants have type int. 
  4175.  
  4176.  In C++, each enumeration constant has a value that can be promoted to a signed 
  4177.  or unsigned integer value and a distinct type that does not have to be 
  4178.  integral. Use an enumeration constant anywhere an integer constant is allowed, 
  4179.  or for C++, anywhere a value of the enumeration type is allowed. 
  4180.  
  4181.  Each enumeration constant must be unique within the scope in which the 
  4182.  enumeration is defined. It is possible to associate the same integer with two 
  4183.  different enumeration constants. 
  4184.  
  4185.  Additional information is provided on: 
  4186.  
  4187.      Defining Enumeration Variables 
  4188.      Defining Enumeration Types and Objects 
  4189.      Example Program Using Enumeration Types 
  4190.  
  4191.  Examples of Enumeration Types and Constants 
  4192.  
  4193.  Related Information 
  4194.  
  4195.      Constant Expressions 
  4196.      Identifiers 
  4197.      Declarators 
  4198.      Initializers 
  4199.  
  4200.  
  4201. ΓòÉΓòÉΓòÉ <hidden> Enumeration Syntax ΓòÉΓòÉΓòÉ
  4202.  
  4203. An enumeration type declaration has the form: 
  4204.  
  4205.                ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  4206.                       Γöé
  4207. >>ΓöÇΓöÇenumΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇenumeratorΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ;ΓöÇΓöÇ><
  4208.      ΓööΓöÇidentifierΓöÇΓöÿ
  4209.  
  4210. An enumerator has the form: 
  4211.  
  4212. >>ΓöÇΓöÇidentifierΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  4213.         ΓööΓöÇ=ΓöÇΓöÇintegral_constant_expressionΓöÇΓöÿ
  4214.  
  4215.  
  4216. ΓòÉΓòÉΓòÉ <hidden> Examples of Enumeration Types and Constants ΓòÉΓòÉΓòÉ
  4217.  
  4218. In the following example, the declarations of average on line 4 and of poor on 
  4219. line 5 cause compiler error messages: 
  4220.  
  4221.  1   func()
  4222.  2   {
  4223.  3      enum score { poor, average, good };
  4224.  4      enum rating { below, average, above };
  4225.  5      int poor;
  4226.  6   }
  4227.  
  4228. The following data type declarations list oats, wheat, barley, corn, and rice 
  4229. as enumeration constants. The number under each constant shows the integer 
  4230. value. 
  4231.  
  4232. enum grain { oats, wheat, barley, corn, rice };
  4233.    /*         0      1      2      3     4         */
  4234.  
  4235. enum grain { oats=1, wheat, barley, corn, rice };
  4236.    /*         1        2      3      4     5       */
  4237.  
  4238. enum grain { oats, wheat=10, barley, corn=20, rice };
  4239.    /*          0     10        11     20       21  */
  4240.  
  4241. It is possible to associate the same integer with two different enumeration 
  4242. constants. For example, the following definition is valid. The identifiers 
  4243. suspend and hold have the same integer value. 
  4244.  
  4245. enum status { run, clear=5, suspend, resume, hold=6 };
  4246.    /*          0      5        6       7       6       */
  4247.  
  4248. The following example is a different declaration of the enumeration tag status: 
  4249.  
  4250. enum status { run, create, clear=5, suspend };
  4251.    /*          0     1        5       6             */
  4252.  
  4253.  
  4254. ΓòÉΓòÉΓòÉ 4.9.4.1. Defining Enumeration Variables ΓòÉΓòÉΓòÉ
  4255.  
  4256. An enumeration variable definition contains an optional storage class 
  4257. specifier, a type specifier, a declarator, and an optional initializer. The 
  4258. type specifier contains the keyword enum followed by the name of the 
  4259. enumeration data type. You must declare the enumeration data type before you 
  4260. can define a variable having that type. 
  4261.  
  4262. The initializer for an enumeration variable contains the = symbol followed by 
  4263. an expression. 
  4264.  
  4265. In C, the initializer expression must evaluate to an int value. In C++, the 
  4266. initializer must be have the same type as the associated enumeration type 
  4267.  
  4268. The first line of the following example declares the enumeration tag grain. The 
  4269. second line defines the variable g_food and gives g_food the initial value of 
  4270. barley (2). 
  4271.  
  4272. enum grain { oats, wheat, barley, corn, rice };
  4273. enum grain g_food = barley;
  4274.  
  4275. In C, the type specifier enum grain indicates that the value of g_food is a 
  4276. member of the enumerated data type grain. In C++, the value of g_food has the 
  4277. enumerated data type grain. 
  4278.  
  4279. C++ also makes the enum keyword optional in an initialization expression like 
  4280. the one in the second line of the preceding example. For example, both of the 
  4281. following statements are valid C++ code: 
  4282.  
  4283. enum grain g_food = barley;
  4284.      grain cob_food = corn;
  4285.  
  4286.  
  4287. ΓòÉΓòÉΓòÉ 4.9.4.2. Defining Enumeration Types and Objects ΓòÉΓòÉΓòÉ
  4288.  
  4289. You can define a type and a variable in one statement by using a declarator and 
  4290. an optional initializer after the type definition. To specify a storage class 
  4291. specifier for the variable, you must put the storage class specifier at the 
  4292. beginning of the declaration. For example: 
  4293.  
  4294. register enum score { poor=1, average, good } rating = good;
  4295.  
  4296. C++ also lets you put the storage class immediately before the declarator. For 
  4297. example: 
  4298.  
  4299. enum score { poor=1, average, good } register rating = good;
  4300.  
  4301. Either of these examples is equivalent to the following two declarations: 
  4302.  
  4303. enum score { poor=1, average, good };
  4304. register enum score rating = good;
  4305.  
  4306. Both examples define the enumeration data type score and the variable rating. 
  4307. rating has the storage class specifier register, the data type enum score, and 
  4308. the initial value good. 
  4309.  
  4310. Combining a data type definition with the definitions of all variables having 
  4311. that data type lets you leave the data type unnamed. For example: 
  4312.  
  4313. enum { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
  4314.       Saturday } weekday;
  4315.  
  4316. defines the variable weekday, which can be assigned any of the specified 
  4317. enumeration constants. 
  4318.  
  4319.  
  4320. ΓòÉΓòÉΓòÉ 4.9.4.3. Example Program Using Enumerations ΓòÉΓòÉΓòÉ
  4321.  
  4322. /**********************************************************************************
  4323. *
  4324. The following program receives an integer as input. The output is a sentence 
  4325. that gives the French name for the weekday that is associated with the integer. 
  4326. If the integer is not associated with a weekday, the program prints "C'est le 
  4327. mauvais jour." 
  4328.  
  4329.                                                                         *
  4330. ************************************************************************/
  4331.  
  4332. /**
  4333.  ** Example program using enumerations
  4334.  **/
  4335.  
  4336. #include <stdio.h>
  4337.  
  4338. enum days {
  4339.             Monday=1, Tuesday, Wednesday,
  4340.             Thursday, Friday, Saturday, Sunday
  4341.           } weekday;
  4342.  
  4343. void french(enum days);
  4344.  
  4345. int main(void)
  4346. {
  4347.    int num;
  4348.  
  4349.    printf("Enter an integer for the day of the week.  "
  4350.           "Mon=1,...,Sun=7\n");
  4351.    scanf("%d", &num);
  4352.    weekday=num;
  4353.    french(weekday);
  4354.    return(0);
  4355. }
  4356. void french(enum days weekday)
  4357. {
  4358.    switch (weekday)
  4359.    {
  4360.       case Monday:
  4361.          printf("Le jour de la semaine est lundi.\n");
  4362.          break;
  4363.       case Tuesday:
  4364.          printf("Le jour de la semaine est mardi.\n");
  4365.          break;
  4366.       case Wednesday:
  4367.          printf("Le jour de la semaine est mercredi.\n");
  4368.          break;
  4369.       case Thursday:
  4370.          printf("Le jour de la semaine est jeudi.\n");
  4371.          break;
  4372.       case Friday:
  4373.          printf("Le jour de la semaine est vendredi.\n");
  4374.          break;
  4375.       case Saturday:
  4376.          printf("Le jour de la semaine est samedi.\n");
  4377.          break;
  4378.       case Sunday:
  4379.          printf("Le jour de la semaine est dimanche.\n");
  4380.          break;
  4381.       default:
  4382.          printf("C'est le mauvais jour.\n");
  4383.    }
  4384. }
  4385.  
  4386.  
  4387. ΓòÉΓòÉΓòÉ 4.9.5. Pointers ΓòÉΓòÉΓòÉ
  4388.  
  4389. A pointer type variable holds the address of a data object or a function. A 
  4390. pointer can refer to an object of any one data type except to a bit field or a 
  4391. reference. Additionally, in C, a pointer cannot point to an object with the 
  4392. register storage class. Some common uses for pointers are: 
  4393.  
  4394.      To access dynamic data structures such as linked lists, trees, and 
  4395.       queues. 
  4396.      To access elements of an array or members of a structure or C++ class. 
  4397.      To access an array of characters as a string. 
  4398.      To pass the address of a variable to a function. (In C++, you can also 
  4399.       use a reference to do this.) By referencing a variable through its 
  4400.       address, a function can change the contents of that variable. Calling 
  4401.       Functions and Passing Arguments describes passing arguments by reference. 
  4402.  
  4403.  The following example declares pcoat as a pointer to an object having type 
  4404.  long: 
  4405.  
  4406.   extern long *pcoat;
  4407.  
  4408.  If the keyword volatile appears before the *, the declarator describes a 
  4409.  pointer to a volatile object. If the keyword volatile comes between the * and 
  4410.  the identifier, the declarator describes a volatile pointer. The keyword const 
  4411.  operates in the same manner as the volatile keyword. 
  4412.  
  4413.  Examples of Pointer Declarations 
  4414.  
  4415.  Additional information is provided on: 
  4416.  
  4417.      Assigning Pointers 
  4418.      Initializing Pointers 
  4419.      Restrictions on Pointers 
  4420.      Using Pointers 
  4421.      Pointer Arithmetic 
  4422.      Example Program Using Pointers 
  4423.  
  4424.  Related Information 
  4425.  
  4426.      Address  & 
  4427.      Indirection  * 
  4428.      _Seg16 Type Qualifier 
  4429.      References 
  4430.      Declarators 
  4431.      volatile and const Qualifiers 
  4432.      Initializers 
  4433.  
  4434.  
  4435. ΓòÉΓòÉΓòÉ <hidden> Examples of Pointer Declarations ΓòÉΓòÉΓòÉ
  4436.  
  4437. In the following example, pvolt is a constant pointer to an object having type 
  4438. short: 
  4439.  
  4440. short * const pvolt;
  4441.  
  4442. The following example declares pnut as a pointer to an int object having the 
  4443. volatile qualifier: 
  4444.  
  4445. extern int volatile *pnut;
  4446.  
  4447. The following example defines psoup as a volatile pointer to an object having 
  4448. type float: 
  4449.  
  4450. float * volatile psoup;
  4451.  
  4452. The following example defines pfowl as a pointer to an enumeration object of 
  4453. type bird: 
  4454.  
  4455. enum bird *pfowl;
  4456.  
  4457. The next example declares pvish as a pointer to a function that takes no 
  4458. parameters and returns a char object: 
  4459.  
  4460. char (*pvish)(void);
  4461.  
  4462.  
  4463. ΓòÉΓòÉΓòÉ 4.9.5.1. Assigning Pointers ΓòÉΓòÉΓòÉ
  4464.  
  4465. When you use pointers in an assignment operation, you must ensure that the 
  4466. types of the pointers in the operation are compatible. 
  4467.  
  4468. The following example shows compatible declarations for the assignment 
  4469. operation: 
  4470.  
  4471.    float subtotal;
  4472.    float * sub_ptr;
  4473.          .
  4474.          .
  4475.          .
  4476.    sub_ptr = &subtotal;
  4477.    printf("The subtotal is %f\n", *sub_ptr);
  4478.  
  4479. The next example shows incompatible declarations for the assignment operation: 
  4480.  
  4481.    double league;
  4482.    int * minor;
  4483.          .
  4484.          .
  4485.          .
  4486.    minor = &league;     /* error */
  4487.  
  4488.  
  4489. ΓòÉΓòÉΓòÉ 4.9.5.2. Initializing Pointers ΓòÉΓòÉΓòÉ
  4490.  
  4491. The initializer is an = (equal sign) followed by the expression that represents 
  4492. the address that the pointer is to contain. The following example defines the 
  4493. variables time and speed as having type double and amount as having type 
  4494. pointer to a double. The pointer amount is initialized to point to total: 
  4495.  
  4496. double total, speed, *amount = &total;
  4497.  
  4498. The compiler converts an unsubscripted array name to a pointer to the first 
  4499. element in the array. You can assign the address of the first element of an 
  4500. array to a pointer by specifying the name of the array. The following two sets 
  4501. of definitions are equivalent. Both define the pointer student and initialize 
  4502. student to the address of the first element in section: 
  4503.  
  4504. int section[80];
  4505. int *student = section;
  4506.  
  4507. is equivalent to: 
  4508.  
  4509. int section[80];
  4510. int *student = §ion[0];
  4511.  
  4512. You can assign the address of the first character in a string constant to a 
  4513. pointer by specifying the string constant in the initializer. 
  4514.  
  4515. The following example defines the pointer variable string and the string 
  4516. constant "abcd". The pointer string is initialized to point to the character a 
  4517. in the string "abcd". 
  4518.  
  4519. char *string = "abcd";
  4520.  
  4521. The following example defines weekdays as an array of pointers to string 
  4522. constants. Each element points to a different string. The pointer weekdays[2], 
  4523. for example, points to the string "Tuesday". 
  4524.  
  4525. static char *weekdays[ ] =
  4526.             {
  4527.               "Sunday", "Monday", "Tuesday", "Wednesday",
  4528.               "Thursday", "Friday", "Saturday"
  4529.             };
  4530.  
  4531. A pointer can also be initialized to NULL using any integer constant expression 
  4532. that evaluates to 0, for example char * a=0;. Such a pointer is a NULL pointer. 
  4533. It does not point to any object. 
  4534.  
  4535.  
  4536. ΓòÉΓòÉΓòÉ 4.9.5.3. Restrictions on Pointers ΓòÉΓòÉΓòÉ
  4537.  
  4538. You cannot use pointers to reference bit fields or objects having the register 
  4539. storage class specifier. 
  4540.  
  4541. A pointer to a packed structure or union is incompatible with a pointer to a 
  4542. corresponding nonpacked structure or union because packed and nonpacked objects 
  4543. have different memory layouts. As a result, comparisons and assignments between 
  4544. pointers to packed and nonpacked objects are not valid. 
  4545.  
  4546. You can, however, perform these assignments and comparisons with type casts. In 
  4547. the following example: 
  4548.  
  4549. int main(void)
  4550. {
  4551.    _Packed struct ss *ps1;
  4552.    struct ss         *ps2;
  4553.       .
  4554.       .
  4555.       .
  4556.    ps1 = (_Packed struct ss *)ps2;
  4557.       .
  4558.       .
  4559.       .
  4560. }
  4561.  
  4562. the cast operation lets you compare the two pointers, but you must be aware 
  4563. that ps1 still points to a nonpacked object. For the VisualAge C++ compiler, 
  4564. all pointers that are shared between 32-bit and 16-bit code must be declared 
  4565. with the _Seg16 type qualifier. This includes pointers that are indirectly 
  4566. passed to 16-bit code, such as pointers in structures and pointers that are 
  4567. referenced by pointers directly passed to 16-bit code. 
  4568.  
  4569. For more information, see _Seg16 Type Qualifier and the chapter on "Calling 
  4570. Between 32-Bit and 16-Bit Code" in the IBM VisualAge C++ for OS/2 Programming 
  4571. Guide. 
  4572.  
  4573.  
  4574. ΓòÉΓòÉΓòÉ 4.9.5.4. Using Pointers ΓòÉΓòÉΓòÉ
  4575.  
  4576. Two operators are commonly used in working with pointers, the address (&) 
  4577. operator and the indirection (*) operator. You can use the & operator to refer 
  4578. to the address of an object. For example, the following statement assigns the 
  4579. address of x to the variable p_to_x. The variable p_to_x has been defined as a 
  4580. pointer. 
  4581.  
  4582. int x, *p_to_x;
  4583.  
  4584. p_to_x = &x;
  4585.  
  4586. The * (indirection) operator lets you access the value of the object a pointer 
  4587. refers to. The following statement assigns to y the value of the object that 
  4588. p_to_x points to: 
  4589.  
  4590. float y, *p_to_x;
  4591.   .
  4592.   .
  4593.   .
  4594. y = *p_to_x;
  4595.  
  4596. The following statement assigns the value of y to the variable that *p_to_x 
  4597. references: 
  4598.  
  4599. char y ,
  4600.      *p_to_x,
  4601.   .
  4602.   .
  4603.   .
  4604. *p_to_x = y;
  4605.  
  4606.  
  4607. ΓòÉΓòÉΓòÉ 4.9.5.5. Pointer Arithmetic ΓòÉΓòÉΓòÉ
  4608.  
  4609. You can perform a limited number of arithmetic operations on pointers. These 
  4610. operations are: 
  4611.  
  4612.      Increment and decrement 
  4613.      Addition and subtraction 
  4614.      Comparison 
  4615.      Assignment. 
  4616.  
  4617.  The increment (++) operator increases the value of a pointer by the size of 
  4618.  the data object the pointer refers to. For example, if the pointer refers to 
  4619.  the second element in an array, the ++ makes the pointer refer to the third 
  4620.  element in the array. 
  4621.  
  4622.  The decrement (--) operator decreases the value of a pointer by the size of 
  4623.  the data object the pointer refers to. For example, if the pointer refers to 
  4624.  the second element in an array, the -- makes the pointer refer to the first 
  4625.  element in the array. 
  4626.  
  4627.  You can add a pointer to an integer, but you cannot add a pointer to a 
  4628.  pointer. 
  4629.  
  4630.  If the pointer p points to the first element in an array, the following 
  4631.  expression causes the pointer to point to the third element in the same array: 
  4632.  
  4633.   p = p + 2;
  4634.  
  4635.  If you have two pointers that point to the same array, you can subtract one 
  4636.  pointer from the other. This operation yields the number of elements in the 
  4637.  array that separate the two addresses that the pointers refer to. 
  4638.  
  4639.  You can compare two pointers with the following operators:  ==, !=, <, >, <=, 
  4640.  and >=. See Expressions and Operators for more information on these operators. 
  4641.  
  4642.  Pointer comparisons are defined only when the pointers point to elements of 
  4643.  the same array. Pointer comparisons using the == and != operators can be 
  4644.  performed even when the pointers point to elements of different arrays. 
  4645.  
  4646.  You can assign to a pointer the address of a data object, the value of another 
  4647.  compatible pointer or the NULL pointer. 
  4648.  
  4649.  
  4650. ΓòÉΓòÉΓòÉ 4.9.5.6. Example Program Using Pointers ΓòÉΓòÉΓòÉ
  4651.  
  4652. /************************************************************************
  4653. *
  4654.  
  4655. The following program contains pointer arrays: 
  4656.  
  4657.                                                                         *
  4658. ************************************************************************/
  4659.  
  4660. /********************************************************************
  4661. **   Program to search for the first occurrence of a specified     **
  4662. **   character string in an array of character strings.            **
  4663. ********************************************************************/
  4664.  
  4665. #include <stdio.h>
  4666. #include <stdlib.h>
  4667. #include <string.h>
  4668.  
  4669. #define  SIZE  20
  4670. #define  EXIT_FAILURE 999
  4671.  
  4672. int main(void)
  4673. {
  4674.    static char *names[ ] = { "Jim", "Amy", "Mark", "Sue", NULL };
  4675.    char * find_name(char **, char *);
  4676.    char new_name[SIZE], *name_pointer;
  4677.  
  4678.    printf("Enter name to be searched.\n");
  4679.    scanf("%s", new_name);
  4680.    name_pointer = find_name(names, new_name);
  4681.    printf("name %s%sfound\n", new_name,
  4682.           (name_pointer == NULL) ? " not " : " ");
  4683.    exit(EXIT_FAILURE);
  4684. } /* End of main */
  4685. /********************************************************************
  4686. **     Function find_name.  This function searches an array of     **
  4687. **     names to see if a given name already exists in the array.   **
  4688. **     It returns a pointer to the name or NULL if the name is     **
  4689. **     not found.                                                  **
  4690. **                                                                 **
  4691. ** char **arry is a pointer to arrays of pointers (existing names) **
  4692. ** char *strng is a pointer to character array entered (new name)  **
  4693. ********************************************************************/
  4694.  
  4695. char * find_name(char **arry, char *strng)
  4696. {
  4697.    for (; *arry != NULL; arry++)         /* for each name          */
  4698.    {
  4699.       if (strcmp(*arry, strng) == 0)     /* if strings match       */
  4700.          return(*arry);                  /* found it!              */
  4701.    }
  4702.    return(*arry);                        /* return the pointer     */
  4703. } /* End of find_name */
  4704.  
  4705. /************************************************************************
  4706. *
  4707.  
  4708. Interaction with this program could produce the following sessions: 
  4709.  
  4710.  Output    Enter name to be searched. 
  4711.  
  4712.  Input     Mark 
  4713.  
  4714.  Output    name Mark found 
  4715.  
  4716.  OR: 
  4717.  
  4718.  Output    Enter name to be searched. 
  4719.  
  4720.  Input     Deborah 
  4721.  
  4722.  Output    name Deborah not found 
  4723.  
  4724.                                                                           *
  4725.   ************************************************************************/
  4726.  
  4727.  
  4728. ΓòÉΓòÉΓòÉ 4.9.6. void Type ΓòÉΓòÉΓòÉ
  4729.  
  4730. The void data type always represents an empty set of values. The only object 
  4731. that can be declared with the type specifier void is a pointer. 
  4732.  
  4733. When a function does not return a value, you should use void as the type 
  4734. specifier in the function definition and declaration. An argument list for a 
  4735. function taking no arguments is void. 
  4736.  
  4737. You cannot declare a variable of type void, but you can explicitly convert any 
  4738. expression to type void, but the resulting expression can only be used as one 
  4739. of the following: 
  4740.  
  4741.      An expression statement 
  4742.      The left operand of a comma expression 
  4743.      The second or third operand in a conditional expression. 
  4744.  
  4745.  Example of void Type 
  4746.  
  4747.  Related Information 
  4748.  
  4749.      Cast Expressions 
  4750.      Type Specifiers 
  4751.      Expressions and Operators 
  4752.  
  4753.  
  4754. ΓòÉΓòÉΓòÉ <hidden> Example of void Type ΓòÉΓòÉΓòÉ
  4755.  
  4756. /************************************************************************
  4757. *
  4758.  
  4759. On line 7 of the following example, the function find_max is declared as having 
  4760. type void. Lines 15 through 26 contain the complete definition of find_max. 
  4761.  
  4762. Note:  The use of the sizeof operator in line 13 is a standard method of 
  4763. determining the number of elements in an array. 
  4764.  
  4765.                                                                         *
  4766. ************************************************************************/
  4767.  
  4768.  1   /**
  4769.  2   ** Example of void type
  4770.  3   **/
  4771.  4   #include <stdio.h>
  4772.  5
  4773.  6   /* declaration of function find_max */
  4774.  7   extern void find_max(int x[ ], int j);
  4775.  8
  4776.  9   int main(void)
  4777. 10   {
  4778. 11      static int numbers[ ] = { 99, 54, -102, 89 };
  4779. 12
  4780. 13      find_max(numbers, (sizeof(numbers) / sizeof(numbers[0])));
  4781. 14
  4782. 15      return(0);
  4783. 16   }
  4784. 17
  4785. 18   void find_max(int x[ ], int j)
  4786. 19   { /* begin definition of function find_max */
  4787. 20      int i, temp = x[0];
  4788. 21
  4789. 22      for (i = 1; i < j; i++)
  4790. 23      {
  4791. 24          if (x[i] > temp)
  4792. 25             temp = x[i];
  4793. 26      }
  4794. 27      printf("max number = %d\n", temp);
  4795. 28   } /* end definition of function find_max  */
  4796.  
  4797.  
  4798. ΓòÉΓòÉΓòÉ 4.9.7. Arrays ΓòÉΓòÉΓòÉ
  4799.  
  4800. An array is an ordered group of data objects. Each object is called an element. 
  4801. All elements within an array have the same data type. 
  4802.  
  4803. Use any type specifier in an array definition or declaration. Array elements 
  4804. can be of any data type, except function or, in C++, a reference. You can, 
  4805. however, declare an array of pointers to functions. 
  4806.  
  4807. The array declarator contains an identifier followed by an optional subscript 
  4808. declarator. An identifier preceded by an * (asterisk) is an array of pointers. 
  4809.  
  4810. Syntax of a Subscript Declarator 
  4811.  
  4812. The subscript declarator describes the number of dimensions in the array and 
  4813. the number of elements in each dimension. Each bracketed expression, or 
  4814. subscript, describes a different dimension and must be a constant expression. 
  4815.  
  4816. The following example defines a one-dimensional array that contains four 
  4817. elements having type char: 
  4818.  
  4819. char list[4];
  4820.  
  4821. The first subscript of each dimension is 0. The array list contains the 
  4822. elements: 
  4823.  
  4824. list[0]
  4825. list[1]
  4826. list[2]
  4827. list[3]
  4828.  
  4829. The following example defines a two-dimensional array that contains six 
  4830. elements of type int: 
  4831.  
  4832. int roster[3][2];
  4833.  
  4834. Multidimensional arrays are stored in row-major order. When elements are 
  4835. referred to in order of increasing storage location, the last subscript varies 
  4836. the fastest. For example, the elements of array roster are stored in the order: 
  4837.  
  4838. roster[0][0]
  4839. roster[0][1]
  4840. roster[1][0]
  4841. roster[1][1]
  4842. roster[2][0]
  4843. roster[2][1]
  4844.  
  4845. In storage, the elements of roster would be stored as: 
  4846.  
  4847.  
  4848.  Γöé                Γöé                Γöé
  4849.  Γöö ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ ΓöÇΓöÇΓöÇΓöÇΓöÇ Γö┤ ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ ΓöÇΓöÇΓöÇΓöÇΓöÇ Γö┤ ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ ΓöÇΓöÇΓöÇΓöÇΓöÇ
  4850.                                  
  4851.  Γöé                Γöé                Γöé
  4852.  roster [ 0 ] [ 0 ]     roster [ 0 ] [ 1 ]     roster [ 1 ] [ 0 ]
  4853.  
  4854. You can leave the first (and only the first) set of subscript brackets empty in 
  4855.  
  4856.      Array definitions that contain initializations 
  4857.      extern declarations 
  4858.      Parameter declarations. 
  4859.  
  4860.  In array definitions that leave the first set of subscript brackets empty, the 
  4861.  initializer determines the number of elements in the first dimension. In a 
  4862.  one-dimensional array, the number of initialized elements becomes the total 
  4863.  number of elements. In a multidimensional array, the initializer is compared 
  4864.  to the subscript declarator to determine the number of elements in the first 
  4865.  dimension. 
  4866.  
  4867.  An unsubscripted array name (for example, region instead of region[4]) 
  4868.  represents a pointer whose value is the address of the first element of the 
  4869.  array, provided the array has previously been declared. An unsubscripted array 
  4870.  name with square brackets (for example, region[]) is allowed only when 
  4871.  declaring arrays at file scope or in the argument list of a function 
  4872.  declaration. In declarations, only the first dimension can be left empty; you 
  4873.  must specify the sizes of additional dimensions. 
  4874.  
  4875.  Whenever an array is used in a context (such as a parameter) where it cannot 
  4876.  be used as an array, the identifier is treated as a pointer. The two 
  4877.  exceptions are when an array is used as an operand of the sizeof or the 
  4878.  address (&) operator. 
  4879.  
  4880.  Additional information is provided on: 
  4881.  
  4882.      Initializing Arrays 
  4883.      Example Programs Using Arrays 
  4884.  
  4885.  Related Information 
  4886.  
  4887.      Pointers 
  4888.      Array Subscript [ ] 
  4889.      String Literals 
  4890.      Declarators 
  4891.      Initializers 
  4892.      Implicit Type Conversions 
  4893.      Implicit Type Conversions 
  4894.  
  4895.  
  4896. ΓòÉΓòÉΓòÉ <hidden> Subscript Declarator Syntax ΓòÉΓòÉΓòÉ
  4897.  
  4898. A subscript declarator has the form: 
  4899.  
  4900. >>ΓöÇΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  4901.     ΓööΓöÇconstant_expressionΓöÇΓöÿ   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  4902.                   Γöé               Γöé Γöé
  4903.                   ΓööΓöÇΓöÇΓöÇ[ΓöÇΓöÇconstant_expressionΓöÇΓöÇ]ΓöÇΓö┤ΓöÇΓöÿ
  4904.  
  4905.  
  4906. ΓòÉΓòÉΓòÉ 4.9.7.1. Initializing Arrays ΓòÉΓòÉΓòÉ
  4907.  
  4908. The initializer for an array contains the = symbol followed by a 
  4909. comma-separated list of constant expressions enclosed in braces ({ }). You do 
  4910. not need to initialize all elements in an array. Elements that are not 
  4911. initialized (in extern and static definitions only) receive the value 0 of the 
  4912. appropriate type. 
  4913.  
  4914. Note:  Array initializations can be either fully braced (with braces around 
  4915. each dimension) or unbraced (with only one set of braces enclosing the entire 
  4916. set of initializers). Avoid placing braces around some dimensions and not 
  4917. around others. 
  4918. Initializing a one-dimensional character array 
  4919.  
  4920. Initialize a one-dimensional character array by specifying: 
  4921.  
  4922.      A brace-enclosed comma-separated list of constants, each of which can be 
  4923.       contained in a character 
  4924.      A string constant. (Braces surrounding the constant are optional.) 
  4925.  
  4926.  Initializing a string constant places the null character (\0) at the end of 
  4927.  the string if there is room or if the array dimensions are not specified. 
  4928.  
  4929.  Examples of Initialized Arrays 
  4930.  
  4931.  The following show four different character array initializations: 
  4932.  
  4933.   static char name1[] = { 'J', 'a', 'n' };
  4934.   static char name2[] = { "Jan" };
  4935.   static char name3[3] = "Jan";
  4936.   static char name4[4] = "Jan";
  4937.  
  4938.  These initializations create the following elements: 
  4939.  
  4940.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  4941.   Γöé  ELEMENT  Γöé VALUEΓöé  ELEMENT  Γöé VALUEΓöé  ELEMENT  Γöé VALUEΓöé  ELEMENT  Γöé VALUΓöé
  4942.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4943.   Γöé "name1[0]" Γöé  "J" Γöé "name2[0]" Γöé  "J" Γöé "name3[0]" Γöé  "J" Γöé "name4[0]" Γöé "J" Γöé
  4944.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4945.   Γöé "name1[1]" Γöé  "a" Γöé "name2[1]" Γöé  "a" Γöé "name3[1]" Γöé  "a" Γöé "name4[1]" Γöé "a" Γöé
  4946.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4947.   Γöé "name1[2]" Γöé  "n" Γöé "name2[2]" Γöé  "n" Γöé "name3[2]" Γöé  "n" Γöé "name4[2]" Γöé "n" Γöé
  4948.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  4949.   Γöé       Γöé    Γöé "name2[3]" Γöé "\0" Γöé       Γöé    Γöé "name4[3]" Γöé "\0"Γöé
  4950.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  4951.  
  4952.  Note that the NULL character is lost for name1[] and name3[3]. In C, a 
  4953.  compiler warning is issued for name3[3]. In C++, the compiler issues a severe 
  4954.  error for name3[3]. 
  4955.  Initializing a multidimensional array 
  4956.  
  4957.  Initialize a multidimensional array by: 
  4958.  
  4959.      Listing the values of all elements you want to initialize, in the order 
  4960.       that the compiler assigns the values.  The compiler assigns values by 
  4961.       increasing the subscript of the last dimension fastest.  This form of a 
  4962.       multidimensional array initialization looks like a one-dimensional array 
  4963.       initialization.  The following definition completely initializes the 
  4964.       array month_days: 
  4965.  
  4966.                static month_days[2][12] =
  4967.                {
  4968.                 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  4969.                 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
  4970.                };
  4971.  
  4972.      Using braces to group the values of the elements you want initialized. 
  4973.       You can put braces around each element, or around any nesting level of 
  4974.       elements. The following definition contains two elements in the first 
  4975.       dimension. (You can consider these elements as rows.) The initialization 
  4976.       contains braces around each of these two elements: 
  4977.  
  4978.                static int month_days[2][12] =
  4979.                {
  4980.                 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  4981.                 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  4982.                };
  4983.  
  4984.      Using use nested braces to initialize dimensions and elements in a 
  4985.       dimension selectively. 
  4986.  
  4987.  You cannot have more initializers than the number of elements in the array. 
  4988.  
  4989.  
  4990. ΓòÉΓòÉΓòÉ <hidden> Examples of Initialized Arrays ΓòÉΓòÉΓòÉ
  4991.  
  4992. The following definition shows a completely initialized one-dimensional array: 
  4993.  
  4994. static int number[3] = { 5, 7, 2 };
  4995.  
  4996. The array number contains the following values: 
  4997.  
  4998.  Element        Value 
  4999.  number[0]      5 
  5000.  number[1]      7 
  5001.  number[2]      2 
  5002.  
  5003.  The following definition shows a partially initialized one-dimensional array: 
  5004.  
  5005.   static int number1[3] = { 5, 7 };
  5006.  
  5007.  The values of number1 are: 
  5008.  
  5009.  Element        Value 
  5010.  number1[0]     5 
  5011.  number1[1]     7 
  5012.  number1[2]     0 
  5013.  
  5014.  Instead of an expression in the subscript declarator defining the number of 
  5015.  elements, the following one-dimensional array definition defines one element 
  5016.  for each initializer specified: 
  5017.  
  5018.   static int item[ ] = { 1, 2, 3, 4, 5 };
  5019.  
  5020.  The compiler gives item the five initialized elements: 
  5021.  
  5022.  Element        Value 
  5023.  item[0]        1 
  5024.  item[1]        2 
  5025.  item[2]        3 
  5026.  item[3]        4 
  5027.  item[4]        5 
  5028.  
  5029.  The following definitions show character array initializations: 
  5030.  
  5031.      static char name1[ ] = { 'J', 'a', 'n' };
  5032.      static char name2[ ] = { "Jan" };
  5033.      static char name3[4] = "Jan";
  5034.  
  5035.  These definitions create the following elements: 
  5036.  
  5037.  Element             Value 
  5038.  name1[0]            J 
  5039.  name1[1]            a 
  5040.  name1[2]            n 
  5041.  name2[0]            J 
  5042.  name2[1]            a 
  5043.  name2[2]            n 
  5044.  name2[3]            \0 
  5045.  name3[0]            J 
  5046.  name3[1]            a 
  5047.  name3[2]            n 
  5048.  
  5049.  The following definition explicitly initializes six elements in a 12-element 
  5050.  array: 
  5051.  
  5052.   static int matrix[3][4] =
  5053.      {
  5054.        {1, 2},
  5055.        {3, 4},
  5056.        {5, 6}
  5057.      };
  5058.  
  5059.  The initial values of matrix are: 
  5060.  
  5061.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5062.   Γöé ELEMENT      Γöé VALUE       Γöé ELEMENT      Γöé VALUE       Γöé
  5063.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5064.   Γöé "matrix[0][0]"   Γöé "1"        Γöé "matrix[1][2]"   Γöé "0"        Γöé
  5065.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5066.   Γöé "matrix[0][1]"   Γöé "2"        Γöé "matrix[1][3]"   Γöé "0"        Γöé
  5067.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5068.   Γöé "matrix[0][2]"   Γöé "0"        Γöé "matrix[2][0]"   Γöé "5"        Γöé
  5069.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5070.   Γöé "matrix[0][3]"   Γöé "0"        Γöé "matrix[2][1]"   Γöé "6"        Γöé
  5071.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5072.   Γöé "matrix[1][0]"   Γöé "3"        Γöé "matrix[2][2]"   Γöé "0"        Γöé
  5073.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  5074.   Γöé "matrix[1][1]"   Γöé "4"        Γöé "matrix[2][3]"   Γöé "0"        Γöé
  5075.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  5076.  
  5077.  
  5078. ΓòÉΓòÉΓòÉ 4.9.7.2. Example Programs Using Arrays ΓòÉΓòÉΓòÉ
  5079.  
  5080. /************************************************************************
  5081. *
  5082.  
  5083. The following program defines a floating-point array called prices. 
  5084.  
  5085. The first for statement prints the values of the elements of prices. The second 
  5086. for statement adds five percent to the value of each element of prices, and 
  5087. assigns the result to total, and prints the value of total. 
  5088.  
  5089.                                                                         *
  5090. ************************************************************************/
  5091.  
  5092. /**
  5093.  ** Example of one-dimensional arrays
  5094.  **/
  5095.  
  5096. #include <stdio.h>
  5097. #define  ARR_SIZE  5
  5098.  
  5099. int main(void)
  5100. {
  5101.   static float const prices[ARR_SIZE] = { 1.41, 1.50, 3.75, 5.00, .86 };
  5102.   auto float total;
  5103.   int i;
  5104.  
  5105.   for (i = 0; i < ARR_SIZE; i++)
  5106.   {
  5107.     printf("price = $%.2f\n", prices[i]);
  5108.   }
  5109.  
  5110.   printf("\n");
  5111.  
  5112.   for (i = 0; i < ARR_SIZE; i++)
  5113.   {
  5114.     total = prices[i] * 1.05;
  5115.  
  5116.     printf("total = $%.2f\n", total);
  5117.   }
  5118.  
  5119.   return(0);
  5120. }
  5121.  
  5122. /************************************************************************
  5123. *
  5124.  
  5125. This program produces the following output: 
  5126.  
  5127. price = $1.41
  5128. price = $1.50
  5129. price = $3.75
  5130. price = $5.00
  5131. price = $0.86
  5132.  
  5133. total = $1.48
  5134. total = $1.57
  5135. total = $3.94
  5136. total = $5.25
  5137. total = $0.90
  5138.  
  5139. The following program defines the multidimensional array salary_tbl. A for loop 
  5140. prints the values of salary_tbl. 
  5141.  
  5142.                                                                         *
  5143. ************************************************************************/
  5144.  
  5145. /**
  5146.  ** Example of a multidimensional array
  5147.  **/
  5148.  
  5149. #include <stdio.h>
  5150. #define  ROW_SIZE     3
  5151. #define  COLUMN_SIZE  5
  5152.  
  5153. int main(void)
  5154. {
  5155.   static int salary_tbl[ROW_SIZE][COLUMN_SIZE] =
  5156.   {
  5157.     {  500,  550,  600,  650,  700   },
  5158.     {  600,  670,  740,  810,  880   },
  5159.     {  740,  840,  940, 1040, 1140   }
  5160.   };
  5161.   int grade , step;
  5162.  
  5163.   for (grade = 0; grade < ROW_SIZE; ++grade)
  5164.    for (step = 0; step < COLUMN_SIZE; ++step)
  5165.    {
  5166.      printf("salary_tbl[%d] [%d] = %d\n", grade, step,
  5167.              salary_tbl[grade] [step]);
  5168.    }
  5169.  
  5170.    return(0);
  5171. }
  5172.  
  5173. /************************************************************************
  5174. *
  5175.  
  5176. This program produces the following output: 
  5177.  
  5178. salary_tbl[0] [0] = 500
  5179. salary_tbl[0] [1] = 550
  5180. salary_tbl[0] [2] = 600
  5181. salary_tbl[0] [3] = 650
  5182. salary_tbl[0] [4] = 700
  5183. salary_tbl[1] [0] = 600
  5184. salary_tbl[1] [1] = 670
  5185. salary_tbl[1] [2] = 740
  5186. salary_tbl[1] [3] = 810
  5187. salary_tbl[1] [4] = 880
  5188. salary_tbl[2] [0] = 740
  5189. salary_tbl[2] [1] = 840
  5190. salary_tbl[2] [2] = 940
  5191. salary_tbl[2] [3] = 1040
  5192. salary_tbl[2] [4] = 1140
  5193.  
  5194.                                                                         *
  5195. ************************************************************************/
  5196.  
  5197.  
  5198. ΓòÉΓòÉΓòÉ 4.9.8. Structures ΓòÉΓòÉΓòÉ
  5199.  
  5200. A structure contains an ordered group of data objects. Unlike the elements of 
  5201. an array, the data objects within a structure can have varied data types. Each 
  5202. data object in a structure is a member or field. 
  5203.  
  5204. Use structures to group logically related objects. For example, to allocate 
  5205. storage for the components of one address, define a number of variables for the 
  5206. street name and number, the city, and so on. To allocate storage for more than 
  5207. one address, group the components of each address by defining a structure data 
  5208. type and as many variables as you need to have the structure data type. 
  5209.  
  5210. In the following example, lines 1 through 7 declare the structure tag address: 
  5211.  
  5212.     1   struct address {
  5213.     2                    int street_no;
  5214.     3                    char *street_name;
  5215.     4                    char *city;
  5216.     5                    char *prov;
  5217.     6                    char *postal_code;
  5218.     7                  };
  5219.     8   struct address perm_address;
  5220.     9   struct address temp_address;
  5221.    10   struct address *p_perm_address = &perm_address;
  5222.  
  5223. The variables perm_address and temp_address are instances of the structure data 
  5224. type address. Both contain the members described in the declaration of address. 
  5225. The pointer p_perm_address points to a structure of address and is initialized 
  5226. to point to perm_address. 
  5227.  
  5228. Refer to a member of a structure by specifying the structure variable name with 
  5229. the dot operator (.) or a pointer with the arrow operator (->) and the member 
  5230. name. For example, both of the following: 
  5231.  
  5232.  perm_address.prov = "Ontario";
  5233.  p_perm_address -> prov = "Ontario";
  5234.  
  5235. assign a pointer to the string "Ontario" to the pointer prov that is in the 
  5236. structure perm_address. 
  5237.  
  5238. All references to structures must be fully qualified. In the example, you 
  5239. cannot reference the fourth field by prov alone. You must reference this field 
  5240. by perm_address.prov. 
  5241.  
  5242. Structures with identical members but different names are not compatible and 
  5243. cannot be assigned to each other. 
  5244.  
  5245. Structures are not intended to conserve storage. If you need direct control of 
  5246. byte mapping, use pointers. 
  5247.  
  5248. Structure member references are described in Dot Operator . and Arrow 
  5249. Operator -> 
  5250.  
  5251. You cannot declare a structure with members of incomplete types. 
  5252.  
  5253. A structure type declaration describes the members that are part of the 
  5254. structure. It contains the struct keyword followed by an optional identifier 
  5255. (the structure tag) and a brace-enclosed list of members. 
  5256.  
  5257. Syntax of a Structure 
  5258.  
  5259. The keyword struct followed by the identifier (tag) names the data type. If you 
  5260. do not provide a tag name to the data type, you must put all variable 
  5261. definitions that refer to it within the declaration of the data type. 
  5262.  
  5263. The list of members provides the data type with a description of the values 
  5264. that can be stored in the structure. 
  5265.  
  5266. If a : (colon) and a constant expression follow the member declarator, the 
  5267. member represents a bit field. A member that does not represent a bit field can 
  5268. be of any data type and can have the volatile or const qualifier. 
  5269.  
  5270. Identifiers used as structure or member names can be redefined to represent 
  5271. different objects in the same scope without conflicting. You cannot use the 
  5272. name of a member more than once in a structure type, but you can use the same 
  5273. member name in another structure type that is defined within the same scope. 
  5274.  
  5275. You cannot declare a structure type that contains itself as a member, but you 
  5276. can declare a structure type that contains a pointer to itself as a member. 
  5277.  
  5278. A structure variable definition contains an optional storage class keyword, the 
  5279. struct keyword, a structure tag, a declarator, and an optional identifier. The 
  5280. structure tag indicates the data type of the structure variable. 
  5281.  
  5282. C++ Note:  The keyword struct is optional in C++. 
  5283.  
  5284. You can declare structures having any storage class. 
  5285.  
  5286. Additional information is provided on: 
  5287.  
  5288.      Initializing Structures 
  5289.      Declaring Structure Types and Variables 
  5290.      Declaring and Using Bit Fields in Structures 
  5291.      Declaring a Packed Structure 
  5292.      Example Program Using Structures 
  5293.  
  5294.  Related Information 
  5295.  
  5296.      Dot Operator . 
  5297.      Arrow Operator -> 
  5298.      _Packed Qualifier 
  5299.      Declarators 
  5300.      Initializers 
  5301.  
  5302.  
  5303. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Structure ΓòÉΓòÉΓòÉ
  5304.  
  5305. A structure declaration has the form: 
  5306.  
  5307.                 ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5308.                       Γöé
  5309. >>ΓöÇΓöÇstructΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇmemberΓöÇΓöÇ;ΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  5310.       ΓööΓöÇidentifierΓöÇΓöÿ
  5311.  
  5312. A structure member has the form: 
  5313.  
  5314.            ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5315.                                 Γöé
  5316. >>ΓöÇΓöÇtype_specifierΓöÇΓöÇΓöÇΓö¼ΓöÇdeclaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ><
  5317.            ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ:ΓöÇΓöÇconstant_expressionΓöÇΓöÿ
  5318.             ΓööΓöÇ.declaratorΓöÇΓöÿ
  5319.  
  5320.  
  5321. ΓòÉΓòÉΓòÉ 4.9.8.1. Initializing Structures ΓòÉΓòÉΓòÉ
  5322.  
  5323. The initializer contains an = (equal sign) followed by a brace-enclosed 
  5324. comma-separated list of values. You do not have to initialize all members of a 
  5325. structure. 
  5326.  
  5327. The following definition shows a completely initialized structure: 
  5328.  
  5329. struct address {
  5330.                  int street_no;
  5331.                  char *street_name;
  5332.                  char *city;
  5333.                  char *prov;
  5334.                  char *postal_code;
  5335.                };
  5336. static struct address perm_address =
  5337.                { 3, "Savona Dr.", "Dundas", "Ontario", "L4B 2A1"};
  5338.  
  5339. The values of perm_address are: 
  5340.  
  5341.  Member              Value 
  5342.  perm_address.street_no 3 
  5343.  perm_address.street_name address of string "Savona Dr." 
  5344.  perm_address.city   address of string "Dundas" 
  5345.  perm_address.prov   address of string "Ontario" 
  5346.  perm_address.postal_code address of string "L4B 2A1" 
  5347.  
  5348.  The following definition shows a partially initialized structure: 
  5349.  
  5350.   struct address {
  5351.                    int street_no;
  5352.                    char *street_name;
  5353.                    char *city;
  5354.                    char *prov;
  5355.                    char *postal_code;
  5356.                  };
  5357.   struct address temp_address =
  5358.                  { 44, "Knyvet Ave.", "Hamilton", "Ontario" };
  5359.  
  5360.  The values of temp_address are: 
  5361.  
  5362.  Member                                  Value 
  5363.  temp_address.street_no                  44 
  5364.  temp_address.street_name                address of string "Knyvet Ave." 
  5365.  temp_address.city                       address of string "Hamilton" 
  5366.  temp_address.prov                       address of string "Ontario" 
  5367.  temp_address.postal_code                value depends on the storage class. 
  5368.  
  5369.  Note:  The initial value of uninitialized structure members like 
  5370.  temp_address.postal_code depends on the storage class associated with the 
  5371.  member. See Storage Class Specifiers for details on the initialization of 
  5372.  different storage classes. 
  5373.  
  5374.  
  5375. ΓòÉΓòÉΓòÉ 4.9.8.2. Declaring Structure Types and Variables ΓòÉΓòÉΓòÉ
  5376.  
  5377. To define a structure type and a structure variable in one statement, put a 
  5378. declarator and an optional initializer after the type definition. To specify a 
  5379. storage class specifier for the variable, you must put the storage class 
  5380. specifier at the beginning of the statement. 
  5381.  
  5382. For example: 
  5383.  
  5384. static struct {
  5385.                  int street_no;
  5386.                  char *street_name;
  5387.                  char *city;
  5388.                  char *prov;
  5389.                  char *postal_code;
  5390.               } perm_address, temp_address;
  5391.  
  5392. Because this example does not name the structure data type, perm_address and 
  5393. temp_address are the only structure variables that will have this data type. 
  5394. Putting an identifier after struct, lets you make additional variable 
  5395. definitions of this data type later in the program. 
  5396.  
  5397. The structure type (or tag) cannot have the volatile qualifier, but a member or 
  5398. a structure variable can be defined as having the volatile qualifier. 
  5399.  
  5400. For example: 
  5401.  
  5402. static struct class1 {
  5403.                         char descript[20];
  5404.                         volatile long code;
  5405.                         short complete;
  5406.                      } volatile file1, file2;
  5407. struct class1 subfile;
  5408.  
  5409. This example qualifies the structures file1 and file2, and the structure member 
  5410. subfile.code as volatile. 
  5411.  
  5412.  
  5413. ΓòÉΓòÉΓòÉ 4.9.8.3. Declaring and Using Bit Fields ΓòÉΓòÉΓòÉ
  5414.  
  5415. A structure or a C++ class can contain bit fields that allow you to access 
  5416. individual bits. You can use bit fields for data that requires just a few bits 
  5417. of storage. A bit field declaration contains a type specifier followed by an 
  5418. optional declarator, a colon, a constant expression, and a semicolon. The 
  5419. constant expression specifies how many bits the field reserves. A bit field 
  5420. that is declared as having a length of 0 causes the next field to be aligned on 
  5421. the next integer boundary. For a _Packed structure, a bit field of length 0 
  5422. causes the next field to be aligned on the next byte boundary. Bit fields with 
  5423. a length of 0 must be unnamed. Unnamed bit fields cannot be referenced or 
  5424. initialized. 
  5425.  
  5426. The maximum bit field length is implementation dependent. The maximum bit field 
  5427. length for the VisualAge C++ compiler is 32 bits (4 bytes, or 1 word). 
  5428.  
  5429. For portability, do not use bit fields greater than 32 bits in size. 
  5430.  
  5431. The following restrictions apply to bit fields. You cannot: 
  5432.  
  5433.      Define an array of bit fields 
  5434.      Take the address of a bit field 
  5435.      Have a pointer to a bitfield 
  5436.      Have a reference to a bit field (C++ only) 
  5437.  
  5438.  In C, you can declare a bit field as type int, signed int, or unsigned int. 
  5439.  Bit fields of the type int are equivalent to those of type unsigned int. 
  5440.  
  5441.  C++ Note:  Unlike ISO/ANSI C, C++ bit fields can be any integral type or 
  5442.  enumeration type. When you assign a value that is out of range to a bit field, 
  5443.  the low-order bit pattern is preserved and the appropriate bits are assigned. 
  5444.  
  5445.  If a series of bit fields does not add up to the size of an int, padding can 
  5446.  take place. The amount of padding is determined by the alignment 
  5447.  characteristics of the members of the structure. In some instances, bit fields 
  5448.  can cross word boundaries. 
  5449.  
  5450.  The following example declares the identifier kitchen to be of type struct 
  5451.  on_off: 
  5452.  
  5453.   struct on_off {
  5454.                     unsigned light : 1;
  5455.                     unsigned toaster : 1;
  5456.                     int count;            /* 4 bytes */
  5457.                     unsigned ac : 4;
  5458.                     unsigned : 4;
  5459.                     unsigned clock : 1;
  5460.                     unsigned : 0;
  5461.                     unsigned flag : 1;
  5462.                    } kitchen ;
  5463.  
  5464.  The structure kitchen contains eight members totalling 16 bytes. The following 
  5465.  table describes the storage that each member occupies: 
  5466.  
  5467.  Member Name              Storage Occupied 
  5468.  light                    1 bit 
  5469.  toaster                  1 bit 
  5470.  (padding - 30 bits)      To next int boundary 
  5471.  count                    The size of an int 
  5472.  ac                       4 bits 
  5473.  (unnamed field)          4 bits 
  5474.  clock                    1 bit 
  5475.  (padding - 23 bits)      To next int boundary (unnamed field) 
  5476.  flag                     1 bit 
  5477.  (padding - 31 bits)      To next int boundary 
  5478.  
  5479.  All references to structure fields must be fully qualified. For instance, you 
  5480.  cannot reference the second field by toaster. You must reference this field by 
  5481.  kitchen.toaster. 
  5482.  
  5483.  The following expression sets the light field to 1: 
  5484.  
  5485.     kitchen.light = 1;
  5486.  
  5487.  When you assign to a bit field a value that is out of its range, the bit 
  5488.  pattern is preserved and the appropriate bits are assigned. The following 
  5489.  expression sets the toaster field of the kitchen structure to 0 because only 
  5490.  the least significant bit is assigned to the toaster field: 
  5491.  
  5492.     kitchen.toaster = 2;
  5493.  
  5494.  
  5495. ΓòÉΓòÉΓòÉ 4.9.8.4. Declaring a Packed Structure ΓòÉΓòÉΓòÉ
  5496.  
  5497. Data elements of a structure are stored in memory on an address boundary 
  5498. specific for that data type. For example, a double value is stored in memory on 
  5499. a doubleword (8-byte) boundary. Gaps may be left in memory between elements of 
  5500. a structure to align elements on their natural boundaries. You can reduce the 
  5501. padding of bytes within a structure by using the _Packed qualifier on the 
  5502. structure declaration. 
  5503.  
  5504. C++ Note:  C++ does not support the _Packed qualifier. To change the alignment 
  5505. of structures, use the #pragma pack directive or the /Sp compiler option. Both 
  5506. of these methods are also supported by C. 
  5507.  
  5508.  
  5509. ΓòÉΓòÉΓòÉ 4.9.8.5. Example Program Using Structures ΓòÉΓòÉΓòÉ
  5510.  
  5511. /************************************************************************
  5512. *
  5513.  
  5514. The following program finds the sum of the integer numbers in a linked list: 
  5515.  
  5516.                                                                         *
  5517. ************************************************************************/
  5518.  
  5519. /**
  5520.  ** Example program illustrating structures using linked lists
  5521.  **/
  5522.  
  5523. #include <stdio.h>
  5524.  
  5525. struct record {
  5526.                 int number;
  5527.                 struct record *next_num;
  5528.               };
  5529.  
  5530. int main(void)
  5531. {
  5532.    struct  record name1, name2, name3;
  5533.    struct  record *recd_pointer = &name1;
  5534.    int sum = 0;
  5535.  
  5536.    name1.number = 144;
  5537.    name2.number = 203;
  5538.    name3.number = 488;
  5539.  
  5540.    name1.next_num = &name2;
  5541.    name2.next_num = &name3;
  5542.    name3.next_num = NULL;
  5543.  
  5544.    while (recd_pointer != NULL)
  5545.    {
  5546.       sum += recd_pointer->number;
  5547.       recd_pointer = recd_pointer->next_num;
  5548.    }
  5549.    printf("Sum = %d\n", sum);
  5550.  
  5551.    return(0);
  5552. }
  5553.  
  5554. /************************************************************************
  5555. *
  5556.  
  5557. The structure type record contains two members: the integer number and 
  5558. next_num, which is a pointer to a structure variable of type record. 
  5559.  
  5560. The record type variables name1, name2, and name3 are assigned the following 
  5561. values: 
  5562.  
  5563.  Member Name                   Value 
  5564.  name1.number                  144 
  5565.  name1.next_num                The address of name2 
  5566.  
  5567.  name2.number                  203 
  5568.  name2.next_num                The address of name3 
  5569.  
  5570.  name3.number                  488 
  5571.  name3.next_num                NULL (Indicating the end of the linked list.) 
  5572.  
  5573.  The variable recd_pointer is a pointer to a structure of type record. It is 
  5574.  initialized to the address of name1 (the beginning of the linked list). 
  5575.  
  5576.  The while loop causes the linked list to be scanned until recd_pointer equals 
  5577.  NULL. The statement: 
  5578.  
  5579.   recd_pointer = recd_pointer->next_num;
  5580.  
  5581.  advances the pointer to the next object in the list. 
  5582.  
  5583.                                                                                     *
  5584.   ***********************************************************************************/
  5585.  
  5586.  
  5587. ΓòÉΓòÉΓòÉ 4.9.9. Unions ΓòÉΓòÉΓòÉ
  5588.  
  5589. A union is an object that can hold any one of a set of named members. The 
  5590. members of the named set can be of any data type. Members are overlaid in 
  5591. storage. 
  5592.  
  5593. The storage allocated for a union is the storage required for the largest 
  5594. member of the union (plus any padding that is required so that the union will 
  5595. end at a natural boundary of its strictest member). 
  5596.  
  5597. C++ Notes: 
  5598.  
  5599. In C++, a union can have member functions, including constructors and 
  5600. destructors, but not virtual member functions. A union cannot be used as a base 
  5601. class and cannot be derived from a base class. 
  5602.  
  5603. A C++ union member cannot be a class object that has a constructor, destructor, 
  5604. or overloaded copy assignment operator. In C++, a member of a union cannot be 
  5605. declared with the keyword static. 
  5606.  
  5607. A union type declaration contains the union keyword followed by an identifier 
  5608. (optional) and a brace-enclosed list of members. 
  5609.  
  5610. Syntax of a Union 
  5611.  
  5612. The identifier is a tag given to the union specified by the member list. If you 
  5613. specify a tag, any subsequent declaration of the union (in the same scope) can 
  5614. be made by declaring the tag and omitting the member list. If you do not 
  5615. specify a tag, you must put all variable definitions that refer to that union 
  5616. within the statement that defines the data type. 
  5617.  
  5618. The list of members provides the data type with a description of the objects 
  5619. that can be stored in the union. 
  5620.  
  5621. You can reference one of the possible members of a union the same way as 
  5622. referencing a member of a structure. 
  5623.  
  5624. For example: 
  5625.  
  5626. union {
  5627.       char birthday[9];
  5628.       int age;
  5629.       float weight;
  5630.       } people;
  5631.  
  5632. people.birthday[0] = '\n';
  5633.  
  5634. assigns '\n' to the first element in the character array birthday, a member of 
  5635. the union people. 
  5636.  
  5637. A union can represent only one of its members at a time. In the example, the 
  5638. union people contains either age, birthday, or weight but never more than one 
  5639. of these. The printf statement in the following example does not give the 
  5640. correct result because people.age replaces the value assigned to 
  5641. people.birthday in the first line: 
  5642.  
  5643. 1  people.birthday = "03/06/56";
  5644. 2  people.age = 38;
  5645. 3  printf("%s\n", people.birthday);
  5646.  
  5647. Examples of Unions 
  5648.  
  5649. Additional information is provided on: 
  5650.  
  5651.      Defining a Union Variable 
  5652.      Defining a Packed Union 
  5653.      Anonymous Unions in C 
  5654.      Anonymous Unions in C++ 
  5655.  
  5656.  Related Information 
  5657.  
  5658.      Dot Operator . 
  5659.      Arrow Operator -> 
  5660.      _Packed Qualifier 
  5661.      Declarators 
  5662.      Initializers 
  5663.  
  5664.  
  5665. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Union ΓòÉΓòÉΓòÉ
  5666.  
  5667. A union type declaration has the form: 
  5668.  
  5669.                        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5670.                               Γöé
  5671. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇunionΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇmemberΓöÇΓöÇ???ΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  5672.   ΓööΓöÇqualifierΓöÇΓöÿ     ΓööΓöÇidentifierΓöÇΓöÿ
  5673.  
  5674. A member has the form: 
  5675.  
  5676.           ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  5677.                                  Γöé
  5678. >>ΓöÇΓöÇtype_specifierΓöÇΓöÇΓöÇΓö¼ΓöÇdeclaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ><
  5679.            ΓööΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ???ΓöÇΓöÇconstant_expressionΓöÇΓöÿ
  5680.             ΓööΓöÇdeclaratorΓöÇΓöÿ
  5681.  
  5682.  
  5683. ΓòÉΓòÉΓòÉ 4.9.9.1. Defining a Union Variable ΓòÉΓòÉΓòÉ
  5684.  
  5685. A union variable definition contains an optional storage class keyword, the 
  5686. union keyword, a union tag, and a declarator. The union tag indicates the data 
  5687. type of the union variable. 
  5688.  
  5689. The type specifier contains the keyword union followed by the name of the union 
  5690. type. You must declare the union data type before you can define a union having 
  5691. that type. 
  5692.  
  5693. You can define a union data type and a union of that type in the same statement 
  5694. by placing the variable declarator after the data type definition. 
  5695.  
  5696. The declarator is an identifier, possibly with the volatile or const qualifier. 
  5697.  
  5698. You can only initialize the first member of a union. 
  5699.  
  5700. The following example shows how you would initialize the first union member 
  5701. birthday of the union variable people: 
  5702.  
  5703. union {
  5704.       char birthday[9];
  5705.       int age;
  5706.       float weight;
  5707.       } people = {"23/07/57"};
  5708.  
  5709. To define union type and a union variable in one statement, put a declarator 
  5710. after the type definition. The storage class specifier for the variable must go 
  5711. at the beginning of the statement. 
  5712.  
  5713.  
  5714. ΓòÉΓòÉΓòÉ 4.9.9.2. Defining a Packed Union ΓòÉΓòÉΓòÉ
  5715.  
  5716. You can use _Packed to qualify a union. However, the memory layout of the union 
  5717. members is not affected. Each member starts at offset zero. The _Packed 
  5718. qualifier does affect the total alignment restriction of the whole union. 
  5719.  
  5720. C++ Note:  C++ does not support the _Packed qualifier. To change the alignment 
  5721. of unions, use the #pragma pack directive or the /Sp compiler option. Both of 
  5722. these methods are also supported by C. 
  5723.  
  5724. In the following example, each of the elements in the nonpacked n_array is of 
  5725. type union uu. 
  5726.  
  5727.           union uu {
  5728.             short    a;
  5729.             struct {
  5730.               char x;
  5731.               char y;
  5732.               char z;
  5733.             } b;
  5734.           };
  5735.  
  5736.           union uu           n_array[2];
  5737.           _Packed union uu   p_array[2];
  5738.  
  5739. Because it is not packed, each element in the array has an alignment 
  5740. restriction of 2 bytes (the largest alignment requirement among the union 
  5741. members is that of short a), and there is 1 byte of padding at the end of each 
  5742. element to enforce this requirement. 
  5743.  
  5744. Now consider the packed array p_array. Because each of its elements is of type 
  5745. _Packed union uu, the alignment restriction of every element is the byte 
  5746. boundary. Therefore, each element has a length of only 3 bytes, instead of the 
  5747. 4 bytes in the previous example. 
  5748.  
  5749.  
  5750. ΓòÉΓòÉΓòÉ 4.9.9.3. Anonymous Unions in C ΓòÉΓòÉΓòÉ
  5751.  
  5752. Unions can be declared without declarators if they are members of another 
  5753. structure or union. Unions without declarators are called anonymous unions. 
  5754.  
  5755. Members of an anonymous union can be accessed as if they were declared directly 
  5756. in the containing structure or union. For example, given the following 
  5757. structure: 
  5758.  
  5759.    struct s {
  5760.       int a;
  5761.       union {
  5762.         int b;
  5763.         float c;
  5764.       };        /* no declarator */
  5765.    } kurt;
  5766.  
  5767. you can make the following statements: 
  5768.  
  5769.    kurt.a = 5;
  5770.    kurt.b = 36;
  5771.  
  5772. You can also declare an anonymous union: 
  5773.  
  5774.    1. By creating a typedef and using the typedef name without a declarator: 
  5775.  
  5776.                typedef union {
  5777.                   int a;
  5778.                   int b;
  5779.                }  UNION_T;
  5780.  
  5781.                struct s1 {
  5782.                   UNION_T;
  5783.                   int c;
  5784.                } dave;
  5785.  
  5786.    2. By using an existing union tag without a declarator: 
  5787.  
  5788.                union u1 {
  5789.                   int a;
  5790.                   int b;
  5791.                };
  5792.  
  5793.                struct s1 {
  5794.                   union u1;
  5795.                   int c;
  5796.                } dave;
  5797.  
  5798.  In both of the examples, the members can be accessed as dave.a, dave.b, and 
  5799.  dave.c. 
  5800.  
  5801.  An anonymous union must be a member of, or nested within another anonymous 
  5802.  union that is a member of, a named structure or union. If a union is declared 
  5803.  at file scope without a declarator, its members are not available to the 
  5804.  surrounding scope. For example, the following union only declares the union 
  5805.  tag tom: 
  5806.  
  5807.      union tom {
  5808.         int b;
  5809.         float c;
  5810.      };
  5811.  
  5812.  The variables b and c from this union cannot be used at file scope, and the 
  5813.  following statements will generate errors: 
  5814.  
  5815.      b = 5;
  5816.      c = 2.5;
  5817.  
  5818.  C++ Note:  Anonymous unions are treated differently in C++. See Anonymous 
  5819.  Unions in C++ for more information. 
  5820.  
  5821.  
  5822. ΓòÉΓòÉΓòÉ 4.9.9.4. Anonymous Unions in C++ ΓòÉΓòÉΓòÉ
  5823.  
  5824. It cannot be followed by a declarator. An anonymous union is not a type; it 
  5825. defines an unnamed object and it cannot have member functions. 
  5826.  
  5827. The member names of an anonymous union must be distinct from other names within 
  5828. the scope in which the union is declared. You can use member names directly in 
  5829. the union scope without any additional member access syntax. 
  5830.  
  5831. For example, in the following code fragment, you can access the data members i 
  5832. and cptr directly because they are in the scope containing the anonymous union. 
  5833. Because i and cptr are union members and have the same address, you should only 
  5834. use one of them at a time. The assignment to the member cptr will change the 
  5835. value of the member i. 
  5836.  
  5837. void f()
  5838. {
  5839. union { int i; char* cptr ; };
  5840. //      .
  5841. //      .
  5842. //      .
  5843. i = 5;
  5844. cptr = "string_in_union"; // overrides i
  5845. }
  5846.  
  5847. An anonymous union cannot have protected or private members. A global anonymous 
  5848. union must be declared with the keyword static. 
  5849.  
  5850.  
  5851. ΓòÉΓòÉΓòÉ <hidden> Examples of Unions ΓòÉΓòÉΓòÉ
  5852.  
  5853. The following example defines a union data type (not named) and a union 
  5854. variable (named length). The member of length can be a long int, a float, or a 
  5855. double. 
  5856.  
  5857. union {
  5858.         float meters;
  5859.         double centimeters;
  5860.         long inches;
  5861.       } length;
  5862.  
  5863. The following example defines the union type data as containing one member. The 
  5864. member can be named charctr, whole, or real. The second statement defines two 
  5865. data type variables: input and output. 
  5866.  
  5867. union data {
  5868.              char charctr;
  5869.              int whole;
  5870.              float real;
  5871.            };
  5872. union data input, output;
  5873.  
  5874. The following statement assigns a character to input: 
  5875.  
  5876. input.charctr = 'h';
  5877.  
  5878. The following statement assigns a floating-point number to member output: 
  5879.  
  5880. output.real = 9.2;
  5881.  
  5882. The following example defines an array of structures named records. Each 
  5883. element of records contains three members: the integer id_num, the integer 
  5884. type_of_input, and the union variable input. input has the union data type 
  5885. defined in the previous example. 
  5886.  
  5887. struct {
  5888.          int id_num;
  5889.          int type_of_input;
  5890.          union data input;
  5891.        } records[10];
  5892.  
  5893. The following statement assigns a character to the structure member input of 
  5894. the first element of records: 
  5895.  
  5896. records[0].input.charctr = 'g';
  5897.  
  5898.  
  5899. ΓòÉΓòÉΓòÉ 4.9.10. typedef ΓòÉΓòÉΓòÉ
  5900.  
  5901. A typedef declaration lets you define your own identifiers that can be used in 
  5902. place of type specifiers such as int, float, and double. The names you define 
  5903. using typedef are not new data types. They are synonyms for the data types or 
  5904. combinations of data types they represent. 
  5905.  
  5906. Syntax of a typedef Declaration 
  5907.  
  5908. A typedef declaration does not reserve storage. 
  5909.  
  5910. When an object is defined using a typedef identifier, the properties of the 
  5911. defined object are exactly the same as if the object were defined by explicitly 
  5912. listing the data type associated with the identifier. 
  5913.  
  5914. A C++ class defined in a typedef without being named is given a dummy name and 
  5915. the typedef name for linkage. Such a class cannot have constructors or 
  5916. destructors. For example: 
  5917.  
  5918. typedef class {
  5919.                Trees();
  5920.               } Trees;
  5921.  
  5922. Here the function Trees() is an ordinary member function of a class whose type 
  5923. name is unspecified. In the above example, Trees is an alias for the unnamed 
  5924. class, not the class type name itself, so Trees() cannot be a constructor for 
  5925. that class. 
  5926.  
  5927. The following statements declare LENGTH as a synonym for int and then use this 
  5928. typedef to declare length, width, and height as integral variables: 
  5929.  
  5930. typedef int LENGTH;
  5931. LENGTH length, width, height;
  5932.  
  5933. The following declarations are equivalent to the above declaration: 
  5934.  
  5935. int length, width, height;
  5936.  
  5937. Similarly, typedef can be used to define a class type (structure, union, or C++ 
  5938. class). For example: 
  5939.  
  5940. typedef struct {
  5941.                 int scruples;
  5942.                 int drams;
  5943.                 int grains;
  5944.                } WEIGHT;
  5945.  
  5946. The structure WEIGHT can then be used in the following declarations: 
  5947.  
  5948. WEIGHT  chicken, cow, horse, whale;
  5949.  
  5950. Related Information 
  5951.  
  5952.      Characters 
  5953.      Floating-Point Variables 
  5954.      Integer Variables 
  5955.      Enumerations 
  5956.      Pointers 
  5957.      void Type 
  5958.      Arrays 
  5959.      Structures 
  5960.      Unions 
  5961.      C++ Classes 
  5962.      Constructors and Destructors Overview 
  5963.  
  5964.  
  5965. ΓòÉΓòÉΓòÉ <hidden> Syntax of a typedef Declaration ΓòÉΓòÉΓòÉ
  5966.  
  5967. The syntax of a typedef declaration is: 
  5968.  
  5969. >>ΓöÇΓöÇtypedefΓöÇΓöÇtype_specifierΓöÇΓöÇidentifierΓöÇΓöÇ;ΓöÇΓöÇ><
  5970.  
  5971.  
  5972. ΓòÉΓòÉΓòÉ 5. Expressions and Operators ΓòÉΓòÉΓòÉ
  5973.  
  5974. Expressions are sequences of operators, operands, and punctuators that specify 
  5975. a computation. The evaluation of expressions is based on the operators that the 
  5976. expressions contain and the context in which they are used. 
  5977.  
  5978. This section discusses: 
  5979.  
  5980.      Primary Expressions 
  5981.      Unary Expressions 
  5982.      Binary Expressions 
  5983.      Conditional Expressions 
  5984.      Assignment Expressions 
  5985.      Comma Expression  , 
  5986.      lvalues 
  5987.      Constant Expressions 
  5988.  
  5989.  An expression can result in an lvalue, rvalue, or no value, and can produce 
  5990.  side effects in each case. 
  5991.  
  5992.  C++ Note:  C++ operators can be defined to behave differently when applied to 
  5993.  operands of class type. This is called operator overloading. This section 
  5994.  describes the behavior of operators that are not overloaded. The C language 
  5995.  does not permit overloading. 
  5996.  
  5997.  Related Information 
  5998.  
  5999.      Declarations 
  6000.      Overloading Operators 
  6001.  
  6002.  
  6003. ΓòÉΓòÉΓòÉ 5.1. Operator Precedence and Associativity ΓòÉΓòÉΓòÉ
  6004.  
  6005. Two operator characteristics determine how operands group with operators: 
  6006. precedence and associativity. Precedence is the priority for grouping different 
  6007. types of operators with their operands. Associativity is the left-to-right or 
  6008. right-to-left order for grouping operands to operators that have the same 
  6009. precedence. 
  6010.  
  6011. For example, in the following statements, the value of 5 is assigned to both a 
  6012. and b because of the right-to-left associativity of the = operator. The value 
  6013. of c is assigned to b first, and then the value of b is assigned to a. 
  6014.  
  6015. b = 9;
  6016. c = 5;
  6017. a = b = c;
  6018.  
  6019. Because the order of expression evaluation is not specified, you can explicitly 
  6020. force the grouping of operands with operators by using parentheses. 
  6021.  
  6022. In the expression a + b * c / d, the * and / operations are performed before + 
  6023. because of precedence. b is multiplied by c before it is divided by d because 
  6024. of associativity. 
  6025.  
  6026. Table of Operator Precedence and Associativity lists the C and C++ language 
  6027. operators in order of precedence and shows the direction of associativity for 
  6028. each operator. In C++, the primary scope resolution operator (::) has the 
  6029. highest precedence, followed by the other primary operators. In C, because 
  6030. there is no scope resolution operator, the other primary operators have the 
  6031. highest precedence. The comma operator has the lowest precedence. Operators 
  6032. that appear in the same group have the same precedence. 
  6033.  
  6034. The order of evaluation for function call arguments or for the operands of 
  6035. binary operators is not specified. Avoid writing such ambiguous expressions as: 
  6036.  
  6037. z = (x * ++y) / func1(y);
  6038. func2(++i, x[i]);
  6039.  
  6040. In the example above, the order of evaluation of ++y and func1(y) is not 
  6041. defined. If y had the value of 1 before the first statement, it is not known 
  6042. whether or not the value of 1 or 2 is passed to func1(). In the second 
  6043. statement, if i had the value of 1, it is not known whether the first or second 
  6044. array element of x[ ] is passed as the second argument to func2(). Do not write 
  6045. code that depends on a particular order of evaluation of operators with the 
  6046. same precedence. 
  6047.  
  6048. The order of grouping operands with operators in an expression containing more 
  6049. than one instance of an operator with both associative and commutative 
  6050. properties is not specified. The operators that have the same associative and 
  6051. commutative properties are:  *, +, &, |, and ^ (or ╨║). The grouping of operands 
  6052. can be forced by grouping the expression in parentheses. 
  6053.  
  6054. Examples of Expressions and Precedence 
  6055.  
  6056. Related Information 
  6057.  
  6058.      Parenthesized Expressions ( ) 
  6059.      Expressions and Operators 
  6060.      Table of Operator Precedence and Associativity 
  6061.  
  6062.  
  6063. ΓòÉΓòÉΓòÉ <hidden> Examples of Expressions and Precedence ΓòÉΓòÉΓòÉ
  6064.  
  6065. The parentheses in the following expressions explicitly show how the compiler 
  6066. groups operands and operators. If parentheses did not appear in these 
  6067. expressions, the operands and operators are grouped in the same manner as 
  6068. indicated by the parentheses. 
  6069.  
  6070. total = (4 + (5 * 3));
  6071. total = (((8 * 5) / 10) / 3);
  6072. total = (10 + (5/3));
  6073.  
  6074. Because the order of grouping operands with operators that are both associative 
  6075. and commutative is not specified, the compiler can group the operands and 
  6076. operators in the expression: 
  6077.  
  6078. total = price + prov_tax + city_tax;
  6079.  
  6080. in the following ways (as indicated by parentheses): 
  6081.  
  6082. total = (price + (prov_tax + city_tax));
  6083. total = ((price + prov_tax) + city_tax);
  6084. total = ((price + city_tax) + prov_tax);
  6085.  
  6086. If the values in this expression are integers, the grouping of operands and 
  6087. operators does not affect the result. Because intermediate values are rounded, 
  6088. different groupings of floating-point operators give different results. 
  6089.  
  6090. In certain expressions, the grouping of operands and operators can affect the 
  6091. result. For example, in the following expression, each function call might be 
  6092. modifying the same global variables. 
  6093.  
  6094. a = b() + c() + d();
  6095.  
  6096. This expression can give different results depending on the order in which the 
  6097. functions are called. 
  6098.  
  6099. If the expression contains operators that are both associative and commutative 
  6100. and the order of grouping operands with operators can affect the result of the 
  6101. expression, separate the expression into several expressions. For example, the 
  6102. following expressions could replace the previous expression if the called 
  6103. functions do not produce any side effects that affect the variable a. 
  6104.  
  6105. a = b();
  6106. a += c();
  6107. a += d();
  6108.  
  6109. Integer overflows are ignored. Division by zero and floating-point exceptions 
  6110. are implementation dependent. 
  6111.  
  6112. See the IBM VisualAge C++ for OS/2 User's Guide and Reference for information 
  6113. about VisualAge C++ implementation dependencies. 
  6114.  
  6115.  
  6116. ΓòÉΓòÉΓòÉ <hidden> Table of Operator Precedence and Associativity ΓòÉΓòÉΓòÉ
  6117.  
  6118.  Operator Name           Operators 
  6119.  
  6120.  Primary scope resolution :: 
  6121.                             Associativity:  left to right 
  6122.  
  6123.  Primary                 ()  [ ]  .  -> 
  6124.                             Associativity:  left to right 
  6125.  
  6126.  Unary                   ++  --  -  +  !  ~  &  *  sizeof  new  delete 
  6127.                          (typename) (C cast) 
  6128.                             Associativity:  right to left 
  6129.  
  6130.  C++ Cast                (typename) 
  6131.                             Associativity:  left to right 
  6132.  
  6133.  C++ Pointer to Member   .*  ->* 
  6134.                             Associativity:  left to right 
  6135.  
  6136.  Multiplicative          *  /  % 
  6137.                             Associativity:  left to right 
  6138.  
  6139.  Additive                +  - 
  6140.                             Associativity:  left to right 
  6141.  
  6142.  Bitwise Shift           <<  >> 
  6143.                             Associativity:  left to right 
  6144.  
  6145.  Relational              <  >  <=  >= 
  6146.                             Associativity:  left to right 
  6147.  
  6148.  Equality                ==  != 
  6149.                             Associativity:  left to right 
  6150.  
  6151.  Bitwise Logical AND     & 
  6152.                             Associativity:  left to right 
  6153.  
  6154.  Bitwise Exclusive OR    ^  or  ╨║ 
  6155.                             Associativity:  left to right 
  6156.  
  6157.  Bitwise Inclusive OR    | 
  6158.                             Associativity:  left to right 
  6159.  
  6160.  Logical AND             && 
  6161.                             Associativity:  left to right 
  6162.  
  6163.  Logical OR              || 
  6164.                             Associativity:  left to right 
  6165.  
  6166.  Conditional             ?  : 
  6167.                             Associativity:  right to left 
  6168.  
  6169.  Assignment              =  +=  -=  *=  /=  <<=  >>=  %=  &=  ^=  |= 
  6170.                             Associativity:  right to left 
  6171.  
  6172.  Comma                   , 
  6173.                             Associativity:  left to right 
  6174.  
  6175.  
  6176. ΓòÉΓòÉΓòÉ 5.2. Operands ΓòÉΓòÉΓòÉ
  6177.  
  6178. Most expressions can contain several different, but related, types of operands. 
  6179. The following type classes describe related types of operands: 
  6180.  
  6181.  Integral    Character objects and constants, objects having an enumeration 
  6182.              type, and objects having the type short, int, long, or unsigned 
  6183.              long. 
  6184.  
  6185.  Arithmetic  Integral objects and objects having the type float, double, and 
  6186.              long double. 
  6187.  
  6188.  Scalar      Arithmetic objects and pointers to objects of any type. Also C++ 
  6189.              references. 
  6190.  
  6191.  Aggregate   Arrays, structures, and unions. Also C++ classes. 
  6192.  
  6193.  Many operators cause conversions from one data type to another. Conversions 
  6194.  are discussed in Implicit Type Conversions. 
  6195.  
  6196.  
  6197. ΓòÉΓòÉΓòÉ 5.3. lvalues ΓòÉΓòÉΓòÉ
  6198.  
  6199. An lvalue is an expression that represents an object. A modifiable lvalue is an 
  6200. expression representing an object that can be changed. It is typically the left 
  6201. operand in an assignment expression. For example, arrays and const objects are 
  6202. not modifiable lvalues, but static int objects are. 
  6203.  
  6204. All assignment operators evaluate their right operand and assign that value to 
  6205. their left operand. The left operand must evaluate to a reference to an object. 
  6206.  
  6207. The address operator (&) requires an lvalue as an operand while the increment 
  6208. (++) and the decrement (--) operators require a modifiable lvalue as an 
  6209. operand. 
  6210.  
  6211. Examples of Lvalues 
  6212.  
  6213. Related Information 
  6214.  
  6215.      Assignment Expressions 
  6216.      Address  & 
  6217.      Dot Operator . 
  6218.      Arrow Operator -> 
  6219.  
  6220.  
  6221. ΓòÉΓòÉΓòÉ <hidden> Examples of Lvalues ΓòÉΓòÉΓòÉ
  6222.  
  6223.  Expression               Lvalue 
  6224.  x = 42;                  x 
  6225.  *ptr = newvalue;         *ptr 
  6226.  a++                      a 
  6227.  
  6228.  
  6229. ΓòÉΓòÉΓòÉ 5.4. Primary Expressions ΓòÉΓòÉΓòÉ
  6230.  
  6231. A primary expression can be: 
  6232.  
  6233.      Identifiers 
  6234.      String Literals 
  6235.      Scope Resolution Operator :: 
  6236.      Parenthesized Expressions ( ) 
  6237.      Constant Expressions 
  6238.      Function Calls ( ) 
  6239.      Array Subscript [ ] 
  6240.      Dot Operator . 
  6241.      Arrow Operator -> 
  6242.  
  6243.  All primary operators have the same precedence and have left-to-right 
  6244.  associativity. 
  6245.  
  6246.  Related Information 
  6247.  
  6248.      Expressions and Operators 
  6249.      Operator Precedence and Associativity 
  6250.  
  6251.  
  6252. ΓòÉΓòÉΓòÉ 5.4.1. Scope Resolution Operator :: ΓòÉΓòÉΓòÉ
  6253.  
  6254. The :: (scope resolution) operator is used to qualify hidden names so that you 
  6255. can still use them. You can use the unary scope operator if a file scope name 
  6256. is hidden by an explicit declaration of the same name in a block or class. For 
  6257. example: 
  6258.  
  6259. int i = 10;
  6260. int f(int i)
  6261. {
  6262.       return i ? i : :: i; // return global i if local i is zero
  6263. }
  6264.  
  6265. You can also use the class scope operator to qualify class names or class 
  6266. member names. If a class member name is hidden, you can use it by qualifying it 
  6267. with its class name and the class scope operator. Whenever a name is followed 
  6268. by a :: operator, the name is interpreted as a class name. 
  6269.  
  6270. In the following example, the declaration of the variable X hides the class 
  6271. type X, but you can still use the static class member count by qualifying it 
  6272. with the class type X and the scope resolution operator. 
  6273.  
  6274. #include <iostream.h>
  6275. class X
  6276. {
  6277. public:
  6278.       static int count;
  6279. };
  6280. int X::count = 10;                // define static data member
  6281. void main ()
  6282. {
  6283.       int X = 0;                  // hides class type X
  6284.       cout << X::count << endl;   // use static member of class X
  6285. }
  6286.  
  6287. The scope resolution operator is also discussed in Class Names and in Scope of 
  6288. Class Names. 
  6289.  
  6290. Related Information 
  6291.  
  6292.      Class Names 
  6293.      Scope of Class Names 
  6294.      Expressions and Operators 
  6295.  
  6296.  
  6297. ΓòÉΓòÉΓòÉ 5.4.2. Parenthesized Expressions ( ) ΓòÉΓòÉΓòÉ
  6298.  
  6299. Use parentheses to explicitly force the order of expression evaluation. The 
  6300. following expression does not contain any parentheses used for grouping 
  6301. operands and operators. The parentheses surrounding weight, zipcode are used to 
  6302. form a function call. Note how the compiler groups the operands and operators 
  6303. in the expression according to the rules for operator precedence and 
  6304. associativity: 
  6305.  
  6306.  
  6307. -discount * item + handling(weight, zipcode) < .10 * item
  6308. |    |    |  |            |  |     |
  6309. '---.---'    |  '-----------.-----------'  '----.---'
  6310.   '----.-----'        |           |
  6311.      '----------.----------'           |
  6312.           '-------------------------------'
  6313.  
  6314. The following expression is similar to the previous expression, but it contains 
  6315. parentheses that change how the operands and operators are grouped: 
  6316.  
  6317.  
  6318. (-discount * (item + handling(weight, zipcode) ) ) < (.10 * item)
  6319.  |    |   |    |            |    |      |
  6320.  '---.---'   |    '----------.------------'    '-----.----'
  6321.    |     '--------.--------'              |
  6322.    '-------.---------'                  |
  6323.        '---------------------------------------------'
  6324.  
  6325. In an expression that contains both associative and commutative operators, you 
  6326. can use parentheses to specify the grouping of operands with operators. The 
  6327. parentheses in the following expression guarantee the order of grouping 
  6328. operands with the operators: 
  6329.  
  6330. x = f + (g + h);
  6331.  
  6332. Related Information 
  6333.  
  6334.      Operator Precedence and Associativity 
  6335.      Function Calls ( ) 
  6336.      Expressions and Operators 
  6337.  
  6338.  
  6339. ΓòÉΓòÉΓòÉ 5.4.3. Constant Expressions ΓòÉΓòÉΓòÉ
  6340.  
  6341. A constant expression is an expression with a value that is determined during 
  6342. compilation and cannot be changed at runtime, it can only be evaluated. 
  6343. Constant expressions can be composed of integer constants, character constants, 
  6344. floating-point constants, and enumeration constants, address constants, and 
  6345. other constant expressions. Some constant expressions, such as a string literal 
  6346. or an address constant, are lvalues. 
  6347.  
  6348. The C and C++ languages require constant expressions in the following places: 
  6349.  
  6350.      In the subscript declarator, as the description of an array bound 
  6351.      After the keyword case in a switch statement 
  6352.      In an enumerator, as the numeric value of an enum constant 
  6353.      In a bit-field width specifier 
  6354.      In the preprocessor #if statement (Enumeration constants, address 
  6355.       constants, and sizeof cannot be specified in the preprocessor #if 
  6356.       statement.) 
  6357.      In the initializer of a file scope data definition. 
  6358.  
  6359.  In all these contexts except for an initializer of a file scope data 
  6360.  definition, the constant expression can contain integer, character, and 
  6361.  enumeration constants, casts to integral types, and sizeof expressions. 
  6362.  Function-scope static and extern declarations can be initialized with the 
  6363.  address of a previously defined static or extern. 
  6364.  
  6365.  In a file scope data definition, the initializer must evaluate to a constant 
  6366.  or to the address of a static storage (extern or static) object (plus or minus 
  6367.  an integer constant) that is defined or declared earlier in the file. The 
  6368.  constant expression in the initializer can contain integer, character, 
  6369.  enumeration, and float constants, casts to any type, sizeof expressions, and 
  6370.  unary address expressions. 
  6371.  
  6372.  Functions, class objects, pointers, and references are not allowed unless they 
  6373.  occur in sizeof expressions. Comma operators and assignment operators cannot 
  6374.  appear in constant expressions. 
  6375.  
  6376.  Examples of Constant Expressions 
  6377.  
  6378.  Related Information 
  6379.  
  6380.      Arrays 
  6381.      Initializers 
  6382.      File Scope Data Declarations 
  6383.      switch 
  6384.      Enumerations 
  6385.      Structures 
  6386.      Conditional Compilation Directives 
  6387.      sizeof (Size of an Object) 
  6388.  
  6389.  
  6390. ΓòÉΓòÉΓòÉ <hidden> Examples of Constant Expressions ΓòÉΓòÉΓòÉ
  6391.  
  6392. The following examples show constants used in expressions. 
  6393.  
  6394.  Expression                         Constant 
  6395.  x = 42;                            42 
  6396.  extern int cost = 1000;            1000 
  6397.  y = 3 * 29;                        3 * 29 
  6398.  
  6399.  
  6400. ΓòÉΓòÉΓòÉ 5.4.4. Function Calls ( ) ΓòÉΓòÉΓòÉ
  6401.  
  6402. A function call is a primary expression containing a simple type name and a 
  6403. parenthesized argument list. The argument list can contain any number of 
  6404. expressions separated by commas. It can also be empty. 
  6405.  
  6406. For example: 
  6407.  
  6408. stub()
  6409. overdue(account, date, amount)
  6410. notify(name, date + 5)
  6411. report(error, time, date, ++num)
  6412.  
  6413. The arguments are evaluated, and each formal parameter is assigned the value of 
  6414. the corresponding argument. Assigning a value to a formal parameter within the 
  6415. function body changes the value of the parameter within the function, but has 
  6416. no effect on the argument. 
  6417.  
  6418. The type of a function call expression is the return type of the function. The 
  6419. return value is determined by the return statement in the function definition. 
  6420. The result of a function call is an lvalue only if the function returns a 
  6421. reference. A function can call itself. 
  6422.  
  6423. If you want a function to change the value of a variable, pass a pointer to the 
  6424. variable you want changed. When a pointer is passed as a parameter, the pointer 
  6425. is copied; the object pointed to is not copied. (See Pointers.) 
  6426.  
  6427. Arguments that are arrays and functions are converted to pointers before being 
  6428. passed as function arguments. 
  6429.  
  6430. Arguments passed to nonprototyped C functions undergo conversions: type short 
  6431. or char parameters are converted to int, and float parameters to double. Use a 
  6432. cast expression for other conversions. (See Cast Expressions.) 
  6433.  
  6434. If the function has not been previously declared, an implicit declaration of 
  6435. extern int func(); is assumed. 
  6436.  
  6437. The compiler compares the data types provided by the calling function with the 
  6438. data types that the called function expects. The compiler might also perform 
  6439. type conversions if the declaration of the function is in function prototype 
  6440. format and the parameters differ from the prototype or visible at the point 
  6441. where the function is called. 
  6442.  
  6443. The order in which parameters are evaluated is not specified. Avoid such calls 
  6444. as: 
  6445.  
  6446. method(samp1, bat.proc--, bat.proc);
  6447.  
  6448. In this example, bat.proc-- might be evaluated last, causing the last two 
  6449. arguments to be passed with the same value. 
  6450.  
  6451. Example of a Function Call 
  6452.  
  6453. Related Information 
  6454.  
  6455.      Functions 
  6456.      Pointers 
  6457.      Cast Expressions 
  6458.      Primary Expressions 
  6459.  
  6460.  
  6461. ΓòÉΓòÉΓòÉ <hidden> Example of a Function Call ΓòÉΓòÉΓòÉ
  6462.  
  6463. /************************************************************************
  6464. *
  6465.  
  6466. In the following example, main passes func two values: 5 and 7. The function 
  6467. func receives copies of these values and accesses them by the identifiers: a 
  6468. and b. The function func changes the value of a. When control passes back to 
  6469. main, the actual values of x and y are not changed. The called function func 
  6470. only receives copies of x and y, not the values themselves. 
  6471.  
  6472.                                                                         *
  6473. ************************************************************************/
  6474.  
  6475. /**
  6476.  ** This example illustrates function calls
  6477.  **/
  6478.  
  6479. #include <stdio.h>
  6480.  
  6481. int main(void)
  6482. {
  6483.    int x = 5, y = 7;
  6484.  
  6485.    func(x, y);
  6486.    printf("In main, x = %d    y = %d\n", x, y);
  6487. }
  6488.  
  6489. void func (int a, int b)
  6490. {
  6491.    a += b;
  6492.    printf("In func, a = %d    b = %d\n", a, b);
  6493. }
  6494.  
  6495. /************************************************************************
  6496. *
  6497.  
  6498. This program produces the following output: 
  6499.  
  6500. In func, a = 12   b = 7
  6501. In main, x = 5    y = 7
  6502.  
  6503.                                                                         *
  6504. ************************************************************************/
  6505.  
  6506.  
  6507. ΓòÉΓòÉΓòÉ 5.4.5. Array Subscript [ ] ΓòÉΓòÉΓòÉ
  6508.  
  6509. A primary expression followed by an expression in [ ] (square brackets) 
  6510. specifies an element of an array. The expression within the square brackets is 
  6511. referred to as a subscript. 
  6512.  
  6513. The primary expression must have a pointer type, and the subscript must have 
  6514. integral type. The result of an array subscript is an lvalue. 
  6515.  
  6516. The first element of each array has the subscript 0. The expression 
  6517. contract[35] refers to the 36th element in the array contract. 
  6518.  
  6519. In a multidimensional array, you can reference each element (in the order of 
  6520. increasing storage locations) by incrementing the rightmost subscript most 
  6521. frequently. 
  6522.  
  6523. For example, the following statement gives the value 100 to each element in the 
  6524. array code[4][3][6]: 
  6525.  
  6526. for (first = 0; first <= 3; ++first)
  6527.    for (second = 0; second <= 2; ++second)
  6528.       for (third = 0; third <= 5; ++third)
  6529.          code[first][second][third] = 100;
  6530.  
  6531. By definition, the expression: 
  6532.  
  6533. *((exp1) + (exp2))
  6534.  
  6535. is identical to the expression: 
  6536.  
  6537. exp1[exp2]
  6538.  
  6539. which is also identical to: 
  6540.  
  6541. exp2[exp1]
  6542.  
  6543. Related Information 
  6544.  
  6545.      Arrays 
  6546.      lvalues 
  6547.      Primary Expressions 
  6548.  
  6549.  
  6550. ΓòÉΓòÉΓòÉ 5.4.6. Dot Operator . ΓòÉΓòÉΓòÉ
  6551.  
  6552. The . (dot) operator is used to access structure or C++ class members using a 
  6553. structure object. The member is specified by a primary expression, followed by 
  6554. a . (dot) operator, followed by a name. For example: 
  6555.  
  6556.    roster[num].name
  6557.    roster[num].name[1]
  6558.  
  6559. The primary expression must be an object of type class, struct or union. The 
  6560. name must be a member of that object. 
  6561.  
  6562. The value of the expression is the value of the selected member. If the primary 
  6563. expression and the name are lvalues, the expression value is also an lvalue. 
  6564.  
  6565. For more information on class members, see C++ Class Members and Friends. 
  6566.  
  6567. Related Information 
  6568.  
  6569.      Arrow Operator -> 
  6570.      C++ Class Members and Friends 
  6571.      Unions 
  6572.      Structures 
  6573.      lvalues 
  6574.      Primary Expressions 
  6575.  
  6576.  
  6577. ΓòÉΓòÉΓòÉ 5.4.7. Arrow Operator -> ΓòÉΓòÉΓòÉ
  6578.  
  6579. The -> (arrow) operator is used to access structure or C++ class members using 
  6580. a pointer. A primary expression, followed by an -> (arrow) operator, followed 
  6581. by a name, designates a member of the object to which the pointer points. For 
  6582. example: 
  6583.  
  6584.    roster -> name
  6585.  
  6586. The primary expression must be a pointer to an object of type class, struct or 
  6587. union. The name must be a member of that object. 
  6588.  
  6589. The value of the expression is the value of the selected member. If the name is 
  6590. an lvalue, the expression value is also an lvalue. 
  6591.  
  6592. For more information on class members, see C++ Class Members and Friends. 
  6593.  
  6594. Related Information 
  6595.  
  6596.      Dot Operator . 
  6597.      C++ Class Members and Friends 
  6598.      Unions 
  6599.      Structures 
  6600.      lvalues 
  6601.      Pointers 
  6602.      Primary Expressions 
  6603.  
  6604.  
  6605. ΓòÉΓòÉΓòÉ 5.5. Unary Expressions ΓòÉΓòÉΓòÉ
  6606.  
  6607. A unary expression contains one operand and a unary operator. All unary 
  6608. operators have the same precedence and have right-to-left associativity. 
  6609.  
  6610. As indicated in the following descriptions, the usual arithmetic conversions 
  6611. are performed on the operands of most unary expressions. See Arithmetic 
  6612. Conversions for more information. 
  6613.  
  6614.      Increment  ++ 
  6615.      Decrement  - - 
  6616.      Unary Plus  + 
  6617.      Unary Minus  - 
  6618.      Logical Negation  ! 
  6619.      Bitwise Negation  ~ 
  6620.      Address  & 
  6621.      Indirection  * 
  6622.      Cast Expressions 
  6623.      sizeof (Size of an Object) 
  6624.      new Operator 
  6625.      delete Operator 
  6626.      throw Expressions 
  6627.  
  6628.  Related Information 
  6629.  
  6630.      Binary Expressions 
  6631.      Expressions and Operators 
  6632.      Operator Precedence and Associativity 
  6633.  
  6634.  
  6635. ΓòÉΓòÉΓòÉ 5.5.1. Increment  ++ ΓòÉΓòÉΓòÉ
  6636.  
  6637. The ++ (increment) operator adds 1 to the value of a scalar operand, or if the 
  6638. operand is a pointer, increments the operand by the size of the object to which 
  6639. it points. The operand receives the result of the increment operation. The 
  6640. operand must be a modifiable lvalue. 
  6641.  
  6642. You can put the ++ before or after the operand. If it appears before the 
  6643. operand, the operand is incremented. Then the incremented value is used in the 
  6644. expression. If you put the ++ after the operand, the value of the operand is 
  6645. used in the expression before the operand is incremented. For example: 
  6646.  
  6647. play = ++play1 + play2++;
  6648.  
  6649. is equivalent to the following three expressions: 
  6650.  
  6651. play1 = play1 + 1;
  6652. play  = play1 + play2;
  6653. play2 = play2 + 1;
  6654.  
  6655. The return type of the increment expression is the same type as that of the 
  6656. operand. 
  6657.  
  6658. Related Information 
  6659.  
  6660.      Decrement  - - 
  6661.      Addition  + 
  6662.      Pointer Arithmetic 
  6663.      Unary Expressions 
  6664.      Arithmetic Conversions 
  6665.  
  6666.  
  6667. ΓòÉΓòÉΓòÉ 5.5.2. Decrement  - - ΓòÉΓòÉΓòÉ
  6668.  
  6669. The -- (decrement) operator subtracts 1 from the value of a scalar operand, or 
  6670. if the operand is a pointer, decreases the operand by the size of the object to 
  6671. which it points. The operand receives the result of the decrement operation. 
  6672. The operand must be a modifiable lvalue. 
  6673.  
  6674. You can put the -- before or after the operand. If it appears before the 
  6675. operand, the operand is decremented, and the decremented value is used in the 
  6676. expression. If the -- appears after the operand, the current value of the 
  6677. operand is used in the expression and the operand is decremented. 
  6678.  
  6679. For example: 
  6680.  
  6681. play = --play1 + play2--;
  6682.  
  6683. is equivalent to the following three expressions: 
  6684.  
  6685. play1 = play1 - 1;
  6686. play = play1 + play2;
  6687. play2 = play2 - 1;
  6688.  
  6689. The return type of the decrement expression is the same type as that of the 
  6690. operand. 
  6691.  
  6692. Related Information 
  6693.  
  6694.      Increment  ++ 
  6695.      Subtraction  - 
  6696.      Pointer Arithmetic 
  6697.      Unary Expressions 
  6698.      Arithmetic Conversions 
  6699.  
  6700.  
  6701. ΓòÉΓòÉΓòÉ 5.5.3. Unary Plus  + ΓòÉΓòÉΓòÉ
  6702.  
  6703. The + (unary plus) operator maintains the value of the operand.  The operand 
  6704. can have any arithmetic type. The result is not an lvalue. 
  6705.  
  6706. The result of the unary plus expression has the same type as the operand after 
  6707. any integral promotions (for example, char to int). 
  6708.  
  6709. Note:  Any plus sign in front of a constant is not part of the constant. 
  6710.  
  6711. Related Information 
  6712.  
  6713.      Unary Minus  - 
  6714.      Unary Expressions 
  6715.      Arithmetic Conversions 
  6716.  
  6717.  
  6718. ΓòÉΓòÉΓòÉ 5.5.4. Unary Minus  - ΓòÉΓòÉΓòÉ
  6719.  
  6720. The - (unary minus) operator negates the value of the operand.  The operand can 
  6721. have any arithmetic type. The result is not an lvalue. 
  6722.  
  6723. For example, if quality has the value 100, -quality has the value -100. 
  6724.  
  6725. The result of the unary minus expression has the same type as the operand after 
  6726. any integral promotions (for example, char to int). 
  6727.  
  6728. Note:  Any minus sign in front of a constant is not part of the constant. 
  6729.  
  6730. Related Information 
  6731.  
  6732.      Unary Plus  + 
  6733.      Unary Expressions 
  6734.      Arithmetic Conversions 
  6735.  
  6736.  
  6737. ΓòÉΓòÉΓòÉ 5.5.5. Logical Negation  ! ΓòÉΓòÉΓòÉ
  6738.  
  6739. The ! (logical negation) operator determines whether the operand evaluates to 0 
  6740. (false) or nonzero (true). The expression yields the value 1 (true) if the 
  6741. operand evaluates to 0, and yields the value 0 (false) if the operand evaluates 
  6742. to a nonzero value. The operand must have a scalar data type, but the result of 
  6743. the operation has always type int and is not an lvalue. 
  6744.  
  6745. The following two expressions are equivalent: 
  6746.  
  6747. !right;
  6748. right == 0;
  6749.  
  6750. Related Information 
  6751.  
  6752.      Equality  ==  != 
  6753.      Relational  <  >  <=  >= 
  6754.      Unary Expressions 
  6755.      Arithmetic Conversions 
  6756.  
  6757.  
  6758. ΓòÉΓòÉΓòÉ 5.5.6. Bitwise Negation  ~ ΓòÉΓòÉΓòÉ
  6759.  
  6760. The ~ (bitwise negation) operator yields the bitwise complement of the operand. 
  6761. In the binary representation of the result, every bit has the opposite value of 
  6762. the same bit in the binary representation of the operand. The operand must have 
  6763. an integral type. The result has the same type as the operand but is not an 
  6764. lvalue. 
  6765.  
  6766. Suppose x represents the decimal value 5. The 32-bit binary representation of x 
  6767. is: 
  6768.  
  6769. 00000000000000000000000000000101
  6770.  
  6771. The expression ~x yields the following result, represented here as a 32-bit 
  6772. binary number: 
  6773.  
  6774. 11111111111111111111111111111010
  6775.  
  6776. The 32-bit binary representation of ~0 is: 
  6777.  
  6778. 11111111111111111111111111111111
  6779.  
  6780. Related Information 
  6781.  
  6782.      Bitwise Left and Right Shift  <<  >> 
  6783.      Bitwise AND  & 
  6784.      Bitwise Exclusive OR  ^ 
  6785.      Bitwise Inclusive OR  | 
  6786.      Unary Expressions 
  6787.      Arithmetic Conversions 
  6788.  
  6789.  
  6790. ΓòÉΓòÉΓòÉ 5.5.7. Address  & ΓòÉΓòÉΓòÉ
  6791.  
  6792. The & (address) operator yields a pointer to its operand. The operand must be 
  6793. an lvalue, a function designator, or a qualified name. It cannot be a bit 
  6794. field, nor can it have the storage class register. 
  6795.  
  6796. If the operand is an lvalue or function, the resulting type is a pointer to the 
  6797. expression type. For example, if the expression has type int, the result is a 
  6798. pointer to an object having type int. 
  6799.  
  6800. If the operand is a qualified name and the member is not static, the result is 
  6801. a pointer to a member of class and has the same type as the member. The result 
  6802. is not an lvalue. 
  6803.  
  6804. If p_to_y is defined as a pointer to an int and y as an int, the following 
  6805. expression assigns the address of the variable y to the pointer p_to_y: 
  6806.  
  6807. p_to_y = &y;
  6808.  
  6809. C++ Note:  You can use the & operator with overloaded functions only in an 
  6810. initialization or assignment where the left side uniquely determines which 
  6811. version of the overloaded function is used. For more information, see 
  6812. Overloading Functions. 
  6813.  
  6814. Related Information 
  6815.  
  6816.      Pointers 
  6817.      lvalues 
  6818.      register Storage Class Specifier 
  6819.      Overloading Functions 
  6820.      Unary Expressions 
  6821.  
  6822.  
  6823. ΓòÉΓòÉΓòÉ 5.5.8. Indirection  * ΓòÉΓòÉΓòÉ
  6824.  
  6825. The * (indirection) operator determines the value referred to by the 
  6826. pointer-type operand. The operand cannot be a pointer to an incomplete type. 
  6827. The operation yields an lvalue or a function designator if the operand points 
  6828. to a function. The usual unary conversions are performed. Arrays and functions 
  6829. are converted to pointers. 
  6830.  
  6831. The type of the operand determines the type of the result. For example, if the 
  6832. operand is a pointer to an int, the result has type int. 
  6833.  
  6834. Do not apply the indirection operator to any pointer that contains an address 
  6835. that is not valid, such as NULL. The result is not defined. 
  6836.  
  6837. If p_to_y is defined as a pointer to an int and y as an int, the expressions: 
  6838.  
  6839. p_to_y = &y;
  6840. *p_to_y = 3;
  6841.  
  6842. cause the variable y to receive the value 3. 
  6843.  
  6844. Related Information 
  6845.  
  6846.      Pointers 
  6847.      lvalues 
  6848.      Functions 
  6849.      Unary Expressions 
  6850.  
  6851.  
  6852. ΓòÉΓòÉΓòÉ 5.5.9. Cast Expressions ΓòÉΓòÉΓòÉ
  6853.  
  6854. The cast operator is used for explicit type conversions. It converts the value 
  6855. of the operand to a specified data type and performs the necessary conversions 
  6856. to the operand for the type. 
  6857.  
  6858. For C, the operand must be scalar and the type must be either scalar or void. 
  6859. For C++, the operand can have class type. If the operand has class type, it can 
  6860. be cast to any type for which the class has a user-defined conversion function. 
  6861. User-defined conversion functions are described in Conversion Functions. 
  6862.  
  6863. The result of a cast is not an lvalue unless the cast is to a reference type. 
  6864. When you cast to a reference type, no user-defined conversions are performed 
  6865. and the result is an lvalue. 
  6866.  
  6867. There are two types of casts that take one argument: 
  6868.  
  6869.      C-style casts, with the format (X)a. These are the only casts allowed in 
  6870.       C. 
  6871.      function-style casts with one argument, such as X(a). These are allowed 
  6872.       in C++ only. 
  6873.  
  6874.  Both types of casts convert the argument a to the type X. In C++, they can 
  6875.  invoke a constructor, if the target type is a class, or they can invoke a 
  6876.  conversion function, if the source type is a class. They can be ambiguous if 
  6877.  both conditions hold. 
  6878.  
  6879.  A function-style cast with no arguments, such as X(), creates a temporary 
  6880.  object of type X. If X is a class with constructors, the default constructor 
  6881.  X::X() is called. 
  6882.  
  6883.  A function-style cast with more than one argument, such as X(a,b), creates a 
  6884.  temporary object of type X. This object must be a class with a constructor 
  6885.  that takes two arguments of types compatible with the types of a and b. The 
  6886.  constructor is called with a and b as arguments. 
  6887.  
  6888.  Related Information 
  6889.  
  6890.      Implicit Type Conversions 
  6891.      Conversion by Constructor 
  6892.      Conversion Functions 
  6893.      Type Specifiers 
  6894.  
  6895.  
  6896. ΓòÉΓòÉΓòÉ 5.5.10. sizeof (Size of an Object) ΓòÉΓòÉΓòÉ
  6897.  
  6898. The sizeof operator yields the size in bytes of the operand. Types cannot be 
  6899. defined in a sizeof expression. The sizeof operation cannot be performed on 
  6900.  
  6901.      A bit field 
  6902.      A function 
  6903.      An undefined structure or class 
  6904.      An incomplete type (such as void) 
  6905.  
  6906.  The operand can be the parenthesized name of a type. 
  6907.  
  6908.  The compiler must be able to evaluate the size at compile time. The expression 
  6909.  is not evaluated; there are no side effects. For example, the value of b is 5 
  6910.  from initialization to the end of program runtime: 
  6911.  
  6912.   #include <stdio.h>
  6913.  
  6914.   int main(void){
  6915.     int b = 5;
  6916.     sizeof(b++);
  6917.   }
  6918.  
  6919.  The size of a char object is the size of a byte. For example, if a variable x 
  6920.  has type char, the expression sizeof(x) always evaluates to 1. 
  6921.  
  6922.  The result of a sizeof operation has type size_t, which is an unsigned 
  6923.  integral type defined in the <stddef.h> header file. 
  6924.  
  6925.  The size of an object is determined on the basis of its definition. The sizeof 
  6926.  operator does not perform any conversions. If the operand contains operators 
  6927.  that perform conversions, the compiler does take these conversions into 
  6928.  consideration. The following expression causes the usual arithmetic 
  6929.  conversions to be performed. The result of the expression x + 1 has type int 
  6930.  (if x has type char, short, or int or any enumeration type) and is equivalent 
  6931.  to sizeof(int): 
  6932.  
  6933.   sizeof (x + 1)
  6934.  
  6935.  Except in preprocessor directives, you can use a sizeof expression wherever a 
  6936.  constant or unsigned constant is required. One of the most common uses for the 
  6937.  sizeof operator is to determine the size of objects that are referred to 
  6938.  during storage allocation, input, and output functions. 
  6939.  
  6940.  Another use of sizeof is in porting code across platforms. You should use the 
  6941.  sizeof operator to determine the size that a data type represents. For 
  6942.  example: 
  6943.  
  6944.   sizeof(int)
  6945.  
  6946.  C++ Notes:  The result of a sizeof expression depends on the type it is 
  6947.  applied to: 
  6948.  
  6949.  An array    The result is the total number of bytes in the array. For example, 
  6950.              in an array with 10 elements, the size is equal to 10 times the 
  6951.              size of a single element. The compiler does not convert the array 
  6952.              to a pointer before evaluating the expression. 
  6953.  
  6954.  A class     The result is always nonzero, and is equal to the number of bytes 
  6955.              in an object of that class including any padding required for 
  6956.              placing class objects in an array. 
  6957.  
  6958.  A reference The result is the size of the referenced object. 
  6959.  
  6960.  Related Information 
  6961.  
  6962.      Constant Expressions 
  6963.      Implicit Type Conversions 
  6964.      Type Specifiers 
  6965.      Unary Expressions 
  6966.  
  6967.  
  6968. ΓòÉΓòÉΓòÉ 5.5.11. new Operator ΓòÉΓòÉΓòÉ
  6969.  
  6970. The new operator provides dynamic storage allocation. The syntax for an 
  6971. allocation expression containing the new operator is: 
  6972.  
  6973. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇnewΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇ(type)ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>
  6974.   ΓööΓöÇ::ΓöÇΓöÿ    ΓööΓöÇ(argument_list)ΓöÇΓöÿ  ΓööΓöÇnew_typeΓöÇΓöÿ
  6975. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  6976.   ΓööΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÿ
  6977.     ΓööΓöÇinitial_valueΓöÇΓöÿ
  6978.  
  6979. If you prefix new with the scope resolution operator (::), the global operator 
  6980. new() is used. If you specify an argument_list, the overloaded new operator 
  6981. that corresponds to that argument_list is used. The type is an existing 
  6982. built-in or user-defined type. A new_type is a type that has not already been 
  6983. defined and can include type specifiers and declarators. 
  6984.  
  6985. An allocation expression containing the new operator is used to find storage in 
  6986. free store for the object being created. The new expression returns a pointer 
  6987. to the object created and can be used to initialize the object. If the object 
  6988. is an array, a pointer to the initial element is returned. 
  6989.  
  6990. You can use the routine set_new_handler() to change the default behavior of 
  6991. new. You can also use the /Tm option to enable a debug version of new, as 
  6992. described in Debug Versions of new and delete. 
  6993.  
  6994. You cannot use the new operator to allocate function types, void, or incomplete 
  6995. class types because these are not object types. However, you can allocate 
  6996. pointers to functions with the new operator. You cannot create a reference with 
  6997. the new operator. 
  6998.  
  6999. When the object being created is an array, only the first dimension can be a 
  7000. general expression. All subsequent dimensions must be constant integral 
  7001. expressions. The first dimension can be a general expression even when an 
  7002. existing type is used. You can create an array with zero bounds with the new 
  7003. operator. For example: 
  7004.  
  7005. char * c = new char[0];
  7006.  
  7007. In this case, a pointer to a unique object is returned. 
  7008.  
  7009. An object created with operator new() exists until the operator delete() is 
  7010. called to deallocate the object's memory, or until program ends. 
  7011.  
  7012. If parentheses are used within a new_type, parentheses should also surround the 
  7013. new_type to prevent syntax errors. 
  7014.  
  7015. Example of Allocating Storage with new() 
  7016.  
  7017. The type of the object being created cannot contain class declarations, 
  7018. enumeration declarations, or const or volatile types. It can contain pointers 
  7019. to const or volatile objects. 
  7020.  
  7021. For example, const char* is allowed, but char* const is not. 
  7022.  
  7023. Additional arguments can be supplied to new by using the argument_list, also 
  7024. called the placement syntax. If placement arguments are used, a declaration of 
  7025. operator new() with these arguments must exist. For example: 
  7026.  
  7027. #include <stddef.h>
  7028. class X
  7029. {
  7030. public:
  7031.       void* operator new(size_t,int, int){ /* ... */ }
  7032. };
  7033. void main ()
  7034. {
  7035.       X* ptr = new(1,2) X;
  7036. }
  7037.  
  7038. Additional information is provided on: 
  7039.  
  7040.      Member Functions and the Global operator new() 
  7041.      Initializing Objects Created with the new Operator 
  7042.  
  7043.  Related Information 
  7044.  
  7045.      set_new_handler() - Set Behavior for new Failure 
  7046.      Overloaded new and delete 
  7047.      Debug Versions of new and delete 
  7048.      Constructors and Destructors Overview 
  7049.      Free Store 
  7050.      delete Operator 
  7051.      Unary Expressions 
  7052.      /Tm option 
  7053.  
  7054.  
  7055. ΓòÉΓòÉΓòÉ 5.5.11.1. Member Functions and the Global operator new() and operator new[]() ΓòÉΓòÉΓòÉ
  7056.  
  7057. When an object of a class type is created with the new operator, the member 
  7058. operator new() function is implicitly called. The first argument is the amount 
  7059. of space requested. 
  7060.  
  7061. The following rules determine which storage allocation function is used: 
  7062.  
  7063.    1. If your own operator new() exists, and the :: operator is not used, your 
  7064.       operator new() is used. 
  7065.  
  7066.    2. If you have not defined an operator new() function, the global ::operator 
  7067.       new() function defined in <new.h> is used. The allocation expression of 
  7068.       the form ::operator new() ensures that the global new operator is called, 
  7069.       rather than your class member operator. 
  7070.  
  7071.  When a nonclass object is created with the new operator, the global ::operator 
  7072.  new() is used. 
  7073.  
  7074.  The order of evaluation of a call to an operator new() is undefined in the 
  7075.  evaluation of arguments to constructors. If operator new() returns 0, the 
  7076.  arguments to a constructor may or may not have been evaluated. 
  7077.  
  7078.  
  7079. ΓòÉΓòÉΓòÉ 5.5.11.2. Initializing Objects Created with the new Operator ΓòÉΓòÉΓòÉ
  7080.  
  7081. You can initialize objects created with the new operator in several ways. For 
  7082. nonclass objects, or for class objects without constructors, a new initializer 
  7083. expression can be provided in a new expression by specifying ( expression ) or 
  7084. (). For example: 
  7085.  
  7086. double* pi = new double(3.1415926);
  7087. int* score = new int(89);
  7088. float* unknown = new float();
  7089.  
  7090. If a class has a constructor, the new initializer must be provided when any 
  7091. object of that class is allocated. The arguments of the new initializer must 
  7092. match the arguments of a class constructor, unless the class has a default 
  7093. constructor. 
  7094.  
  7095. You cannot specify an initializer for arrays. You can initialize an array of 
  7096. class objects only if the class has a default constructor. The constructor is 
  7097. called to initialize each array element (class object). 
  7098.  
  7099. Initialization using the new initializer is performed only if new successfully 
  7100. allocates storage. 
  7101.  
  7102.  
  7103. ΓòÉΓòÉΓòÉ <hidden> Example of Allocating Storage with new() ΓòÉΓòÉΓòÉ
  7104.  
  7105. /***********************************************************************
  7106. *
  7107.  
  7108. In the following example, storage is allocated for an array of pointers to 
  7109. functions: 
  7110.  
  7111.                                                                         *
  7112. ************************************************************************/
  7113.  
  7114. void f();
  7115. void g();
  7116. void main()
  7117. {
  7118.       void (**p)(), (**q)();
  7119.       // declare p and q as pointers to pointers to void functions
  7120.       p = new (void (*[3])());
  7121.       // p now points to an array of pointers to functions
  7122.       q = new void(*[3])(); // error
  7123.       // error - bound as 'q = (new void) (*[3])();'
  7124.       p[0] = f;  // p[0] to point to function f
  7125.       q[2] = g;  // q[2] to point to function g
  7126.       p[0]();    // call f()
  7127.       q[2]();    // call g()
  7128. }
  7129.  
  7130. /************************************************************************
  7131. *
  7132.  
  7133. However, the second use of new causes an erroneous binding of q = (new void) 
  7134. (*[3])(). 
  7135.  
  7136.                                                                         *
  7137. ************************************************************************/
  7138.  
  7139.  
  7140. ΓòÉΓòÉΓòÉ 5.5.11.3. set_new_handler() - Set Behavior for new Failure ΓòÉΓòÉΓòÉ
  7141.  
  7142. When the new operator creates a new object, it calls the operator new() 
  7143. function to obtain the needed storage. 
  7144.  
  7145. When new cannot allocate storage, it calls a new handler function if one has 
  7146. been installed by a call to set_new_handler(). The set_new_handler() function 
  7147. is defined in <new.h>. Use it to call a new handler you have defined or the 
  7148. default new handler. 
  7149.  
  7150. The set_new_handler() function has the prototype: 
  7151.  
  7152. typedef void(*PNH)();
  7153. PNH set_new_handler(PNH);
  7154.  
  7155. set_new_handler() takes as an argument a pointer to a function (the new 
  7156. handler), which has no arguments and returns void.  It returns a pointer to the 
  7157. previous new handler function. 
  7158.  
  7159. If you do not specify your own set_new_handler() function, new returns the NULL 
  7160. pointer. 
  7161.  
  7162. The _set_mt_new_handler() function behaves exactly the same way as 
  7163. set_new_handler(), except that it only affects the current thread. When a new 
  7164. handler function needs to be called, the code first checks for a thread new 
  7165. handler. If one has been registered, it is called. If not, the new handler 
  7166. registered with set_new_handler() is called. 
  7167.  
  7168. Example of set_new_handler() 
  7169.  
  7170. Related Information 
  7171.  
  7172.      new Operator 
  7173.      Member Functions and the Global operator new() 
  7174.      Initializing Objects Created with the new Operator 
  7175.      Overloaded new and delete 
  7176.      Constructors and Destructors Overview 
  7177.      Free Store 
  7178.  
  7179.  
  7180. ΓòÉΓòÉΓòÉ <hidden> Example of set_new_handler() ΓòÉΓòÉΓòÉ
  7181.  
  7182. The following program segment shows how you could use set_new_handler() to 
  7183. return a message if the new operator cannot allocate storage: 
  7184.  
  7185. #include <iostream.h>
  7186. #include <new.h>
  7187. void no_storage()
  7188. {
  7189.     cerr << "Operator new failed: no storage is available.\n";
  7190.       exit(1);
  7191. }
  7192. main()
  7193. {
  7194.      set_new_handler(&no_storage);
  7195.    // Rest of program ...
  7196. }
  7197.  
  7198. If the program fails because new cannot allocate storage, the program exits 
  7199. with the message: 
  7200.  
  7201.  Operator new failed: no storage is available.
  7202.  
  7203.  
  7204. ΓòÉΓòÉΓòÉ 5.5.12. delete Operator ΓòÉΓòÉΓòÉ
  7205.  
  7206. The delete operator destroys the object created with new by deallocating the 
  7207. memory associated with the object. 
  7208.  
  7209. The delete operator has a void return type. It has the syntax: 
  7210.  
  7211. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdeleteΓöÇΓöÇobject_pointerΓöÇΓöÇ><
  7212.   ΓööΓöÇ::ΓöÇΓöÿ
  7213.  
  7214. For example:   delete myobj; 
  7215.  
  7216. The operand of delete must be a pointer returned by new, and cannot be a 
  7217. pointer to constant. If an attempt to create an object with new fails, the 
  7218. pointer returned by new will have a zero value, but it can still be used with 
  7219. delete. Deleting a null pointer has no effect. 
  7220.  
  7221. The delete[] operator frees storage allocated for array objects created with 
  7222. new. The delete operator frees storage allocated for individual objects created 
  7223. with new. 
  7224.  
  7225. It has the syntax: 
  7226.  
  7227. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdeleteΓöÇΓöÇ[ΓöÇΓöÇ]ΓöÇΓöÇarrayΓöÇΓöÇ><
  7228.   ΓööΓöÇ::ΓöÇΓöÿ
  7229.  
  7230. For example:   delete [] myarray; 
  7231.  
  7232. The result of deleting an array object with delete is undefined, as is deleting 
  7233. an individual object with delete[]. The array dimensions do not need to be 
  7234. specified with delete[]. 
  7235.  
  7236. The results of attempting to access a deleted object are undefined because the 
  7237. deletion of an object can change its value. 
  7238.  
  7239. If a destructor has been defined for a class, delete invokes that destructor. 
  7240. Whether a destructor exists or not, delete frees the storage pointed to by 
  7241. calling the function operator delete() of the class if one exists. 
  7242.  
  7243. The global ::operator delete() is used if: 
  7244.  
  7245.      The class has no operator delete(). 
  7246.      The object is of a nonclass type. 
  7247.      The object is deleted with the ::delete expression. For example: 
  7248.       ::delete p; 
  7249.  
  7250.  The default global operator delete() only frees storage allocated by the 
  7251.  default global operator new(). The default global operator delete[]() only 
  7252.  frees storage allocated for arrays by the default global operator new(). 
  7253.  
  7254.  You can also use the /Tm compiler option to enable a debug version of the 
  7255.  delete operator, as described in Debug Versions of new and delete. 
  7256.  
  7257.  Related Information 
  7258.  
  7259.      Overloaded new and delete 
  7260.      Debug Versions of new and delete 
  7261.      Constructors and Destructors Overview 
  7262.      Free Store 
  7263.      new Operator 
  7264.      Unary Expressions 
  7265.      /Tm option 
  7266.  
  7267.  
  7268. ΓòÉΓòÉΓòÉ 5.5.13. throw Expressions ΓòÉΓòÉΓòÉ
  7269.  
  7270. A throw expression is used to throw exceptions to C++ exception handlers. It 
  7271. causes control to be passed out of the block enclosing the throw statement to 
  7272. the first C++ exception handler whose catch argument matches the throw 
  7273. expression. A throw expression is a unary expression of type void. 
  7274.  
  7275. For more information on the throw expression, see C++ Exception Handling. 
  7276.  
  7277. Related Information 
  7278.  
  7279.      C++ Exception Handling 
  7280.      Unary Expressions 
  7281.  
  7282.  
  7283. ΓòÉΓòÉΓòÉ 5.6. Binary Expressions ΓòÉΓòÉΓòÉ
  7284.  
  7285. A binary expression contains two operands separated by one operator. 
  7286.  
  7287. Not all binary operators have the same precedence. The table in the section 
  7288. Operator Precedence and Associativity shows the order of precedence among 
  7289. operators. All binary operators have left-to-right associativity. 
  7290.  
  7291. The order in which the operands of most binary operators are evaluated is not 
  7292. specified. To ensure correct results, avoid creating binary expressions that 
  7293. depend on the order in which the compiler evaluates the operands. 
  7294.  
  7295. As indicated in the following descriptions, the usual arithmetic conversions 
  7296. are performed on the operands of most binary expressions. See Arithmetic 
  7297. Conversions for more information. 
  7298.  
  7299.      Multiplication  * 
  7300.      Division  / 
  7301.      Remainder  % 
  7302.      Addition  + 
  7303.      Subtraction  - 
  7304.      Bitwise Left and Right Shift  <<  >> 
  7305.      Relational  <  >  <=  >= 
  7306.      Equality  ==  != 
  7307.      Bitwise AND  & 
  7308.      Bitwise Exclusive OR  ^ 
  7309.      Bitwise Inclusive OR  | 
  7310.      Logical AND  && 
  7311.      Logical OR  || 
  7312.      Pointer to Member Operators .* ->* 
  7313.  
  7314.  Related Information 
  7315.  
  7316.      Unary Expressions 
  7317.      Expressions and Operators 
  7318.      Operator Precedence and Associativity 
  7319.  
  7320.  
  7321. ΓòÉΓòÉΓòÉ 5.6.1. Multiplication  * ΓòÉΓòÉΓòÉ
  7322.  
  7323. The * (multiplication) operator yields the product of its operands.  The 
  7324. operands must have an arithmetic type.  The result is not an lvalue. 
  7325.  
  7326. Because the multiplication operator has both associative and commutative 
  7327. properties, the compiler can rearrange the operands in an expression that 
  7328. contains more than one multiplication operator. For example, the expression: 
  7329.  
  7330. sites * number * cost
  7331.  
  7332. can be interpreted in any of the following ways: 
  7333.  
  7334. (sites * number) * cost
  7335. sites * (number * cost)
  7336. (cost * sites) * number
  7337.  
  7338. Related Information 
  7339.  
  7340.      Division  / 
  7341.      Remainder  % 
  7342.      Binary Expressions 
  7343.      Arithmetic Conversions 
  7344.  
  7345.  
  7346. ΓòÉΓòÉΓòÉ 5.6.2. Division  / ΓòÉΓòÉΓòÉ
  7347.  
  7348. The / (division) operator yields the quotient of its operands. The operands 
  7349. must have an arithmetic type. The result is not an lvalue. 
  7350.  
  7351. If both operands are positive integers and the operation produces a remainder, 
  7352. the remainder is ignored. For example, expression 7 / 4 yields the value 1 
  7353. (rather than 1.75 or 2). 
  7354.  
  7355. How the compiler treats the result when either of the operands has a negative 
  7356. value is not specified. On all IBM C compilers, the result of -7 / 4 is -1 with 
  7357. a remainder of -3, assuming both -7 and 4 are signed. 
  7358.  
  7359. The result is undefined if the second operand evaluates to 0. 
  7360.  
  7361. Related Information 
  7362.  
  7363.      Multiplication  * 
  7364.      Remainder  % 
  7365.      Binary Expressions 
  7366.      Arithmetic Conversions 
  7367.  
  7368.  
  7369. ΓòÉΓòÉΓòÉ 5.6.3. Remainder  % ΓòÉΓòÉΓòÉ
  7370.  
  7371. The % (remainder) operator yields the remainder from the division of the left 
  7372. operand by the right operand.  For example, the expression 5 % 3 yields 2.  The 
  7373. result is not an lvalue. 
  7374.  
  7375. Both operands must have an integral type. If the right operand evaluates to 0, 
  7376. the result is undefined. If either operand has a negative value, the result is 
  7377. such that the following expression always yields the value of a if b is not 0 
  7378. and a/b is representable: 
  7379.  
  7380.    ( a / b ) * b + a % b;
  7381.  
  7382. Related Information 
  7383.  
  7384.      Multiplication  * 
  7385.      Division  / 
  7386.      Binary Expressions 
  7387.      Arithmetic Conversions 
  7388.  
  7389.  
  7390. ΓòÉΓòÉΓòÉ 5.6.4. Addition  + ΓòÉΓòÉΓòÉ
  7391.  
  7392. The + (addition) operator yields the sum of its operands.  Both operands must 
  7393. have an arithmetic type, or the first operand must be a pointer to an object 
  7394. type and the other operand must have an integral type. 
  7395.  
  7396. When both operands have an arithmetic type, the usual arithmetic conversions on 
  7397. the operands are performed. The result has the type produced by the conversions 
  7398. on the operands and is not an lvalue. 
  7399.  
  7400. A pointer to an object in an array can be added to a value having integral 
  7401. type. The result is a pointer of the same type as the pointer operand. The 
  7402. result refers to another element in the array, offset from the original element 
  7403. by the amount specified by the integral value. If the resulting pointer points 
  7404. to storage outside the array, other than the first location outside the array, 
  7405. the result is undefined. The compiler does not provide boundary checking on the 
  7406. pointers. 
  7407.  
  7408. Related Information 
  7409.  
  7410.      Pointers 
  7411.      Unary Plus  + 
  7412.      Subtraction  - 
  7413.      Binary Expressions 
  7414.      Arithmetic Conversions 
  7415.  
  7416.  
  7417. ΓòÉΓòÉΓòÉ 5.6.5. Subtraction  - ΓòÉΓòÉΓòÉ
  7418.  
  7419. The - (subtraction) operator yields the difference of its operands. Both 
  7420. operands must have an arithmetic type, or the left operand must have a pointer 
  7421. type and the right operand must have the same pointer type or an integral type. 
  7422. You cannot subtract a pointer from an integral value. 
  7423.  
  7424. When both operands have an arithmetic type, the usual arithmetic conversions on 
  7425. the operands are performed. The result has the type produced by the conversions 
  7426. on the operands and is not an lvalue. 
  7427.  
  7428. When the left operand is a pointer and the right operand has an integral type, 
  7429. the compiler converts the value of the right to an address offset. The result 
  7430. is a pointer of the same type as the pointer operand. 
  7431.  
  7432. If both operands are pointers to the same type, the compiler converts the 
  7433. result to an integral type that represents the number of objects separating the 
  7434. two addresses. Behavior is undefined if the pointers do not refer to objects in 
  7435. the same array. 
  7436.  
  7437. Related Information 
  7438.  
  7439.      Pointers 
  7440.      Unary Minus  - 
  7441.      Addition  + 
  7442.      Binary Expressions 
  7443.      Arithmetic Conversions 
  7444.  
  7445.  
  7446. ΓòÉΓòÉΓòÉ 5.6.6. Bitwise Left and Right Shift  <<  >> ΓòÉΓòÉΓòÉ
  7447.  
  7448. The bitwise shift operators move the bit values of a binary object.  The left 
  7449. operand specifies the value to be shifted.  The right operand specifies the 
  7450. number of positions that the bits in the value are to be shifted. The result is 
  7451. not an lvalue. Both operands have the same precedence and are left-to-right 
  7452. associative. 
  7453.  
  7454. The << (bitwise left shift) operator indicates the bits are to be shifted to 
  7455. the left.  The >> (bitwise right shift) operator indicates the bits are to be 
  7456. shifted to the right. 
  7457.  
  7458. Each operand must have an integral type.  The compiler performs integral 
  7459. promotions on the operands.  Then the right operand is converted to type int. 
  7460. The result has the same type as the left operand (after the arithmetic 
  7461. conversions). 
  7462.  
  7463. The right operand should not have a negative value or a value that is greater 
  7464. than or equal to the width in bits of the expression being shifted. The result 
  7465. of bitwise shifts on such values is unpredictable. 
  7466.  
  7467. If the right operand has the value 0, the result is the value of the left 
  7468. operand (after the usual arithmetic conversions). 
  7469.  
  7470. The << operator fills vacated bits with zeros. For example, if left_op has the 
  7471. value 4019, the bit pattern (in 32-bit format) of left_op is: 
  7472.  
  7473. 00000000000000000000111110110011
  7474.  
  7475. The expression left_op << 3 yields: 
  7476.  
  7477. 00000000000000000111110110011000
  7478.  
  7479. If the left operand has an unsigned type, the >> operator fills vacated bits 
  7480. with zeros. Otherwise, the compiler fills the vacated bits of a signed value 
  7481. with a copy of the value's sign bit. 
  7482.  
  7483. For example, if left_op has the value -25, the bit pattern (in 32-bit format) 
  7484. of left_op is: 
  7485.  
  7486. 11111111111111111111111111100111
  7487.  
  7488. The expression left_op >> 3 yields: 
  7489.  
  7490. 11111111111111111111111111111100
  7491.  
  7492. Related Information 
  7493.  
  7494.      Bitwise Negation  ~ 
  7495.      Bitwise AND  & 
  7496.      Bitwise Exclusive OR  ^ 
  7497.      Bitwise Inclusive OR  | 
  7498.      Binary Expressions 
  7499.      Arithmetic Conversions 
  7500.  
  7501.  
  7502. ΓòÉΓòÉΓòÉ 5.6.7. Relational  <  >  <=  >= ΓòÉΓòÉΓòÉ
  7503.  
  7504. The relational operators compare two operands and determine the validity of a 
  7505. relationship. If the relationship stated by the operator is true, the value of 
  7506. the result is 1. If false, the value of the result is 0. The result is not an 
  7507. lvalue. 
  7508.  
  7509. The following table describes the four relational operators: 
  7510.  
  7511.  Operator   Usage 
  7512.  
  7513.  <          Indicates whether the value of the left operand is less than the 
  7514.             value of the right operand. 
  7515.  
  7516.  >          Indicates whether the value of the left operand is greater than the 
  7517.             value of the right operand. 
  7518.  
  7519.  <=         Indicates whether the value of the left operand is less than or 
  7520.             equal to the value of the right operand. 
  7521.  
  7522.  >=         Indicates whether the value of the left operand is greater than or 
  7523.             equal to the value of the right operand. 
  7524.  
  7525.  Both operands must have arithmetic types or be pointers to the same type. The 
  7526.  result has type int. If the operands have arithmetic types, the usual 
  7527.  arithmetic conversions on the operands are performed. 
  7528.  
  7529.  When the operands are pointers, the result is determined by the locations of 
  7530.  the objects to which the pointers refer. If the pointers do not refer to 
  7531.  objects in the same array, the result is not defined. 
  7532.  
  7533.  A pointer can be compared to a constant expression that evaluates to 0. You 
  7534.  can also compare a pointer to a pointer of type void*. The pointer is 
  7535.  converted to a pointer of type void*. 
  7536.  
  7537.  If two pointers refer to the same object, they are considered equal. If two 
  7538.  pointers refer to nonstatic members of the same object, the pointer to the 
  7539.  object declared later has the higher address value. If two pointers refer to 
  7540.  data members of the same union, they have the same address value. 
  7541.  
  7542.  If two pointers refer to elements of the same array, or to the first element 
  7543.  beyond the last element of an array, the pointer to the element with the 
  7544.  higher subscript value has the higher address value. 
  7545.  
  7546.  You can only compare members of the same object with relational operators. 
  7547.  
  7548.  Relational operators have left-to-right associativity. For example, the 
  7549.  expression: 
  7550.  
  7551.   a < b <= c
  7552.  
  7553.  is interpreted as: 
  7554.  
  7555.   (a < b) <= c
  7556.  
  7557.  If the value of a is less than the value of b, the first relationship is true 
  7558.  and yields the value 1. The compiler then compares the value 1 with the value 
  7559.  of c. 
  7560.  
  7561.  Related Information 
  7562.  
  7563.      Equality  ==  != 
  7564.      Logical Negation  ! 
  7565.      Pointers 
  7566.      Binary Expressions 
  7567.      Arithmetic Conversions 
  7568.  
  7569.  
  7570. ΓòÉΓòÉΓòÉ 5.6.8. Equality  ==  != ΓòÉΓòÉΓòÉ
  7571.  
  7572. The equality operators, like the relational operators, compare two operands for 
  7573. the validity of a relationship. The equality operators, however, have a lower 
  7574. precedence than the relational operators. If the relationship stated by an 
  7575. equality operator is true, the value of the result is 1. Otherwise, the value 
  7576. of the result is 0. 
  7577.  
  7578. The following table describes the two equality operators: 
  7579.  
  7580.  Operator   Usage 
  7581.  
  7582.  ==         Indicates whether the value of the left operand is equal to the 
  7583.             value of the right operand. 
  7584.  
  7585.  !=         Indicates whether the value of the left operand is not equal to the 
  7586.             value of the right operand. 
  7587.  
  7588.  Both operands must have arithmetic types or be pointers to the same type, or 
  7589.  one operand must have a pointer type and the other operand must be a pointer 
  7590.  to void or NULL. The result has type int. 
  7591.  
  7592.  If the operands have arithmetic types, the usual arithmetic conversions on the 
  7593.  operands are performed. If the operands are pointers, the result is determined 
  7594.  by the locations of the objects to which the pointers refer. 
  7595.  
  7596.  If one operand is a pointer and the other operand is an integer having the 
  7597.  value 0, the == expression is true only if the pointer operand evaluates to 
  7598.  NULL. The != operator evaluates to true if the pointer operand does not 
  7599.  evaluate to NULL. 
  7600.  
  7601.  You can also use the equality operators to compare pointers to members that 
  7602.  are of the same type but do not belong to the same object. 
  7603.  
  7604.  Note:  The equality operator (==) should not be confused with the assignment 
  7605.  (=) operator. 
  7606.  
  7607.  For example, 
  7608.  
  7609.  if(x == 3)    evaluates to 1 if x is equal to three An equality tests like 
  7610.                this should be coded with spaces between the operator and the 
  7611.                operands to prevent unintentional assignments. 
  7612.  
  7613.                while 
  7614.  if(x = 3)     is taken to be true because (x = 3) evaluates to a non-zero 
  7615.                value (3). The expression also assigns the value 3 to x. 
  7616.  
  7617.  Related Information 
  7618.  
  7619.      Relational  <  >  <=  >= 
  7620.      Logical Negation  ! 
  7621.      Pointers 
  7622.      Binary Expressions 
  7623.      Arithmetic Conversions 
  7624.  
  7625.  
  7626. ΓòÉΓòÉΓòÉ 5.6.9. Bitwise AND  & ΓòÉΓòÉΓòÉ
  7627.  
  7628. The & (bitwise AND) operator compares each bit of its first operand to the 
  7629. corresponding bit of the second operand.  If both bits are 1's, the 
  7630. corresponding bit of the result is set to 1. Otherwise, it sets the 
  7631. corresponding result bit to 0. 
  7632.  
  7633. Both operands must have an integral type.  The usual arithmetic conversions on 
  7634. each operand are performed. The result has the same type as the converted 
  7635. operands. 
  7636.  
  7637. Because the bitwise AND operator has both associative and commutative 
  7638. properties, the compiler can rearrange the operands in an expression that 
  7639. contains more than one bitwise AND operator. 
  7640.  
  7641. The following example shows the values of a, b, and the result of a & b 
  7642. represented as 32-bit binary numbers: 
  7643.  
  7644.  bit pattern of a              00000000000000000000000001011100 
  7645.  bit pattern of b              00000000000000000000000000101110 
  7646.  bit pattern of a & b          00000000000000000000000000001100 
  7647.  
  7648.  Note:  The bitwise AND (&) should not be confused with the logical AND. (&&) 
  7649.  operator. For example, 
  7650.  
  7651.     1 & 4 evaluates to 0
  7652.   while
  7653.     1 && 4 evaluates to 1
  7654.  
  7655.  Related Information 
  7656.  
  7657.      Bitwise Exclusive OR  ^ 
  7658.      Bitwise Inclusive OR  | 
  7659.      Logical AND  && 
  7660.      Binary Expressions 
  7661.      Arithmetic Conversions 
  7662.  
  7663.  
  7664. ΓòÉΓòÉΓòÉ 5.6.10. Bitwise Exclusive OR  ^ ΓòÉΓòÉΓòÉ
  7665.  
  7666. The bitwise exclusive OR operator compares each bit of its first operand to the 
  7667. corresponding bit of the second operand. If both bits are 1's or both bits are 
  7668. 0's, the corresponding bit of the result is set to 0. Otherwise, it sets the 
  7669. corresponding result bit to 1. 
  7670.  
  7671. Both operands must have an integral type. The usual arithmetic conversions on 
  7672. each operand are performed. The result has the same type as the converted 
  7673. operands and is not an lvalue. 
  7674.  
  7675. Because the bitwise exclusive OR operator has both associative and commutative 
  7676. properties, the compiler can rearrange the operands in an expression that 
  7677. contains more than one bitwise exclusive OR operator even when the 
  7678. sub-expressions are explicitly grouped with parentheses. 
  7679.  
  7680. The following example shows the values of a, b, and the result of a ^ b 
  7681. represented as 32-bit binary numbers: 
  7682.  
  7683.  bit pattern of a              00000000000000000000000001011100 
  7684.  bit pattern of b              00000000000000000000000000101110 
  7685.  bit pattern of a ^ b          00000000000000000000000001110010 
  7686.  
  7687.  Related Information 
  7688.  
  7689.      Bitwise Inclusive OR  | 
  7690.      Bitwise AND  & 
  7691.      Logical OR  || 
  7692.      Binary Expressions 
  7693.      Arithmetic Conversions 
  7694.  
  7695.  
  7696. ΓòÉΓòÉΓòÉ 5.6.11. Bitwise Inclusive OR  | ΓòÉΓòÉΓòÉ
  7697.  
  7698. The | (bitwise inclusive OR) operator compares the values (in binary format) of 
  7699. each operand and yields a value whose bit pattern shows which bits in either of 
  7700. the operands has the value 1. If both of the bits are 0, the result of that bit 
  7701. is 0;  otherwise, the result is 1. 
  7702.  
  7703. Both operands must have an integral type.  The usual arithmetic conversions on 
  7704. each operand are performed. The result has the same type as the converted 
  7705. operands and is not an lvalue. 
  7706.  
  7707. Because the bitwise inclusive OR operator has both associative and commutative 
  7708. properties, the compiler can rearrange the operands in an expression that 
  7709. contains more than one bitwise inclusive OR operator even when the 
  7710. subexpressions are explicitly grouped with parentheses. 
  7711.  
  7712. The following example shows the values of a, b, and the result of a | b 
  7713. represented as 32-bit binary numbers: 
  7714.  
  7715.  bit pattern of a              00000000000000000000000001011100 
  7716.  bit pattern of b              00000000000000000000000000101110 
  7717.  bit pattern of a | b          00000000000000000000000001111110 
  7718.  
  7719.  Note:  The bitwise OR (|) should not be confused with the logical OR (||) 
  7720.  operator. For example, 
  7721.  
  7722.     1 | 4 evaluates to 5
  7723.   while
  7724.     1 || 4 evaluates to 1
  7725.  
  7726.  Related Information 
  7727.  
  7728.      Bitwise Exclusive OR  ^ 
  7729.      Bitwise AND  & 
  7730.      Logical OR  || 
  7731.      Binary Expressions 
  7732.      Arithmetic Conversions 
  7733.  
  7734.  
  7735. ΓòÉΓòÉΓòÉ 5.6.12. Logical AND  && ΓòÉΓòÉΓòÉ
  7736.  
  7737. The && (logical AND) operator indicates whether both operands have a nonzero 
  7738. value.  If both operands have nonzero values, the result has the value 1. 
  7739. Otherwise, the result has the value 0. 
  7740.  
  7741. Both operands must have a scalar type. The usual arithmetic conversions on each 
  7742. operand are performed. The result has type int and is not an lvalue. 
  7743.  
  7744. Unlike the & (bitwise AND) operator, the && operator guarantees left-to-right 
  7745. evaluation of the operands. If the left operand evaluates to 0, the right 
  7746. operand is not evaluated. 
  7747.  
  7748. The following examples show how the expressions that contain the logical AND 
  7749. operator are evaluated: 
  7750.  
  7751.  Expression          Result 
  7752.  1 && 0              0 
  7753.  1 && 4              1 
  7754.  0 && 0              0 
  7755.  
  7756.  The following example uses the logical AND operator to avoid division by zero: 
  7757.  
  7758.   (y != 0) && (x / y)
  7759.  
  7760.  The expression x / y is not evaluated when y != 0 evaluates to 0. 
  7761.  
  7762.  Note:  The logical AND (&&) should not be confused with the bitwise AND (&) 
  7763.  operator. For example: 
  7764.  
  7765.     1 && 4 evaluates to 1
  7766.   while
  7767.     1 & 4 evaluates to 0
  7768.  
  7769.  Related Information 
  7770.  
  7771.      Logical OR  || 
  7772.      Bitwise AND  & 
  7773.      Binary Expressions 
  7774.      Arithmetic Conversions 
  7775.  
  7776.  
  7777. ΓòÉΓòÉΓòÉ 5.6.13. Logical OR  || ΓòÉΓòÉΓòÉ
  7778.  
  7779. The || (logical OR) operator indicates whether either operand has a nonzero 
  7780. value. If either operand has a nonzero value, the result has the value 1. 
  7781. Otherwise, the result has the value 0. 
  7782.  
  7783. Both operands must have a scalar type. The usual arithmetic conversions on each 
  7784. operand are performed. The result has type int and is not an lvalue. 
  7785.  
  7786. Unlike the | (bitwise inclusive OR) operator, the The || operator guarantees 
  7787. left-to-right evaluation of the operands. If the left operand has a nonzero 
  7788. value, the right operand is not evaluated. 
  7789.  
  7790. The following examples show how expressions that contain the logical OR 
  7791. operator are evaluated: 
  7792.  
  7793.  Expression          Result 
  7794.  1 || 0              1 
  7795.  1 || 4              1 
  7796.  0 || 0              0 
  7797.  
  7798.  The following example uses the logical OR operator to conditionally increment 
  7799.  y: 
  7800.  
  7801.   ++x || ++y;
  7802.  
  7803.  The expression ++y is not evaluated when the expression ++x evaluates to a 
  7804.  nonzero quantity. 
  7805.  
  7806.  Note:  The logical OR (||) should not be confused with the bitwise OR (|) 
  7807.  operator. For example: 
  7808.  
  7809.     1 || 4 evaluates to 1
  7810.   while
  7811.     1 | 4 evaluates to 5
  7812.  
  7813.  Related Information 
  7814.  
  7815.      Logical AND  && 
  7816.      Bitwise Inclusive OR  | 
  7817.      Binary Expressions 
  7818.      Arithmetic Conversions 
  7819.  
  7820.  
  7821. ΓòÉΓòÉΓòÉ 5.6.14. Pointer to Member Operators .* ->* ΓòÉΓòÉΓòÉ
  7822.  
  7823. The .* operator is used to dereference pointers to class members. The first 
  7824. operand must be a class type. If the type of the first operand is class type T, 
  7825. or is a class that has been derived from class type T, the second operand must 
  7826. be a pointer to a member of a class type T. 
  7827.  
  7828. The ->* operator is also used to dereference pointers to class members. The 
  7829. first operand must be a pointer to a class type. If the type of the first 
  7830. operand is a pointer to class type T, or is a pointer to a class derived from 
  7831. class type T, the second operand must be a pointer to a member of class type T. 
  7832.  
  7833. The .* and ->* operators bind the second operand to the first, resulting in an 
  7834. object or function of the type specified by the second operand. 
  7835.  
  7836. If the result of.* or ->* is a function, you can only use the result as the 
  7837. operand for the ( ) (function call) operator. If the second operand is an 
  7838. lvalue, the result of .* or ->* is an lvalue. 
  7839.  
  7840. For more information on pointer to member operators, see Pointers to Members. 
  7841.  
  7842. Related Information 
  7843.  
  7844.      Pointers to Members 
  7845.      Pointers 
  7846.      C++ Classes 
  7847.      Binary Expressions 
  7848.  
  7849.  
  7850. ΓòÉΓòÉΓòÉ 5.7. Conditional Expressions ΓòÉΓòÉΓòÉ
  7851.  
  7852. A conditional expression is a compound expression that contains a condition 
  7853. (operand{1}), an expression to be evaluated if the condition has a nonzero 
  7854. value (operand{2}), and an expression to be evaluated if the condition has the 
  7855. value 0 (operand{3}). 
  7856.  
  7857. Conditional expressions have right-to-left associativity. The left operand is 
  7858. evaluated first, and then only one of the remaining two operands is evaluated. 
  7859.  
  7860. The conditional expression contains one two-part operator.  The ? symbol 
  7861. follows the condition, and the : symbol appears between the two action 
  7862. expressions. All expressions that occur between the ? and : are treated as one 
  7863. expression. 
  7864.  
  7865. The first operand must have a scalar type. The type of the second and third 
  7866. operands must be one of the following: 
  7867.  
  7868.      An arithmetic type 
  7869.      A compatible pointer, structure, or union type 
  7870.      void. 
  7871.  
  7872.  The second and third operands can also be a pointer or a null pointer 
  7873.  constant. 
  7874.  
  7875.  Two objects are compatible when they have the same type but not necessarily 
  7876.  the same type qualifiers (volatile, const, or _Packed). Pointer objects are 
  7877.  compatible if they have the same type or are pointers to void. 
  7878.  
  7879.  The first expression is evaluated first. If the first expression has a nonzero 
  7880.  value, the second expression is evaluated and converted to the result type. It 
  7881.  becomes the value of the conditional expression. The third operand is not 
  7882.  evaluated. If the first operand is zero, the third operand is evaluated. 
  7883.  
  7884.  If the second and third expressions evaluate to arithmetic types, the usual 
  7885.  arithmetic conversions are performed on the values. The types of the second 
  7886.  and third operands determine the type of the result as shown in the following 
  7887.  tables. 
  7888.  
  7889.  
  7890. ΓòÉΓòÉΓòÉ 5.7.1. Type of Conditional C Expressions ΓòÉΓòÉΓòÉ
  7891.  
  7892. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  7893. Γöé TYPE OF ONE OPERAND   Γöé TYPE OF OTHER OPERAND   Γöé TYPE OF RESULT      Γöé
  7894. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7895. Γöé Arithmetic        Γöé Arithmetic        Γöé Arithmetic type after  Γöé
  7896. Γöé             Γöé              Γöé usual arithmetic con-  Γöé
  7897. Γöé             Γöé              Γöé versions         Γöé
  7898. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7899. Γöé Structure or union type Γöé Compatible structure or  Γöé Structure or union type Γöé
  7900. Γöé             Γöé union type        Γöé with all the qualifiers Γöé
  7901. Γöé             Γöé              Γöé on both operands     Γöé
  7902. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7903. Γöé void           Γöé void           Γöé void           Γöé
  7904. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7905. Γöé Pointer to compatible  Γöé Pointer to compatible   Γöé Pointer to type with   Γöé
  7906. Γöé type           Γöé type           Γöé all the qualifiers    Γöé
  7907. Γöé             Γöé              Γöé specified for the type  Γöé
  7908. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7909. Γöé Pointer to type     Γöé "NULL" pointer (the con- Γöé Pointer to type     Γöé
  7910. Γöé             Γöé stant "0")        Γöé             Γöé
  7911. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7912. Γöé Pointer to object or   Γöé Pointer to void      Γöé Pointer to void with   Γöé
  7913. Γöé incomplete type     Γöé              Γöé all the qualifiers    Γöé
  7914. Γöé             Γöé              Γöé specified for the type  Γöé
  7915. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  7916.  
  7917.  
  7918. ΓòÉΓòÉΓòÉ 5.7.2. Type of Conditional C++ Expressions ΓòÉΓòÉΓòÉ
  7919.  
  7920. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  7921. Γöé TYPE OF ONE OPERAND   Γöé TYPE OF OTHER OPERAND   Γöé TYPE OF RESULT      Γöé
  7922. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7923. Γöé Reference to type    Γöé Reference to type     Γöé Reference after usual  Γöé
  7924. Γöé             Γöé              Γöé reference conversions  Γöé
  7925. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7926. Γöé Class "T"        Γöé Class "T"         Γöé Class "T"        Γöé
  7927. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7928. Γöé Class "T"        Γöé Class "X"         Γöé Class type for which a  Γöé
  7929. Γöé             Γöé              Γöé conversion exists.  If  Γöé
  7930. Γöé             Γöé              Γöé more than one possible  Γöé
  7931. Γöé             Γöé              Γöé conversion exists, the  Γöé
  7932. Γöé             Γöé              Γöé result is ambiguous.   Γöé
  7933. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  7934. Γöé throw expression     Γöé Other (type, pointer,   Γöé Type of the expression  Γöé
  7935. Γöé             Γöé reference)        Γöé that is not a throw   Γöé
  7936. Γöé             Γöé              Γöé expression        Γöé
  7937. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  7938.  
  7939. Examples of Conditional Expressions 
  7940.  
  7941. Related Information 
  7942.  
  7943.      Type Specifiers 
  7944.      Declarators 
  7945.      Expressions and Operators 
  7946.      Arithmetic Conversions 
  7947.      Operator Precedence and Associativity 
  7948.  
  7949.  
  7950. ΓòÉΓòÉΓòÉ <hidden> Examples of Conditional Expressions ΓòÉΓòÉΓòÉ
  7951.  
  7952. The following expression determines which variable has the greater value, y or 
  7953. z, and assigns the greater value to the variable x: 
  7954.  
  7955. x = (y > z) ? y : z;
  7956.  
  7957. The following is an equivalent statement: 
  7958.  
  7959. if (y > z)
  7960.    x = y;
  7961. else
  7962.    x = z;
  7963.  
  7964. The following expression calls the function printf, which receives the value of 
  7965. the variable c, if c evaluates to a digit. Otherwise, printf receives the 
  7966. character constant 'x'. 
  7967.  
  7968. printf(" c = %c\n", isdigit(c) ? c : 'x');
  7969.  
  7970. If the last operand of a conditional expression contains an assignment 
  7971. operator, use parentheses to ensure the expression evaluates properly. For 
  7972. example, the = operator has higher precedence than the ?: operator in the 
  7973. following expression: 
  7974.  
  7975. int i,j,k;
  7976. (i == 7) ? j ++ : k = j;
  7977.  
  7978. This expression generates an error because it is interpreted as if it were 
  7979. parenthesized this way: 
  7980.  
  7981. int i,j,k;
  7982. ((i == 7) ? j ++ : k) = j;
  7983.  
  7984. That is, k is treated as the third operand, not the entire assignment 
  7985. expression k = j. The error arises because a conditional expression is not an 
  7986. lvalue, and the assignment is not valid. 
  7987.  
  7988. To make the expression evaluate correctly, enclose the last operand in 
  7989. parentheses: 
  7990.  
  7991. int i,j,k;
  7992. (i == 7) ? j ++ : (k = j);
  7993.  
  7994.  
  7995. ΓòÉΓòÉΓòÉ 5.8. Assignment Expressions ΓòÉΓòÉΓòÉ
  7996.  
  7997. An assignment expression stores a value in the object designated by the left 
  7998. operand. There are two types of assignment operators: simple assignment and 
  7999. compound assignment. 
  8000.  
  8001. The left operand in all assignment expressions must be a modifiable lvalue. The 
  8002. type of the expression is the type of the left operand. The value of the 
  8003. expression is the value of the left operand after the assignment has completed. 
  8004. The result of an assignment expression is not an lvalue. 
  8005.  
  8006. All assignment operators have the same precedence and have right-to-left 
  8007. associativity. 
  8008.  
  8009.      Simple Assignment  = 
  8010.      Compound Assignment 
  8011.  
  8012.  Related Information 
  8013.  
  8014.      Expressions and Operators 
  8015.      Operator Precedence and Associativity 
  8016.  
  8017.  
  8018. ΓòÉΓòÉΓòÉ 5.8.1. Simple Assignment  = ΓòÉΓòÉΓòÉ
  8019.  
  8020. The simple assignment operator stores the value of the right operand in the 
  8021. object designated by the left operand. 
  8022.  
  8023. Both operands must have arithmetic types, the same structure type, or the same 
  8024. union type.  Otherwise, both operands must be pointers to the same type, or the 
  8025. left operand must be a pointer and the right operand must be the constant 0 or 
  8026. NULL. 
  8027.  
  8028. If both operands have arithmetic types, the system converts the type of the 
  8029. right operand to the type of the left operand before the assignment. 
  8030.  
  8031. If the right operand is a pointer to a type, the left operand can be a pointer 
  8032. to a const of the same type. If the right operand is a pointer to a const type, 
  8033. the left operand must also be a pointer to a const type. 
  8034.  
  8035. If the right operand is a pointer to a type, the left operand can be a pointer 
  8036. to a volatile of the same type. If the right operand is a pointer to a volatile 
  8037. type, the left operand must also be a pointer to a volatile type. 
  8038.  
  8039. If the left operand is a pointer to a member, the right operand must be a 
  8040. pointer to a member or a constant expression that evaluates to zero. The right 
  8041. operand is converted to the type of the left operand before assignment. 
  8042.  
  8043. If the left operand is an object of reference type, the assignment is to the 
  8044. object denoted by the reference. 
  8045.  
  8046. If the left operand is a pointer and the right operand is the constant 0, the 
  8047. result is NULL. 
  8048.  
  8049. Pointers to void can appear on either side of the simple assignment operator. 
  8050.  
  8051. A packed structure or union can be assigned to a nonpacked structure or union 
  8052. of the same type, and a nonpacked structure or union can be assigned to a 
  8053. packed structure or union of the same type. 
  8054.  
  8055. If one operand is packed and the other is not, the layout of the right operand 
  8056. is remapped to match the layout of the left. This remapping of structures might 
  8057. degrade performance. For efficiency, when you perform assignment operations 
  8058. with structures or unions, you should ensure that both operands are either 
  8059. packed or nonpacked. 
  8060.  
  8061. Note:  If you assign pointers to structures or unions, the objects they point 
  8062. to must both be either packed or nonpacked. See Pointers for more information 
  8063. on assignments with pointers. 
  8064.  
  8065. You can assign values to operands with the type qualifier volatile. You cannot 
  8066. assign a pointer of an object with the type qualifier const to a pointer of an 
  8067. object without the const type qualifier. For example: 
  8068.  
  8069. const int *p1;
  8070. int *p2;
  8071. p2 = p1;  /* this is NOT allowed */
  8072.  
  8073. p1 = p2;  /* this IS allowed */
  8074.  
  8075. Examples of Simple Assignments 
  8076.  
  8077. Note:  The assignment (=) operator should not be confused with the equality 
  8078. comparison (==) operator. For example: 
  8079.  
  8080.  if(x == 3)  evaluates to 1 if x is equal to three 
  8081.  
  8082.              while 
  8083.  if(x = 3)   is taken to be true because (x = 3) evaluates to a non-zero value 
  8084.              (3). The expression also assigns the value 3 to x. 
  8085.  
  8086.  Related Information 
  8087.  
  8088.      Compound Assignment 
  8089.      Equality  ==  != 
  8090.      Pointers 
  8091.      volatile and const Qualifiers 
  8092.      Type Specifiers 
  8093.      Arithmetic Conversions 
  8094.  
  8095.  
  8096. ΓòÉΓòÉΓòÉ <hidden> Examples of Simple Assignments ΓòÉΓòÉΓòÉ
  8097.  
  8098. The following example assigns the value of number to the member employee of the 
  8099. structure payroll: 
  8100.  
  8101. payroll.employee = number;
  8102.  
  8103. The following example assigns in order the value 0 (zero) to strangeness, the 
  8104. value of strangeness to charm, the value of charm to beauty, and the value of 
  8105. beauty to truth: 
  8106.  
  8107. truth = beauty = charm = strangeness = 0;
  8108.  
  8109.  
  8110. ΓòÉΓòÉΓòÉ 5.8.2. Compound Assignment ΓòÉΓòÉΓòÉ
  8111.  
  8112. The compound assignment operators consist of a binary operator and the simple 
  8113. assignment operator. They perform the operation of the binary operator on both 
  8114. operands and give the result of that operation to the left operand. 
  8115.  
  8116. The following table shows the operand types of compound assignment expressions: 
  8117.  
  8118. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8119. Γöé OPERATOR         Γöé LEFT OPERAND       Γöé RIGHT OPERAND      Γöé
  8120. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8121. Γöé += or -=         Γöé Arithmetic        Γöé Arithmetic        Γöé
  8122. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8123. Γöé += or -=         Γöé Pointer          Γöé Integral type      Γöé
  8124. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8125. Γöé *=, /=, and %=      Γöé Arithmetic        Γöé Arithmetic        Γöé
  8126. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8127. Γöé <<=, >>=, &=, ^=, and  Γöé Integral type       Γöé Integral type      Γöé
  8128. Γöé |=            Γöé              Γöé             Γöé
  8129. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  8130.  
  8131. Note that the expression a *= b + c is equivalent to a = a * (b + c), and not 
  8132. a = a * b + c. 
  8133.  
  8134. The following table lists the compound assignment operators and shows an 
  8135. expression using each operator: 
  8136.  
  8137.  Operator    Example 
  8138.  
  8139.  +=          index += 2 
  8140.                 Equivalent expression:  index = index + 2 
  8141.  
  8142.  -=          *(pointer++) -= 1 
  8143.                 Equivalent expression:  *pointer = *(pointer++) - 1 
  8144.  
  8145.  *=          bonus *= increase 
  8146.                 Equivalent expression:  bonus = bonus * increase 
  8147.  
  8148.  /=          time /= hours 
  8149.                 Equivalent expression:  time = time / hours 
  8150.  
  8151.  %=          allowance %= 1000 
  8152.                 Equivalent expression:  allowance = allowance % 1000 
  8153.  
  8154.  <<=         result <<= num 
  8155.                 Equivalent expression:  result = result << num 
  8156.  
  8157.  >>=         form >>= 1 
  8158.                 Equivalent expression:  form = form >> 1 
  8159.  
  8160.  &=          mask &= 2 
  8161.                 Equivalent expression:  mask = mask & 2 
  8162.  
  8163.  ^=          test ^= pre_test 
  8164.                 Equivalent expression:  test = test ^ pre_test 
  8165.  
  8166.  |=          flag |= ON 
  8167.                 Equivalent expression:  flag = flag | ON 
  8168.  
  8169.  Although the equivalent expression column shows the left operands (from the 
  8170.  example column) evaluated twice, the left operand is evaluated only once. 
  8171.  
  8172.  Related Information 
  8173.  
  8174.      Simple Assignment  = 
  8175.      Binary Expressions 
  8176.  
  8177.  
  8178. ΓòÉΓòÉΓòÉ 5.9. Comma Expression  , ΓòÉΓòÉΓòÉ
  8179.  
  8180. A comma expression contains two operands separated by a comma. Although the 
  8181. compiler evaluates both operands, the value of the right operand is the value 
  8182. of the expression. The left operand is evaluated, possibly producing side 
  8183. effects, and the value is discarded. The result of a comma expression is not an 
  8184. lvalue. 
  8185.  
  8186. Both operands of a comma expression can have any type.  All comma expressions 
  8187. have left-to-right associativity. The left operand is fully evaluated before 
  8188. the right operand. 
  8189.  
  8190. In the following example, if omega has the value 11, the expression increments 
  8191. delta and assigns the value 3 to alpha: 
  8192.  
  8193. alpha = (delta++, omega % 4);
  8194.  
  8195. Any number of expressions separated by commas can form a single expression. The 
  8196. compiler evaluates the leftmost expression first. The value of the rightmost 
  8197. expression becomes the value of the entire expression. 
  8198.  
  8199. For example, the value of the expression: 
  8200.  
  8201. intensity++, shade * increment, rotate(direction);
  8202.  
  8203. is the value of the expression: 
  8204.  
  8205. rotate(direction)
  8206.  
  8207. The primary use of the comma operator is to produce side effects in the 
  8208. following situations: 
  8209.  
  8210.      Calling a function 
  8211.      Entering or repeating an iteration loop 
  8212.      Testing a condition 
  8213.      Other situations where a side effect is required but the result of the 
  8214.       expression is not immediately needed 
  8215.  
  8216.  To use the comma operator in a context where the comma has other meanings, 
  8217.  such as in a list of function arguments or a list of initializers, you must 
  8218.  enclose the comma operator in parentheses. For example, the function 
  8219.  
  8220.   f(a, (t = 3, t + 2), c);
  8221.  
  8222.  has only three arguments: the value of a, the value 5, and the value of c. The 
  8223.  value of the second argument is the result of the comma expression in 
  8224.  parentheses: 
  8225.  
  8226.   t = 3, t + 2
  8227.  
  8228.  which has the value 5. 
  8229.  
  8230.  The following table gives some examples of the uses of the comma operator: 
  8231.  
  8232.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8233.   Γöé STATEMENT             Γöé EFFECTS                  Γöé
  8234.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8235.   Γöé  for (i=0; i<2; ++i, f() );    Γöé A for statement in which "i" is incre-  Γöé
  8236.   Γöé                  Γöé mented and "f()" is called at each iter- Γöé
  8237.   Γöé                  Γöé ation.                  Γöé
  8238.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8239.   Γöé  if ( f(), ++i, i>1 )       Γöé An if statement in which function "f()"  Γöé
  8240.   Γöé    { /* ... */ }         Γöé is called, variable "i" is incremented,  Γöé
  8241.   Γöé                  Γöé and variable "i" is tested against a   Γöé
  8242.   Γöé                  Γöé value.  The first two expressions within Γöé
  8243.   Γöé                  Γöé this comma expression are evaluated    Γöé
  8244.   Γöé                  Γöé before the expression "i>1".  Regardless Γöé
  8245.   Γöé                  Γöé of the results of the first two      Γöé
  8246.   Γöé                  Γöé expressions, the third is evaluated and  Γöé
  8247.   Γöé                  Γöé its result determines whether the if   Γöé
  8248.   Γöé                  Γöé statement is processed.          Γöé
  8249.   Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8250.   Γöé  func( ( ++a, f(a) ) );      Γöé A function call to "func()" in which "a" Γöé
  8251.   Γöé                  Γöé is incremented, the resulting value is  Γöé
  8252.   Γöé                  Γöé passed to a function "f()", and the    Γöé
  8253.   Γöé                  Γöé return value of "f()" is passed to    Γöé
  8254.   Γöé                  Γöé "func()".  The function "func()" is    Γöé
  8255.   Γöé                  Γöé passed only a single argument, because  Γöé
  8256.   Γöé                  Γöé the comma expression is enclosed in    Γöé
  8257.   Γöé                  Γöé parentheses within the function argument Γöé
  8258.   Γöé                  Γöé list.                   Γöé
  8259.   Γöé                  Γöé                      Γöé
  8260.   ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  8261.  
  8262.  Related Information 
  8263.  
  8264.      Expressions and Operators 
  8265.      Operator Precedence and Associativity 
  8266.  
  8267.  
  8268. ΓòÉΓòÉΓòÉ 6. Implicit Type Conversions ΓòÉΓòÉΓòÉ
  8269.  
  8270. There are two kinds of implicit type conversions: standard conversions and 
  8271. user-defined conversions This chapter describes the following standard type 
  8272. conversions: 
  8273.  
  8274.      integral promotions. 
  8275.      Implicit standard type conversions: 
  8276.         -  Signed-integer conversions 
  8277.         -  Unsigned-integer conversions 
  8278.         -  Floating-point conversions 
  8279.         -  Pointer conversions 
  8280.         -  Reference conversions 
  8281.         -  Pointer-to-member conversions 
  8282.         -  Function argument conversions 
  8283.         -  Other conversions 
  8284.      Arithmetic conversions. 
  8285.  
  8286.  Related Information 
  8287.  
  8288.      Expressions and Operators 
  8289.      Functions 
  8290.      Cast Expressions. 
  8291.      User-Defined Conversions. 
  8292.  
  8293.  The VisualAge C++ implementation of type conversions is described in the IBM 
  8294.  VisualAge C++ for OS/2 User's Guide and Reference. 
  8295.  
  8296.  
  8297. ΓòÉΓòÉΓòÉ 6.1. Integral Promotions ΓòÉΓòÉΓòÉ
  8298.  
  8299. Certain fundamental types can be used wherever an integer can be used. The 
  8300. fundamental types that can be converted through integral promotion are: 
  8301.  
  8302.      char 
  8303.      wchar_t 
  8304.      short int 
  8305.      enumerators 
  8306.      objects of enumeration type 
  8307.      integer bit-fields (both signed and unsigned) 
  8308.  
  8309.  Except for wchar_t, if the value cannot be represented by an int, the value is 
  8310.  converted to an unsigned int. For wchar_t, if an int can represent all the 
  8311.  values of the original type, the value is converted to the type that can best 
  8312.  represent all the values of the original type. For example, if a long can 
  8313.  represent all the values, the value is converted to a long. 
  8314.  
  8315.  
  8316. ΓòÉΓòÉΓòÉ 6.2. Standard Type Conversions ΓòÉΓòÉΓòÉ
  8317.  
  8318. Many C and C++ operators cause implicit type conversions, which change the type 
  8319. of a value. When you add values having different data types, both values are 
  8320. first converted to the same type. For example, when a short int value and an 
  8321. int value are added together, the short int value is converted to the int type. 
  8322.  
  8323. Implicit type conversions can occur when: 
  8324.  
  8325.      An operand is prepared for an arithmetic or logical operation. 
  8326.      An assignment is made to an lvalue that has a different type than the 
  8327.       assigned value. 
  8328.      A prototyped function is provided a value that has a different type than 
  8329.       the parameter. 
  8330.      The value specified in the return statement of a function has a different 
  8331.       type from the defined return type for the function. 
  8332.  
  8333.  You can perform explicit type conversions using the cast operator or the 
  8334.  function style cast. For more information on explicit type conversions, see 
  8335.  Cast Expressions. 
  8336.  
  8337.  
  8338. ΓòÉΓòÉΓòÉ 6.2.1. Signed-Integer Conversions ΓòÉΓòÉΓòÉ
  8339.  
  8340. The compiler converts a signed integer to a shorter integer by truncating the 
  8341. high-order bits and converting the variable to a longer signed integer by 
  8342. sign-extension. 
  8343.  
  8344. Conversion of signed integers to floating-point values takes place without loss 
  8345. of information, except when an int or long int value is converted to a float, 
  8346. in which case some precision may be lost. When a signed integer is converted to 
  8347. an unsigned integer, the signed integer is converted to the size of the 
  8348. unsigned integer, and the result is interpreted as an unsigned value. 
  8349.  
  8350.  
  8351. ΓòÉΓòÉΓòÉ 6.2.2. Unsigned-Integer Conversions ΓòÉΓòÉΓòÉ
  8352.  
  8353. An unsigned integer is converted to a shorter unsigned or signed integer by 
  8354. truncating the high-order bits. An unsigned integer is converted to a longer 
  8355. unsigned or signed integer by zero-extending. Zero-extending pads the leftmost 
  8356. bits of the longer integer with binary zeros. 
  8357.  
  8358. When an unsigned integer is converted to a signed integer of the same size, no 
  8359. change in the bit pattern occurs. However, the value changes if the sign bit is 
  8360. set. 
  8361.  
  8362.  
  8363. ΓòÉΓòÉΓòÉ 6.2.3. Floating-Point Conversions ΓòÉΓòÉΓòÉ
  8364.  
  8365. A float value converted to a double undergoes no change in value. A double 
  8366. converted to a float is represented exactly, if possible. If the compiler 
  8367. cannot exactly represent the double value as a float, the value loses 
  8368. precision. If the value is too large to fit into a float, the result is 
  8369. undefined. 
  8370.  
  8371. When a floating-point value is converted to an integer value, the decimal 
  8372. fraction portion of the floating-point value is discarded in the conversion. If 
  8373. the result is too large for the given integer type, the result of the 
  8374. conversion is undefined. 
  8375.  
  8376.  
  8377. ΓòÉΓòÉΓòÉ 6.2.4. Pointer Conversions ΓòÉΓòÉΓòÉ
  8378.  
  8379. Pointer conversions are performed when pointers are used, including pointer 
  8380. assignment, initialization, and comparison. 
  8381.  
  8382. A constant expression that evaluates to zero can be converted to a pointer. 
  8383. This pointer will be a null pointer (pointer with a zero value), and is 
  8384. guaranteed not to point to any object. 
  8385.  
  8386. Any pointer to an object that is not a const or volatile object can be 
  8387. converted to a void*. You can also convert any pointer to a function to a 
  8388. void*, provided that a void* has sufficient bits to hold it. 
  8389.  
  8390. You can convert an expression with type array of some type to a pointer to the 
  8391. initial element of the array, except when the expression is used as the operand 
  8392. of the & (address) operator or the sizeof operator. 
  8393.  
  8394. You can convert an expression with a type of function returning T to a pointer 
  8395. to a function returning T, except when the expression is used as the operand of 
  8396. the & (address) operator, the () (function call) operator, or the sizeof 
  8397. operator. 
  8398.  
  8399. You can convert an integer value to an address offset. 
  8400.  
  8401. You can convert a pointer to a class A to a pointer to an accessible base class 
  8402. B of that class, as long as the conversion is not ambiguous. The conversion is 
  8403. ambiguous if the expression for the accessible base class can refer to more 
  8404. than one distinct class. The resulting value points to the base class subobject 
  8405. of the derived class object. A null pointer (pointer with a zero value) is 
  8406. converted into itself. 
  8407.  
  8408. Note:  You cannot convert a pointer to a class into a pointer to its base class 
  8409. if the base class is a virtual base class of the derived class. 
  8410.  
  8411. For more information on pointer conversions, see Pointer Arithmetic. 
  8412.  
  8413.  
  8414. ΓòÉΓòÉΓòÉ 6.2.5. Reference Conversions ΓòÉΓòÉΓòÉ
  8415.  
  8416. A reference conversion can be performed wherever a reference initialization 
  8417. occurs, including reference initialization done in argument passing and 
  8418. function return values. A reference to a class can be converted to a reference 
  8419. to an accessible base class of that class as long as the conversion is not 
  8420. ambiguous. The result of the conversion is a reference to the base class 
  8421. subobject of the derived class object. 
  8422.  
  8423. Reference conversion is allowed if the corresponding pointer conversion is 
  8424. allowed. 
  8425.  
  8426.  
  8427. ΓòÉΓòÉΓòÉ 6.2.6. Pointer-to-Member Conversions ΓòÉΓòÉΓòÉ
  8428.  
  8429. Pointer-to-member conversion can occur when pointers to members are 
  8430. initialized, assigned, or compared. 
  8431.  
  8432. A constant expression that evaluates to zero is converted to a distinct pointer 
  8433. to a member. 
  8434.  
  8435. Note:  A pointer to a member is not the same as a pointer to an object or a 
  8436. pointer to a function. 
  8437.  
  8438. A pointer to a member of a base class can be converted to a pointer to a member 
  8439. of a derived class if the following conditions are true: 
  8440.  
  8441.      The conversion is not ambiguous. The conversion is ambiguous if multiple 
  8442.       instances of the base class are in the derived class. 
  8443.      A pointer to the derived class can be converted to a pointer to the base 
  8444.       class. If this is the case, the base class is said to be accessible. See 
  8445.       Derivation Access of Base Classes for more information. 
  8446.  
  8447.  For more information, see Pointers to Members and Pointer to Member 
  8448.  Operators .* ->*. 
  8449.  
  8450.  
  8451. ΓòÉΓòÉΓòÉ 6.2.7. Function Argument Conversions ΓòÉΓòÉΓòÉ
  8452.  
  8453. If no function prototype declaration is visible when a function is called, the 
  8454. compiler can perform default argument promotions, which consist of the 
  8455. following: 
  8456.  
  8457.      Integral promotions 
  8458.      Arguments with type float are converted to type double. 
  8459.  
  8460.  
  8461. ΓòÉΓòÉΓòÉ 6.2.8. Other Conversions ΓòÉΓòÉΓòÉ
  8462.  
  8463. By definition, the void type has no value. Therefore, it cannot be converted to 
  8464. any other type, and no other value can be converted to void by assignment. 
  8465. However, a value can be explicitly cast to void. 
  8466.  
  8467. No conversions between structure or union types are allowed. 
  8468.  
  8469. There are no standard conversions between class types. 
  8470.  
  8471. In C, when you define a value using the enum type specifier, the value is 
  8472. treated as an int. Conversions to and from an enum value proceed as for the int 
  8473. type. 
  8474.  
  8475. In C++, you can convert from an enum to any integral type but not from an 
  8476. integral type to an enum. 
  8477.  
  8478.  
  8479. ΓòÉΓòÉΓòÉ 6.3. Arithmetic Conversions ΓòÉΓòÉΓòÉ
  8480.  
  8481. Most C++ operators perform type conversions to bring the operands of an 
  8482. expression to a common type or to extend short values to the integer size used 
  8483. by the machine. The conversions depend on the specific operator and the type of 
  8484. the operand or operands. However, many operators perform similar conversions on 
  8485. operands of integer and floating-point types. These standard conversions are 
  8486. known as the arithmetic conversions because they apply to the types of values 
  8487. ordinarily used in arithmetic. 
  8488.  
  8489. Arithmetic conversions are used for matching operands of arithmetic operators. 
  8490.  
  8491. The VisualAge C++ implementation of type conversions is described in the IBM 
  8492. VisualAge C++ for OS/2 User's Guide and Reference. 
  8493.  
  8494. Arithmetic conversion proceeds in the following order: 
  8495.  
  8496. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8497. Γöé OPERAND TYPE              Γöé CONVERSION              Γöé
  8498. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8499. Γöé One operand has long double type    Γöé The other operand is converted to   Γöé
  8500. Γöé                    Γöé long double type.           Γöé
  8501. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8502. Γöé One operand has double type      Γöé The other operand is converted to   Γöé
  8503. Γöé                    Γöé double.                Γöé
  8504. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8505. Γöé One operand has float type       Γöé The other operand is converted to   Γöé
  8506. Γöé                    Γöé float.                Γöé
  8507. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8508. Γöé One operand has unsigned long int   Γöé The other operand is converted to   Γöé
  8509. Γöé type                  Γöé unsigned long int.          Γöé
  8510. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8511. Γöé One operand has unsigned int type and Γöé The operand with unsigned int type  Γöé
  8512. Γöé the other operand has long int type  Γöé is converted to long int.       Γöé
  8513. Γöé and the value of the unsigned int can Γöé                    Γöé
  8514. Γöé be represented in a long int      Γöé                    Γöé
  8515. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8516. Γöé One operand has unsigned int type and Γöé Both operands are converted to    Γöé
  8517. Γöé the other operand has long int type  Γöé unsigned long int           Γöé
  8518. Γöé and the value of the unsigned int   Γöé                    Γöé
  8519. Γöé cannot be represented in a long int  Γöé                    Γöé
  8520. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8521. Γöé One operand has long int type     Γöé The other operand is converted to   Γöé
  8522. Γöé                    Γöé long int.               Γöé
  8523. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8524. Γöé One operand has unsigned int type   Γöé The other operand is converted to   Γöé
  8525. Γöé                    Γöé unsigned int.             Γöé
  8526. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  8527. Γöé Both operands have int type      Γöé The result is type int.        Γöé
  8528. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  8529.  
  8530.  
  8531. ΓòÉΓòÉΓòÉ 7. Functions ΓòÉΓòÉΓòÉ
  8532.  
  8533. This section describes the structure and use of functions in C and C++. It 
  8534. discusses the following topics: 
  8535.  
  8536.      C++ Enhancements to C Functions 
  8537.      Function Declarations 
  8538.      Function Definitions 
  8539.      The main() Function 
  8540.      Calling Functions and Passing Arguments 
  8541.      Default Arguments in C++ Functions 
  8542.      C++ Inline Functions 
  8543.  
  8544.  Related Information 
  8545.  
  8546.      Member Functions 
  8547.      Inline Member Functions 
  8548.      C++ Overloading 
  8549.      Special C++ Member Functions 
  8550.      Virtual Functions 
  8551.  
  8552.  Functions specify the logical structure of a program and define how particular 
  8553.  operations are to be implemented. 
  8554.  
  8555.  A function declaration consists of a return type, a name, and an argument 
  8556.  list. It is used to declare the format and existence of a function prior to 
  8557.  its use. 
  8558.  
  8559.  A function definition contains a function declaration and the body of the 
  8560.  function. A function can only have one definition. 
  8561.  
  8562.  Both C++ and ISO/ANSI C use the style of declaration called prototyping. A 
  8563.  prototype refers to the return type, name, and argument list components of a 
  8564.  function. It is used by the compiler for argument type checking and argument 
  8565.  conversions. Prototypes can appear several times in a program, provided the 
  8566.  declarations are compatible. They allow the compiler to check for mismatches 
  8567.  between the parameters of a function call and those in the function 
  8568.  declaration. 
  8569.  
  8570.  C++ Note:  C++ functions must use prototypes. They are usually placed in 
  8571.  header files, while function definitions appear in source files. Nonprototype 
  8572.  functions are allowed in C only. 
  8573.  
  8574.  
  8575. ΓòÉΓòÉΓòÉ 7.1. C++ Enhancements to C Functions ΓòÉΓòÉΓòÉ
  8576.  
  8577. The C++ language provides many enhancements to C functions. These are: 
  8578.  
  8579.      Reference arguments 
  8580.      Default arguments 
  8581.      Reference return types 
  8582.      Member functions 
  8583.      Overloaded functions 
  8584.      Operator functions 
  8585.      Constructor and destructor functions 
  8586.      Conversion functions 
  8587.      Virtual functions 
  8588.      Function templates 
  8589.  
  8590.  
  8591. ΓòÉΓòÉΓòÉ 7.2. Function Declarations ΓòÉΓòÉΓòÉ
  8592.  
  8593. A function declaration establishes the name and the parameters of the function. 
  8594.  
  8595. Syntax of a Function Declaration 
  8596.  
  8597. A function is declared implicitly by its appearance in an expression if it has 
  8598. not been defined or declared previously; the implicit declaration is equivalent 
  8599. to a declaration of extern int func_name(). The default return type of a 
  8600. function is int. 
  8601.  
  8602. To indicate that the function does not return a value, declare it with a a 
  8603. return type of void. 
  8604.  
  8605. C++ Note:  The use of the const and volatile specifiers is only supported by 
  8606. C++. 
  8607.  
  8608.  
  8609. ΓòÉΓòÉΓòÉ 7.2.1. C Function Declarations ΓòÉΓòÉΓòÉ
  8610.  
  8611. A function cannot be declared as returning a data object having a volatile or 
  8612. const type but it can return a pointer to a volatile or const object. Also, a 
  8613. function cannot return a value that has a type of array or function. 
  8614.  
  8615. If the called function returns a value that has a type other than int, you must 
  8616. declare the function before the function call. Even if a called function 
  8617. returns a type int, explicitly declaring the function prior to its call is good 
  8618. programming practice. 
  8619.  
  8620. Some declarations do not have parameter lists; the declarations simply specify 
  8621. the types of parameters and the return values, such as in the following 
  8622. example: 
  8623.  
  8624.    int func(int,long);
  8625.  
  8626. Examples of Function Declarations and Definitions 
  8627.  
  8628. Related Information 
  8629.  
  8630.      Function Declarator 
  8631.      Function Definitions 
  8632.      Calling Functions and Passing Arguments 
  8633.      extern Storage Class Specifier 
  8634.  
  8635.  
  8636. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Function Declaration ΓòÉΓòÉΓòÉ
  8637.  
  8638. A function declaration has the form: 
  8639.  
  8640.                               ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8641.                                      Γöé
  8642. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇfunction_declaratorΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>
  8643.   Γö£ΓöÇexternΓöÇΓöñ  ΓööΓöÇtype_specifierΓöÇΓöÿ              ΓööΓöÇparameterΓöÇΓöÿ
  8644.   ΓööΓöÇstaticΓöÇΓöÿ
  8645. >ΓöÇΓöÇ)ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  8646.    Γö£ΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöñ
  8647.    ΓööΓöÇvolatileΓöÇΓöÿ
  8648.  
  8649. C++ Note:  The use of the const and volatile specifiers is only supported by 
  8650. C++. 
  8651.  
  8652.  
  8653. ΓòÉΓòÉΓòÉ 7.2.2. C++ Function Declarations ΓòÉΓòÉΓòÉ
  8654.  
  8655. In C++, you can specify the qualifiers volatile and const in member function 
  8656. declarations. You can also specify exception specifications in function 
  8657. declarations. All C++ functions must be declared before they can be called. 
  8658.  
  8659. Types cannot be defined in return or argument types. For example, the following 
  8660. declarations are not valid in C++: 
  8661.  
  8662. void print(struct X { int i; } x);           //error
  8663. enum count{one, two, three} counter();       //error
  8664.  
  8665. This example attempts to declare a function print() that takes an object x of 
  8666. class X as its argument. However, the class definition is not allowed within 
  8667. the argument list. In the attempt to declare counter(), the enumeration type 
  8668. definition cannot appear in the return type of the function declaration. The 
  8669. two function declarations and their corresponding type definitions can be 
  8670. rewritten as follows: 
  8671.  
  8672. struct X { int i; };
  8673. void print(X x);
  8674. enum count {one, two, three};
  8675. count counter();
  8676.  
  8677. Multiple Function Declarations 
  8678.  
  8679. All function declarations for a particular function must have the same number 
  8680. and type of arguments, and must have the same return type and the same linkage 
  8681. keywords. These return and argument types are part of the function type, 
  8682. although the default arguments are not. 
  8683.  
  8684. For the purposes of argument matching, ellipsis and linkage keywords are 
  8685. considered a part of the function type. They must be used consistently in all 
  8686. declarations of a function. If the only difference between the argument types 
  8687. in two declarations is in the use of typedef names or unspecified argument 
  8688. array bounds, the declarations are the same. A const or volatile specifier is 
  8689. also part of the function type, but can only be part of a declaration or 
  8690. definition of a nonstatic member function. 
  8691.  
  8692. Declaring two functions differing only in return type is not valid function 
  8693. overloading, and is flagged as an error. For example: 
  8694.  
  8695. void f();
  8696. int f();      // error, two definitions differ only in
  8697.               // return type
  8698. int g()
  8699. {
  8700.    return f();
  8701. }
  8702.  
  8703. Checking Function Calls 
  8704.  
  8705. The compiler checks C++ function calls by comparing the number and type of the 
  8706. actual arguments used in the function call with the number and type of the 
  8707. formal arguments in the function declaration. Implicit type conversion is 
  8708. performed when necessary. 
  8709. Argument Names in Function Declarations 
  8710.  
  8711. You can supply argument names in a function declaration, but the compiler 
  8712. ignores them except in the following two situations: 
  8713.  
  8714.    1. If two argument names have the same name within a single declaration. 
  8715.       This is an error. 
  8716.  
  8717.    2. If an argument name is the same as a name outside the function. In this 
  8718.       case the name outside the function is hidden and cannot be used in the 
  8719.       argument declaration. 
  8720.  
  8721.  In the following example, the third argument intersects is meant to have 
  8722.  enumeration type subway_line, but this name is hidden by the name of the first 
  8723.  argument. The declaration of the function subway() causes a compile-time error 
  8724.  because subway_line is not a valid type name in the context of the argument 
  8725.  declarations. 
  8726.  
  8727.   enum subway_line {yonge, university, spadina, bloor};
  8728.   int subway(char * subway_line, int stations,
  8729.                     subway_line intersects);
  8730.  
  8731.  
  8732. ΓòÉΓòÉΓòÉ <hidden> Examples of Function Declarations and Definitions ΓòÉΓòÉΓòÉ
  8733.  
  8734. /************************************************************************
  8735. *
  8736.  
  8737. The following example defines the function absolute with the return type 
  8738. double. Because this is a noninteger return type, absolute is declared prior to 
  8739. the function call. 
  8740.  
  8741.                                                                         *
  8742. ************************************************************************/
  8743.  
  8744. /**
  8745.  ** This example shows how a function is declared and defined
  8746.  **/
  8747.  
  8748. #include <stdio.h>
  8749. double absolute(double);
  8750.  
  8751. int main(void)
  8752. {
  8753.    double f = -3.0;
  8754.  
  8755.    printf("absolute number = %lf\n", absolute(f));
  8756.  
  8757.    return (0);
  8758. }
  8759.  
  8760. double absolute(double number)
  8761. {
  8762.    if (number < 0.0)
  8763.       number = -number;
  8764.  
  8765.    return (number);
  8766. }
  8767.  
  8768. /************************************************************************
  8769. *
  8770.  
  8771. Specifying a return type of void on a function declaration indicates that the 
  8772. function does not return a value. The following example defines the function 
  8773. absolute with the return type void. Within the function main, absolute is 
  8774. declared with the return type void. 
  8775.  
  8776.                                                                         *
  8777. ************************************************************************/
  8778.  
  8779. /**
  8780.  ** This example uses a function with a void return type
  8781.  **/
  8782.  
  8783. #include <stdio.h>
  8784.  
  8785. int main(void)
  8786. {
  8787.   void absolute(float);
  8788.   float f = -8.7;
  8789.  
  8790.   absolute(f);
  8791.  
  8792.   return(0);
  8793. }
  8794.  
  8795. void absolute(float number)
  8796. {
  8797.   if (number < 0.0)
  8798.     number = -number;
  8799.  
  8800.   printf("absolute number = %f\n", number);
  8801. }
  8802.  
  8803. The following code fragments show several function declarations. The first 
  8804. declares a function f that takes two integer arguments and has a return type of 
  8805. void: 
  8806.  
  8807.       void f(int, int);
  8808.  
  8809. The following code fragment declares a function f1 that takes an integer 
  8810. argument, and returns a pointer to a function that takes an integer argument 
  8811. and returns an integer: 
  8812.  
  8813.       int (*f1(int))(int);
  8814.  
  8815. Alternatively, a typedef can be used for the complicated return type of 
  8816. function f1: 
  8817.  
  8818.       typedef int pf1(int);
  8819.       pf1* f1(int);
  8820.  
  8821. The following code fragment declares a pointer p1 to a function that takes a 
  8822. pointer to a constant character and returns an integer: 
  8823.  
  8824.       int (*p1) (const char*);
  8825.  
  8826. The following declaration is of an external function f2 that takes a constant 
  8827. integer as its first argument, can have a variable number and variable types of 
  8828. other arguments, and returns type int. 
  8829.  
  8830.       int extern f2(const int ...);
  8831.  
  8832. Function f3 takes an int argument with a default value that is the value 
  8833. returned from function f2, and that has a return type of int: 
  8834.  
  8835.       const int j = 5;
  8836.       int f3( int x = f2(j) );
  8837.  
  8838. Function f6 is a constant class member function of class X with no arguments, 
  8839. and with an int return type: 
  8840.  
  8841. class X
  8842. {
  8843. public:
  8844.       int f6() const;
  8845. };
  8846.  
  8847. Function f4 takes no arguments, has return type void, and can throw class 
  8848. objects of types X and Y. 
  8849.  
  8850. class X;
  8851. class Y;
  8852. //      .
  8853. //      .
  8854. //      .
  8855. void f4() throw(X,Y);
  8856.  
  8857. Function f5 takes no arguments, has return type void, and cannot throw an 
  8858. exception. 
  8859.  
  8860. void f5() throw();
  8861.  
  8862.  
  8863. ΓòÉΓòÉΓòÉ 7.3. Function Definitions ΓòÉΓòÉΓòÉ
  8864.  
  8865. A function definition contains a function declaration and the body of a 
  8866. function. It specifies the function name, formal parameters, the return type, 
  8867. and storage class of the function. 
  8868.  
  8869. Syntax of a Function Definition 
  8870.  
  8871. A function definition (either prototype or nonprototype) contains the 
  8872. following: 
  8873.  
  8874.      An optional storage class specifier extern or static, which determines 
  8875.       the scope of the function. If a storage class specifier is not given, the 
  8876.       function has external linkage. 
  8877.      An optional linkage keyword, which determines the calling convention used 
  8878.       to call the function. The keywords are a VisualAge C++ extension to the 
  8879.       ISO/ANSI C definition. The default VisualAge C++ calling convention is 
  8880.       _Optlink. The _Optlink calling convention is described in the IBM 
  8881.       VisualAge C++ for OS/2 User's Guide and Reference. 
  8882.      An optional type specifier, which determines the type of value that the 
  8883.       function returns. If a type specifier is not given, the function has type 
  8884.       int. 
  8885.      A function declarator, which provides the function with a name, can 
  8886.       further describe the type of the value that the function returns, and can 
  8887.       list any parameters that the function expects and their types. The 
  8888.       parameters that the function is expecting are enclosed in parentheses. 
  8889.      A block statement, which contains data definitions and code. 
  8890.  
  8891.  A nonprototype function definition can also have a list of parameter 
  8892.  declarations, which describe the types of parameters that the function 
  8893.  receives. In nonprototype functions, parameters that are not declared have 
  8894.  type int. 
  8895.  
  8896.  A function can be called by itself or by other functions. Unless a function 
  8897.  definition has the storage class specifier static, the function also can be 
  8898.  called by functions that appear in other files. Functions with a storage class 
  8899.  specifier of static can only be directly invoked from within the same source 
  8900.  file. 
  8901.  
  8902.  If a function has the storage class specifier static or a return type other 
  8903.  than int, the function definition or a declaration for the function must 
  8904.  appear before, and in the same file as, a call to the function. If a function 
  8905.  definition has external linkage and a return type of int, calls to the 
  8906.  function can be made before it is visible because an implicit declaration of 
  8907.  extern int func(); is assumed. 
  8908.  
  8909.  All declarations for a given function must be compatible; that is, the return 
  8910.  type is the same and the parameters have the same type. 
  8911.  
  8912.  The default type for the return value and parameters of a function is int, and 
  8913.  the default storage class specifier is extern. If the function does not return 
  8914.  a value or it is not passed any parameters, use the keyword void as the type 
  8915.  specifier. 
  8916.  
  8917.  A function can return a pointer or reference to a function, array, or to an 
  8918.  object with a volatile or const type. In C, you cannot declare a function as a 
  8919.  struct or union member. (This restriction does not apply to C++.) 
  8920.  
  8921.  A function cannot have a return type of function or array. In C, a function 
  8922.  cannot return any type having the volatile or const qualifier. (This 
  8923.  restriction does not apply to C++.) 
  8924.  
  8925.  You cannot define an array of functions. You can, however, define an array of 
  8926.  pointers to functions. 
  8927.  
  8928.  Examples of Function Definitions 
  8929.  
  8930.  Related Information 
  8931.  
  8932.      Storage Class Specifiers 
  8933.      Linkage Keywords 
  8934.      Type Specifiers 
  8935.      Function Declarator 
  8936.      Block 
  8937.      volatile and const Qualifiers 
  8938.      Function Declarations 
  8939.  
  8940.  
  8941. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Function Definition ΓòÉΓòÉΓòÉ
  8942.  
  8943. A function definition has the form: 
  8944.  
  8945. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ>
  8946.   Γö£ΓöÇexternΓöÇΓöñ  ΓööΓöÇlinkage_specifierΓöÇΓöÿ  ΓööΓöÇtype_specifierΓöÇΓöÿ
  8947.   ΓööΓöÇstaticΓöÇΓöÿ
  8948.             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  8949.                          Γöé
  8950. >ΓöÇΓöÇfunction_declaratorΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇblock_statementΓöÇΓöÇ><
  8951.              ΓööΓöÇparameter_declarationΓöÇΓöÿ
  8952.  
  8953.  
  8954. ΓòÉΓòÉΓòÉ <hidden> Examples of Function Definitions ΓòÉΓòÉΓòÉ
  8955.  
  8956. /************************************************************************
  8957. *
  8958.  
  8959. In the following example, ary is an array of two function pointers. Type 
  8960. casting is performed to the values assigned to ary for compatibility: 
  8961.  
  8962.                                                                         *
  8963. ************************************************************************/
  8964.  
  8965. /**
  8966.  ** This example uses an array of pointers to functions
  8967.  **/
  8968.  
  8969. #include <stdio.h>
  8970.  
  8971. int func1(void);
  8972. void func2(double a);
  8973.  
  8974. int main(void)
  8975. {
  8976.    double num;
  8977.    int retnum;
  8978.    void (*ary[2]) ();
  8979.    ary[0] = ((void(*)())func1);
  8980.    ary[1] = ((void(*)())func2);
  8981.  
  8982.    retnum=((int (*)())ary[0])();      /*  calls func1  */
  8983.    printf("number returned = %i\n", retnum);
  8984.    ((void (*)(double))ary[1])(num);   /*  calls func2  */
  8985.  
  8986.    return(0);
  8987. }
  8988.  
  8989. int func1(void)
  8990. {
  8991. int number=3;
  8992. return number;
  8993. }
  8994.  
  8995. void func2(double a)
  8996. {
  8997. a=333.3333;
  8998. printf("result of func2 = %f\n", a);
  8999. }
  9000.  
  9001. /************************************************************************
  9002. *
  9003.  
  9004. The following example is a complete definition of the function sum: 
  9005.  
  9006. int sum(int x,int y)
  9007. {
  9008.    return(x + y);
  9009. }
  9010.  
  9011. The function sum has external linkage, returns an object that has type int, and 
  9012. has two parameters of type int declared as x and y. The function body contains 
  9013. a single statement that returns the sum of x and y. 
  9014.  
  9015.                                                                         *
  9016. ************************************************************************/
  9017.  
  9018.  
  9019. ΓòÉΓòÉΓòÉ 7.3.1. Linkage Keywords ΓòÉΓòÉΓòÉ
  9020.  
  9021. Use linkage keywords to set linkage conventions for function calls. Each 
  9022. linkage convention has a corresponding keyword that you can use with a function 
  9023. name to set the convention for that function. The keywords are: 
  9024.  
  9025.  _Optlink                        VisualAge C++ default linkage for C++ 
  9026.                                  non-member functions 
  9027.  _System                         OS/2 system linkage 
  9028.  _Pascal                         32-bit _Pascal linkage 
  9029.  _Far32 _Pascal                  32-bit far _Pascal linkage 
  9030.  _Far16 _Cdecl                   16-bit __cdecl linkage 
  9031.  _Far16 _Pascal                  16-bit _Pascal linkage 
  9032.  _Far16 _Fastcall                16-bit _Fastcall linkage 
  9033.  
  9034.  Note: 
  9035.  
  9036.    1. You must specify the _Far16 keyword to use a 16-bit calling convention. 
  9037.       If you specify only _Far16, the _Far16 _Cdecl linkage is used. 
  9038.  
  9039.    2. Do not confuse the 32-bit _Pascal linkage with the 16-bit _Far16 _Pascal 
  9040.       linkage. If you specify only the _Pascal keyword, the 32-bit convention 
  9041.       is used. 
  9042.  
  9043.    3. _Far32 _Pascal linkage is only available when the /Gr+ option is 
  9044.       specified. 
  9045.  
  9046.  You can use the linkage keywords at any language level. To set the calling 
  9047.  convention for a function, place the linkage keyword immediately before the 
  9048.  function name. For example, 
  9049.  
  9050.      int _System deborah(int);
  9051.      char (* _Far16 _Cdecl donna)(int);
  9052.  
  9053.  Linkage keywords take precedence over the compiler options that set calling 
  9054.  conventions (/Mp and /Ms). If you specify conflicting linkage types for a 
  9055.  function using both a #pragma linkage directive and a keyword, an error 
  9056.  message is generated and your program will not compile. 
  9057.  
  9058.  Note:  Using a keyword is generally quicker and easier than using a #pragma 
  9059.         linkage and they let you declare both the function and its linkage type 
  9060.         in one statement. Because the #pragma linkage directive, is obsolete in 
  9061.         this release of VisualAge C++, linkage keywords are the preferred 
  9062.         method for setting the calling conventions. Avoid using it in new code. 
  9063.         For your new applications, use linkage keywords to specify the calling 
  9064.         convention for a function. 
  9065.  
  9066.  #pragma linkage is not supported at all for C++ functions. 
  9067.  
  9068.  For more information on the different calling conventions and how they work, 
  9069.  see the IBM VisualAge C++ for OS/2 Programming Guide. 
  9070.  
  9071.  Related Information 
  9072.  
  9073.      #pragma linkage 
  9074.      /Mp and /Ms options 
  9075.      Function Declarations 
  9076.      Function Definitions 
  9077.  
  9078.  
  9079. ΓòÉΓòÉΓòÉ 7.3.2. Inline Specifiers ΓòÉΓòÉΓòÉ
  9080.  
  9081. VisualAge C++ provides two keywords, _Inline for C programs and inline for C++ 
  9082. programs, that you can use to specify the user functions you want the compiler 
  9083. to inline. For example: 
  9084.  
  9085.    _Inline int catherine(int a);
  9086.  
  9087. causes catherine to be inlined, meaning that code is generated for the 
  9088. function, rather than a function call. The inline keywords also implicitly 
  9089. declare the function as static. 
  9090.  
  9091. By default, function inlining is turned off, and functions qualified with 
  9092. _Inline or inline are treated simply as static functions. To turn on function 
  9093. inlining, specify the /Oi+ option. If you turn optimization on (/O+), /Oi+ 
  9094. becomes the default. 
  9095.  
  9096. Recursive functions (functions that call themselves) are inlined for the first 
  9097. occurrence only. The call to the function from within itself will not be 
  9098. inlined. 
  9099.  
  9100. You can also use the /Oivalue option to automatically inline all functions 
  9101. smaller than value abstract code units as well as those qualified with _Inline 
  9102. or inline. For best performance, use the inline keywords to choose the 
  9103. functions you want to inline rather than using automatic inlining. 
  9104.  
  9105. When inlining is turned on, the following functions are also considered 
  9106. candidates to be inlined: 
  9107.  
  9108.      C++ member functions that are defined in class declarations. 
  9109.      For C programs only, small functions of static storage class that are 
  9110.       called only once. 
  9111.  
  9112.  Note:  If you plan to debug your code (specifying /Ti+), you should turn 
  9113.  inlining off. You should also be aware that profiling hooks are not generated 
  9114.  for inlined functions. 
  9115.  
  9116.  For more information on function inlining, see the IBM VisualAge C++ for OS/2 
  9117.  User's Guide and Reference. 
  9118.  
  9119.  Related Information 
  9120.  
  9121.      static Storage Class Specifier 
  9122.      Storage Class Specifiers 
  9123.      C++ Inline Functions 
  9124.      Inline Member Functions 
  9125.      /Oi option 
  9126.  
  9127.  
  9128. ΓòÉΓòÉΓòÉ 7.3.3. _Export Qualifier ΓòÉΓòÉΓòÉ
  9129.  
  9130. Use the _Export keyword with a function name to declare that the function is to 
  9131. be exported, that is, made available to other modules. For example: 
  9132.  
  9133.    int _Export anthony(float);
  9134.  
  9135. causes the function anthony to be exported. 
  9136.  
  9137. You can use _Export at any language level. If you also use linkage keywords, 
  9138. you can place _Export either before or after a linkage keyword. For example, 
  9139. both of the following declarations are valid: 
  9140.  
  9141.    int _Export _Optlink brian(int);
  9142.    int _Optlink _Export brian(int);
  9143.  
  9144. The _Export keyword is an alternative to the #pragma export directive. Note 
  9145. that #pragma export lets you specify both a name and an ordinal number the 
  9146. function can be called by. If you use _Export, other modules must call the 
  9147. function using its original name. 
  9148.  
  9149. If you use _Export to export your function, you may still need to provide an 
  9150. EXPORTS entry for that function in your module definition (.DEF) file. If your 
  9151. function has any of the following default characteristics 
  9152.  
  9153.      Has shared data 
  9154.      Has no I/O privileges 
  9155.      Is not resident 
  9156.  
  9157.  it does not require an EXPORTS entry. If your function has characteristics 
  9158.  other than the defaults, the only way you can specify them is with an EXPORTS 
  9159.  entry in your .DEF file. 
  9160.  
  9161.  Note:  To create an import library for the DLL, you must either create it from 
  9162.  the DLL itself or provide a .DEF file with an EXPORTS entry for every 
  9163.  function, regardless of whether _Export is used. 
  9164.  
  9165.  For more information on DLLs and .DEF files, see the IBM VisualAge C++ for 
  9166.  OS/2 Programming Guide. 
  9167.  
  9168.  Related Information 
  9169.  
  9170.      #pragma export 
  9171.      Declarators 
  9172.      volatile and const Qualifiers 
  9173.      _Packed Qualifier 
  9174.      _Seg16 Type Qualifier 
  9175.  
  9176.  
  9177. ΓòÉΓòÉΓòÉ 7.3.4. Function Declarator ΓòÉΓòÉΓòÉ
  9178.  
  9179. The function declarator names the function and lists the function parameters. 
  9180. It contains an identifier that names the function and a list of the function 
  9181. parameters. You should always use prototype function declarators because of the 
  9182. parameter checking that can be performed. C++ functions must have prototype 
  9183. function declarators. 
  9184.  
  9185. Syntax of a Function Declarator 
  9186.  
  9187.  
  9188. Prototype Function Declarators 
  9189.  
  9190. Each parameter should be declared within the function declarator. Any calls to 
  9191. the function must pass the same number of arguments as there are parameters in 
  9192. the declaration. 
  9193. Nonprototype Function Declarators 
  9194.  
  9195. Each parameter should be declared in a parameter declaration list following the 
  9196. declarator. If a parameter is not declared, it has type int. 
  9197.  
  9198. char and short parameters are widened to int, and float to double. No type 
  9199. checking between the argument type and the parameter type is done for 
  9200. nonprototyped functions. As well, there are no checks to ensure that the number 
  9201. of arguments matches the number of parameters. 
  9202.  
  9203. Each value that a function receives should be declared in a parameter 
  9204. declaration list for nonprototype function definitions that follows the 
  9205. declarator. 
  9206.  
  9207. A parameter declaration determines the storage class specifier and the data 
  9208. type of the value. 
  9209.  
  9210. The only storage class specifier allowed is the register storage class 
  9211. specifier. Any type specifier for a parameter is allowed. If you do not specify 
  9212. the register storage class specifier, the parameter will have the auto storage 
  9213. class specifier. If you omit the type specifier and you are not using the 
  9214. prototype form to define the function, the parameter will have type int. 
  9215.  
  9216.     int func(i,j)
  9217.     {
  9218.        /*  i and j have type int  */
  9219.     }
  9220.  
  9221. You cannot declare a parameter in the parameter declaration list if it is not 
  9222. listed within the declarator. 
  9223.  
  9224. Related Information 
  9225.  
  9226.      Function Declarations 
  9227.      Function Definitions 
  9228.      Function Body 
  9229.      Functions 
  9230.      Declarations 
  9231.  
  9232.  
  9233. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Function Declarator ΓòÉΓòÉΓòÉ
  9234.  
  9235. A function declarator has the form: 
  9236.  
  9237. >>ΓöÇΓöÇdeclaratorΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇparameter_declaration_listΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  9238.           Γöé ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ       Γöé
  9239.           Γöé        Γöé       Γöé
  9240.           ΓööΓöÇΓöÇΓöÇidentifierΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  9241.  
  9242. A parameter declaration list has the form: 
  9243.  
  9244.   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9245.   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ              Γöé
  9246.                  Γöé              Γöé
  9247. >>ΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇstorage_class_specifierΓöÇΓö¼Γö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  9248.     Γö£ΓöÇtype_specifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ  Γö£ΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdeclaratorΓöÇΓöÇΓöÇΓöñ   ΓööΓöÇ,ΓöÇΓöÇ...ΓöÇΓöÿ
  9249.     ΓööΓöÇtype_qualifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ  Γöé ΓööΓöÇ*ΓöÇΓöÿ        Γöé
  9250.                    ΓööΓöÇabstract_declaratorΓöÇΓöÿ
  9251.  
  9252. An abstract declarator has the form: 
  9253.  
  9254. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  9255.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  9256.      Γöé
  9257. >>ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓö¼ΓöÇ(ΓöÇΓöÇabstract_declaratorΓöÇΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  9258.    ΓööΓöÇ*ΓöÇΓöÿ  ΓööΓöÇΓöñ  direct_abstract_declarator Γö£ΓöÇΓöÿ
  9259. DIRECT_ABSTRACT_DECLARATOR:
  9260. Γö£ΓöÇΓöÇabstract_declaratorΓöÇΓöÇΓö¼ΓöÇ[ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ]ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöñ
  9261.             Γöé   ΓööΓöÇconstant_expressionΓöÇΓöÿ      Γöé
  9262.             ΓööΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÿ
  9263.                ΓööΓöÇparameter_declaration_listΓöÇΓöÿ
  9264. ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇ
  9265.  
  9266.  
  9267. ΓòÉΓòÉΓòÉ 7.3.5. Ellipsis and void ΓòÉΓòÉΓòÉ
  9268.  
  9269. An ellipsis at the end of an parameter declaration indicates that the number of 
  9270. arguments is equal to, or greater than, the number of specified argument types. 
  9271. At least one parameter declaration must come before the ellipsis. Where it is 
  9272. permitted, an ellipsis preceded by a comma is equivalent to a simple ellipsis. 
  9273.  
  9274.       int f(int,...);
  9275.  
  9276. The comma before the ellipsis is optional in C++ only 
  9277.  
  9278. Parameter promotions are performed as needed, but no type checking is done on 
  9279. the variable arguments. 
  9280.  
  9281. You can declare a function with no arguments in two ways: 
  9282.  
  9283.       int f(void);      // ISO/ANSI C Standard
  9284.  
  9285.       int f();          // C++ enhancement
  9286.                         // Note: In ISO/ANSI C, this declaration means that
  9287.                         // f may take any number or type or parameters
  9288.  
  9289. An empty argument declaration list or the argument declaration list of (void) 
  9290. indicates a function that takes no arguments. void cannot be used as an 
  9291. argument type, although types derived from void (such as pointers to void) can 
  9292. be used. 
  9293.  
  9294. In the following example, the function f() takes one integer parameter and 
  9295. returns no value, while g() expects no parameters and returns an integer. 
  9296.  
  9297. void f(int);
  9298. int g(void);
  9299.  
  9300.  
  9301. ΓòÉΓòÉΓòÉ 7.3.6. Function Body ΓòÉΓòÉΓòÉ
  9302.  
  9303. The body of a function is a block statement. 
  9304.  
  9305. The following function body contains a definition for the integer variable 
  9306. big_num, an if-else control statement, and a call to the function printf: 
  9307.  
  9308. void largest(int num1, int num2)
  9309. {
  9310.    int big_num;
  9311.  
  9312.    if (num1 >= num2)
  9313.       big_num = num1;
  9314.    else
  9315.       big_num = num2;
  9316.  
  9317.    printf("big_num = %d\n", big_num);
  9318. }
  9319.  
  9320. Examples of Prototype Function Declarators 
  9321.  
  9322.  
  9323. ΓòÉΓòÉΓòÉ <hidden> Examples of Prototype Function Declarators ΓòÉΓòÉΓòÉ
  9324.  
  9325. The following example contains a function declarator sort with table declared 
  9326. as a pointer to int and length declared as type int. Note that arrays as 
  9327. parameters are implicitly converted to a pointer to the type. 
  9328.  
  9329. /**
  9330.  ** This example illustrates function declarators.
  9331.  ** Note that arrays as parameters are implicitly
  9332.  ** converted to a pointer to the type.
  9333.  **/
  9334.  
  9335. #include <stdio.h>
  9336.  
  9337. void sort(int table[ ], int length);
  9338.  
  9339. int main(void)
  9340. {
  9341.    int table[ ]={1,5,8,4};
  9342.    int length=4;
  9343.    printf("length is %d\n",length);
  9344.    sort(table,length);
  9345. }
  9346.  
  9347. void sort(int table[ ], int length)
  9348. {
  9349.   int i, j, temp;
  9350.  
  9351.   for (i = 0; i < length -1; i++)
  9352.     for (j = i + 1; j < length; j++)
  9353.       if (table[i] > table[j])
  9354.       {
  9355.         temp = table[i];
  9356.         table[i] = table[j];
  9357.         table[j] = temp;
  9358.       }
  9359. }
  9360.  
  9361. The following examples contain prototype function declarators: 
  9362.  
  9363. double square(float x);
  9364. int area(int x,int y);
  9365. static char *search(char);
  9366.  
  9367. The following example illustrates how a typedef identifier can be used in a 
  9368. function declarator: 
  9369.  
  9370. typedef struct tm_fmt { int minutes;
  9371.                       int hours;
  9372.                       char am_pm;
  9373.                     } struct_t;
  9374. long time_seconds(struct_t arrival)
  9375.  
  9376. The following function set_date declares a pointer to a structure of type date 
  9377. as a parameter.  date_ptr has the storage class specifier register. 
  9378.  
  9379. set_date(register struct date *date_ptr)
  9380. {
  9381.   date_ptr->mon = 12;
  9382.   date_ptr->day = 25;
  9383.   date_ptr->year = 87;
  9384. }
  9385.  
  9386. Related Information 
  9387.  
  9388.      Block 
  9389.      Function Definitions 
  9390.      Function Declarations 
  9391.  
  9392.  
  9393. ΓòÉΓòÉΓòÉ 7.4. The main() Function ΓòÉΓòÉΓòÉ
  9394.  
  9395. When a program begins running, the system automatically calls the function 
  9396. main, which marks the entry point of the program. Every program must have one 
  9397. function named main. No other function in the program can be called main. 
  9398.  
  9399. Syntax of the main Function 
  9400.  
  9401. By default, main has the storage class extern and a return type of int. It can 
  9402. also be declared to return void. 
  9403.  
  9404. In C++, you cannot use the inline or static specifiers when declaring main. You 
  9405. cannot call main from within a program or take the address of main. 
  9406.  
  9407.  
  9408. ΓòÉΓòÉΓòÉ 7.4.1. Arguments to main ΓòÉΓòÉΓòÉ
  9409.  
  9410. Syntax of the Arguments to main 
  9411.  
  9412. The function main can be declared with or without arguments that pass program 
  9413. parameters and environment settings to the program. Although any name can be 
  9414. given to these parameters, they are usually referred to as argc, argv, and 
  9415. envp. 
  9416.  
  9417.  argc            Is the argument count. It has type int and indicates how many 
  9418.                  arguments are entered on the command line. 
  9419.  
  9420.  argv            Is the argument vector. It is an array of pointers to char 
  9421.                  array objects. These char objects are null-terminated strings 
  9422.                  that are the program arguments passed to the program when it 
  9423.                  is invoked. 
  9424.  
  9425.  envp            Is an optional environment pointer. It is an array of pointers 
  9426.                  to char objects that are the environment variables available 
  9427.                  to the program. These have the form name=value. The system 
  9428.                  determines the value of this parameter during program 
  9429.                  initialization (before calling main). Because you can use the 
  9430.                  function getenv to get the value of these pointers, there is 
  9431.                  usually no need to declare this parameter. 
  9432.  
  9433.  The value of argc indicates the number of pointers in the array argv. If a 
  9434.  program name is available, the first element in argv points to a character 
  9435.  array that contains the program name or the invocation name of the program 
  9436.  that is being run. If the name cannot be determined, the first element in argv 
  9437.  points to a null character. 
  9438.  
  9439.  This name is counted as one of the arguments to the function main. For 
  9440.  example, if only the program name is entered on the command line, argc has a 
  9441.  value of 1 and argv[0] points to the program name. 
  9442.  
  9443.  Regardless of the number of arguments entered on the command line, argv[argc] 
  9444.  always contains NULL. 
  9445.  
  9446.  Example of Arguments to main 
  9447.  
  9448.  Related Information 
  9449.  
  9450.      Function Definitions 
  9451.      Calling Functions and Passing Arguments 
  9452.      Type Specifiers 
  9453.      Identifiers 
  9454.      Block 
  9455.  
  9456.  
  9457. ΓòÉΓòÉΓòÉ <hidden> Syntax of the main Function ΓòÉΓòÉΓòÉ
  9458.  
  9459. The main function has the form: 
  9460.  
  9461. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇmainΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇblock_statementΓöÇΓöÇ><
  9462.   Γö£ΓöÇvoidΓöÇΓöñ      Γö£ΓöÇvoidΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  9463.   ΓööΓöÇintΓöÇΓöÇΓöÿ      ΓööΓöÇparametersΓöÇΓöÿ
  9464.  
  9465.  
  9466. ΓòÉΓòÉΓòÉ <hidden> Syntax of the Arguments to main ΓòÉΓòÉΓòÉ
  9467.  
  9468. The main function has the following arguments: 
  9469.  
  9470. >>ΓöÇΓöÇintΓöÇΓöÇargcΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  9471.         ΓööΓöÇ, char*ΓöÇΓöÇargvΓöÇΓöÇ[]ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  9472.                   ΓööΓöÇ, char*ΓöÇΓöÇenvpΓöÇΓöÇ[]ΓöÇΓöÿ
  9473.  
  9474.  
  9475. ΓòÉΓòÉΓòÉ <hidden> Example of Arguments to main ΓòÉΓòÉΓòÉ
  9476.  
  9477. /************************************************************************
  9478. *
  9479.  
  9480. The following program backward prints the arguments entered on a command line 
  9481. such that the last argument is printed first: 
  9482.  
  9483.                                                                         *
  9484. ************************************************************************/
  9485.  
  9486. #include <stdio.h>
  9487. int main(int argc, char *argv[])
  9488. {
  9489.   while (--argc > 0)
  9490.     printf("%s ", argv[argc]);
  9491. }
  9492.  
  9493. /************************************************************************
  9494. *
  9495.  
  9496. Invoking this program from a command line with the following: 
  9497.  
  9498.    backward string1 string2
  9499.  
  9500. gives the following output: 
  9501.  
  9502.    string2 string1
  9503.  
  9504. The arguments argc and argv would contain the following values: 
  9505.  
  9506.  Object              Value 
  9507.  argc                3 
  9508.  argv[0]             pointer to string "backward" 
  9509.  argv[1]             pointer to string "string1" 
  9510.  argv[2]             pointer to string "string2" 
  9511.  argv[3]             NULL 
  9512.  
  9513.                                                                           *
  9514.   ************************************************************************/
  9515.  
  9516.  
  9517. ΓòÉΓòÉΓòÉ 7.5. Calling Functions and Passing Arguments ΓòÉΓòÉΓòÉ
  9518.  
  9519. A function call specifies a function name and a list of arguments. The calling 
  9520. function passes the value of each argument to the specified function. The 
  9521. argument list is surrounded by parentheses, and each argument is separated by a 
  9522. comma. The argument list can be empty. When a function is called, the actual 
  9523. arguments are used to initialize the formal arguments. 
  9524.  
  9525. The type of an actual argument is checked against the type of the corresponding 
  9526. formal argument in the function prototype. All standard and user-defined type 
  9527. conversions are applied as necessary. 
  9528.  
  9529. For example: 
  9530.  
  9531. #include <iostream.h>
  9532. #include <math.h>
  9533. extern double root(double, double);    // declaration
  9534. double root(double value, double base) // definition
  9535. {
  9536.       double temp = exp(log(value)/base);
  9537.       return temp;
  9538. }
  9539. void main()
  9540. {
  9541.       int value = 144;
  9542.       int base = 2;
  9543.       // Call function root and print return value
  9544.       cout << "The root is: " << root(value,base) << endl;
  9545. }
  9546.  
  9547. The output is The root is: 12 
  9548.  
  9549. In the above example, because the function root is expecting arguments of type 
  9550. double, the two int arguments value and base are implicitly converted to type 
  9551. double when the function is called. 
  9552.  
  9553. The arguments to a function are evaluated before the function is called. When 
  9554. an argument is passed in a function call, the function receives a copy of the 
  9555. argument value. If the value of the argument is an address, the called function 
  9556. can use indirection to change the contents pointed to by the address. If a 
  9557. function or array is passed as an argument, the argument is converted to a 
  9558. pointer that points to the function or array. 
  9559.  
  9560. Arguments passed to parameters in prototype declarations will be converted to 
  9561. the declared parameter type. For nonprototype function declarations, char and 
  9562. short parameters are promoted to int, and float to double. 
  9563.  
  9564. You can pass a packed structure argument to a function expecting a nonpacked 
  9565. structure of the same type and vice versa. (The same applies to packed and 
  9566. nonpacked unions.) 
  9567.  
  9568. Note:  If you do not use a function prototype and you send a packed structure 
  9569. when a nonpacked structure is expected, a runtime error may occur. 
  9570.  
  9571. The order in which arguments are evaluated and passed to the function is 
  9572. implementation-defined. For example, the following sequence of statements calls 
  9573. the function tester: 
  9574.  
  9575. int x;
  9576. x = 1;
  9577. tester(x++, x);
  9578.  
  9579. The call to tester in the example may produce different results on different 
  9580. compilers. Depending on the implementation, x++ may be evaluated first or x may 
  9581. be evaluated first. To avoid the ambiguity and have x++ evaluated first, 
  9582. replace the preceding sequence of statements with the following: 
  9583.  
  9584. int x, y;
  9585. x = 1;
  9586. y = x++;
  9587. tester(y, x);
  9588.  
  9589.  
  9590. ΓòÉΓòÉΓòÉ 7.5.1. Passing Arguments in C++ ΓòÉΓòÉΓòÉ
  9591.  
  9592. In C++, if a nonstatic class member function is passed as an argument, the 
  9593. argument is converted to a pointer to member. 
  9594.  
  9595. Passing a class object by value is actually passed by reference if the class 
  9596. has a destructor or the class has a copy constructor that does more than a 
  9597. bitwise copy. 
  9598.  
  9599. It is an error when a function argument is a class object and all of the 
  9600. following properties hold: 
  9601.  
  9602.      The class needs a copy constructor. 
  9603.      The class does not have a user-defined copy constructor. 
  9604.      A copy constructor cannot be generated for that class. 
  9605.  
  9606.  Examples of Calling Functions and Passing Arguments 
  9607.  
  9608.  Related Information 
  9609.  
  9610.      Passing Arguments by Reference 
  9611.      Constructors and Destructors Overview 
  9612.      Member Functions 
  9613.      Function Declarator 
  9614.      Function Declarations 
  9615.      Function Definitions 
  9616.      Type Specifiers 
  9617.  
  9618.  
  9619. ΓòÉΓòÉΓòÉ <hidden> Examples of Calling Functions ΓòÉΓòÉΓòÉ
  9620.  
  9621. /************************************************************************
  9622. *
  9623.  
  9624. The following statement calls the function startup and passes no parameters: 
  9625.  
  9626. startup();
  9627.  
  9628. The following function call causes copies of a and b to be stored in a local 
  9629. area for the function sum. The function sum runs using the copies of a and b. 
  9630.  
  9631. sum(a, b);
  9632.  
  9633. The following function call passes the value 2 and the value of the expression 
  9634. a +b to sum: 
  9635.  
  9636. sum(2, a + b);
  9637.  
  9638. The following statement calls the function printf, which receives a character 
  9639. string and the return value of the function sum, which receives the values of a 
  9640. and b: 
  9641.  
  9642. printf("sum = %d\n", sum(a,b));
  9643.  
  9644. The following program passes the value of count to the function increment. 
  9645. increment increases the value of the parameter x by 1. 
  9646.  
  9647.                                                                         *
  9648. ************************************************************************/
  9649.  
  9650. /**
  9651.  ** This example shows how a parameter is passed to a function
  9652.  **/
  9653.  
  9654. #include <stdio.h>
  9655.  
  9656. void increment(int);
  9657.  
  9658. int main(void)
  9659. {
  9660.   int count = 5;
  9661.  
  9662.   /* value of count is passed to the function */
  9663.   increment(count);
  9664.   printf("count = %d\n", count);
  9665.  
  9666.   return(0);
  9667. }
  9668.  
  9669. void increment(int x)
  9670. {
  9671.   ++x;
  9672.   printf("x = %d\n", x);
  9673. }
  9674.  
  9675. /************************************************************************
  9676. *
  9677.  
  9678. The output illustrates that the value of count in main remains unchanged: 
  9679.  
  9680. x = 6
  9681. count = 5
  9682.  
  9683. In the following program, main passes the address of count to increment. The 
  9684. function increment was changed to handle the pointer. The parameter x is 
  9685. declared as a pointer. The contents to which x points are then incremented. 
  9686.  
  9687.                                                                         *
  9688. ************************************************************************/
  9689.  
  9690. /**
  9691.  ** This example shows how an address is passed to a function
  9692.  **/
  9693.  
  9694. #include <stdio.h>
  9695.  
  9696. int main(void)
  9697. {
  9698.   void increment(int *x);
  9699.   int count = 5;
  9700.  
  9701.   /* address of count is passed to the function */
  9702.   increment(&count);
  9703.   printf("count = %d\n", count);
  9704.  
  9705.   return(0);
  9706. }
  9707.  
  9708. void increment(int *x)
  9709. {
  9710.   ++*x;
  9711.   printf("*x = %d\n", *x);
  9712. }
  9713.  
  9714. /************************************************************************
  9715. *
  9716.  
  9717. The output shows that the variable count is increased: 
  9718.  
  9719. *x = 6
  9720. count = 6
  9721.  
  9722.                                                                         *
  9723. ************************************************************************/
  9724.  
  9725.  
  9726. ΓòÉΓòÉΓòÉ 7.5.2. Passing Arguments by Reference ΓòÉΓòÉΓòÉ
  9727.  
  9728. If you use a reference type as a formal argument, you can make a 
  9729. pass-by-reference call to a function. In a pass-by-reference call, the values 
  9730. of arguments in the calling function can be modified in the called function. In 
  9731. pass-by-value calls, only copies of the arguments are passed to the function. 
  9732.  
  9733. Note:  The term pass by reference describes a general method of passing 
  9734. arguments from a calling routine to a called routine. The term reference in the 
  9735. context of C++ refers to a specific way of declaring objects and functions. 
  9736.  
  9737. Example of Passing Arguments by Reference 
  9738.  
  9739. Ellipsis arguments cannot be passed as references. 
  9740.  
  9741. In addition, when the actual argument cannot be referenced directly by the 
  9742. formal argument, the compiler creates a temporary variable that is referenced 
  9743. by the formal argument and initialized using the value of the actual argument. 
  9744. In this case, the formal argument must be a const reference. 
  9745.  
  9746. Reference arguments declared const can be used to pass large objects 
  9747. efficiently to functions without making a temporary copy of the object that is 
  9748. passed to the function. Because the reference is declared const, the actual 
  9749. arguments cannot be changed by the function. For example: 
  9750.  
  9751. void printbig (const bigvar&); // Function prototype
  9752.  
  9753. When a function printbig is called, it cannot modify the object of type bigvar 
  9754. because the object was passed by constant reference. 
  9755.  
  9756. Related Information 
  9757.  
  9758.      Calling Functions and Passing Arguments 
  9759.      References 
  9760.      volatile and const Qualifiers 
  9761.  
  9762.  
  9763. ΓòÉΓòÉΓòÉ <hidden> Example of Passing Arguments by Reference ΓòÉΓòÉΓòÉ
  9764.  
  9765. /************************************************************************
  9766. *
  9767.  
  9768. The following example shows how arguments are passed by reference. Note that 
  9769. reference formal arguments are initialized with the actual arguments when the 
  9770. function is called. 
  9771.  
  9772.                                                                         *
  9773. ************************************************************************/
  9774.  
  9775. /**
  9776.  ** This example shows how arguments are passed by reference
  9777.  **/
  9778.  
  9779. #include <iostream.h>
  9780. void swapnum(int &i, int &j)
  9781. {
  9782.       int temp = i;
  9783.       i = j;
  9784.       j = temp;
  9785. }
  9786. //    .
  9787. //    .
  9788. //    .
  9789. main()
  9790. {
  9791.       int   a = 10,    // a is 10
  9792.             b = 20;    // b is 20
  9793.       swapnum(a,b);    // now a is 20 and b is 10
  9794.       cout << "A is : " << a
  9795.            << " and B is : " << b << endl;
  9796. }
  9797.  
  9798. /************************************************************************
  9799. *
  9800.  
  9801. When the function swapnum() is called, the actual values of the variables a and 
  9802. b are exchanged because they are passed by reference. The output is: 
  9803.  
  9804. A is : 20 and B is : 10
  9805.  
  9806. You must define the formal arguments of swapnum() as references if you want the 
  9807. values of the actual arguments to be modified by the function swapnum(). 
  9808.  
  9809.                                                                         *
  9810. ************************************************************************/
  9811.  
  9812. If the last argument specified in the function declaration before the ellipsis 
  9813. is a reference argument, arguments passed using an ellipsis (variable 
  9814. arguments) are accessible using the mechanism from the <stdarg.h> standard 
  9815. header file. 
  9816.  
  9817.  
  9818. ΓòÉΓòÉΓòÉ 7.6. Default Arguments in C++ Functions ΓòÉΓòÉΓòÉ
  9819.  
  9820. In C++, you can provide default values for function arguments. All default 
  9821. argument names of a function are bound when the function is declared. All 
  9822. functions have their types checked at declaration, and are evaluated at each 
  9823. point of call. 
  9824.  
  9825. For example: 
  9826.  
  9827. /**
  9828.  ** This example illustrates default function arguments
  9829.  **/
  9830.  
  9831. #include <iostream.h>
  9832. int a = 1;
  9833. int f(int a) {return a;}
  9834. int g(int x = f(a)) {return f(a);}
  9835.  
  9836. int h()
  9837. {
  9838.      a=2;
  9839.      {
  9840.             int a = 3;
  9841.             return g();
  9842.      }
  9843. }
  9844.  
  9845. main()
  9846. {
  9847.      cout << h() << endl;
  9848. }
  9849.  
  9850. This example prints 2 to standard output, because the a referred to in the 
  9851. declaration of g() is the one at file scope, which has the value 2 when g() is 
  9852. called. The value of a is determined after entry into function h() but before 
  9853. the call to g() is resolved. 
  9854.  
  9855. A default argument can have any type. 
  9856.  
  9857. A pointer to a function must have the same type as the function. Attempts to 
  9858. take the address of a function by reference without specifying the type of the 
  9859. function produce an error. The type of a function is not affected by arguments 
  9860. with default values. 
  9861.  
  9862. The following example shows that the fact that a function has default arguments 
  9863. does not change its type. The default argument allows you to call a function 
  9864. without specifying all of the arguments, it does not allow you to create a 
  9865. pointer to the function that does not specify the types of all the arguments. 
  9866. Function f can be called without an explicit argument, but the pointer 
  9867. badpointer cannot be defined without specifying the type of the argument: 
  9868.  
  9869. int f(int = 0);
  9870. void g()
  9871. {
  9872.    int a = f(1);                // ok
  9873.    int b = f();                 // ok, default argument used
  9874. }
  9875. int (*pointer)(int) = &f;       // ok, type of f() specified (int)
  9876. int (*badpointer)() = &f;       // error, badpointer and f have
  9877.                                 // different types. badpointer must
  9878.                                 // be initialized with a pointer to
  9879.                                 // a function taking no arguments.
  9880.  
  9881. For additional information about default arguments, see: 
  9882.  
  9883.      Restrictions on Default Arguments 
  9884.      Evaluating Default Arguments 
  9885.  
  9886.  Related Information 
  9887.  
  9888.      Calling Functions and Passing Arguments 
  9889.      Functions 
  9890.  
  9891.  
  9892. ΓòÉΓòÉΓòÉ 7.6.1. Restrictions on Default Arguments ΓòÉΓòÉΓòÉ
  9893.  
  9894. Of the operators, only the function call operator and the operator new can have 
  9895. default arguments when they are overloaded. 
  9896.  
  9897. Arguments with default values must be the trailing arguments in the function 
  9898. declaration argument list. For example: 
  9899.  
  9900. void f(int a, int b = 2, int c = 3);  // trailing defaults
  9901. void g(int a = 1, int b = 2, int c);  // error, leading defaults
  9902. void h(int a, int b = 3, int c);      // error, default in middle
  9903.  
  9904. Once a default argument has been given in a declaration or definition, you 
  9905. cannot redefine that argument, even to the same value. However, you can add 
  9906. default arguments not given in previous declarations. For example, the last 
  9907. declaration below attempts to redefine the default values for a and b: 
  9908.  
  9909. void f(int a, int b, int c=1);     // valid
  9910. void f(int a, int b=1, int c);     // valid, add another default
  9911. void f(int a=1, int b, int c);     // valid, add another default
  9912. void f(int a=1, int b=1, int c=1); // error, redefined defaults
  9913.  
  9914. You can supply any default argument values in the function declaration or in 
  9915. the definition. All subsequent arguments must have default arguments supplied 
  9916. in this or a previous declaration of the function. 
  9917.  
  9918. You cannot use local variables in default argument expressions. For example, 
  9919. the compiler generates errors for both function g() and function h() below: 
  9920.  
  9921. void f(int a)
  9922. {
  9923.       int b=4;
  9924.       void g(int c=a); // Local variable "a" inaccessible
  9925.       void h(int d=b); // Local variable "b" inaccessible
  9926. }
  9927.  
  9928. Related Information 
  9929.  
  9930.      Function Calls ( ) 
  9931.      new Operator 
  9932.      Default Arguments in C++ Functions 
  9933.      Evaluating Default Arguments 
  9934.      Calling Functions and Passing Arguments 
  9935.      Functions 
  9936.  
  9937.  
  9938. ΓòÉΓòÉΓòÉ 7.6.2. Evaluating Default Arguments ΓòÉΓòÉΓòÉ
  9939.  
  9940. When a function defined with default arguments is called with trailing 
  9941. arguments missing, the default expressions are evaluated. For example: 
  9942.  
  9943. void f(int a, int b = 2, int c = 3); // declaration
  9944. // ...
  9945. int a = 1;
  9946. f(a);            // same as call f(a,2,3)
  9947. f(a,10);         // same as call f(a,10,3)
  9948. f(a,10,20);      // no default arguments
  9949.  
  9950. Default arguments are checked against the function declaration and evaluated 
  9951. when the function is called. The order of evaluation of default arguments is 
  9952. undefined. Default argument expressions cannot use formal arguments of a 
  9953. function. For example: 
  9954.  
  9955. int f(int q = 3, int r = q); // error
  9956.  
  9957. The argument r cannot be initialized with the value of the argument q because 
  9958. the value of q may not be known when it is assigned to r. If the above function 
  9959. declaration is rewritten: 
  9960.  
  9961. int q=5;
  9962. int f(int q = 3, int r = q); // error
  9963.  
  9964. the value of r in the function declaration still produces an error because the 
  9965. variable q defined outside of the function is hidden by the argument q declared 
  9966. for the function. Similarly: 
  9967.  
  9968. typedef double D;
  9969. int f(int D, int z = D(5.3) ); // error
  9970.  
  9971. Here the type D is interpreted within the function declaration as the name of 
  9972. an integer. The type D is hidden by the argument D. The cast D(5.3) is 
  9973. therefore not interpreted as a cast because D is the name of the argument not a 
  9974. type. 
  9975.  
  9976. In the following example, the nonstatic member a cannot be used as an 
  9977. initializer because a does not exist until an object of class X is constructed. 
  9978. You can use the static member b as an initializer because b is created 
  9979. independently of any objects of class X. You can declare the member b after its 
  9980. use as a default argument because the default values are not analyzed until 
  9981. after the final bracket } of the class declaration. 
  9982.  
  9983. class X
  9984. {
  9985.    int a;
  9986.     f(int z = a) ; // error
  9987.     g(int z = b) ; // valid
  9988.     static int b;
  9989. };
  9990.  
  9991. You must put parentheses around default argument expressions that contain 
  9992. template references. In the following example: 
  9993.  
  9994. class C {
  9995.    void f(int i = X<int,5>::y);
  9996. };
  9997.  
  9998. the compiler cannot tell that the < represents the start of a template argument 
  9999. list and not the less than operator because the default argument X<int,5>::y 
  10000. cannot be processed until the end of the class. 
  10001.  
  10002. To avoid error messages, put parentheses around the expression containing the 
  10003. default argumement: 
  10004.  
  10005. class C {
  10006.    void f( int i = (X<int,5>::y) );
  10007. };
  10008.  
  10009. Related Information 
  10010.  
  10011.      Default Arguments in C++ Functions 
  10012.      Restrictions on Default Arguments 
  10013.      Calling Functions and Passing Arguments 
  10014.      Functions 
  10015.      Constructors and Destructors Overview 
  10016.  
  10017.  
  10018. ΓòÉΓòÉΓòÉ 7.7. Function Return Values ΓòÉΓòÉΓòÉ
  10019.  
  10020. A value must be returned from a function unless the function has a return type 
  10021. of void. The return value is specified in a return statement. The following 
  10022. code fragment shows a function definition, including the return statement: 
  10023.  
  10024. int add(int i, int j)
  10025. {
  10026.   return i + j; // return statement
  10027. }
  10028.  
  10029. The function add() can be called as shown in the following code fragment: 
  10030.  
  10031. int a = 10,
  10032.     b = 20;
  10033. int answer = add(a, b); // answer is 30
  10034.  
  10035. In this example, the return statement initializes a variable of the returned 
  10036. type. The variable answer is initialized with the int value 30. The type of the 
  10037. returned expression is checked against the returned type. All standard and 
  10038. user-defined conversions are performed as necessary. 
  10039.  
  10040. The following return statements show different ways of returning values to a 
  10041. caller: 
  10042.  
  10043. return;                    // Returns no value
  10044. return result;             // Returns the value of result
  10045. return 1;                  // Returns the value 1
  10046. return (x * x);            // Returns the value of x * x
  10047.  
  10048. Other than main(), if a function that does not have type void returns without a 
  10049. value (as in the first return statement shown in the example above) the result 
  10050. returned is undefined. In C++, the compiler issues an error message as well. 
  10051.  
  10052. If main has a return type of int, and does not contain a return expression, it 
  10053. returns the value zero. 
  10054.  
  10055. Each time a function is called, new copies of its local variables are created. 
  10056. Because the storage for a local variable may be reused after the function has 
  10057. terminated, a pointer to a local variable or a reference to a local variable 
  10058. should not be returned. 
  10059.  
  10060. If a class object is returned, a temporary object may be created if the class 
  10061. has copy constructors or a destructor. 
  10062.  
  10063. References can also be used as return types for functions. The reference 
  10064. returns the lvalue of the object to which it refers. This allows you to place 
  10065. function calls on the left side of assignment statements. Referenced return 
  10066. values are used when assignment operators and subscripting operators are 
  10067. overloaded so that the results of the overloaded operators can be used as 
  10068. actual values. 
  10069.  
  10070. Note:  Returning a reference to an automatic variable gives unpredictable 
  10071. results. 
  10072.  
  10073. Related Information 
  10074.  
  10075.      return 
  10076.      Calling Functions and Passing Arguments 
  10077.      The main() Function 
  10078.      Temporary Objects 
  10079.      Special Overloaded Operators 
  10080.  
  10081.  
  10082. ΓòÉΓòÉΓòÉ 7.8. Pointers to Functions ΓòÉΓòÉΓòÉ
  10083.  
  10084. A pointer to a function points to the address of the function's executable 
  10085. code. You can use pointers to call functions and to pass functions as arguments 
  10086. to other functions. You cannot perform pointer arithmetic on pointers to 
  10087. functions. 
  10088.  
  10089. The type of a pointer to a function is based on both the return type and 
  10090. argument types of the function. 
  10091.  
  10092. A declaration of a pointer to a function must have the pointer name in 
  10093. parentheses. Without them, the compiler interprets the statement as a function 
  10094. that returns a pointer to a specified return type. For example: 
  10095.  
  10096. int *f(int a);       // function f returning an int*
  10097. int (*g)(int a);     // pointer g to a function returning an int
  10098.  
  10099. In the first declaration, f is interpreted as a function that takes an int as 
  10100. argument, and returns a pointer to an int. In the second declaration, g is 
  10101. interpreted as a pointer to a function that takes an int argument and that 
  10102. returns an int. 
  10103.  
  10104. For more information on pointers, see Pointers and Pointer Conversions. 
  10105.  
  10106.  
  10107. ΓòÉΓòÉΓòÉ 7.9. C++ Inline Functions ΓòÉΓòÉΓòÉ
  10108.  
  10109. Inline functions are used in C++ to reduce the overhead of a normal function 
  10110. call. A function is declared inline by using the specifier inline for C++ 
  10111. functions or _Inline for C functions. The inline specifier is a suggestion to 
  10112. the compiler that an inline expansion can be performed. Instead of transferring 
  10113. control to and from the function code segment, a modified copy of the function 
  10114. body may be substituted directly for the function call. 
  10115.  
  10116. An inline function can be declared and defined simultaneously. If it is 
  10117. declared with the keyword inline or _Inline, it can be declared without a 
  10118. definition. The following code fragment shows an inline function definition. 
  10119. Note that the definition includes both the declaration and body of the inline 
  10120. function. 
  10121.  
  10122. inline int add(int i, int j) { return i + j; }
  10123.  
  10124. Both member and nonmember functions can be inline, and both have internal 
  10125. linkage. 
  10126.  
  10127. The use of the inline specifier does not change the meaning of the function. 
  10128. The inline expansion of a function may not preserve the order of evaluation of 
  10129. the actual arguments. 
  10130.  
  10131. For more information on inlining, see the IBM VisualAge C++ for OS/2 
  10132. Programming Guide. 
  10133.  
  10134. Related Information 
  10135.  
  10136.      Inline Specifiers 
  10137.      Inline Member Functions 
  10138.      Functions 
  10139.  
  10140.  
  10141. ΓòÉΓòÉΓòÉ 7.10. Resolving Ambiguous Statements in C++ ΓòÉΓòÉΓòÉ
  10142.  
  10143. There are situations in C++ where a statement can be parsed as both a 
  10144. declaration and as an expression. Specifically, a declaration can look like a 
  10145. function call in certain cases. The compiler resolves these ambiguities by 
  10146. applying the following rules to the whole statement: 
  10147.  
  10148.      If the statement can be parsed as a declaration but there are no 
  10149.       declaration specifiers in the declaration and the statement is inside the 
  10150.       body of a function, the statement is assumed to be an expression. 
  10151.  
  10152.       The following statement, for example, is a declaration at file scope of 
  10153.       the function f() that returns type int. There is no declaration specifier 
  10154.       and int is the default, but at function scope this is a call to f(): 
  10155.  
  10156.              f();
  10157.  
  10158.      In every other case, if the statement can be parsed as a declaration, it 
  10159.       is assumed to be a declaration. The following statement, for example, is 
  10160.       a declaration of x with redundant parentheses around the declarator, not 
  10161.       a function-style cast of x to type int: 
  10162.  
  10163.              int (x);
  10164.  
  10165.  In some cases, C++ syntax does not disambiguate between expression statements 
  10166.  and declaration statements. The ambiguity arises when an expression statement 
  10167.  has a function-style cast as its leftmost subexpression. (Note that, because C 
  10168.  does not support function-style casts, this ambiguity does not occur in C 
  10169.  programs.) If the statement can be interpreted both as a declaration and as an 
  10170.  expression, the statement is interpreted as a declaration statement. 
  10171.  
  10172.  Note:  The ambiguity is resolved only on a syntactic level. The disambiguation 
  10173.  does not use the meaning of the names, except to assess whether or not they 
  10174.  are type names. 
  10175.  
  10176.  The following expressions disambiguate into expression statements because the 
  10177.  ambiguous subexpression is followed by an assignment or an operator. type_spec 
  10178.  in the expressions can be any type specifier: 
  10179.  
  10180.   type_spec(i)++;             // expression statement
  10181.   type_spec(i,3)<<d;          // expression statement
  10182.   type_spec(i)->l=24;         // expression statement
  10183.  
  10184.  In the following examples, the ambiguity cannot be resolved syntactically, and 
  10185.  the statements are interpreted as declarations. type_spec is any type 
  10186.  specifier: 
  10187.  
  10188.   type_spec(*i)(int);         // declaration
  10189.   type_spec(j)[5];            // declaration
  10190.   type_spec(m) = { 1, 2 };    // declaration
  10191.   type_spec(*k) (float(3));   // declaration
  10192.  
  10193.  The last statement above causes a compile-time error because you cannot 
  10194.  initialize a pointer with a float value. 
  10195.  
  10196.  Any ambiguous statement that is not resolved by the above rules is by default 
  10197.  a declaration statement. All of the following are declaration statements: 
  10198.  
  10199.   type_spec(a);               // declaration
  10200.   type_spec(*b)();            // declaration
  10201.   type_spec(c)=23;            // declaration
  10202.   type_spec(d),e,f,g=0;       // declaration
  10203.   type_spec(h)(e,3);          // declaration
  10204.  
  10205.  Another C++ ambiguity between expression statements and declaration statements 
  10206.  is resolved by requiring an explicit return type for function declarations 
  10207.  within a block: 
  10208.  
  10209.   a();         // declaration of a function returning int
  10210.                // and taking no arguments
  10211.   void func()
  10212.   {
  10213.      int a();  // declaration of a function
  10214.      int b;    // declaration of a variable
  10215.      a();      // expression-statement calling function a()
  10216.      b;        // expression-statement referring to a variable
  10217.   }
  10218.  
  10219.  The last statement above does not produce any action. It is semantically 
  10220.  equivalent to a null statement. However, it is a valid C++ statement. 
  10221.  
  10222.  Related Information 
  10223.  
  10224.      Function Declarations 
  10225.      Cast Expressions 
  10226.  
  10227.  
  10228. ΓòÉΓòÉΓòÉ 8. Statements ΓòÉΓòÉΓòÉ
  10229.  
  10230. This section describes the following C and C++ language statements: 
  10231.  
  10232.      Labels 
  10233.      Block 
  10234.      break 
  10235.      continue 
  10236.      do 
  10237.      Expression 
  10238.      for 
  10239.      goto 
  10240.      if 
  10241.      Null Statement 
  10242.      return 
  10243.      switch 
  10244.      while 
  10245.  
  10246.  Related Information 
  10247.  
  10248.      Scope in C 
  10249.      Scope in C++ 
  10250.      Declarations 
  10251.      Expressions and Operators 
  10252.      Functions 
  10253.  
  10254.  
  10255. ΓòÉΓòÉΓòÉ 8.1. Labels ΓòÉΓòÉΓòÉ
  10256.  
  10257. A label is an identifier that allows your program to transfer control to other 
  10258. statements within the same function. It is the only type of identifier that has 
  10259. function scope. Control is transferred to the statement following the label by 
  10260. means of the goto or switch statements. 
  10261.  
  10262. Syntax of a Labelled Statement 
  10263.  
  10264. The label is the identifier and the colon (:) character. 
  10265.  
  10266. The case and default labels can only appear within the body of a switch 
  10267. statement. 
  10268.  
  10269.  comment_complete : ;            /* null statement label */
  10270.  test_for_null : if (NULL == pointer)
  10271.  
  10272. Related Information 
  10273.  
  10274.      Scope in C 
  10275.      Scope in C++ 
  10276.      goto 
  10277.      switch 
  10278.  
  10279.  
  10280. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Labelled Statement ΓòÉΓòÉΓòÉ
  10281.  
  10282. A labelled statement has the form: 
  10283.  
  10284. >>ΓöÇΓöÇidentifierΓöÇΓöÇ:ΓöÇΓöÇstatementΓöÇΓöÇ><
  10285.  
  10286.  
  10287. ΓòÉΓòÉΓòÉ 8.2. Block ΓòÉΓòÉΓòÉ
  10288.  
  10289. A block statement, or compound statement, lets you group any number of data 
  10290. definitions, declarations, and statements into one statement. All definitions, 
  10291. declarations, and statements enclosed within a single set of braces are treated 
  10292. as a single statement. You can use a block wherever a single statement is 
  10293. allowed. 
  10294.  
  10295. Syntax of a Block Statement 
  10296.  
  10297. In C, Any definitions and declarations must come before the statements. 
  10298.  
  10299. Redefining a data object inside a nested block hides the outer object while the 
  10300. inner block runs. Defining several variables that have the same identifier can 
  10301. make a program difficult to understand and maintain. You should avoid 
  10302. redefining of identifiers within nested blocks. If a data object is usable 
  10303. within a block and its identifier is not redefined, all nested blocks can use 
  10304. that data object. 
  10305.  
  10306. Examples of Block Statements 
  10307.  
  10308. Related Information 
  10309.  
  10310.      Block Scope Data Declarations 
  10311.      Initialization within Block Statements 
  10312.      Function Body 
  10313.      auto Storage Class Specifier 
  10314.      register Storage Class Specifier 
  10315.      static Storage Class Specifier 
  10316.      extern Storage Class Specifier 
  10317.  
  10318.  
  10319. ΓòÉΓòÉΓòÉ <hidden> Initialization within Block Statements ΓòÉΓòÉΓòÉ
  10320.  
  10321. Initialization of an auto or register variable occurs each time the block is 
  10322. run from the beginning. If you transfer control from one block to the middle of 
  10323. another block, initializations are not always performed. You cannot initialize 
  10324. an extern variable within a block. 
  10325.  
  10326. A static local object is initialized only once, when control passes through its 
  10327. declaration for the first time. A static variable initialized with an 
  10328. expression other than a constant expression is initialized to 0 before its 
  10329. block is first entered. 
  10330.  
  10331. C++ Note:  Unlike ISO/ANSI C, in C++ it is an error to jump over a declaration 
  10332. or definition containing an initializer. 
  10333.  
  10334. The following code produces an error in C++: 
  10335.  
  10336. goto skiplabel;
  10337. int i=3      // error, jumped over declaration of i with initializer
  10338. skiplabel: i=4;
  10339.  
  10340. When control exits from a block, all objects with destructors that are defined 
  10341. in the block are destroyed. The destructor for a static local object is called 
  10342. only if the object was constructed. The destructor must be called before or as 
  10343. part of the atexit function. 
  10344.  
  10345. Local variables declared in a block are also destroyed on exit. Automatic 
  10346. variables defined in a loop are destroyed at each iteration. 
  10347.  
  10348. Related Information 
  10349.  
  10350.      Block Scope Data Declarations 
  10351.      Block 
  10352.      auto Storage Class Specifier 
  10353.      register Storage Class Specifier 
  10354.      static Storage Class Specifier 
  10355.      extern Storage Class Specifier 
  10356.      Destructors 
  10357.  
  10358.  
  10359. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Block Statement ΓòÉΓòÉΓòÉ
  10360.  
  10361. A block statement has the form: 
  10362.  
  10363.     ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  10364.                      Γöé         Γöé
  10365. >>ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  10366.     Γö£ΓöÇtype_definitionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ   ΓööΓöÇstatementΓöÇΓöÿ
  10367.     Γö£ΓöÇfile_scope_data_declarationΓöÇΓöÇΓöñ
  10368.     ΓööΓöÇblock_scope_data_declarationΓöÇΓöÿ
  10369.  
  10370.  
  10371. ΓòÉΓòÉΓòÉ <hidden> Examples of Block Statements ΓòÉΓòÉΓòÉ
  10372.  
  10373. /************************************************************************
  10374. *
  10375.  
  10376. The following program shows how the values of data objects change in nested 
  10377. blocks: 
  10378.  
  10379.                                                                         *
  10380. ************************************************************************/
  10381.  
  10382.  1 /**
  10383.  2  ** This example shows how data objects change in nested blocks.
  10384.  3  **/
  10385.  4   #include <stdio.h>
  10386.  5
  10387.  6   int main(void)
  10388.  7   {
  10389.  8      int x = 1;                     /* Initialize x to 1  */
  10390.  9      int y = 3;
  10391. 10
  10392. 11      if (y > 0)
  10393. 12      {
  10394. 13         int x = 2;                  /* Initialize x to 2  */
  10395. 14         printf("second x = %4d\n", x);
  10396. 15      }
  10397. 16      printf("first  x = %4d\n", x);
  10398. 17
  10399. 18      return(0);
  10400. 19   }
  10401.  
  10402. /************************************************************************
  10403. *
  10404.  
  10405. The program produces the following output: 
  10406.  
  10407. second x =    2
  10408. first  x =    1
  10409.  
  10410. Two variables named x are defined in main. The definition of x on line 8 
  10411. retains storage while main is running. However, because the definition of x on 
  10412. line 13 occurs within a nested block, line 14 recognizes x as the variable 
  10413. defined on line 13. Because line 16 is not part of the nested block, x is 
  10414. recognized as the variable defined on line 8. 
  10415.  
  10416.                                                                         *
  10417. ************************************************************************/
  10418.  
  10419.  
  10420. ΓòÉΓòÉΓòÉ 8.3. break ΓòÉΓòÉΓòÉ
  10421.  
  10422. A break statement lets you end an iterative (do, for, while) or switch 
  10423. statement and exit from it at any point other than the logical end. 
  10424.  
  10425. Syntax of a break Statement 
  10426.  
  10427. In an iterative statement the break statement ends the loop and moves control 
  10428. to the next statement outside the loop. Within nested statements, the break 
  10429. statement ends only the smallest enclosing do, for, switch, or while statement. 
  10430.  
  10431. In a switch body, the break passes control out of the switch body to the next 
  10432. statement outside the switch body. 
  10433.  
  10434. A break statement can only appear in the body of an iterative statement or a 
  10435. switch statement. 
  10436.  
  10437. Examples of break Statements 
  10438.  
  10439. Related Information 
  10440.  
  10441.      do 
  10442.      for 
  10443.      switch 
  10444.      while 
  10445.  
  10446.  
  10447. ΓòÉΓòÉΓòÉ <hidden> Syntax of a break Statement ΓòÉΓòÉΓòÉ
  10448.  
  10449. A break statement has the form: 
  10450.  
  10451. >>ΓöÇΓöÇbreakΓöÇΓöÇ;ΓöÇΓöÇ><
  10452.  
  10453.  
  10454. ΓòÉΓòÉΓòÉ <hidden> Examples of break Statements ΓòÉΓòÉΓòÉ
  10455.  
  10456. /************************************************************************
  10457. *
  10458.  
  10459. The following example shows a break statement in the action part of a for 
  10460. statement. If the ith element of the array string is equal to '\0', the break 
  10461. statement causes the for statement to end. 
  10462.  
  10463. for (i = 0; i < 5; i++)
  10464. {
  10465.    if (string[i] == '\0')
  10466.       break;
  10467.    length++;
  10468. }
  10469.  
  10470. The following is an equivalent for statement, if string does not contain any 
  10471. embedded null characters: 
  10472.  
  10473. for (i = 0; i < 5; i++)
  10474. {
  10475.    if (string[i] != '\0')
  10476.       length++;
  10477. }
  10478.  
  10479. The following example shows a break statement in a nested iterative statement. 
  10480. The outer loop goes through an array of pointers to strings. The inner loop 
  10481. examines each character of the string. When the break statement is processed, 
  10482. the inner loop ends and control returns to the outer loop. 
  10483.  
  10484.                                                                         *
  10485. ************************************************************************/
  10486.  
  10487. /**
  10488.  **  This program counts the characters in the strings that are
  10489.  **  part of an array of pointers to characters.  The count stops
  10490.  **  when one of the digits 0 through 9 is encountered
  10491.  **  and resumes at the beginning of the next string.
  10492.  **/
  10493.  
  10494. #include <stdio.h>
  10495. #define  SIZE  3
  10496.  
  10497. int main(void)
  10498. {
  10499.    static char *strings[SIZE] = { "ab", "c5d", "e5" };
  10500.    int i;
  10501.    int letter_count = 0;
  10502.    char *pointer;
  10503.  
  10504.    for (i = 0; i < SIZE; i++)        /* for each string    */
  10505.                                      /* for each character */
  10506.       for (pointer = strings[i]; *pointer != '\0'; ++pointer)
  10507.       {                                   /* if a number        */
  10508.          if (*pointer >= '0' && *pointer <= '9')
  10509.             break;
  10510.          letter_count++;
  10511.       }
  10512.    printf("letter count = %d\n", letter_count);
  10513.  
  10514.    return(0);
  10515. }
  10516.  
  10517. /************************************************************************
  10518. *
  10519.  
  10520. The program produces the following output: 
  10521.  
  10522. letter count = 4
  10523.  
  10524. The following example is a switch statement that contains several break 
  10525. statements. Each break statement indicates the end of a specific clause and 
  10526. ends the switch statement. 
  10527.  
  10528. /**
  10529.  ** This example shows a switch statement with break statements.
  10530.  **/
  10531.  
  10532. #include <stdio.h>
  10533.  
  10534. enum {morning, afternoon, evening} timeofday = morning;
  10535.  
  10536. int main(void) {
  10537.  
  10538.    switch (timeofday) {
  10539.       case (morning):
  10540.          printf("Good Morning\n");
  10541.          break;
  10542.  
  10543.       case (evening):
  10544.          printf("Good Evening\n");
  10545.          break;
  10546.  
  10547.       default:
  10548.          printf("Good Day, eh\n");
  10549.    }
  10550. }
  10551.  
  10552.                                                                         *
  10553. ************************************************************************/
  10554.  
  10555.  
  10556. ΓòÉΓòÉΓòÉ 8.4. continue ΓòÉΓòÉΓòÉ
  10557.  
  10558. A continue statement lets you end the current iteration of a loop. Program 
  10559. control is passed from the continue statement to the end of the loop body. 
  10560.  
  10561. Syntax of a continue Statement 
  10562.  
  10563. The continue statement ends the processing of the action part of an iterative 
  10564. (do, for, or while) statement and moves control to the condition part of the 
  10565. statement. If the iterative statement is a for statement, control moves to the 
  10566. third expression in the condition part of the statement, then to the second 
  10567. expression (the test) in the condition part of the statement. 
  10568.  
  10569. Within nested statements, the continue statement ends only the current 
  10570. iteration of the do, for, or while statement immediately enclosing it. 
  10571.  
  10572. A continue statement can only appear within the body of an iterative statement. 
  10573.  
  10574. Examples of continue Statements 
  10575.  
  10576. Related Information 
  10577.  
  10578.      do 
  10579.      for 
  10580.      while 
  10581.  
  10582.  
  10583. ΓòÉΓòÉΓòÉ <hidden> Syntax of a continue Statement ΓòÉΓòÉΓòÉ
  10584.  
  10585. A continue statement has the form: 
  10586.  
  10587. >>ΓöÇΓöÇcontinueΓöÇΓöÇ;ΓöÇΓöÇ><
  10588.  
  10589.  
  10590. ΓòÉΓòÉΓòÉ <hidden> Examples of continue Statements ΓòÉΓòÉΓòÉ
  10591.  
  10592. /************************************************************************
  10593. *
  10594.  
  10595. The following example shows a continue statement in a for statement. The 
  10596. continue statement causes processing to skip over those elements of the array 
  10597. rates that have values less than or equal to 1. 
  10598.  
  10599.                                                                         *
  10600. ************************************************************************/
  10601.  
  10602. /**
  10603.  ** This example shows a continue statement in a for statement.
  10604.  **/
  10605.  
  10606. #include <stdio.h>
  10607. #define  SIZE  5
  10608.  
  10609. int main(void)
  10610. {
  10611.    int i;
  10612.    static float rates[SIZE] = { 1.45, 0.05, 1.88, 2.00, 0.75 };
  10613.  
  10614.    printf("Rates over 1.00\n");
  10615.    for (i = 0; i < SIZE; i++)
  10616.    {
  10617.       if (rates[i] <= 1.00)  /*  skip rates <= 1.00  */
  10618.          continue;
  10619.       printf("rate = %.2f\n", rates[i]);
  10620.    }
  10621.  
  10622.    return(0);
  10623. }
  10624.  
  10625. /************************************************************************
  10626. *
  10627.  
  10628. The program produces the following output: 
  10629.  
  10630. Rates over 1.00
  10631. rate = 1.45
  10632. rate = 1.88
  10633. rate = 2.00
  10634.  
  10635. The following example shows a continue statement in a nested loop. When the 
  10636. inner loop encounters a number in the array strings, that iteration of the loop 
  10637. ends. Processing continues with the third expression of the inner loop. The 
  10638. inner loop ends when the '\0' escape sequence is encountered. 
  10639.  
  10640.                                                                         *
  10641. ************************************************************************/
  10642.  
  10643. /**
  10644.  ** This program counts the characters in strings that are part
  10645.  ** of an array of pointers to characters.  The count excludes
  10646.  ** the digits 0 through 9.
  10647.  **/
  10648.  
  10649. #include <stdio.h>
  10650. #define  SIZE  3
  10651.  
  10652. int main(void)
  10653. {
  10654.    static char *strings[SIZE] = { "ab", "c5d", "e5" };
  10655.    int i;
  10656.    int letter_count = 0;
  10657.    char *pointer;
  10658.    for (i = 0; i < SIZE; i++)                 /* for each string         */
  10659.                                               /* for each each character */
  10660.       for (pointer = strings[i]; *pointer != '\0'; ++pointer)
  10661.       {                                  /* if a number             */
  10662.          if (*pointer >= '0' && *pointer <= '9')
  10663.             continue;
  10664.          letter_count++;
  10665.       }
  10666.    printf("letter count = %d\n", letter_count);
  10667.  
  10668.    return(0);
  10669. }
  10670.  
  10671. /************************************************************************
  10672. *
  10673.  
  10674. The program produces the following output: 
  10675.  
  10676. letter count = 5
  10677.  
  10678.                                                                         *
  10679. ************************************************************************/
  10680.  
  10681.  
  10682. ΓòÉΓòÉΓòÉ 8.5. do ΓòÉΓòÉΓòÉ
  10683.  
  10684. A do statement repeatedly runs a statement until the test expression evaluates 
  10685. to 0. Because of the order of processing, the statement is run at least once. 
  10686.  
  10687. Syntax of a do Statement 
  10688.  
  10689. The body of the loop is run before the controlling while clause is evaluated. 
  10690. Further processing of the do statement depends on the value of the while 
  10691. clause. If the while clause does not evaluate to 0, the statement runs again. 
  10692. When the while clause evaluates to 0, the statement ends. The controlling 
  10693. expression must be evaluate to a scalar type. 
  10694.  
  10695. A break, return, or goto statement can cause the processing of a do statement 
  10696. to end, even when the while clause does not evaluate to 0. 
  10697.  
  10698. Example of a do Statement 
  10699.  
  10700. Related Information 
  10701.  
  10702.      break 
  10703.      continue 
  10704.      for 
  10705.      goto 
  10706.      return 
  10707.      while 
  10708.  
  10709.  
  10710. ΓòÉΓòÉΓòÉ <hidden> Syntax of a do Statement ΓòÉΓòÉΓòÉ
  10711.  
  10712. A do statement has the form: 
  10713.  
  10714. >>ΓöÇΓöÇdoΓöÇΓöÇstatementΓöÇΓöÇwhileΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇ;ΓöÇΓöÇ><
  10715.  
  10716.  
  10717. ΓòÉΓòÉΓòÉ <hidden> Example of a do Statement ΓòÉΓòÉΓòÉ
  10718.  
  10719. /************************************************************************
  10720. *
  10721.  
  10722. The following statement prompts the user to enter a 1. If the user enters a 1, 
  10723. the statement ends. If not, it displays another prompt. 
  10724.  
  10725.                                                                         *
  10726. ************************************************************************/
  10727. The example contains error-checking code to verify that the user entered an 
  10728. integer value and to clear the input stream if an error occurs. 
  10729.  
  10730. /**
  10731.  ** This example illustrates the do statement.
  10732.  **/
  10733.  
  10734. #include <iostream.h>
  10735. void main()
  10736. {
  10737.   int reply1;
  10738.   char c;
  10739.   do
  10740.   {
  10741.     cout << "Enter a 1: ";
  10742.     cin >> reply1;
  10743.     if (cin.fail())
  10744.        {
  10745.        cerr << "Not a valid number." << endl;
  10746.           // Clear the error flag.
  10747.        cin.clear(cin.rdstate() & ~ios::failbit);
  10748.           // Purge incorrect input.
  10749.        cin.ignore(cin.rdbuf()->in_avail());
  10750.        }
  10751.   }
  10752.   while (reply1 != 1);
  10753. }
  10754.  
  10755.  
  10756. ΓòÉΓòÉΓòÉ 8.6. Expression ΓòÉΓòÉΓòÉ
  10757.  
  10758. An expression statement contains an expression. The expression can be null. 
  10759. Expressions are described in Expressions and Operators. 
  10760.  
  10761. Syntax of an Expression Statement 
  10762.  
  10763. An expression statement evaluates the given expression. It is used to assign 
  10764. the value of the expression to a variable or to call a function. 
  10765.  
  10766. The following are examples of expressions: 
  10767.  
  10768. printf("Account Number: \n");             /* call to the printf     */
  10769. marks = dollars * exch_rate;              /* assignment to marks    */
  10770. (difference < 0) ? ++losses : ++gain;     /* conditional increment  */
  10771. switches = flags Γûî BIT_MASK;              /* assignment to switches */
  10772.  
  10773.      Resolving Ambiguous Statements in C++ 
  10774.  
  10775.  Related Information 
  10776.  
  10777.      Expressions and Operators 
  10778.  
  10779.  
  10780. ΓòÉΓòÉΓòÉ <hidden> Syntax of an Expression Statement ΓòÉΓòÉΓòÉ
  10781.  
  10782. An expression statement has the form: 
  10783.  
  10784. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇ><
  10785.   ΓööΓöÇexpressionΓöÇΓöÿ
  10786.  
  10787.  
  10788. ΓòÉΓòÉΓòÉ 8.7. for ΓòÉΓòÉΓòÉ
  10789.  
  10790. A for statement lets you do the following: 
  10791.  
  10792.      Evaluate an expression before the first iteration of the statement 
  10793.       (initialization) 
  10794.      Specify an expression to determine whether or not the statement should be 
  10795.       processed (controlling part) 
  10796.      Evaluate an expression after each iteration of the statement 
  10797.  
  10798.  Syntax of a for Statement 
  10799.  
  10800.  A break, return, or goto statement can cause a for statement to end, even when 
  10801.  the second expression does not evaluate to 0. If you omit expression2, you 
  10802.  must use a break, return, or goto statement to end the for statement. 
  10803.  
  10804.  C++ Note:  In C++ programs, you can also use expression1 to declare a variable 
  10805.  as well as initialize it. If you declare a variable in this expression, the 
  10806.  variable has the same scope as the for statement and is not local to the for 
  10807.  statement. 
  10808.  
  10809.  Examples of for Statements 
  10810.  
  10811.  Related Information 
  10812.  
  10813.      break 
  10814.      continue 
  10815.      do 
  10816.      return 
  10817.      goto 
  10818.      while 
  10819.      Expressions and Operators 
  10820.  
  10821.  
  10822. ΓòÉΓòÉΓòÉ <hidden> Syntax of a for Statement ΓòÉΓòÉΓòÉ
  10823.  
  10824. A for statement has the form: 
  10825.  
  10826. >>ΓöÇΓöÇforΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ>
  10827.       ΓööΓöÇexpression1ΓöÇΓöÿ   ΓööΓöÇexpression2ΓöÇΓöÿ   ΓööΓöÇexpression3ΓöÇΓöÿ
  10828. >ΓöÇΓöÇstatementΓöÇΓöÇ><
  10829.  
  10830.  Expression1     Is the initialization expression. It is evaluated only before 
  10831.                  the statement is processed for the first time. You can use 
  10832.                  this expression to initialize a variable. If you do not want 
  10833.                  to evaluate an expression prior to the first iteration of the 
  10834.                  statement, you can omit this expression. 
  10835.  
  10836.  Expression2     Is the controlling part. It is evaluated before each iteration 
  10837.                  of the statement. It must evaluate to a scalar type. 
  10838.  
  10839.                  If it evaluates to 0 (zero), the statement is not processed 
  10840.                  and control moves to the next statement following the for 
  10841.                  statement. If expression2 does not evaluate to 0, the 
  10842.                  statement is processed. If you omit expression2, it is as if 
  10843.                  the expression had been replaced by a nonzero constant, and 
  10844.                  the for statement is not terminated by failure of this 
  10845.                  condition. 
  10846.  
  10847.  Expression3     Is evaluated after each iteration of the statement. You can 
  10848.                  use this expression to increase, decrease, or reinitialize a 
  10849.                  variable. This expression is optional. 
  10850.  
  10851.  
  10852. ΓòÉΓòÉΓòÉ <hidden> Examples of for Statements ΓòÉΓòÉΓòÉ
  10853.  
  10854. The following for statement prints the value of count 20 times. The for 
  10855. statement initially sets the value of count to 1. After each iteration of the 
  10856. statement, count is incremented. 
  10857.  
  10858. for (count = 1; count <= 20; count++)
  10859.    printf("count = %d\n", count);
  10860.  
  10861. The following sequence of statements accomplishes the same task. Note the use 
  10862. of the while statement instead of the for statement. 
  10863.  
  10864. count = 1;
  10865. while (count <= 20)
  10866. {
  10867.    printf("count = %d\n", count);
  10868.    count++;
  10869. }
  10870.  
  10871. The following for statement does not contain an initialization expression: 
  10872.  
  10873. for (; index > 10; --index)
  10874. {
  10875.    list[index] = var1 + var2;
  10876.    printf("list[%d] = %d\n", index, list[index]);
  10877. }
  10878.  
  10879. The following for statement will continue running until scanf receives the 
  10880. letter e: 
  10881.  
  10882. for (;;)
  10883. {
  10884.    scanf("%c", &letter);
  10885.    if (letter == '\n')
  10886.       continue;
  10887.    if (letter == 'e')
  10888.       break;
  10889.    printf("You entered the letter %c\n", letter);
  10890. }
  10891.  
  10892. The following for statement contains multiple initializations and increments. 
  10893. The comma operator makes this construction possible. The first comma in the for 
  10894. expression is a punctuator for a declaration. It declares and initializes two 
  10895. integers, i and j. The second comma, a comma operator, allows both i and j to 
  10896. be incremented at each step through the loop. 
  10897.  
  10898. for (int i = 0, j = 50; i < 10; ++i, j += 50)
  10899. {
  10900.    cout << "i = " << i << "and j = " << j << endl;
  10901. }
  10902.  
  10903. The following example shows a nested for statement. It prints the values of an 
  10904. array having the dimensions [5][3]. 
  10905.  
  10906. for (row = 0; row < 5; row++)
  10907.    for (column = 0; column < 3; column++)
  10908.       printf("%d\n", table[row][column]);
  10909.  
  10910. The outer statement is processed as long as the value of row is less than 5. 
  10911. Each time the outer for statement is executed, the inner for statement sets the 
  10912. initial value of column to zero and the statement of the inner for statement is 
  10913. executed 3 times. The inner statement is executed as long as the value of 
  10914. column is less than 3. 
  10915.  
  10916.  
  10917. ΓòÉΓòÉΓòÉ 8.8. goto ΓòÉΓòÉΓòÉ
  10918.  
  10919. A goto statement causes your program to unconditionally transfer control to the 
  10920. statement associated with the label specified on the goto statement. 
  10921.  
  10922. Syntax of a goto Statement 
  10923.  
  10924. Because the goto statement can interfere with the normal sequence of 
  10925. processing, it makes a program more difficult to read and maintain. Often, a 
  10926. break statement, a continue statement, or a function call can eliminate the 
  10927. need for a goto statement. 
  10928.  
  10929. If you use a goto statement to transfer control to a statement inside of a loop 
  10930. or block, initializations of automatic storage for the loop do not take place 
  10931. and the result is undefined. The label must appear in the same function as the 
  10932. goto. 
  10933.  
  10934. If an active block is exited using a goto statement, any local variables are 
  10935. destroyed when control is transferred from that block. 
  10936.  
  10937. Example of a goto Statement 
  10938.  
  10939. Related Information 
  10940.  
  10941.      Labels 
  10942.      break 
  10943.      continue 
  10944.      Functions 
  10945.  
  10946.  
  10947. ΓòÉΓòÉΓòÉ <hidden> Syntax of a goto Statement ΓòÉΓòÉΓòÉ
  10948.  
  10949. A goto statement has the form: 
  10950.  
  10951. >>ΓöÇΓöÇgotoΓöÇΓöÇlabel_identifierΓöÇΓöÇ;ΓöÇΓöÇ><
  10952.  
  10953.  
  10954. ΓòÉΓòÉΓòÉ <hidden> Example of a goto Statement ΓòÉΓòÉΓòÉ
  10955.  
  10956. The following example shows a goto statement that is used to jump out of a 
  10957. nested loop. This function could be written without using a goto statement. 
  10958.  
  10959. /**
  10960.  ** This example shows a goto statement that is used to
  10961.  ** jump out of a nested loop.
  10962.  **/
  10963.  
  10964. #include <stdio.h>
  10965. void display(int matrix[3][3]);
  10966.  
  10967. int main(void)
  10968. {
  10969.    int matrix[3][3]={1,2,3,4,5,2,8,9,10};
  10970.    display(matrix);
  10971.    return(0);
  10972. }
  10973.  
  10974. void display(int matrix[3][3])
  10975. {
  10976.    int i, j;
  10977.  
  10978.    for (i = 0; i < 3; i++)
  10979.       for (j = 0; j < 3; j++)
  10980.       {
  10981.          if ( (matrix[i][j] < 1) ΓûîΓûî (matrix[i][j] > 6) )
  10982.             goto out_of_bounds;
  10983.          printf("matrix[%d][%d] = %d\n", i, j, matrix[i][j]);
  10984.       }
  10985.    return;
  10986.    out_of_bounds: printf("number must be 1 through 6\n");
  10987. }
  10988.  
  10989.  
  10990. ΓòÉΓòÉΓòÉ 8.9. if ΓòÉΓòÉΓòÉ
  10991.  
  10992. An if statement lets you conditionally process a statement when the specified 
  10993. test expression evaluates to a nonzero value. The expression must evaluate to a 
  10994. scalar type. You can optionally specify an else clause on the if statement. If 
  10995. the test expression evaluates to 0 and an else clause exists, the statement 
  10996. associated with the else clause runs. If the test expression evaluates to a 
  10997. nonzero value, the statement following the expression runs and the else clause 
  10998. is ignored. 
  10999.  
  11000. Syntax of an if Statement 
  11001.  
  11002. When if statements are nested and else clauses are present, a given else is 
  11003. associated with the closest preceding if statement within the same block. 
  11004.  
  11005. Examples of if Statements 
  11006.  
  11007. Related Information 
  11008.  
  11009.      Conditional Compilation Directives 
  11010.      switch 
  11011.  
  11012.  
  11013. ΓòÉΓòÉΓòÉ <hidden> Syntax of an if Statement ΓòÉΓòÉΓòÉ
  11014.  
  11015. An if statement has the form: 
  11016.  
  11017. >>ΓöÇΓöÇifΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇstatementΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  11018.                    ΓööΓöÇelseΓöÇΓöÇstatementΓöÇΓöÿ
  11019.  
  11020.  
  11021. ΓòÉΓòÉΓòÉ <hidden> Examples of if Statements ΓòÉΓòÉΓòÉ
  11022.  
  11023. The following example causes grade to receive the value A if the value of score 
  11024. is greater than or equal to 90. 
  11025.  
  11026. if (score >= 90)
  11027.    grade = 'A';
  11028.  
  11029. The following example displays Number is positive if the value of number is 
  11030. greater than or equal to 0. If the value of number is less than 0, it displays 
  11031. Number is negative. 
  11032.  
  11033. if (number >= 0)
  11034.    printf("Number is positive\n");
  11035. else
  11036.    printf("Number is negative\n");
  11037.  
  11038. The following example shows a nested if statement: 
  11039.  
  11040. if (paygrade == 7)
  11041.    if (level >= 0 && level <= 8)
  11042.       salary *= 1.05;
  11043.    else
  11044.       salary *= 1.04;
  11045. else
  11046.    salary *= 1.06;
  11047. cout << "salary is " << salary << endl;
  11048.  
  11049. The following example shows a nested if statement that does not have an else 
  11050. clause. Because an else clause always associates with the closest if statement, 
  11051. braces might be needed to force a particular else clause to associate with the 
  11052. correct if statement. In this example, omitting the braces would cause the else 
  11053. clause to associate with the nested if statement. 
  11054.  
  11055. if (kegs > 0) {
  11056.    if (furlongs > kegs)
  11057.       fpk = furlongs/kegs;
  11058. }
  11059. else
  11060.    fpk = 0;
  11061.  
  11062. The following example shows an if statement nested within an else clause. This 
  11063. example tests multiple conditions. The tests are made in order of their 
  11064. appearance. If one test evaluates to a nonzero value, a statement runs and the 
  11065. entire if statement ends. 
  11066.  
  11067. if (value > 0)
  11068.    ++increase;
  11069. else if (value == 0)
  11070.    ++break_even;
  11071. else
  11072.    ++decrease;
  11073.  
  11074.  
  11075. ΓòÉΓòÉΓòÉ 8.10. Null Statement ΓòÉΓòÉΓòÉ
  11076.  
  11077. The null statement performs no operation. 
  11078.  
  11079. Syntax of a Null Statement 
  11080.  
  11081. A null statement can hold the label of a labeled statement or complete the 
  11082. syntax of an iterative statement. 
  11083.  
  11084. The following example initializes the elements of the array price. Because the 
  11085. initializations occur within the for expressions, a statement is only needed to 
  11086. finish the for syntax; no operations are required. 
  11087.  
  11088. for (i = 0; i < 3; price[i++] = 0)
  11089.    ;
  11090.  
  11091. A null statement can be used when a label is needed before the end of a block 
  11092. statement. For example: 
  11093.  
  11094. void func(void) {
  11095.   if (error_detected)
  11096.     goto depart;
  11097.   /* further processing */
  11098.   depart: ;  /* null statement required */
  11099. }
  11100.  
  11101. Related Information 
  11102.  
  11103.      Null Directive (#) 
  11104.      Labels 
  11105.  
  11106.  
  11107. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Null Statement ΓòÉΓòÉΓòÉ
  11108.  
  11109. A null statement has the form: 
  11110.  
  11111. >>ΓöÇΓöÇ;ΓöÇΓöÇ><
  11112.  
  11113.  
  11114. ΓòÉΓòÉΓòÉ 8.11. return ΓòÉΓòÉΓòÉ
  11115.  
  11116. A return statement ends the processing of the current function and returns 
  11117. control to the caller of the function. 
  11118.  
  11119. Syntax of a return Statement 
  11120.  
  11121. A return statement in a function is optional. The compiler issues a warning if 
  11122. a return statement is not found in a function declared with a return type. If 
  11123. the end of a function is reached without encountering a return statement, 
  11124. control is passed to the caller as if a return statement without an expression 
  11125. were encountered. A function can contain multiple return statements. 
  11126.  
  11127. If an expression is present on a return statement, the value of the expression 
  11128. is returned to the caller. If the data type of the expression is different from 
  11129. the function return type, conversion of the return value takes place as if the 
  11130. value of the expression were used to initialize an object with the same 
  11131. function return type. 
  11132.  
  11133. If an expression is not present on a return statement, the value of the return 
  11134. statement is undefined. If an expression is not given on a return statement in 
  11135. a function declared with a nonvoid return type, an error message is issued, and 
  11136. the result of calling the function is unpredictable. For example: 
  11137.  
  11138. int func1()
  11139. {
  11140.  return;
  11141. }
  11142. int func2()
  11143. {
  11144.  return (4321);
  11145. }
  11146.  
  11147. void main() {
  11148. int a=func1(); // result is unpredictable!
  11149. int b=func2();
  11150. }
  11151.  
  11152. You cannot use a return statement with an expression when the function is 
  11153. declared as returning type void. 
  11154.  
  11155. You can use the /Wret compiler option to generate diagnostic messages about the 
  11156. use of return statements in your functions. 
  11157.  
  11158. C++ Note:  If a function returns a class object with constructors, a temporary 
  11159. class object might be constructed. The temporary object is not in the scope of 
  11160. the function returning the temporary object but is local to the caller of the 
  11161. function. 
  11162.  
  11163. When a function returns, all temporary local variables are destroyed. If local 
  11164. class objects with destructors exist, destructors are called. For more details, 
  11165. see Temporary Objects. 
  11166.  
  11167. Examples of return Statements 
  11168.  
  11169. Related Information 
  11170.  
  11171.      Functions 
  11172.      /W option 
  11173.      Temporary Objects 
  11174.      Expression 
  11175.  
  11176.  
  11177. ΓòÉΓòÉΓòÉ <hidden> Syntax of a return Statement ΓòÉΓòÉΓòÉ
  11178.  
  11179. A return statement has the form: 
  11180.  
  11181. >>ΓöÇΓöÇreturnΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ;ΓöÇΓöÇ><
  11182.       ΓööΓöÇexpressionΓöÇΓöÿ
  11183.  
  11184.  
  11185. ΓòÉΓòÉΓòÉ <hidden> Examples of return Statements ΓòÉΓòÉΓòÉ
  11186.  
  11187. return;            /* Returns no value            */
  11188. return result;     /* Returns the value of result */
  11189. return 1;          /* Returns the value 1         */
  11190. return (x * x);    /* Returns the value of x * x  */
  11191.  
  11192. The following function searches through an array of integers to determine if a 
  11193. match exists for the variable number. If a match exists, the function match 
  11194. returns the value of i. If a match does not exist, the function match returns 
  11195. the value -1 (negative one). 
  11196.  
  11197. int match(int number, int array[ ], int n)
  11198. {
  11199.    int i;
  11200.  
  11201.    for (i = 0; i < n; i++)
  11202.       if (number == array[i])
  11203.          return (i);
  11204.    return(-1);
  11205. }
  11206.  
  11207.  
  11208. ΓòÉΓòÉΓòÉ 8.12. switch ΓòÉΓòÉΓòÉ
  11209.  
  11210. A switch statement lets you transfer control to different statements within the 
  11211. switch body depending on the value of the switch expression. The switch 
  11212. expression must evaluate to an integral value. The body of the switch statement 
  11213. contains case clauses that consist of 
  11214.  
  11215.      A case label 
  11216.      An optional default label 
  11217.      A case expression 
  11218.      A list of statements. 
  11219.  
  11220.  If the value of the switch expression equals the value of one of the case 
  11221.  expressions, the statements following that case expression are processed. If 
  11222.  not, the default label statements, if any, are processed. 
  11223.  
  11224.  A switch statement has the form: 
  11225.  
  11226.   >>ΓöÇΓöÇswitchΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇswitch_bodyΓöÇΓöÇ><
  11227.  
  11228.  Syntax of a switch Body 
  11229.  
  11230.  A case clause contains a case label followed by any number of statements. 
  11231.  
  11232.  A case label contains the word case followed by an integral constant 
  11233.  expression and a colon. Anywhere you can put one case label, you can put 
  11234.  multiple case labels. 
  11235.  
  11236.  A default clause contains a default label followed by one or more statements. 
  11237.  You can put a case label on either side of the default label. A switch 
  11238.  statement can have only one default label. 
  11239.  
  11240.  The switch statement passes control to the statement following one of the 
  11241.  labels or to the statement following the switch body. The value of the 
  11242.  expression that precedes the switch body determines which statement receives 
  11243.  control. This expression is called the switch expression. 
  11244.  
  11245.  The value of the switch expression is compared with the value of the 
  11246.  expression in each case label. If a matching value is found, control is passed 
  11247.  to the statement following the case label that contains the matching value. If 
  11248.  there is no matching value but there is a default label in the switch body, 
  11249.  control passes to the default labelled statement. If no matching value is 
  11250.  found, and there is no default label anywhere in the switch body, no part of 
  11251.  the switch body is processed. 
  11252.  
  11253.  When control passes to a statement in the switch body, control only leaves the 
  11254.  switch body when a break statement is encountered or the last statement in the 
  11255.  switch body is processed. 
  11256.  
  11257.  If necessary, an integral promotion is performed on the controlling 
  11258.  expression, and all expressions in the case statements are converted to the 
  11259.  same type as the controlling expression. 
  11260.  
  11261.  Restrictions 
  11262.  The switch expression and the case expressions must have an integral type. The 
  11263.  value of each case expression must represent a different value and must be a 
  11264.  constant expression. 
  11265.  
  11266.  Only one default label can occur in each switch statement. You cannot have 
  11267.  duplicate case labels in a switch statement. 
  11268.  
  11269.  You can put data definitions at the beginning of the switch body, but the 
  11270.  compiler does not initialize auto and register variables at the beginning of a 
  11271.  switch body. 
  11272.  
  11273.  C++ Note:  You can have declarations in the body of the switch statement. In 
  11274.  C++, you cannot transfer control over a declaration containing an initializer 
  11275.  unless the declaration is located in an inner block that is completely 
  11276.  bypassed by the transfer of control. All declarations within the body of a 
  11277.  switch statement that contain initializers must be contained in an inner 
  11278.  block. 
  11279.  
  11280.  Examples of switch Statements 
  11281.  
  11282.  Related Information 
  11283.  
  11284.      break 
  11285.      if 
  11286.      Labels 
  11287.      Expression 
  11288.      Type Specifiers 
  11289.      Storage Class Specifiers 
  11290.  
  11291.  
  11292. ΓòÉΓòÉΓòÉ <hidden> Syntax of a switch Body ΓòÉΓòÉΓòÉ
  11293.  
  11294. The switch body is enclosed in braces and can contain definitions, 
  11295. declarations, case clauses, and a default clause. Each case clause and default 
  11296. clause can contain statements. 
  11297.  
  11298.     ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ  ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11299.                      Γöé          Γöé
  11300. >>ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>
  11301.     Γö£ΓöÇtype_definitionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ   ΓööΓöÇcase_clauseΓöÇΓöÿ
  11302.     Γö£ΓöÇfile_scope_data_declarationΓöÇΓöÇΓöñ
  11303.     ΓööΓöÇblock_scope_data_declarationΓöÇΓöÿ
  11304.             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11305.                     Γöé
  11306. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  11307.   ΓööΓöÇdefault_clauseΓöÇΓöÿ  ΓööΓöÇcase_clauseΓöÇΓöÿ
  11308.  
  11309. A case clause has the form: 
  11310.  
  11311.         ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11312.               Γöé
  11313. >>ΓöÇΓöÇcase_labelΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ><
  11314.  
  11315. A case label has the form: 
  11316.  
  11317.   ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11318.                       Γöé
  11319. >>ΓöÇΓöÇΓöÇΓöÇcaseΓöÇΓöÇintegral_constant_expressionΓöÇΓöÇ:ΓöÇΓö┤ΓöÇΓöÇ><
  11320.  
  11321. A default clause has the form: 
  11322.  
  11323.                         ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11324.                               Γöé
  11325. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇdefaultΓöÇΓöÇ:ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ><
  11326.   ΓööΓöÇcase_labelΓöÇΓöÿ        ΓööΓöÇcase_labelΓöÇΓöÿ
  11327.  
  11328.  
  11329. ΓòÉΓòÉΓòÉ <hidden> Examples of switch Statements ΓòÉΓòÉΓòÉ
  11330.  
  11331. The following switch statement contains several case clauses and one default 
  11332. clause. Each clause contains a function call and a break statement. The break 
  11333. statements prevent control from passing down through each statement in the 
  11334. switch body. 
  11335.  
  11336. If the switch expression evaluated to '/', the switch statement would call the 
  11337. function divide. Control would then pass to the statement following the switch 
  11338. body. 
  11339.  
  11340. char key;
  11341.  
  11342. cout << "Enter an arithmetic operator\n");
  11343. cin >> key;
  11344.  
  11345. switch (key)
  11346. {
  11347.    case '+':
  11348.       add();
  11349.       break;
  11350.  
  11351.    case '-':
  11352.       subtract();
  11353.       break;
  11354.  
  11355.    case '*':
  11356.       multiply();
  11357.       break;
  11358.  
  11359.    case '/':
  11360.       divide();
  11361.       break;
  11362.  
  11363.    default:
  11364.       cout << "The key you pressed is not valid\n";
  11365.       break;
  11366. }
  11367.  
  11368. If the switch expression matches a case expression, the statements following 
  11369. the case expression are processed until a break statement is encountered or the 
  11370. end of the switch body is reached. In the following example, break statements 
  11371. are not present. If the value of text[i] is equal to 'A', all three counters 
  11372. are incremented. If the value of text[i] is equal to 'a', lettera and total are 
  11373. increased. Only total is increased if text[i] is not equal to 'A' or 'a'. 
  11374.  
  11375. char text[100];
  11376. int capa, lettera, total;
  11377.  
  11378. for (i=0; i<sizeof(text); i++) {
  11379.  
  11380.     switch (text[i])
  11381.     {
  11382.        case 'A':
  11383.          capa++;
  11384.        case 'a':
  11385.          lettera++;
  11386.        default:
  11387.          total++;
  11388.     }
  11389. }
  11390.  
  11391. The following switch statement performs the same statements for more than one 
  11392. case label: 
  11393.  
  11394. /**
  11395.  ** This example contains a switch statement that performs
  11396.  ** the same statement for more than one case label.
  11397.  **/
  11398.  
  11399. #include <stdio.h>
  11400.  
  11401. int main(void)
  11402. {
  11403.   int month;
  11404.  
  11405.   /* Read in a month value */
  11406.   printf("Enter month: ");
  11407.   scanf("%d", &month);
  11408.  
  11409.   /* Tell what season it falls into */
  11410.   switch (month)
  11411.   {
  11412.      case 12:
  11413.      case 1:
  11414.      case 2:
  11415.         printf("month %d is a winter month\n", month);
  11416.         break;
  11417.  
  11418.      case 3:
  11419.      case 4:
  11420.      case 5:
  11421.         printf("month %d is a spring month\n", month);
  11422.         break;
  11423.  
  11424.      case 6:
  11425.      case 7:
  11426.      case 8:
  11427.         printf("month %d is a summer month\n", month);
  11428.         break;
  11429.  
  11430.      case 9:
  11431.      case 10:
  11432.      case 11:
  11433.         printf("month %d is a fall month\n", month);
  11434.         break;
  11435.  
  11436.      case 66:
  11437.      case 99:
  11438.      default:
  11439.         printf("month %d is not a valid month\n", month);
  11440.   }
  11441.  
  11442.   return(0);
  11443. }
  11444.  
  11445. If the expression month has the value 3, control passes to the statement: 
  11446.  
  11447. printf("month %d is a spring month\n", month);
  11448.  
  11449. The break statement passes control to the statement following the switch body. 
  11450.  
  11451.  
  11452. ΓòÉΓòÉΓòÉ 8.13. while ΓòÉΓòÉΓòÉ
  11453.  
  11454. A while statement repeatedly runs the body of a loop until the controlling 
  11455. expression evaluates to 0. 
  11456.  
  11457. Syntax of a while Statement 
  11458.  
  11459. The expression is evaluated to determine whether or not to process the body of 
  11460. the loop. The expression must be convertible to a scalar type. If the 
  11461. expression evaluates to 0, the body of the loop never runs. If the expression 
  11462. does not evaluate to 0, the loop body is processed. After the body has run, 
  11463. control passes back to the expression. Further processing depends on the value 
  11464. of the condition. 
  11465.  
  11466. A break, return, or goto statement can cause a while statement to end, even 
  11467. when the condition does not evaluate to 0. 
  11468.  
  11469. Example of a while Statement 
  11470.  
  11471. Related Information 
  11472.  
  11473.      break 
  11474.      continue 
  11475.      do 
  11476.      for 
  11477.      goto 
  11478.      return 
  11479.  
  11480.  
  11481. ΓòÉΓòÉΓòÉ <hidden> Syntax of a while Statement ΓòÉΓòÉΓòÉ
  11482.  
  11483. A while statement has the form: 
  11484.  
  11485. >>ΓöÇΓöÇwhileΓöÇΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇstatementΓöÇΓöÇ><
  11486.  
  11487.  
  11488. ΓòÉΓòÉΓòÉ <hidden> Example of a while Statement ΓòÉΓòÉΓòÉ
  11489.  
  11490. /************************************************************************
  11491. *
  11492.  
  11493. In the following program, item[index] triples each time the value of the 
  11494. expression ++index is less than MAX_INDEX. When ++index evaluates to MAX_INDEX, 
  11495. the while statement ends. 
  11496.  
  11497.                                                                         *
  11498. ************************************************************************/
  11499.  
  11500. /**
  11501.  ** This example illustrates the while statement.
  11502.  **/
  11503.  
  11504. #define MAX_INDEX  (sizeof(item) / sizeof(item[0]))
  11505. #include <stdio.h>
  11506.  
  11507. int main(void)
  11508. {
  11509.    static int item[ ] = { 12, 55, 62, 85, 102 };
  11510.    int index = 0;
  11511.  
  11512.    while (index < MAX_INDEX)
  11513.    {
  11514.       item[index] *= 3;
  11515.       printf("item[%d] = %d\n", index, item[index]);
  11516.       ++index;
  11517.    }
  11518.  
  11519.    return(0);
  11520. }
  11521.  
  11522.  
  11523. ΓòÉΓòÉΓòÉ 9. Preprocessor Directives ΓòÉΓòÉΓòÉ
  11524.  
  11525. This section describes the VisualAge C++ preprocessor directives. Preprocessing 
  11526. is a step that takes place before compilation that lets you: 
  11527.  
  11528.      Replace tokens in the current file with specified replacement tokens. 
  11529.      Imbed files within the current file 
  11530.      Conditionally compile sections of the current file 
  11531.      Generate diagnostic messages 
  11532.      Change the line number of the next line of source and change the file 
  11533.       name of the current file. 
  11534.  
  11535.  A token is a series of characters delimited by white space. The only white 
  11536.  space allowed on a preprocessor directive is the space, horizontal tab, and 
  11537.  comments. 
  11538.  
  11539.  The preprocessed source program file must be a valid C or C++ program. 
  11540.  
  11541.  The preprocessor is controlled by the following directives: 
  11542.  
  11543.      Macro Definition and Expansion (#define) 
  11544.      Scope of Macro Names (#undef) 
  11545.      Preprocessor Error Directive (#error) 
  11546.      File Inclusion (#include) 
  11547.      #if, #elif 
  11548.      #ifdef 
  11549.      #ifndef 
  11550.      #else 
  11551.      #endif 
  11552.      Line Control (#line) 
  11553.      Pragma Directives (#pragma) 
  11554.  
  11555.  This section also describes: 
  11556.  
  11557.      The # operator 
  11558.      Macro concatenation with the ## operator 
  11559.      The null directive (#) 
  11560.      Predefined macros. 
  11561.  
  11562.  Related Information 
  11563.  
  11564.      The format of a preprocessor directive 
  11565.      /D option 
  11566.  
  11567.  
  11568. ΓòÉΓòÉΓòÉ 9.1. Preprocessor Directive Format ΓòÉΓòÉΓòÉ
  11569.  
  11570. Preprocessor directives begin with the # token followed by a preprocessor 
  11571. keyword. The # token must appear as the first character that is not white space 
  11572. on a line. The # is not part of the directive name and can be separated from 
  11573. the name with white spaces. 
  11574.  
  11575. A preprocessor directive ends at the new-line character unless the last 
  11576. character of the line is the \ (backslash) character. If the \ character 
  11577. appears as the last character in the preprocessor line, the preprocessor 
  11578. interprets the \ and the new-line character as a continuation marker. The 
  11579. preprocessor deletes the \ (and the following new-line character) and splices 
  11580. the physical source lines into continuous logical lines. 
  11581.  
  11582. Except for some #pragma directives, preprocessor directives can appear anywhere 
  11583. in a program. 
  11584.  
  11585. Related Information 
  11586.  
  11587.      Preprocessor Directives 
  11588.  
  11589.  
  11590. ΓòÉΓòÉΓòÉ 9.2. Phases of Preprocessing ΓòÉΓòÉΓòÉ
  11591.  
  11592. Preprocessing appears as if it occurs in several phases. 
  11593.  
  11594.    1. New-line characters are introduced as needed to replace system-dependent 
  11595.       end-of-line indicators, and any other system-dependent character-set 
  11596.       translations are done. Equivalent single characters replace trigraph 
  11597.       sequences. 
  11598.  
  11599.    2. Each \ (backslash) followed by a new-line character pair is deleted. The 
  11600.       next source line is appended to the line that contained the sequence. 
  11601.  
  11602.    3. The source text is decomposed into preprocessing tokens and sequences of 
  11603.       white space. A single white space replaces each comment. A source file 
  11604.       cannot end with a partial token or comment. 
  11605.  
  11606.    4. Preprocessing directives are executed, and macros are expanded. 
  11607.  
  11608.    5. Escape sequences in character constants and string literals are replaced 
  11609.       by their equivalent values. 
  11610.  
  11611.    6. Adjacent string literals are concatenated. 
  11612.  
  11613.  The rest of the compilation process operates on the preprocessor output, which 
  11614.  is syntactically and semantically analyzed and translated, and then linked as 
  11615.  necessary with other programs and libraries. 
  11616.  
  11617.  
  11618. ΓòÉΓòÉΓòÉ 9.3. Macro Definition and Expansion (#define) ΓòÉΓòÉΓòÉ
  11619.  
  11620. A preprocessor define directive directs the preprocessor to replace all 
  11621. subsequent occurrences of a macro with specified replacement tokens. 
  11622.  
  11623. A preprocessor #define directive has the form: 
  11624.  
  11625.                             ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11626.                                     Γöé
  11627. >>ΓöÇΓöÇ#ΓöÇΓöÇdefineΓöÇΓöÇidentifierΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ><
  11628.               Γöé   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé  Γö£ΓöÇidentifierΓöÇΓöñ
  11629.               Γöé           Γöé   Γöé  Γöé       Γöé
  11630.               ΓööΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÿ  ΓööΓöÇcharacterΓöÇΓöÇΓöÿ
  11631.                  ΓööΓöÇidentifierΓöÇΓöÿ
  11632.  
  11633. The #define directive can contain an object-like definition or a function-like 
  11634. definition 
  11635.  
  11636. Arguments of the # and ## operators are converted before replacement of 
  11637. parameters in a function-like macro. 
  11638.  
  11639. The number of arguments in a macro invocation must be the same as the number of 
  11640. parameters in the corresponding macro definition. 
  11641.  
  11642. Commas in the macro invocation argument list do not act as argument separators 
  11643. when they are: 
  11644.  
  11645.      in character constants 
  11646.      in string literals 
  11647.      surrounded by parentheses. 
  11648.  
  11649.  The scope of a macro definition begins at the definition and does not end 
  11650.  until a corresponding #undef directive is encountered. If there is no 
  11651.  corresponding #undef directive, the scope of the macro definition lasts until 
  11652.  the end of the compilation is reached. 
  11653.  
  11654.  A recursive macro is not fully expanded. For example, the definition 
  11655.  
  11656.      #define x(a,b) x(a+1,b+1) + 4
  11657.  
  11658.  would expand   x(20,10)   to   x(20+1,10+1) + 4   rather than trying to expand 
  11659.  the macro x over and over within itself. 
  11660.  
  11661.  A definition is not required to specify replacement tokens. The following 
  11662.  definition removes all instances of the token debug from subsequent lines in 
  11663.  the current file: 
  11664.  
  11665.   #define debug
  11666.  
  11667.  You can change the definition of a defined identifier or macro with a second 
  11668.  preprocessor #define directive only if the second preprocessor #define 
  11669.  directive is preceded by a preprocessor #undef directive, described in Scope 
  11670.  of Macro Names (#undef). The #undef directive nullifies the first definition 
  11671.  so that the same identifier can be used in a redefinition. 
  11672.  
  11673.  You can also use the /D compiler option to define macros on the command line. 
  11674.  Macros defined on the command line override macros defined in the source code. 
  11675.  The /D option is described in the IBM VisualAge C++ for OS/2 User's Guide and 
  11676.  Reference. 
  11677.  
  11678.  Within the text of the program, the preprocessor does not scan character 
  11679.  constants or string constants for macro invocations. 
  11680.  
  11681.  Examples of #define Directives 
  11682.  
  11683.  Related Information 
  11684.  
  11685.      Object-Like Macros 
  11686.      Function-Like Macros 
  11687.      Scope of Macro Names (#undef) 
  11688.      /D option 
  11689.      # Operator 
  11690.      Macro Concatenation with the ## Operator 
  11691.  
  11692.  
  11693. ΓòÉΓòÉΓòÉ 9.3.1. Object-Like Macros ΓòÉΓòÉΓòÉ
  11694.  
  11695. An object-like macro definition replaces a single identifier with the specified 
  11696. replacement tokens. The following object-like definition causes the 
  11697. preprocessor to replace all subsequent instances of the identifier COUNT with 
  11698. the constant 1000: 
  11699.  
  11700. #define COUNT 1000
  11701.  
  11702. If the statement 
  11703.  
  11704. int arry[COUNT];
  11705.  
  11706. appears after this definition and in the same file as the definition, the 
  11707. preprocessor would change the statement to 
  11708.  
  11709. int arry[1000];
  11710.  
  11711. in the output of the preprocessor. 
  11712.  
  11713. Other definitions can make reference to the identifier COUNT: 
  11714.  
  11715. #define MAX_COUNT COUNT + 100
  11716.  
  11717. The preprocessor replaces each subsequent occurrence of MAX_COUNT with 
  11718. COUNT + 100, which the preprocessor then replaces with 1000 + 100. 
  11719.  
  11720. If a number that is partially built by a macro expansion is produced, the 
  11721. preprocessor does not consider the result to be a single value. For example, 
  11722. the following will not result in the value 10.2 but in a syntax error. 
  11723.  
  11724. #define a 10
  11725. a.2
  11726.  
  11727. Using the following also results in a syntax error: 
  11728.  
  11729. #define a 10
  11730. #define b a.11
  11731.  
  11732. Identifiers that are partially built from a macro expansion may not be 
  11733. produced. Therefore, the following example contains two identifiers and results 
  11734. in a syntax error: 
  11735.  
  11736. #define d efg
  11737. abcd
  11738.  
  11739.  
  11740. ΓòÉΓòÉΓòÉ 9.3.2. Function-Like Macros ΓòÉΓòÉΓòÉ
  11741.  
  11742.  Function-like macro definition: 
  11743.       An identifier followed by a parenthesized parameter list in parenthesis 
  11744.       and the replacement tokens. The parameters are imbedded in the 
  11745.       replacement code. White space cannot separate the identifier (which is 
  11746.       the name of the macro) and the left parenthesis of the parameter list. A 
  11747.       comma must separate each parameter. For portability, you should not have 
  11748.       more than 31 parameters for a macro. 
  11749.  
  11750.  Function-like macro invocation: 
  11751.       An identifier followed by a list of arguments in parentheses. A comma 
  11752.       must separate each argument. Once the preprocessor identifies a 
  11753.       function-like macro invocation, argument substitution takes place. A 
  11754.       parameter in the replacement code is replaced by the corresponding 
  11755.       argument. Any macro invocations contained in the argument itself are 
  11756.       completely replaced before the argument replaces its corresponding 
  11757.       parameter in the replacement code. 
  11758.  
  11759.  The following line defines the macro SUM as having two parameters a and b and 
  11760.  the replacement tokens (a + b): 
  11761.  
  11762.   #define SUM(a,b) (a + b)
  11763.  
  11764.  This definition would cause the preprocessor to change the following 
  11765.  statements (if the statements appear after the previous definition): 
  11766.  
  11767.   c = SUM(x,y);
  11768.   c = d * SUM(x,y);
  11769.  
  11770.  In the output of the preprocessor, these statements would appear as: 
  11771.  
  11772.   c = (x + y);
  11773.   c = d * (x + y);
  11774.  
  11775.  Use parentheses to ensure correct evaluation of replacement text. For example, 
  11776.  the definition: 
  11777.  
  11778.   #define SQR(c)  ((c) * (c))
  11779.  
  11780.  requires parentheses around each parameter c in the definition in order to 
  11781.  correctly evaluate an expression like: 
  11782.  
  11783.   y = SQR(a + b);
  11784.  
  11785.  The preprocessor expands this statement to: 
  11786.  
  11787.   y = ((a + b) * (a + b));
  11788.  
  11789.  Without parentheses in the definition, the correct order of evaluation is not 
  11790.  preserved, and the preprocessor output is: 
  11791.  
  11792.   y = (a + b * a + b);
  11793.  
  11794.  See Operator Precedence and Associativity, and Parenthesized Expressions ( ) 
  11795.  for more information about using parentheses. 
  11796.  
  11797.  
  11798. ΓòÉΓòÉΓòÉ <hidden> Examples of #define Directives ΓòÉΓòÉΓòÉ
  11799.  
  11800. /************************************************************************
  11801. *
  11802.  
  11803. The following program contains two macro definitions and a macro invocation 
  11804. that refers to both of the defined macros: 
  11805.  
  11806.                                                                         *
  11807. ************************************************************************/
  11808.  
  11809. /**
  11810.  ** This example illustrates #define directives.
  11811.  **/
  11812.  
  11813. #include <stdio.h>
  11814.  
  11815. #define SQR(s)  ((s) * (s))
  11816. #define PRNT(a,b) \
  11817.   printf("value 1 = %d\n", a); \
  11818.   printf("value 2 = %d\n", b) ;
  11819.  
  11820. int main(void)
  11821. {
  11822.   int x = 2;
  11823.   int y = 3;
  11824.  
  11825.      PRNT(SQR(x),y);
  11826.  
  11827.   return(0);
  11828. }
  11829.  
  11830. /************************************************************************
  11831. *
  11832.  
  11833. After being interpreted by the preprocessor, this program is replaced by code 
  11834. equivalent to the following: 
  11835.  
  11836.                                                                         *
  11837. ************************************************************************/
  11838.  
  11839. #include <stdio.h>
  11840.  
  11841. int main(void)
  11842. {
  11843.   int x = 2;
  11844.   int y = 3;
  11845.  
  11846.      printf("value 1 = %d\n", ( (x) * (x) ) );
  11847.      printf("value 2 = %d\n", y);
  11848.  
  11849.   return(0);
  11850. }
  11851.  
  11852. /************************************************************************
  11853. *
  11854. This program produces the following output: 
  11855.  
  11856. value 1 = 4
  11857. value 2 = 3
  11858.  
  11859.                                                                         *
  11860. ************************************************************************/
  11861.  
  11862.  
  11863. ΓòÉΓòÉΓòÉ 9.4. Scope of Macro Names (#undef) ΓòÉΓòÉΓòÉ
  11864.  
  11865. A preprocessor undef directive causes the preprocessor to end the scope of a 
  11866. preprocessor definition. 
  11867.  
  11868. A preprocessor #undef directive has the form: 
  11869.  
  11870. >>ΓöÇΓöÇ#ΓöÇΓöÇundefΓöÇΓöÇidentifierΓöÇΓöÇ><
  11871.  
  11872. If the identifier is not currently defined as a macro, #undef is ignored 
  11873.  
  11874. Once defined, a preprocessor identifier remains defined and in scope 
  11875. (independent of the scoping rules of the language) until the end of a 
  11876. translation unit or until it is undefined by an #undef preprocessor directive. 
  11877.  
  11878. You can also use the /U compiler option to undefine macros. The /U option does 
  11879. not undefine macros defined in source code. 
  11880.  
  11881. Examples of #undef Directives 
  11882.  
  11883. Related Information 
  11884.  
  11885.      Macro Definition and Expansion (#define) 
  11886.      Predefined Macro Names 
  11887.      /U option 
  11888.      Preprocessor Directives 
  11889.  
  11890.  
  11891. ΓòÉΓòÉΓòÉ <hidden> Examples of #undef Directives ΓòÉΓòÉΓòÉ
  11892.  
  11893. The following directives define BUFFER and SQR: 
  11894.  
  11895. #define BUFFER 512
  11896. #define SQR(x) ((x) * (x))
  11897.  
  11898. The following directives nullify these definitions: 
  11899.  
  11900. #undef BUFFER
  11901. #undef SQR
  11902.  
  11903. Any occurrences of the identifiers BUFFER and SQR that follow these #undef 
  11904. directives are not replaced with any replacement tokens. Once the definition of 
  11905. a macro has been removed by an #undef directive, the identifier can be used in 
  11906. a new #define directive. 
  11907.  
  11908.  
  11909. ΓòÉΓòÉΓòÉ 9.5. # Operator ΓòÉΓòÉΓòÉ
  11910.  
  11911. The # (single number sign) operator converts a parameter of a function-like 
  11912. macro into a character string literal. For example, if macro ABC is defined 
  11913. using the following directive: 
  11914.  
  11915.    #define ABC(x)   #x
  11916.  
  11917. all subsequent invocations of the macro ABC would be expanded into a character 
  11918. string literal containing the argument passed to ABC. For example: 
  11919.  
  11920. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11921. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  11922. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  11923. Γöé "ABC(1)"       Γöé "1"            Γöé
  11924. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  11925. Γöé "ABC(Hello there)"  Γöé "Hello there"       Γöé
  11926. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  11927.  
  11928. The # operator should not be confused with the null directive. 
  11929.  
  11930. Use the # operator in a function-like macro definition according to the 
  11931. following rules: 
  11932.  
  11933.      A parameter following # operator in a function-like macro is converted 
  11934.       into a character string literal containing the argument passed to the 
  11935.       macro. 
  11936.  
  11937.      White-space characters that appear before or after the argument passed to 
  11938.       the macro are deleted. 
  11939.  
  11940.      Multiple white-space characters imbedded within the argument passed to 
  11941.       the macro is replaced by a single space character. 
  11942.  
  11943.      If the argument passed to the macro contains a string literal and if a \ 
  11944.       (backslash) character appears within the literal, a second \ character is 
  11945.       inserted before the original \ when the macro is expanded. 
  11946.  
  11947.      If the argument passed to the macro contains a " (double quotation mark) 
  11948.       character, a \ character is inserted before the " when the macro is 
  11949.       expanded. 
  11950.  
  11951.      If the argument passed to the macro contains a ' (single quotation mark) 
  11952.       character, a \ character is inserted before the ' when the macro is 
  11953.       expanded. 
  11954.  
  11955.      The conversion of an argument into a string literal occurs before macro 
  11956.       expansion on that argument. 
  11957.  
  11958.      If more than one ## operator or # operator appears in the replacement 
  11959.       list of a macro definition, the order of evaluation of the operators is 
  11960.       not defined. 
  11961.  
  11962.      If the result of the macro expansion is not a valid character string 
  11963.       literal, the behavior is undefined. 
  11964.  
  11965.  See Function-Like Macros for more information about function-like macros. 
  11966.  
  11967.  Examples of the # Operator 
  11968.  
  11969.  Related Information 
  11970.  
  11971.      Macro Definition and Expansion (#define) 
  11972.      Scope of Macro Names (#undef) 
  11973.      Macro Concatenation with the ## Operator 
  11974.      Function-Like Macros 
  11975.      Preprocessor Directives 
  11976.  
  11977.  
  11978. ΓòÉΓòÉΓòÉ <hidden> Examples of the # Operator ΓòÉΓòÉΓòÉ
  11979.  
  11980. The following examples demonstrate the use of the # operator: 
  11981.  
  11982.    #define STR(x)        #x
  11983.    #define XSTR(x)       STR(x)
  11984.    #define ONE           1
  11985.  
  11986. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  11987. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  11988. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  11989. Γöé "STR(\n "\n" '\n')"  Γöé ""\n \"\\n\" '\\n'""    Γöé
  11990. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  11991. Γöé "STR(ONE)"      Γöé "ONE"           Γöé
  11992. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  11993. Γöé "XSTR(ONE)"      Γöé "1"            Γöé
  11994. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  11995. Γöé "XSTR("hello")"    Γöé "\"hello\""        Γöé
  11996. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  11997.  
  11998.  
  11999. ΓòÉΓòÉΓòÉ 9.6. Macro Concatenation with the ## Operator ΓòÉΓòÉΓòÉ
  12000.  
  12001. The ## (double number sign) operator concatenates two tokens in a macro 
  12002. invocation (text and/or arguments) given in a macro definition. 
  12003.  
  12004. If a macro XY was defined using the following directive: 
  12005.  
  12006.    #define XY(x,y)    x##y
  12007.  
  12008. the last token of the argument for x is concatenated with the first token of 
  12009. the argument for y. 
  12010.  
  12011. For example, 
  12012.  
  12013. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12014. Γöé INVOCATION    Γöé RESULT OF MACRO EXPANSION Γöé
  12015. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12016. Γöé "XY(1, 2)"    Γöé "12"            Γöé
  12017. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12018. Γöé "XY(Green,    Γöé "Greenhouse"        Γöé
  12019. Γöé house)"     Γöé              Γöé
  12020. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  12021.  
  12022. Use the ## operator according to the following rules: 
  12023.  
  12024.      The ## operator cannot be the very first or very last item in the 
  12025.       replacement list of a macro definition. 
  12026.  
  12027.      The last token of the item in front of the ## operator is concatenated 
  12028.       with first token of the item following the ## operator. 
  12029.  
  12030.      Concatenation takes place before any macros in arguments are expanded. 
  12031.  
  12032.      If the result of a concatenation is a valid macro name, it is available 
  12033.       for further replacement even if it appears in a context in which it would 
  12034.       not normally be available. 
  12035.  
  12036.      If more than one ## operator and/or # operator appears in the replacement 
  12037.       list of a macro definition, the order of evaluation of the operators is 
  12038.       not defined. 
  12039.  
  12040.  Examples of the ## Operator 
  12041.  
  12042.  Related Information 
  12043.  
  12044.      Macro Definition and Expansion (#define) 
  12045.      Scope of Macro Names (#undef) 
  12046.      # Operator 
  12047.      Preprocessor Directives 
  12048.  
  12049.  
  12050. ΓòÉΓòÉΓòÉ <hidden> Examples of the ## Operator ΓòÉΓòÉΓòÉ
  12051.  
  12052. The following examples demonstrate the use of the ## operator: 
  12053.  
  12054. #define ArgArg(x, y)          x##y
  12055. #define ArgText(x)            x##TEXT
  12056. #define TextArg(x)            TEXT##x
  12057. #define TextText              TEXT##text
  12058. #define Jitter                1
  12059. #define bug                   2
  12060. #define Jitterbug             3
  12061.  
  12062. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12063. Γöé INVOCATION      Γöé RESULT OF MACRO EXPANSION Γöé
  12064. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12065. Γöé "ArgArg(lady, bug)"  Γöé ""ladybug""        Γöé
  12066. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12067. Γöé "ArgText(con)"    Γöé ""conTEXT""        Γöé
  12068. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12069. Γöé "TextArg(book)"    Γöé ""TEXTbook""        Γöé
  12070. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12071. Γöé "TextText"      Γöé ""TEXTtext""        Γöé
  12072. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  12073. Γöé "ArgArg(Jitter,    Γöé "3"            Γöé
  12074. Γöé bug)"         Γöé              Γöé
  12075. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  12076.  
  12077.  
  12078. ΓòÉΓòÉΓòÉ 9.7. Preprocessor Error Directive (#error) ΓòÉΓòÉΓòÉ
  12079.  
  12080. A preprocessor error directive causes the preprocessor to generate an error 
  12081. message and causes the compilation to fail. 
  12082.  
  12083. The #error directive has the form: 
  12084.  
  12085.        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12086.              Γöé
  12087. >>ΓöÇΓöÇ#ΓöÇΓöÇerrorΓöÇΓöÇΓöÇΓöÇcharacterΓöÇΓö┤ΓöÇΓöÇ><
  12088.  
  12089. The directive 
  12090.  
  12091. #error Error in TESTPGM1 - This section should not be compiled
  12092.  
  12093. generates the following error message: 
  12094.  
  12095. Error in TESTPGM1 - This section should not be compiled
  12096.  
  12097. Use the #error directive as a safety check during compilation. For example, if 
  12098. your program uses preprocessor conditional compilation directives, put #error 
  12099. directives in the source file to prevent code generation if a section of the 
  12100. program is reached that should be bypassed. 
  12101.  
  12102. Related Information 
  12103.  
  12104.      Preprocessor Directives 
  12105.  
  12106.  
  12107. ΓòÉΓòÉΓòÉ 9.8. File Inclusion (#include) ΓòÉΓòÉΓòÉ
  12108.  
  12109. A preprocessor include directive causes the preprocessor to replace the 
  12110. directive with the contents of the specified file. 
  12111.  
  12112. A preprocessor #include directive has the form: 
  12113.  
  12114. >>ΓöÇΓöÇ#ΓöÇΓöÇincludeΓöÇΓöÇΓö¼ΓöÇ"file_name"ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  12115.         Γö£ΓöÇΓöÉfile_name>ΓöÇΓöÇΓöÇΓöñ
  12116.         Γö£ΓöÇΓöÉheader_name>ΓöÇΓöñ
  12117.         ΓööΓöÇidentifiersΓöÇΓöÇΓöÇΓöÿ
  12118.  
  12119. The preprocessor resolves macros contained in a #include directive. After macro 
  12120. replacement, the resulting token sequence must consist of a file name enclosed 
  12121. in either double quotation marks or the characters < and >. 
  12122.  
  12123. For example: 
  12124.  
  12125. #define MONTH <july.h>
  12126. #include MONTH
  12127.  
  12128. If the file name is enclosed in double quotation marks, for example:  #include 
  12129. "payroll.h"  the preprocessor treats it as a user-defined file, and searches 
  12130. for the file in: 
  12131.  
  12132.    1. The directory where the original .c source file resides. 
  12133.  
  12134.    2. Any directories specified using the /I compiler option (that have not 
  12135.       been removed by the /Xc option).  Directories specified in the ICC 
  12136.       environment variable are searched before those specified on the command 
  12137.       line. 
  12138.  
  12139.    3. Any directories specified using the INCLUDE environment variable, 
  12140.       provided the /Xi option is not in effect. 
  12141.  
  12142.  If the file name is enclosed in angle brackets, for example: #include 
  12143.  <stdio.h> it is treated as a system-defined file, and the preprocessor 
  12144.  searches the following places in the order given: 
  12145.  
  12146.    1. Any directories specified using the /I compiler option (that have not 
  12147.       been removed by the /Xc option).  Directories specified in the ICC 
  12148.       environment variable are searched before those specified on the command 
  12149.       line. 
  12150.  
  12151.    2. Any directories specified using the INCLUDE environment variable, 
  12152.       provided the /Xi option is not in effect. 
  12153.  
  12154.  Note:  If the file name is fully qualified, the preprocessor searches only the 
  12155.  directory specified by the name. 
  12156.  
  12157.  The new-line and > characters cannot appear in a file name delimited by < and 
  12158.  >. The new-line and " (double quotation marks) character cannot appear in a 
  12159.  file name delimited by " and ", although > can. 
  12160.  
  12161.  Declarations that are used by several files can be placed in one file and 
  12162.  included with #include in each file that uses them. For example, the following 
  12163.  file defs.h contains several definitions and an inclusion of an additional 
  12164.  file of declarations: 
  12165.  
  12166.   /* defs.h */
  12167.   #define TRUE 1
  12168.   #define FALSE 0
  12169.   #define BUFFERSIZE 512
  12170.   #define MAX_ROW 66
  12171.   #define MAX_COLUMN 80
  12172.   int hour;
  12173.   int min;
  12174.   int sec;
  12175.   #include "mydefs.h"
  12176.  
  12177.  You can embed the definitions that appear in defs.h with the following 
  12178.  directive: 
  12179.  
  12180.   #include "defs.h"
  12181.  
  12182.  In the following example, a #define combines several preprocessor macros to 
  12183.  define a macro that represents the name of the C standard I/O header file. A 
  12184.  #include makes the header file available to the program. 
  12185.  
  12186.   #define  IO_HEADER   <stdio.h>
  12187.         .
  12188.         .
  12189.         .
  12190.   #include IO_HEADER   /* equivalent to specifying #include <stdio.h> */
  12191.         .
  12192.         .
  12193.         .
  12194.  
  12195.  Related Information 
  12196.  
  12197.      Macro Definition and Expansion (#define) 
  12198.      Preprocessor Directives 
  12199.      Include Files 
  12200.      /I option 
  12201.  
  12202.  
  12203. ΓòÉΓòÉΓòÉ 9.9. Predefined Macro Names ΓòÉΓòÉΓòÉ
  12204.  
  12205. VisualAge C++ provides the following predefined macro names. 
  12206.  
  12207.      ISO/ANSI Standard Predefined Macro Names 
  12208.      VisualAge C++ Predefined Macro Names 
  12209.      Additional VisualAge C++ Predefined Macros 
  12210.  
  12211.  Examples of Predefined Macros 
  12212.  
  12213.  Related Information 
  12214.  
  12215.      #pragma langlvl 
  12216.      Macro Definition and Expansion (#define) 
  12217.      Scope of Macro Names (#undef) 
  12218.      /S2 option 
  12219.  
  12220.  
  12221. ΓòÉΓòÉΓòÉ 9.9.1. ISO/ANSI Standard Predefined Macro Names ΓòÉΓòÉΓòÉ
  12222.  
  12223. Both C and C++ provide the following predefined macro names as specified in the 
  12224. ISO/ANSI C language standard: 
  12225.  
  12226.  __LINE__ 
  12227.      An integer representing the current source line number. 
  12228.  
  12229.      The value of __LINE__ changes during compilation as the compiler processes 
  12230.      subsequent lines of your source program. It can be set with the #line 
  12231.      directive, described in Line Control (#line). 
  12232.  
  12233.  __FILE__ 
  12234.      A character string literal containing the name of the source file. 
  12235.  
  12236.      The value of __FILE__ changes as the compiler processes include files that 
  12237.      are part of your source program. It can be set with the #line directive, 
  12238.      described in Line Control (#line). 
  12239.  
  12240.  __DATE__ 
  12241.      A character string literal containing the date when the source file was 
  12242.      compiled. 
  12243.  
  12244.      The value of __DATE__ changes as the compiler processes any include files 
  12245.      that are part of your source program. The date is in the form: 
  12246.  
  12247.              "Mmm dd yyyy"
  12248.  
  12249.      where: 
  12250.  
  12251.      Mmm            represents the month in an abbreviated form (Jan, Feb, Mar, 
  12252.                     Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec). 
  12253.  
  12254.      dd             represents the day. If the day is less than 10, the first d 
  12255.                     is a blank character. 
  12256.  
  12257.      yyyy           represents the year. 
  12258.  
  12259.      The date is always set to the system date. 
  12260.  
  12261.  __STDC__ 
  12262.      For C programs, the compiler sets this macro to the integer 1 (one) to 
  12263.      indicate that the C compiler conforms to the ISO/ANSI standard. For C++ 
  12264.      programs, this macro is set to the integer 0, indicating that the C++ 
  12265.      language is not a proper superset of C, and that the compiler does not 
  12266.      conform to ISO/ANSI C. For more information on how C++ differs from 
  12267.      ISO/ANSI C, see C and C++ Compatibility. 
  12268.  
  12269.  __TIME__ 
  12270.      A character string literal containing the time when the source file was 
  12271.      compiled. 
  12272.  
  12273.      The value of __TIME__ changes as the compiler processes any include files 
  12274.      that are part of your source program. The time is in the form: 
  12275.  
  12276.              "hh:mm:ss"
  12277.  
  12278.      where: 
  12279.  
  12280.      hh             represents the hour. 
  12281.  
  12282.      mm             represents the minutes. 
  12283.  
  12284.      ss             represents the seconds. 
  12285.  
  12286.      The time is always set to the system time. 
  12287.  
  12288.  __cplusplus 
  12289.      For C++ programs, this macro is set to the integer 1, indicating that the 
  12290.      compiler is a C++ compiler. Note that this macro name has no trailing 
  12291.      underscores. 
  12292.  
  12293.  
  12294. ΓòÉΓòÉΓòÉ 9.9.2. VisualAge C++ Predefined Macro Names ΓòÉΓòÉΓòÉ
  12295.  
  12296. VisualAge C++ provides the following predefined macros. The value of all these 
  12297. macros is defined when the corresponding #pragma directive or compiler option 
  12298. is used. They cannot be the subject of a #define or #undef preprocessor 
  12299. directive. However, except for the __DATE__, __FUNCTION__, __LINE__, __TIME__, 
  12300. and __TIMESTAMP__ macros, they can be undefined on the command line using the 
  12301. /U option. 
  12302.  
  12303.  __ANSI__ 
  12304.      Allows only language constructs that conform to ISO/ANSI C standard. 
  12305.      Defined using the #pragma langlvl directive or /Sa option. 
  12306.  
  12307.  __EXTENDED__ 
  12308.      Allows additional language constructs provided by the VisualAge C++ 
  12309.      implementation. Defined using the #pragma langlvl directive or /S2 option. 
  12310.  
  12311.  __SAA__ 
  12312.      Allows only language constructs that conform to the most recent level of 
  12313.      SAA C standards. Defined using the #pragma langlvl directive or /S2 
  12314.      option. This macro is not defined for C++. 
  12315.  
  12316.  __SAAL2__ 
  12317.      Allows only language constructs that conform to SAA Level 2 C standards. 
  12318.      Defined using the #pragma langlvldirective or /S2 option. This macro is 
  12319.      not defined for C++. 
  12320.  
  12321.  __COMPAT__ 
  12322.      Macro defined when the compat language level is specified for C++ language 
  12323.      files. This macro is not defined for C. 
  12324.  
  12325.  __FUNCTION__ 
  12326.      Indicates the name of the function currently being compiled. For C++ 
  12327.      programs, expands to the actual function prototype. 
  12328.  
  12329.  __SOM_ENABLED__ 
  12330.      Macro defined when the SOM compiler options are used. Indicates that 
  12331.      native SOM is supported. This option turns on implicit SOM mode, and also 
  12332.      causes the file som.h to be included. SOM support for VisualAge C++ and 
  12333.      the SOM options are described in the IBM VisualAge C++ for OS/2 
  12334.      Programming Guide. 
  12335.  
  12336.  __TIMESTAMP__ 
  12337.      A character string literal containing the date and time when the source 
  12338.      file was last modified. 
  12339.  
  12340.      The value of __TIMESTAMP__ changes as the compiler processes any include 
  12341.      files that are part of your source program. The date and time are in the 
  12342.      form: 
  12343.  
  12344.              "Day Mmm dd hh:mm:ss yyyy"
  12345.  
  12346.      where: 
  12347.  
  12348.      Day            represents the day of the week (Mon, Tue, Wed, Thu, Fri, 
  12349.                     Sat, or Sun). 
  12350.  
  12351.      Mmm            represents the month in an abbreviated form (Jan, Feb, Mar, 
  12352.                     Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, or Dec). 
  12353.  
  12354.      dd             represents the day. If the day is less than 10, the first d 
  12355.                     is a blank character. 
  12356.  
  12357.      hh             represents the hour. mm represents the minutes. 
  12358.  
  12359.      ss             represents the seconds. 
  12360.  
  12361.      yyyy           represents the year. 
  12362.  
  12363.      The date and time are always set to the system date and time. 
  12364.  
  12365.  
  12366. ΓòÉΓòÉΓòÉ 9.9.3. Additional VisualAge C++ Predefined Macros ΓòÉΓòÉΓòÉ
  12367.  
  12368. The macros identified in this section are provided to allow customers to write 
  12369. programs that use VisualAge C++ services. Only those macros identified in this 
  12370. section should be used to request or receive VisualAge C++ services. 
  12371.  
  12372. The additional macros offered by the VisualAge C++ compiler are: 
  12373.  
  12374.  _CHAR_UNSIGNED 
  12375.      Indicates default character type is unsigned. Defined when the #pragma 
  12376.      chars(unsigned) directive is in effect, or when the /J+ compiler option is 
  12377.      set. 
  12378.  
  12379.  _CHAR_SIGNED 
  12380.      Indicates default character type is signed. Defined when the #pragma 
  12381.      chars(signed) directive is in effect, or when the /J- compiler option is 
  12382.      set. 
  12383.  
  12384.  __COMPAT__ 
  12385.      Indicates language constructs compatible with earlier versions of the C++ 
  12386.      language are allowed. Defined using the #pragma langlvl(compat) directive 
  12387.      or /Sc compiler option. This macro is defined for C++ programs only. 
  12388.  
  12389.  __DBCS__ 
  12390.      Indicates DBCS support is enabled. Defined using the /Sn compiler option. 
  12391.  
  12392.  __DDNAMES__ 
  12393.      Indicates ddnames are supported. Defined using the /Sh compiler option. 
  12394.  
  12395.  __DEBUG_ALLOC__ 
  12396.      Maps memory management functions to their debug versions. Defined using 
  12397.      the /Tmcompiler option. 
  12398.  
  12399.  __DLL__ 
  12400.      Indicates code for a DLL is being compiled. Defined using the /Ge- 
  12401.      compiler option. 
  12402.  
  12403.  _FP_INLINE_ 
  12404.      Inlines the trigonometric functions (cos, sin, and so on). 
  12405.  
  12406.  __HHW_INTEL__ 
  12407.      Indicates that the host hardware is an Intel** processor. 
  12408.  
  12409.  __HOS_OS2__ 
  12410.      Indicates that the host operating system is OS/2. 
  12411.  
  12412.  __IBMC__ 
  12413.      Indicates the version number of the VisualAge C compiler. 
  12414.  
  12415.  __IBMCPP__ 
  12416.      Indicates the version number of the VisualAge C++ compiler. 
  12417.  
  12418.  __IMPORTLIB__ 
  12419.      Indicates that dynamic linking is used. Defined using the /Gd option. 
  12420.  
  12421.  _M_I386 
  12422.      Indicates code is being compiled for a 386 chip or higher. 
  12423.  
  12424.  __MULTI__ 
  12425.      Indicates multithread code is being generated. Defined using the /Gm 
  12426.      compiler option. 
  12427.  
  12428.  __NO_DEFAULT_LIBS__ 
  12429.      Indicates that information about default libraries will not be included in 
  12430.      object files. Defined using the /Gd option. 
  12431.  
  12432.  __OS2__ 
  12433.      Set to the integer 1.  Indicates the product is an OS/2 compiler. 
  12434.  
  12435.  __SPC__ 
  12436.      Indicates the subsystem libraries are being used. Defined using the /Rn 
  12437.      compiler option. 
  12438.  
  12439.  __TEMPINC__ 
  12440.      Indicates the template-implementation file method of resolving template 
  12441.      functions is being used.  Defined using the /Ft compiler option. 
  12442.  
  12443.  __THW_INTEL__ 
  12444.      Indicates that the target hardware is an Intel processor. 
  12445.  
  12446.  __TOS_OS2__ 
  12447.      Indicates that the target operating system is OS/2. 
  12448.  
  12449.  __TILED__ 
  12450.      Indicates tiled memory is being used. Defined using the /Gt compiler 
  12451.      option. 
  12452.  
  12453.  __32BIT__ 
  12454.      Set to the integer 1.  Indicates the product is a 32-bit compiler. 
  12455.  
  12456.  The value of the __IBMC__ and __IBMCPP__ macros is 300. One of these two 
  12457.  macros is always defined: when you compile C++ code, __IBMCPP__ is defined; 
  12458.  when you compile C code, __IBMC__ is defined. The macros __OS2__, _M_I386, and 
  12459.  __32BIT__ are always defined also. The remaining macros, with the exception of 
  12460.  __FUNCTION__, are defined when the corresponding #pragma directive or compiler 
  12461.  option is used. 
  12462.  
  12463.  
  12464. ΓòÉΓòÉΓòÉ <hidden> Example of Predefined Macros ΓòÉΓòÉΓòÉ
  12465.  
  12466. /************************************************************************
  12467. *
  12468.  
  12469. The following printf statements display the values of the predefined macros 
  12470. __LINE__, __FILE__, __TIME__, and __DATE__ and print a message indicating the 
  12471. program's conformance to ISO/ANSI standards based on __STDC__: 
  12472.  
  12473.                                                                         *
  12474. ************************************************************************/
  12475.  
  12476. /**
  12477.  ** This example illustrates some predefined macros.
  12478.  **/
  12479.  
  12480. #pragma langlvl(ANSI)
  12481. #include <stdio.h>
  12482.  
  12483. #ifdef __STDC__
  12484. #   define CONFORM    "conforms"
  12485. #else
  12486. #   define CONFORM    "does not conform"
  12487. #endif
  12488.  
  12489. int main(void)
  12490. {
  12491.   printf("Line %d of file %s has been executed\n", __LINE__, __FILE__);
  12492.   printf("This file was compiled at %s on %s\n", __TIME__, __DATE__);
  12493.   printf("This program %s to ISO/ANSI standards\n", CONFORM);
  12494. }
  12495.  
  12496.  
  12497. ΓòÉΓòÉΓòÉ 9.10. Conditional Compilation Directives ΓòÉΓòÉΓòÉ
  12498.  
  12499. A preprocessor conditional compilation directive causes the preprocessor to 
  12500. conditionally suppress the compilation of portions of source code. These 
  12501. directives test a constant expression or an identifier to determine which 
  12502. tokens the preprocessor should pass on to the compiler and which tokens should 
  12503. be bypassed during preprocessing. The directives are: 
  12504.  
  12505.      #if 
  12506.      #ifdef 
  12507.      #ifndef 
  12508.      #else 
  12509.      #elif 
  12510.      #endif 
  12511.  
  12512.  The preprocessor conditional compilation directive spans several lines: 
  12513.  
  12514.      The condition specification line 
  12515.      Lines containing code that the preprocessor passes on to the compiler if 
  12516.       the condition evaluates to a nonzero value (optional) 
  12517.      The #else line (optional) 
  12518.      Lines containing code that the preprocessor passes on to the compiler if 
  12519.       the condition evaluates to zero (optional) 
  12520.      The preprocessor #endif directive 
  12521.  
  12522.  For each #if, #ifdef, and #ifndef directive, there are zero or more #elif 
  12523.  directives, zero or one #else directive, and one matching #endif directive. 
  12524.  All the matching directives are considered to be at the same nesting level. 
  12525.  
  12526.  You can nest conditional compilation directives. In the following directives, 
  12527.  the first #else is matched with the #if directive. 
  12528.  
  12529.   #ifdef MACNAME
  12530.                    /*  tokens added if MACNAME is defined               */
  12531.   #   if TEST <=10
  12532.                    /* tokens added if MACNAME is defined and TEST <= 10 */
  12533.   #   else
  12534.                    /* tokens added if MACNAME is defined and TEST >  10 */
  12535.   #   endif
  12536.   #else
  12537.                    /*  tokens added if MACNAME is not defined           */
  12538.   #endif
  12539.  
  12540.  Each directive controls the block immediately following it. A block consists 
  12541.  of all the tokens starting on the line following the directive and ending at 
  12542.  the next conditional compilation directive at the same nesting level. 
  12543.  
  12544.  Each directive is processed in the order in which it is encountered. If an 
  12545.  expression evaluates to zero, the block following the directive is ignored. 
  12546.  
  12547.  When a block following a preprocessor directive is to be ignored, the tokens 
  12548.  are examined only to identify preprocessor directives within that block so 
  12549.  that the conditional nesting level can be determined. All tokens other than 
  12550.  the name of the directive are ignored. 
  12551.  
  12552.  Only the first block whose expression is nonzero is processed. The remaining 
  12553.  blocks at that nesting level are ignored. If none of the blocks at that 
  12554.  nesting level has been processed and there is a #else directive, the block 
  12555.  following the #else directive is processed. If none of the blocks at that 
  12556.  nesting level has been processed and there is no #else directive, the entire 
  12557.  nesting level is ignored. 
  12558.  
  12559.  Examples of Conditional Compilation 
  12560.  
  12561.  Related Information 
  12562.  
  12563.      #if 
  12564.      #ifdef 
  12565.      #ifndef 
  12566.      #elif 
  12567.      #else 
  12568.      #endif 
  12569.      Preprocessor Directives 
  12570.  
  12571.  
  12572. ΓòÉΓòÉΓòÉ 9.10.1. #if, #elif ΓòÉΓòÉΓòÉ
  12573.  
  12574. The #if and #elif directives compare the value of the expression to zero. 
  12575.  
  12576. If the constant expression evaluates to a nonzero value, the tokens that 
  12577. immediately follow the condition are passed on to the compiler. 
  12578.  
  12579. If the expression evaluates to zero and the conditional compilation directive 
  12580. contains a preprocessor #elif directive, the source text located between the 
  12581. #elif and the next #elif or preprocessor #else directive is selected by the 
  12582. preprocessor to be passed on to the compiler. The #elif directive cannot appear 
  12583. after the preprocessor #else directive. 
  12584.  
  12585. All macros are expanded, any defined() expressions are processed and all 
  12586. remaining identifiers are replaced with the token 0. 
  12587.  
  12588.                    ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12589.                             Γöé
  12590. >>ΓöÇΓöÇ#ΓöÇΓöÇΓö¼ΓöÇifΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇconstant_expressionΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  12591.     ΓööΓöÇelifΓöÇΓöÿ
  12592.  
  12593. The expressions that are tested must be integer constant expressions with the 
  12594. following properties: 
  12595.  
  12596.      No casts are performed. 
  12597.      Arithmetic is performed using long int values. 
  12598.      The expression can contain defined macros. No other identifiers can 
  12599.       appear in the expression. 
  12600.      The constant expression can contain the unary operator defined. This 
  12601.       operator can be used only with the preprocessor keyword #if. The 
  12602.       following expressions evaluate to 1 if the identifier is defined in the 
  12603.       preprocessor, otherwise to 0: 
  12604.  
  12605.             defined identifier
  12606.             defined(identifier)
  12607.  
  12608.       For example: 
  12609.  
  12610.             #if defined(TEST1) || defined(TEST2)
  12611.  
  12612.  Note:  If a macro is not defined, a value of 0 (zero) is assigned to it. In 
  12613.  the following example, TEST must be a macro identifier: 
  12614.  
  12615.   #if TEST >= 1
  12616.      printf("i = %d\n", i);
  12617.      printf("array[i] = %d\n", array[i]);
  12618.   #elif TEST < 0
  12619.      printf("array subscript out of bounds \n");
  12620.   #endif
  12621.  
  12622.  Example of #if and #elif Directives 
  12623.  
  12624.  Related Information 
  12625.  
  12626.      Conditional Compilation Directives 
  12627.      #ifdef 
  12628.      #ifndef 
  12629.      #endif 
  12630.      Preprocessor Directives 
  12631.      if 
  12632.  
  12633.  
  12634. ΓòÉΓòÉΓòÉ <hidden> Examples of #if and #elif Directives ΓòÉΓòÉΓòÉ
  12635.  
  12636. /************************************************************************
  12637. *
  12638.  
  12639. The following example uses the #if and #elif directives to assign values to an 
  12640. array. 
  12641.  
  12642.                                                                         *
  12643. ************************************************************************/
  12644.  
  12645. #include <stdio.h>
  12646.  
  12647. int main(void)
  12648. {
  12649.    int i;
  12650.    char *arrayname = "realarray";
  12651.    int realarray[] = { 1, 2, 3 };
  12652.    int array1[] = { 4, 5, 6 };
  12653.    int array2[] = { 7, 8, 9 };
  12654.  
  12655. #if ( (defined(LEVEL1)) && (TEST > 1) )
  12656.    for (i = 0; i < 3; i++)
  12657.       realarray[i] = array1[i];
  12658.       arrayname = "array1";
  12659. #elif (defined(LEVEL2))
  12660.    for (i = 0; i < 3; i++)
  12661.       realarray[i] = array2[i];
  12662.       arrayname = "array2";
  12663. #endif
  12664.  
  12665.    printf("realarray[] now has the contents of %s[]\n", arrayname);
  12666.  
  12667.    /* Assuming only LEVEL2 is defined, the expected output is:
  12668.  
  12669.       realarray[] now has the contents of array2[] */
  12670.  
  12671. }
  12672.  
  12673.  
  12674. ΓòÉΓòÉΓòÉ 9.10.2. #ifdef ΓòÉΓòÉΓòÉ
  12675.  
  12676. The #ifdef directive checks for the existence of macro definitions. 
  12677.  
  12678. If the identifier specified is defined as a macro, the tokens that immediately 
  12679. follow the condition are passed on to the compiler. 
  12680.  
  12681. The preprocessor #ifdef directive has the form: 
  12682.  
  12683.              ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12684.                       Γöé
  12685. >>ΓöÇΓöÇ#ΓöÇΓöÇifdefΓöÇΓöÇidentifierΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  12686.  
  12687. The following example defines MAX_LEN to be 75 if EXTENDED is defined for the 
  12688. preprocessor. Otherwise, MAX_LEN is defined to be 50. 
  12689.  
  12690. #ifdef EXTENDED
  12691. #   define MAX_LEN 75
  12692. #else
  12693. #   define MAX_LEN 50
  12694. #endif
  12695.  
  12696. Related Information 
  12697.  
  12698.      Conditional Compilation Directives 
  12699.      #ifndef 
  12700.      #if, #elif 
  12701.      #else 
  12702.      #endif 
  12703.      Macro Definition and Expansion (#define) 
  12704.      Scope of Macro Names (#undef) 
  12705.      Preprocessor Directives 
  12706.  
  12707.  
  12708. ΓòÉΓòÉΓòÉ 9.10.3. #ifndef ΓòÉΓòÉΓòÉ
  12709.  
  12710. The #ifndef directive checks for the existence of macro definitions. 
  12711.  
  12712. If the identifier specified is not defined as a macro, the tokens that 
  12713. immediately follow the condition are passed on to the compiler. 
  12714.  
  12715. The preprocessor #ifndef directive has the form: 
  12716.  
  12717.               ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12718.                        Γöé
  12719. >>ΓöÇΓöÇ#ΓöÇΓöÇifndefΓöÇΓöÇidentifierΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  12720.  
  12721. An identifier must follow the #ifndef keyword. The following example defines 
  12722. MAX_LEN to be 50 if EXTENDED is not defined for the preprocessor. Otherwise, 
  12723. MAX_LEN is defined to be 75. 
  12724.  
  12725. #ifndef EXTENDED
  12726. #   define MAX_LEN 50
  12727. #else
  12728. #   define MAX_LEN 75
  12729. #endif
  12730.  
  12731. Related Information 
  12732.  
  12733.      Conditional Compilation Directives 
  12734.      #ifdef 
  12735.      #if, #elif 
  12736.      #else 
  12737.      #endif 
  12738.      Macro Definition and Expansion (#define) 
  12739.      Scope of Macro Names (#undef) 
  12740.      Preprocessor Directives 
  12741.  
  12742.  
  12743. ΓòÉΓòÉΓòÉ 9.10.4. #else ΓòÉΓòÉΓòÉ
  12744.  
  12745. If the condition specified in the #if, #ifdef, or #ifndef directive evaluates 
  12746. to 0, and the conditional compilation directive contains a preprocessor #else 
  12747. directive, the source text located between the preprocessor #else directive and 
  12748. the preprocessor #endif directive is selected by the preprocessor to be passed 
  12749. on to the compiler. 
  12750.  
  12751. The preprocessor #else directive has the form: 
  12752.  
  12753.        ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12754.                 Γöé
  12755. >>ΓöÇΓöÇ#ΓöÇΓöÇelseΓöÇΓöÇΓöÇΓöÇtoken_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  12756.  
  12757. The following example defines MAX_LEN to be 50 if EXTENDED is not defined for 
  12758. the preprocessor. Otherwise, MAX_LEN is defined to be 75. 
  12759.  
  12760. #ifndef EXTENDED
  12761. #   define MAX_LEN 50
  12762. #else
  12763. #   define MAX_LEN 75
  12764. #endif
  12765.  
  12766. Related Information 
  12767.  
  12768.      Conditional Compilation Directives 
  12769.      #if, #elif 
  12770.      #ifdef 
  12771.      #ifndef 
  12772.      #endif 
  12773.      Macro Definition and Expansion (#define) 
  12774.      Preprocessor Directives 
  12775.  
  12776.  
  12777. ΓòÉΓòÉΓòÉ 9.10.5. #endif ΓòÉΓòÉΓòÉ
  12778.  
  12779. The preprocessor #endif directive ends the conditional compilation directive. 
  12780.  
  12781. It has the form: 
  12782.  
  12783. >>ΓöÇΓöÇ#ΓöÇΓöÇendifΓöÇΓöÇ><
  12784.  
  12785. The following example shows preprocessor conditional compilation directives 
  12786. ended by the #endif directive. 
  12787.  
  12788. #if defined(LEVEL1)
  12789. #   define SIZEOF_INT 16
  12790. #   ifdef PHASE2
  12791. #     define MAX_PHASE 2
  12792. #   else
  12793. #     define MAX_PHASE 8
  12794. #   endif
  12795. #elif defined(LEVEL2)
  12796. #   define SIZEOF_INT 32
  12797. #   define MAX_PHASE 16
  12798. #endif
  12799.  
  12800. Related Information 
  12801.  
  12802.      Conditional Compilation Directives 
  12803.      #if, #elif 
  12804.      #ifdef 
  12805.      #ifndef 
  12806.      #else 
  12807.      Preprocessor Directives 
  12808.  
  12809.  
  12810. ΓòÉΓòÉΓòÉ <hidden> Examples of Conditional Compilation Directives ΓòÉΓòÉΓòÉ
  12811.  
  12812. /************************************************************************
  12813. *
  12814.  
  12815. The following example shows how you can nest preprocessor conditional 
  12816. compilation directives: 
  12817.  
  12818. #if defined(TARGET1)
  12819. #   define SIZEOF_INT 16
  12820. #   ifdef PHASE2
  12821. #      define MAX_PHASE 2
  12822. #   else
  12823. #      define MAX_PHASE 8
  12824. #   endif
  12825. #elif defined(TARGET2)
  12826. #   define SIZEOF_INT 32
  12827. #   define MAX_PHASE 16
  12828. #else
  12829. #   define SIZEOF_INT 32
  12830. #   define MAX_PHASE 32
  12831. #endif
  12832.  
  12833. The following program contains preprocessor conditional compilation directives: 
  12834.  
  12835.                                                                         *
  12836. ************************************************************************/
  12837.  
  12838. /**
  12839.  ** This example contains preprocessor
  12840.  ** conditional compilation directives.
  12841.  **/
  12842.  
  12843. #include <stdio.h>
  12844.  
  12845. int main(void)
  12846. {
  12847.    static int array[ ] = { 1, 2, 3, 4, 5 };
  12848.    int i;
  12849.  
  12850.    for (i = 0; i <= 4; i++)
  12851.    {
  12852.       array[i] *= 2;
  12853.  
  12854. #if TEST >= 1
  12855.    printf("i = %d\n", i);
  12856.    printf("array[i] = %d\n", array[i]);
  12857. #endif
  12858.  
  12859.    }
  12860.    return(0);
  12861. }
  12862.  
  12863.  
  12864. ΓòÉΓòÉΓòÉ 9.11. Line Control (#line) ΓòÉΓòÉΓòÉ
  12865.  
  12866. A preprocessor line control directive supplies line numbers for compiler 
  12867. messages. It causes the compiler to view the line number of the next source 
  12868. line as the specified number. 
  12869.  
  12870. A preprocessor #line directive has the form: 
  12871.  
  12872. >>ΓöÇΓöÇ#ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇdecimal_constantΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓö¼ΓöÇΓöÇ><
  12873.     ΓööΓöÇlineΓöÇΓöÿ  Γöé          ΓööΓöÇ"file_name"ΓöÇΓöÿ Γöé
  12874.          ΓööΓöÇcharactersΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  12875.  
  12876. In order for the compiler to produce meaningful references to line numbers in 
  12877. preprocessed source, the preprocessor inserts #line directives where necessary 
  12878. (for example, at the beginning and after the end of included text). 
  12879.  
  12880. A file name specification enclosed in double quotation marks can follow the 
  12881. line number. If you specify a file name, the compiler views the next line as 
  12882. part of the specified file. If you do not specify a file name, the compiler 
  12883. views the next line as part of the current source file. 
  12884.  
  12885. The token sequence on a #line directive is subject to macro replacement. After 
  12886. macro replacement, the resulting character sequence must consist of a decimal 
  12887. constant, optionally followed by a file name enclosed in double quotation 
  12888. marks. 
  12889.  
  12890. You can use #line control directives to make the compiler provide more 
  12891. meaningful error messages. 
  12892.  
  12893. Example of #line Directives 
  12894.  
  12895. Related Information 
  12896.  
  12897.      Preprocessor Directives 
  12898.      Decimal Constants 
  12899.  
  12900.  
  12901. ΓòÉΓòÉΓòÉ <hidden> Example of #line Directives ΓòÉΓòÉΓòÉ
  12902.  
  12903. /************************************************************************
  12904. *
  12905.  
  12906. The following program uses #line control directives to give each function an 
  12907. easily recognizable line number: 
  12908.  
  12909.                                                                         *
  12910. ************************************************************************/
  12911.  
  12912. /**
  12913.  ** This example illustrates #line directives.
  12914.  **/
  12915.  
  12916. #include <stdio.h>
  12917. #define LINE200 200
  12918.  
  12919. int main(void)
  12920. {
  12921.    func_1();
  12922.    func_2();
  12923. }
  12924.  
  12925. #line 100
  12926. func_1()
  12927. {
  12928.    printf("Func_1 - the current line number is %d\n",__LINE__);
  12929. }
  12930.  
  12931. #line LINE200
  12932. func_2()
  12933. {
  12934.    printf("Func_2 - the current line number is %d\n",__LINE__);
  12935. }
  12936.  
  12937. /************************************************************************
  12938. *
  12939.  
  12940. This program produces the following output: 
  12941.  
  12942. Func_1 - the current line number is 102
  12943. Func_2 - the current line number is 202
  12944.  
  12945.                                                                         *
  12946. ************************************************************************/
  12947.  
  12948.  
  12949. ΓòÉΓòÉΓòÉ 9.12. Null Directive (#) ΓòÉΓòÉΓòÉ
  12950.  
  12951. The null directive performs no action. It consists of a single # on a line of 
  12952. its own. 
  12953.  
  12954. The null directive should not be confused with the # operator or the character 
  12955. that starts a preprocessor directive. 
  12956.  
  12957. In the following example, if MINVAL is a defined macro name, no action is 
  12958. performed. If MINVAL is not a defined identifier, it is defined 1. 
  12959.  
  12960. #ifdef MINVAL
  12961.   #
  12962. #else
  12963.   #define MINVAL 1
  12964. #endif
  12965.  
  12966. Related Information 
  12967.  
  12968.      Preprocessor Directives 
  12969.      Null Statement 
  12970.  
  12971.  
  12972. ΓòÉΓòÉΓòÉ 9.13. Pragma Directives (#pragma) ΓòÉΓòÉΓòÉ
  12973.  
  12974. A pragma is an implementation-defined instruction to the compiler. It has the 
  12975. general form given below, where character_sequence is a series of characters 
  12976. that giving a specific compiler instruction and arguments, if any. 
  12977.  
  12978.         ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  12979.                    Γöé
  12980. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇΓöÇΓöÇcharacter_sequenceΓöÇΓö┤ΓöÇΓöÇ><
  12981.  
  12982. The character_sequence on a pragma is not subject to macro substitutions, 
  12983. unless otherwise stated. More than one pragma construct can be specified on a 
  12984. single #pragma directive. The compiler ignores unrecognized pragmas. 
  12985.  
  12986. The following pragmas are available: 
  12987.  
  12988.  alloc_text        Groups functions into separate 32-bit code segments. 
  12989.  
  12990.  chars             Sets the sign type of character data. 
  12991.  
  12992.  checkout          Controls the diagnostic messages generated by the /Kn 
  12993.                    compiler options. This directive is valid for C programs 
  12994.                    only. 
  12995.  
  12996.  comment           Places a comment into the object file. 
  12997.  
  12998.  data_seg          Places static and external variables in different 32-bit 
  12999.                    data segments. 
  13000.  
  13001.  define            Forces the definition of a template class without actually 
  13002.                    defining an object of the class. This directive is valid for 
  13003.                    C++ programs only. 
  13004.  
  13005.  entry             Specifies the function to be used as the entry point for the 
  13006.                    application being built. 
  13007.  
  13008.  export            Declares that a DLL function is to be exported and specifies 
  13009.                    the name of the function outside the DLL. 
  13010.  
  13011.  handler           Registers an exception handler for a function. 
  13012.  
  13013.  hdrfile           Specifies the filename of the precompiled header to be 
  13014.                    generated and/or used. 
  13015.  
  13016.  hdrstop           Manually terminates the initial sequence of #include 
  13017.                    directives being considered for precompilation. 
  13018.  
  13019.  implementation    Tells the compiler the name of the file that contains the 
  13020.                    function template definitions corresponding to the template 
  13021.                    declarations in the include file containing the pragma. This 
  13022.                    directive is valid for C++ programs only. 
  13023.  
  13024.  import            Lets you import a function or a variable from a DLL using 
  13025.                    either an ordinal number or a name different from the one 
  13026.                    that it has in the DLL. 
  13027.  
  13028.  info              Controls the diagnostic messages generated by the /Wgroup 
  13029.                    compiler options. 
  13030.  
  13031.  langlvl           Selects the C or C++ language level for compilation. 
  13032.  
  13033.  library           This tells the linker to pull in the appropriate libraries 
  13034.                    at link time. 
  13035.  
  13036.  linkage           Identifies the linkage or calling convention used on a 
  13037.                    function call. This directive is valid for C programs only. 
  13038.  
  13039.  map               Tells the compiler that all references to an identifier are 
  13040.                    to be converted to a new name. 
  13041.  
  13042.  margins           Specifies the columns in the input line that are to be 
  13043.                    scanned for input to the compiler. This directive is valid 
  13044.                    for C programs only. 
  13045.  
  13046.  pack              Specifies the alignment rules to use for the structures, 
  13047.                    unions, and classes that follow it. 
  13048.  
  13049.  page              Skips pages of the generated source listing. 
  13050.  
  13051.  pagesize          Sets the number of lines per page for the generated source 
  13052.                    listing. 
  13053.  
  13054.  priority          Specifies the order in which static objects are to be 
  13055.                    initialized at run time. This directive is valid for C++ 
  13056.                    programs only. 
  13057.  
  13058.  seg16             Specifies that a data object will be shared between 16-bit 
  13059.                    and 32-bit processes. 
  13060.  
  13061.  sequence          Defines the section of the input line that is to contain 
  13062.                    sequence numbers. 
  13063.  
  13064.  skip              Skips lines of the generated source listing. 
  13065.  
  13066.  sourcedir         Defines a new path to the directory containing the original 
  13067.                    source of an include file. This directive is valid for C++ 
  13068.                    programs only. 
  13069.  
  13070.  stack16           Sets the size of the stack to be allocated for calls to 
  13071.                    16-bit routines. 
  13072.  
  13073.  strings           Sets storage type for strings. 
  13074.  
  13075.  subtitle          Places text on generated source listings. 
  13076.  
  13077.  title             Places text on generated source listings. 
  13078.  
  13079.  undeclared        Used by the compiler to mark template functions that were 
  13080.                    called but never declared. This directive is valid for C++ 
  13081.                    programs only. 
  13082.  
  13083.  weak              Adds an alternate function name with weak binding for the 
  13084.                    specified function. 
  13085.  
  13086.  Related Information 
  13087.  
  13088.      #pragma Restrictions 
  13089.      Preprocessor Directives 
  13090.  
  13091.  VisualAge C++ also provides several pragmas to support the IBM System Object 
  13092.  Model (SOM), which provides a common programming interface for building and 
  13093.  using software objects. 
  13094.  
  13095.  SOM support for VisualAge C++ and the SOM pragmas are described in the IBM 
  13096.  VisualAge C++ for OS/2 User's Guide and Reference. 
  13097.  
  13098.  
  13099. ΓòÉΓòÉΓòÉ 9.13.1. #pragma Restrictions ΓòÉΓòÉΓòÉ
  13100.  
  13101. Some #pragma directives must appear in a certain place in your source, or can 
  13102. appear a limited number of times. The following table lists the restrictions 
  13103. for #pragma directives. 
  13104.  
  13105. #PRAGMA Restrictions
  13106. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13107. Γöé Table 5.                                   Γöé
  13108. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13109. Γöé #PRAGMA  Γöé RESTRICTION OF PLACE-  Γöé RESTRICTION ON NUMBER OF OCCURRENCES   Γöé
  13110. Γöé      Γöé MENT          Γöé                      Γöé
  13111. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13112. Γöé "chars"  Γöé On the first #pragma  Γöé Once                   Γöé
  13113. Γöé      Γöé directive, and before  Γöé                      Γöé
  13114. Γöé      Γöé any code or directive  Γöé                      Γöé
  13115. Γöé      Γöé (except "#line")    Γöé                      Γöé
  13116. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13117. Γöé "comment"Γöé "copyright" directive  Γöé "compiler" and "timestamp" directives   Γöé
  13118. Γöé      Γöé must appear before any Γöé can appear only once           Γöé
  13119. Γöé      Γöé code          Γöé                      Γöé
  13120. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13121. Γöé "entry"  Γöé No restriction     Γöé One per ".exe" or ".dll" If there is   Γöé
  13122. Γöé      Γöé             Γöé more than one, the result is undefined.  Γöé
  13123. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13124. Γöé "langlvl"Γöé On the first #pragma  Γöé Once                   Γöé
  13125. Γöé      Γöé directive, and before  Γöé                      Γöé
  13126. Γöé      Γöé any code or directive  Γöé                      Γöé
  13127. Γöé      Γöé (except "#line")    Γöé                      Γöé
  13128. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13129. Γöé "linkage"Γöé Before any declaration Γöé Once for each function          Γöé
  13130. Γöé      Γöé of or call to the    Γöé                      Γöé
  13131. Γöé      Γöé function        Γöé                      Γöé
  13132. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13133. Γöé "strings"Γöé Before any code     Γöé Once                   Γöé
  13134. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  13135.  
  13136.  
  13137. ΓòÉΓòÉΓòÉ 9.13.2. alloc_text ΓòÉΓòÉΓòÉ
  13138.  
  13139. The #pragma alloc_text directive lets you group functions into different 32-bit 
  13140. code segments. 
  13141.  
  13142.                       ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13143.                              Γöé
  13144. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇalloc_textΓöÇΓöÇ(ΓöÇΓöÇcode_segmentΓöÇΓöÇΓöÇΓöÇ,ΓöÇΓöÇfunctionΓöÇΓö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  13145.  
  13146. The code_segment is the name of the code segment where you want to place 
  13147. function. You can specify any number of functions to be included in the named 
  13148. code_segment. 
  13149.  
  13150. Functions that are not grouped in a code segment by #pragma alloc_text are 
  13151. placed in the default 32-bit code segment CODE32, or whatever was specified on 
  13152. the /NT option. You can also use #pragma alloc_text to explicitly place 
  13153. functions in CODE32 by specifying it as the code_segment. 
  13154.  
  13155. Defining your own code segments allows you to organize functions in memory so 
  13156. that the working set requires fewer pages of memory. You can also specify 
  13157. attributes for each segment, such as execute-only or preload. You specify 
  13158. attributes for code segments in a module definition (.DEF) file. 
  13159.  
  13160. For example, to create two code segments, one load on call, the other preload: 
  13161.  
  13162.     #pragma alloc_text(pl_seg, func1)
  13163.     #pragma alloc_text(loc_seg, func2)
  13164.  
  13165. and use the following statement in the .DEF file for the program: 
  13166.  
  13167.     SEGMENTS
  13168.  
  13169.       pl_seg PRELOAD
  13170.  
  13171. For more information on attributes and how to specify them in a .DEF file, see 
  13172. the Toolkit documentation for the ILINK program. 
  13173.  
  13174. Related Information 
  13175.  
  13176.      #pragma data_seg 
  13177.      Pragma Directives (#pragma) 
  13178.      Preprocessor Directives 
  13179.  
  13180.  
  13181. ΓòÉΓòÉΓòÉ 9.13.3. chars ΓòÉΓòÉΓòÉ
  13182.  
  13183. The #pragma chars directive specifies that the compiler is to treat all char 
  13184. objects as signed or unsigned. 
  13185.  
  13186. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇcharsΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇunsignedΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  13187.              ΓööΓöÇsignedΓöÇΓöÇΓöÇΓöÿ
  13188.  
  13189. This pragma must appear before any statements in a file. Once specified, it 
  13190. applies to the rest of the file and cannot be turned off. If a source file 
  13191. contains any functions that you want to be compiled without #pragma chars, 
  13192. place these functions in a different file. 
  13193.  
  13194. The default character type behaves like an unsigned char. 
  13195.  
  13196. Related Information 
  13197.  
  13198.      Characters 
  13199.      Pragma Directives (#pragma) 
  13200.      Preprocessor Directives 
  13201.  
  13202.  
  13203. ΓòÉΓòÉΓòÉ 9.13.4. checkout ΓòÉΓòÉΓòÉ
  13204.  
  13205. The #pragma checkout directive controls the diagnostic messages generated by 
  13206. the /Kn compiler options. 
  13207.  
  13208. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇcheckoutΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇresumeΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  13209.                ΓööΓöÇsuspendΓöÇΓöÿ
  13210.  
  13211. Use #pragma checkout to suspend the diagnostics performed by the /Kn options 
  13212. during specific portions of your program, and then resume the same level of 
  13213. diagnostics at some later point in the file. 
  13214.  
  13215. Note: 
  13216.  
  13217.    1. This directive is valid for C programs only. 
  13218.  
  13219.    2. The #pragma info directive replaces the #pragma checkout directive for 
  13220.       controlling diagnostics. It is obsolete in this release of VisualAge C++. 
  13221.       The compiler issues a message for each #pragma checkout directive it 
  13222.       encounters. You should not use it in new code; for your new applications, 
  13223.       use the #pragma info. 
  13224.  
  13225.    3. The /Wgroup options have been added to provide greater control over 
  13226.       diagnostic messages. The VisualAge C compiler maps the /Kn options to the 
  13227.       appropriate /Wgroup option. It also maps #pragma checkout to #pragma 
  13228.       info. The VisualAge C++ compiler maps the /Kn options, but ignores 
  13229.       #pragma checkout directives. 
  13230.  
  13231.       The /Kn options are obsolete in this release of VisualAge C++. You should 
  13232.       not use them in new code. For your new applications, use the /Wgroup 
  13233.       options. 
  13234.  
  13235.  Nested #pragma checkout directives are allowed and behave as follows: 
  13236.  
  13237.   /*  Assume /Kpx has been specified  */
  13238.   #pragma checkout(suspend)  /*  No diagnostics are performed */
  13239.      .
  13240.      .
  13241.      .
  13242.   #pragma checkout(suspend)  /*  No effect  */
  13243.      .
  13244.      .
  13245.      .
  13246.   #pragma checkout(resume)   /*  No effect  */
  13247.      .
  13248.      .
  13249.      .
  13250.   #pragma checkout(resume)   /*  Diagnostics continue  */
  13251.  
  13252.  The #pragma checkout directive affects all /Kn options specified. 
  13253.  
  13254.  Related Information 
  13255.  
  13256.      /Kn options 
  13257.      /Wgroup options 
  13258.      #pragma info 
  13259.      Pragma Directives (#pragma) 
  13260.      Preprocessor Directives 
  13261.  
  13262.  
  13263. ΓòÉΓòÉΓòÉ 9.13.5. comment ΓòÉΓòÉΓòÉ
  13264.  
  13265. The #pragma comment directive places a comment into the object file. 
  13266.  
  13267. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇcommentΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇcompilerΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  13268.               Γö£ΓöÇdateΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13269.               Γö£ΓöÇtimestampΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13270.               ΓööΓöÇΓö¼ΓöÇcopyrightΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  13271.                ΓööΓöÇuserΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ  ΓööΓöÇ,"token_sequence"ΓöÇΓöÿ
  13272.  
  13273. The comment type can be: 
  13274.  
  13275.  compiler       the name and version of the compiler is appended to the end of 
  13276.                 the generated object module. 
  13277.  
  13278.  date           the date and time of compilation is appended to the end of the 
  13279.                 generated object module. 
  13280.  
  13281.  timestamp      the date and time of the last modification of the source is 
  13282.                 appended to the end of the generated object module. 
  13283.  
  13284.  copyright      the text specified by the token_sequence is placed by the 
  13285.                 compiler into the generated object module and is loaded into 
  13286.                 memory when the program is run. 
  13287.  
  13288.  user           the text specified by the token_sequence is placed by the 
  13289.                 compiler into the generated object but is not loaded into 
  13290.                 memory when the program is run. 
  13291.  
  13292.  Related Information 
  13293.  
  13294.      Pragma Directives (#pragma) 
  13295.      Preprocessor Directives 
  13296.  
  13297.  
  13298. ΓòÉΓòÉΓòÉ 9.13.6. data_seg ΓòÉΓòÉΓòÉ
  13299.  
  13300. The #pragma data_seg directive lets you place static and external variables in 
  13301. different 32-bit data segments. 
  13302.  
  13303. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇdata_segΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  13304.                ΓööΓöÇdata_segmentΓöÇΓöÿ
  13305.  
  13306. All static and external variables defined after the #pragma data_seg directive 
  13307. are placed in the named data_segment. The pragma is in effect until the next 
  13308. #pragma data_seg directive or the end of the compilation unit. 
  13309.  
  13310. Restrictions: 
  13311.  
  13312.      Writable string literals used to initialize pointers are not placed in 
  13313.       the named data_segment, but in the default 32-bit data segment (DATA32). 
  13314.       To place a string in a particular data segment, use an array to 
  13315.       initialize the string instead of a pointer. For example: 
  13316.  
  13317.                char a[ ] = "mystring";
  13318.       instead of 
  13319.  
  13320.                char *a = "mystring";
  13321.  
  13322.      #pragma data_seg applies only to 32-bit data segments. Data placed in 
  13323.       16-bit segments because of the /Gt option or #pragma seg16 are not 
  13324.       affected by #pragma data_seg, and are placed in 16-bit data segments. 
  13325.  
  13326.  Static and external variables defined before the first #pragma data_seg 
  13327.  directive are placed in the default DATA32 segment, with the exception of 
  13328.  uninitialized variables and variables explicitly initialized to zero, which 
  13329.  are placed in the BSS32 segment. You can also use #pragma data_seg to 
  13330.  explicitly place variables in the DATA32 segment by specifying no 
  13331.  data_segment, for example, #pragma data_seg(). However, you cannot use the 
  13332.  CONST32_RO or BSS32 segments in a #pragma data_seg directive. 
  13333.  
  13334.  Note:  Because the variables in the BSS32 data segment are initialized at load 
  13335.  time and loaded separately from the rest of your program, they take less space 
  13336.  in your executable file. If you place these variables in a different data 
  13337.  segment, this optimization does not take place, and the size of your 
  13338.  executable module increases. For this reason, if the size of your executable 
  13339.  file is critical to you, you should define all variables initialized to zero 
  13340.  (either explicitly or by default) before the first occurrence of #pragma 
  13341.  data_seg. 
  13342.  
  13343.  Defining your own data segments allows you to group data depending on how it 
  13344.  is used and to specify different attributes for different groups of data, such 
  13345.  as when the data should be loaded. You specify attributes for data segments in 
  13346.  a module definition (.DEF) file. 
  13347.  
  13348.  For example, when you build a DLL, you might have one set of data that you 
  13349.  want to make global for all processes that use the DLL, and a different set of 
  13350.  data that you want to copy for each process. You could use #pragma data_seg to 
  13351.  place the data in two different segments as follows: 
  13352.  
  13353.      #pragma data_seg(globdata)
  13354.  
  13355.      static int counter1 = 0;
  13356.      static int counter2 = 0;
  13357.      .
  13358.      .
  13359.      .
  13360.      #pragma data_seg(instdata)
  13361.  
  13362.      static int instcount1 = 0;
  13363.      static int instcount2 = 0;
  13364.      .
  13365.      .
  13366.      .
  13367.  
  13368.  You could then place the following statements in the program's .DEF file: 
  13369.  
  13370.      SEGMENTS
  13371.         globdata CLASS 'DATA' SHARED
  13372.         instdata CLASS 'DATA' NONSHARED
  13373.  
  13374.  SHARED specifies that the data in the globdata segment is global or shared by 
  13375.  all processes that use the DLL. NONSHARED means that each process gets its own 
  13376.  copy of the data in the instdata segment. 
  13377.  
  13378.  For more information on attributes and how to specify them in a .DEF file, see 
  13379.  the Toolkit documentation for the ILINK program. 
  13380.  
  13381.  Related Information 
  13382.  
  13383.      /Gt option 
  13384.      #pragma alloc_text 
  13385.      #pragma seg16 
  13386.      Pragma Directives (#pragma) 
  13387.      Preprocessor Directives 
  13388.  
  13389.  
  13390. ΓòÉΓòÉΓòÉ 9.13.7. define ΓòÉΓòÉΓòÉ
  13391.  
  13392. The #pragma define directive forces the definition of a template class without 
  13393. actually defining an object of the class. 
  13394.  
  13395. Note:  This directive is valid for C++ programs only. 
  13396.  
  13397. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇdefineΓöÇΓöÇ(ΓöÇΓöÇtemplate_class_nameΓöÇΓöÇ)ΓöÇΓöÇ><
  13398.  
  13399. The pragma can appear anywhere that a declaration is allowed. It is used when 
  13400. organizing your program for the efficient or automatic generation of template 
  13401. functions. "Using Templates in C++ Programs" in the IBM VisualAge C++ for OS/2 
  13402. Programming Guide gives more information about using #pragma define. 
  13403.  
  13404. Related Information 
  13405.  
  13406.      C++ Templates 
  13407.      Pragma Directives (#pragma) 
  13408.      Preprocessor Directives 
  13409.      "Using Templates in C++ Programs" in the IBM VisualAge C++ for OS/2 
  13410.       Programming Guide 
  13411.  
  13412.  
  13413. ΓòÉΓòÉΓòÉ 9.13.8. entry ΓòÉΓòÉΓòÉ
  13414.  
  13415. The #pragma entry directive specifies the function to be used as the entry 
  13416. point for the application being built. 
  13417.  
  13418. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇentryΓöÇΓöÇ(ΓöÇΓöÇfunction_nameΓöÇΓöÇ)ΓöÇΓöÇ><
  13419.  
  13420. The function_name function must be in the same compilation unit as the #pragma 
  13421. entry directive, and must be a defined external function. 
  13422.  
  13423. Normally when an application is started, the OS/2 system calls the C library 
  13424. entry point. When you specify a different entry point using #pragma entry, the 
  13425. system calls that entry point and does not perform any C library initialization 
  13426. or termination. If you use #pragma entry, you must ensure that your executable 
  13427. file does not require library initialization or termination, or you must 
  13428. provide your own initialization and termination functions. 
  13429.  
  13430. Related Information 
  13431.  
  13432.      Pragma Directives (#pragma) 
  13433.      Preprocessor Directives 
  13434.  
  13435.  
  13436. ΓòÉΓòÉΓòÉ 9.13.9. export ΓòÉΓòÉΓòÉ
  13437.  
  13438. The #pragma export directive declares that a DLL function or variable is to be 
  13439. exported and specifies the name of the function or variable outside the DLL. 
  13440.  
  13441. >>ΓöÇΓöÇ#-pragma-exportΓöÇΓöÇ(ΓöÇΓöÇidentifierΓöÇΓöÇ,ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ,ΓöÇΓöÇordinalΓöÇΓöÇ)ΓöÇΓöÇ><
  13442.                     ΓööΓöÇ"ΓöÇΓöÇexport_nameΓöÇΓöÇ"ΓöÇΓöÿ
  13443.  
  13444. The identifier is the name of the function or variable in the DLL. The 
  13445. export_name is the name for identifier outside of the DLL. If no export_name is 
  13446. specified, identifier is used. 
  13447.  
  13448. The ordinal is the number of the identifier within the DLL. Another module can 
  13449. import the identifier using either the export_name or the ordinal number. 
  13450. Ordinal numbers are described in more detail in the Toolkit documentation. 
  13451.  
  13452. For example, the statements: 
  13453.  
  13454.    int deborah(int);
  13455.    #pragma export(deborah, "catherine", 4)
  13456.  
  13457. declare that the function deborah is to be exported, and can be imported by 
  13458. another module using the name catherine or the ordinal number 4. See #pragma 
  13459. import for information on importing functions and variables. 
  13460.  
  13461. You can also use the _Export keyword to export a function. If you use the 
  13462. keyword, you cannot specify a different name or an ordinal for the exported 
  13463. function. 
  13464.  
  13465. If you use #pragma export to export your function, you may still need to 
  13466. provide an EXPORTS entry for that function in your module definition (.DEF) 
  13467. file. If your function has any of the following default characteristics 
  13468.  
  13469.      Has shared data 
  13470.      Has no I/O privileges 
  13471.      Is not resident 
  13472.  
  13473.  it does not require an EXPORTS entry. If your function has characteristics 
  13474.  other than the defaults, the only way you can specify them is with an EXPORTS 
  13475.  entry in your .DEF file. 
  13476.  
  13477.  Note:  To create an import library for the DLL, you must either create it from 
  13478.  the DLL itself or provide a .DEF file with an EXPORTS entry for every 
  13479.  function, regardless of whether #pragma export is used. 
  13480.  
  13481.  For more information on DLLs and .DEF files, see the IBM VisualAge C++ for 
  13482.  OS/2 Programming Guide. 
  13483.  
  13484.  Related Information 
  13485.  
  13486.      #pragma import 
  13487.      _Export Qualifier 
  13488.      Pragma Directives (#pragma) 
  13489.      Preprocessor Directives 
  13490.  
  13491.  
  13492. ΓòÉΓòÉΓòÉ 9.13.10. handler ΓòÉΓòÉΓòÉ
  13493.  
  13494. The #pragma handler directive registers an exception handler for a function. 
  13495.  
  13496. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇhandlerΓöÇΓöÇ(ΓöÇΓöÇfunctionΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  13497.                     ΓööΓöÇ,ΓöÇΓöÇexception_handlerΓöÇΓöÿ
  13498.  
  13499. The function is the name of the function for which the exception handler is to 
  13500. be registered. You should declare it before you use it in this directive. 
  13501.  
  13502. The #pragma handler directive generates the code at compile time to install the 
  13503. VisualAge C++ exception handler _Exception before starting execution of the 
  13504. function. It also generates code to remove the exception handler at function 
  13505. exit. 
  13506.  
  13507. You must use this directive whenever you change library environments or enter a 
  13508. user-created DLL. 
  13509.  
  13510. You can remap the _Exception exception handler to another name with 
  13511. exception_handler, where exception_handler is the name of the function you 
  13512. provide that will be the exception handler for the named function. 
  13513.  
  13514. Note:  If you are using the subsystem libraries, the _Exception function is not 
  13515. provided. To use the #pragma handler directive in a subsystem, you must provide 
  13516. your own exception handler named _Exception. Otherwise, you must register and 
  13517. remove your own exception handlers using the OS/2 exception handler APIs 
  13518. described in the IBM OS/2 2.0 Programming Reference. 
  13519.  
  13520. For more information on exception handling and _Exception, see the IBM 
  13521. VisualAge C++ for OS/2 Programming Guide. 
  13522.  
  13523. Related Information 
  13524.  
  13525.      Pragma Directives (#pragma) 
  13526.      Preprocessor Directives 
  13527.  
  13528.  
  13529. ΓòÉΓòÉΓòÉ 9.13.11. hdrfile ΓòÉΓòÉΓòÉ
  13530.  
  13531. The #pragma hdrfile directive specifies the filename of the precompiled header 
  13532. to be generated and/or used. 
  13533.  
  13534. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇhdrfileΓöÇΓöÇ"file_name"ΓöÇΓöÇ><
  13535.  
  13536. It must appear before the first #include directive and either the /Fi option or 
  13537. the /Si option is specified. The /Si and /Fi options allow more than one 
  13538. precompiled header to be use for a single application. 
  13539.  
  13540. If a file name is specified both on the command line and on #pragma hdrfile, 
  13541. the name specified on the pragma takes precedence. If the name specified is a 
  13542. directory, then the the compiler searches for or generates a file with the 
  13543. default name in that directory. 
  13544.  
  13545. In order to maximize the reuse of precompiled headers, the use #pragma hdrfile 
  13546. in combination with #pragma hdrstop to manually limit the initial sequence of 
  13547. #include directives. 
  13548.  
  13549. Use precompiled header files to decrease compile time. Using precompiled 
  13550. headers will not improve compile time performance in most applications without 
  13551. some organization of the headers included by each source file. 
  13552.  
  13553. The IBM VisualAge C++ for OS/2 Programming Guide describes how to structure 
  13554. your files so the compiler can take full advantage of the precompiled headers. 
  13555.  
  13556. Examples of #pragma hdrfile Directives 
  13557.  
  13558. Related Information 
  13559.  
  13560.      /Fi option 
  13561.      /Si option 
  13562.      Precompiled header files 
  13563.      Pragma Directives (#pragma) 
  13564.      Preprocessor Directives 
  13565.  
  13566.  
  13567. ΓòÉΓòÉΓòÉ <hidden> Examples of #pragma hdrfile Directives ΓòÉΓòÉΓòÉ
  13568.  
  13569. /************************************************************************
  13570. *
  13571.  
  13572. In the following example, the headers h1.h and h2.h are precompiled using the 
  13573. file fred.pch (provided /Si or /Fi are specified). If /Fidave.pch is specified 
  13574. alone, the compiler looks for the precompiled headers in fred.pch but will not 
  13575. generate new headers. 
  13576.  
  13577.                                                                         *
  13578. ************************************************************************/
  13579.  
  13580.     #pragma hdrfile "fred.pch"
  13581.     #include "h1.h"
  13582.     #include "h2.h"
  13583.     main () {}
  13584.  
  13585. /************************************************************************
  13586. *
  13587.  
  13588. In the following example, only the header h1.h will be precompiled using the 
  13589. file fred.pch (provided /Si or /Fi are specified). If /Sidave.pch is specified 
  13590. alone, the compiler looks for the precompiled headers in fred.pch but will not 
  13591. generate new headers. 
  13592.  
  13593.                                                                         *
  13594. ************************************************************************/
  13595.  
  13596.     #pragma hdrfile "fred.pch"
  13597.     #include "h1.h"
  13598.     #pragma hdrstop
  13599.     #include "h2.h"
  13600.     main () {}
  13601.  
  13602.  
  13603. ΓòÉΓòÉΓòÉ 9.13.12. hdrstop ΓòÉΓòÉΓòÉ
  13604.  
  13605. The #pragma hdrstop directive manually terminates the initial sequence of 
  13606. #include directives being considered for precompilation. 
  13607.  
  13608. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇhdrstopΓöÇΓöÇ><
  13609.  
  13610. It has no effect if: 
  13611.  
  13612.      The initial sequence of #include directives has already ended 
  13613.      Neither the /Fi option nor the /Si option is specified 
  13614.      It does not appear in the primary source file 
  13615.  
  13616.  Use precompiled header files to decrease compile time. Using precompiled 
  13617.  headers will not improve compile time performance in most applications without 
  13618.  some organization of the headers included by each source file. 
  13619.  
  13620.  The IBM VisualAge C++ for OS/2 User's Guide and Reference describes how to 
  13621.  structure your files so the compiler can take full advantage of the 
  13622.  precompiled headers. 
  13623.  
  13624.  Examples of #pragma hdrstop Directives 
  13625.  
  13626.  Related Information 
  13627.  
  13628.      /Fi option 
  13629.      /Si option 
  13630.      Precompiled header files 
  13631.      Pragma Directives (#pragma) 
  13632.      Preprocessor Directives 
  13633.  
  13634.  
  13635. ΓòÉΓòÉΓòÉ <hidden> Examples of #pragma hdrstop Directives ΓòÉΓòÉΓòÉ
  13636.  
  13637. /************************************************************************
  13638. *
  13639.  
  13640. In the following example, only the header h1.h will be precompiled using the 
  13641. file default.pch (provided /Si or /Fi are specified). If /Sidave.pch 
  13642. /Fijohn.pch are specified, the compiler will look for the precompiled headers 
  13643. in john.pch and will regenerate them if they are not found or not usable. 
  13644.  
  13645.                                                                         *
  13646. ************************************************************************/
  13647.  
  13648.     #include "h1.h"
  13649.     #pragma hdrstop
  13650.     #include "h2.h"
  13651.     main () {}
  13652.  
  13653. /************************************************************************
  13654. *
  13655.  
  13656. In the following example, no precompiled headers will be generated or used for 
  13657. the compilation, even if /Fi or /Si are specified. 
  13658.  
  13659.                                                                         *
  13660. ************************************************************************/
  13661.  
  13662.     #pragma hdrstop
  13663.     #include "h1.h"
  13664.     #include "h2.h"
  13665.     main () {}
  13666.  
  13667.  
  13668. ΓòÉΓòÉΓòÉ 9.13.13. implementation ΓòÉΓòÉΓòÉ
  13669.  
  13670. The #pragma implementation directive tells the compiler the name of the file 
  13671. containing the function-template definitions that correspond to the template 
  13672. declarations in the include file which contains the pragma. 
  13673.  
  13674. Note:  This directive is valid for C++ programs only. 
  13675.  
  13676. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇimplementationΓöÇΓöÇ(ΓöÇΓöÇstring_literalΓöÇΓöÇ)ΓöÇΓöÇ><
  13677.  
  13678. This pragma can appear anywhere that a declaration is allowed. It is used when 
  13679. organizing your program for the efficient or automatic generation of template 
  13680. functions. "Using Templates in C++ Programs" in the IBM VisualAge C++ for OS/2 
  13681. Programming Guide gives more information about using #pragma implementation. 
  13682.  
  13683. Related Information 
  13684.  
  13685.      C++ Templates 
  13686.      Pragma Directives (#pragma) 
  13687.      Preprocessor Directives 
  13688.      "Using Templates in C++ Programs" in the IBM VisualAge C++ for OS/2 
  13689.       Programming Guide 
  13690.  
  13691.  
  13692. ΓòÉΓòÉΓòÉ 9.13.14. import ΓòÉΓòÉΓòÉ
  13693.  
  13694. The #pragma import directive lets you import a function or a variable from a 
  13695. DLL using either an ordinal number or a name different from the one that it has 
  13696. in the DLL. 
  13697.  
  13698. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇimportΓöÇΓöÇ(ΓöÇΓöÇidentifierΓöÇΓöÇ,ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ,ΓöÇΓöÇ>
  13699.                       ΓööΓöÇ"ΓöÇΓöÇexternal_nameΓöÇΓöÇ"ΓöÇΓöÿ
  13700. >ΓöÇΓöÇ"ΓöÇΓöÇmod_nameΓöÇΓöÇ"ΓöÇΓöÇ,ΓöÇΓöÇordinalΓöÇΓöÇ)ΓöÇΓöÇ><
  13701.  
  13702. The identifier is the name you use in your source to refer to the function or 
  13703. variable. The external_name is the name of the function or variable in the DLL. 
  13704. For C++ files, external_name can also be a function prototype. If external_name 
  13705. is not specified, it is assumed to be the same as identifier. 
  13706.  
  13707. Note:  Both identifier and external_name must be defined only once in each 
  13708. compilation unit. 
  13709.  
  13710. The mod_name is the name of the DLL containing the identifier, and ordinal 
  13711. indicates the position of the function or variable within the DLL. Ordinal 
  13712. numbers are described in more detail in the Toolkit documentation. 
  13713.  
  13714. The information provided by #pragma import is used at load time to locate the 
  13715. imported identifier. If ordinal is 0, the external_name is used to find the 
  13716. identifier. If ordinal is any other number, external_name is ignored and the 
  13717. identifier is located by number. It is usually faster to locate the identifier 
  13718. by number than by name. 
  13719.  
  13720. Using #pragma import decreases your link time because the linker does not 
  13721. require an import library to resolve external names. This directive is also 
  13722. useful for C++ programming because you do not have to use the fully qualified 
  13723. name to refer to an imported function or variable. 
  13724.  
  13725. Note:  You cannot use the ordinals provided in the Toolkit header files with 
  13726. #pragma import. These ordinals are provided as C macros that cannot be used in 
  13727. #pragma directives. 
  13728.  
  13729. Related Information 
  13730.  
  13731.      #pragma export 
  13732.      _Export Qualifier 
  13733.      Pragma Directives (#pragma) 
  13734.      Preprocessor Directives 
  13735.  
  13736.  
  13737. ΓòÉΓòÉΓòÉ 9.13.15. info ΓòÉΓòÉΓòÉ
  13738.  
  13739. The #pragma info directive controls the diagnostic messages generated by the 
  13740. /Wgroup compiler options. 
  13741.  
  13742. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇinfoΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇallΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  13743.             Γö£ΓöÇnoneΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13744.             Γö£ΓöÇrestoreΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13745.             Γöé ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ Γöé
  13746.             Γöé       Γöé Γöé
  13747.             ΓööΓöÇΓöÇΓö¼ΓöÇgroupΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÿ
  13748.               ΓööΓöÇnogroupΓöÇΓöÿ
  13749.  
  13750. The #pragma info directive replaces the #pragma checkout directive for 
  13751. controlling diagnostics. You can use this pragma directive in place of the 
  13752. /Wgroup option. Specifying #pragma info(group) causes all messages associated 
  13753. with that diagnostic group to be generated. Specifying #pragma info(nogroup) 
  13754. suppresses all messages associated with that group. 
  13755.  
  13756. For example, to generate messages for missing function prototypes and 
  13757. statements with no effect, but not for uninitialized variables, specify: 
  13758.  
  13759.    #pragma info(pro, eff, nouni)
  13760.  
  13761. The #pragma directive overrides any /Wgroup options stated on the command line. 
  13762.  
  13763. Use #pragma info(all) to turn on all diagnostic checking. Use #pragma 
  13764. info(none) to turn off all diagnostic suboptions for specific portions of your 
  13765. program. Specifying #pragma info(restore) restores the options that were in 
  13766. effect before the previous #pragma info directive. 
  13767.  
  13768. Because #pragma info operates like a stack, the options restored may not be 
  13769. those given on the command line. If no options were previously in effect, 
  13770. #pragma info(restore) does nothing. 
  13771.  
  13772. The following list explains the groups of diagnostic messages controlled by 
  13773. each group option: 
  13774.  
  13775.  Group   Diagnostics 
  13776.  cmp     Possible redundancies in unsigned comparisons. 
  13777.  cnd     Possible redundancies or problems in conditional expressions. 
  13778.  cns     Operations involving constants. 
  13779.  cnv     Conversions. 
  13780.  dcl     Consistency of declarations. 
  13781.  eff     Statements with no effect. 
  13782.  enu     Consistency of enum variables. 
  13783.  ext     Unused external definitions. 
  13784.  gen     General diagnostics. 
  13785.  got     Usage of goto statements. 
  13786.  ini     Possible problems with initialization. 
  13787.  lan     Effects of the language level. 
  13788.  obs     Features that are obsolete. 
  13789.  ord     Unspecified order of evaluation. 
  13790.  par     Unused parameters. 
  13791.  por     Nonportable language constructs. 
  13792.  ppc     Possible problems with using the preprocessor. 
  13793.  ppt     Trace of preprocessor actions. 
  13794.  pro     Missing function prototypes. 
  13795.  rea     Code that cannot be reached. 
  13796.  ret     Consistency of return statements. 
  13797.  trd     Possible truncation or loss of data or precision. 
  13798.  tru     Variable names truncated by the compiler. 
  13799.  uni     Uninitialized variables. 
  13800.  use     Unused auto and static variables. 
  13801.  
  13802.  The /Wgroup options are described in the IBM VisualAge C++ for OS/2 User's 
  13803.  Guide and Reference. 
  13804.  
  13805.  Related Information 
  13806.  
  13807.      #pragma checkout 
  13808.      /Wgroup option 
  13809.      /Kn options 
  13810.      Pragma Directives (#pragma) 
  13811.      Preprocessor Directives 
  13812.  
  13813.  
  13814. ΓòÉΓòÉΓòÉ 9.13.16. langlvl ΓòÉΓòÉΓòÉ
  13815.  
  13816. The #pragma langlvl directive lets you select elements of VisualAge C++ 
  13817. implementation. 
  13818.  
  13819.                ΓöîΓöÇextendedΓöÇΓöÉ
  13820. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇlanglvlΓöÇΓöÇ(ΓöÇΓöÇΓö╝ΓöÇansiΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇ)ΓöÇΓöÇ><
  13821.                Γö£ΓöÇcompatΓöÇΓöÇΓöÇΓöñ
  13822.                Γö£ΓöÇsaaΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13823.                ΓööΓöÇsaal2ΓöÇΓöÇΓöÇΓöÇΓöÿ
  13824.  
  13825. This directive can be specified only once in your source file, and must appear 
  13826. before any C code. 
  13827.  
  13828. The compiler defines preprocessor variables that are used in header files to 
  13829. define the language level. The options are: 
  13830.  
  13831.  extended    Defines the preprocessor variable __EXTENDED__. Allows ANSI and 
  13832.              SAA C constructs and all VisualAge C++ extensions. 
  13833.  
  13834.  ansi        Defines the preprocessor variables __ANSI__ and __STDC__. Allows 
  13835.              only language constructs that conform to ANSI C standards. Note 
  13836.              that for C++, the __STDC__ macro is set to 0, while for C it is 
  13837.              set to 1. 
  13838.  
  13839.  compat      Defines the preprocessor variable __COMPAT__. Allows constructs 
  13840.              supported by earlier versions of the C++ language, as well as ANSI 
  13841.              constructs and VisualAge C++ extensions. This language level is 
  13842.              valid for C++ programs only. 
  13843.  
  13844.  saa         Defines the preprocessor variables __SAA__ and __SAAL2__. Allows 
  13845.              only language constructs that conform to the most recent level of 
  13846.              SAA C standards (currently Level 2). These include ANSI C 
  13847.              constructs. This language level is valid for C programs only. 
  13848.  
  13849.  saal2       Defines the preprocessor variable __SAAL2__. Allows only language 
  13850.              constructs that conform to SAA Level 2 C standards. These include 
  13851.              ANSI C constructs. This language level is valid for C programs 
  13852.              only. 
  13853.  
  13854.  The default language level is extended. 
  13855.  
  13856.  You can also set the language level using the /Sa, /Sc, /S2, and /Se compiler 
  13857.  options. These options are described in /S options 
  13858.  
  13859.  Related Information 
  13860.  
  13861.      /Sa, /Sc, /S2, /Se options 
  13862.      Predefined Macro Names 
  13863.      Pragma Directives (#pragma) 
  13864.      Preprocessor Directives 
  13865.  
  13866.  
  13867. ΓòÉΓòÉΓòÉ 9.13.17. library ΓòÉΓòÉΓòÉ
  13868.  
  13869. The #pragma library directive causes the compiler to insert an INCLUDELIB 
  13870. library search record into the object file. This tells the linker to pull in 
  13871. the appropriate libraries at link time. 
  13872.  
  13873. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇlibraryΓöÇΓöÇ(ΓöÇΓöÇ"library_name"ΓöÇΓöÇ)ΓöÇΓöÇ><
  13874.  
  13875. where library_name is the default library to be made available for the program. 
  13876.  
  13877. The library names specified by #pragma library are imbedded in INCLUDELIB 
  13878. library search records in the order that they are encountered in the source. 
  13879. The library search records are inserted into the object file before the default 
  13880. library search records, so that the behaviour at link time is the same as if 
  13881. the library name were specified at link time. 
  13882.  
  13883. Related Information 
  13884.  
  13885.      Pragma Directives (#pragma) 
  13886.      Preprocessor Directives 
  13887.  
  13888.  
  13889. ΓòÉΓòÉΓòÉ 9.13.18. linkage ΓòÉΓòÉΓòÉ
  13890.  
  13891. The #pragma linkage directive identifies the linkage or calling convention used 
  13892. on a function call. 
  13893.  
  13894. Note: 
  13895.  
  13896.    1. This directive is valid for C programs only. 
  13897.  
  13898.    2. It is obsolete in this release of VisualAge C++. Avoid using it in new 
  13899.       code. For your new applications, use linkage keywords to specify the 
  13900.       calling convention for a function. Linkage keywords are easier to use 
  13901.       than is the #pragma linkage directive, and they let you declare both the 
  13902.       function and its linkage type in one statement. See Linkage Keywords for 
  13903.       more information on these keywords. 
  13904.  
  13905.                        ΓöîΓöÇoptlinkΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  13906.   >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇpragma-linkage-(ΓöÇΓöÇidentifier-,ΓöÇΓöÇΓö╝ΓöÇsystemΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇ)ΓöÇΓöÇ><
  13907.                       Γö£ΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇpascalΓöÇΓöÇΓöÇΓöÇΓöñ
  13908.                       Γöé ΓööΓöÇfar32ΓöÇΓöÿ       Γöé
  13909.                       ΓööΓöÇfar16ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  13910.                            Γö£ΓöÇcdeclΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  13911.                            Γö£ΓöÇ_cdeclΓöÇΓöÇΓöÇΓöÇΓöñ
  13912.                            Γö£ΓöÇpascalΓöÇΓöÇΓöÇΓöÇΓöñ
  13913.                            Γö£ΓöÇ_pascalΓöÇΓöÇΓöÇΓöñ
  13914.                            Γö£ΓöÇfastcallΓöÇΓöÇΓöñ
  13915.                            ΓööΓöÇ_fastcallΓöÇΓöÿ
  13916.  
  13917.  The identifier identifies either the name of the function that will be given 
  13918.  the particular linkage type or the name of a typedef that resolves to a 
  13919.  function type. If identifier is a typedef, any function declared using 
  13920.  identifier will be given the particular linkage type. 
  13921.  
  13922.  The following example shows how to use a typedef to declare functions and 
  13923.  pointers to functions of _System linkage: 
  13924.  
  13925.      #pragma linkage(functype, system)
  13926.  
  13927.      typedef int functype(int);
  13928.  
  13929.      functype f;     /* f is a function with _System linkage */
  13930.      functype *fp;   /* fp is a pointer to a function with _System linkage */
  13931.  
  13932.  The VisualAge C++ default linkage is _Optlink, which is a convention specific 
  13933.  to the VisualAge C++ product. If your program calls OS/2 APIs, you must use 
  13934.  the _System calling convention, which is standard for all OS/2 applications to 
  13935.  call those APIs. If you include the system header files, the OS/2 APIs are 
  13936.  automatically given _System linkage. 
  13937.  
  13938.  If you are developing device drivers, you should use the _Pascal convention. 
  13939.  You should use the _Far32 version of _Pascal linkage if your calls will cross 
  13940.  code segments. Note that _Far32 _Pascal linkage is only available when you 
  13941.  specify the /Gr+ option to generate code that runs at ring zero. 
  13942.  
  13943.  The _Far16 linkage conventions indicate that a function has a 16-bit linkage 
  13944.  type. The cdecl and _cdecl options are equivalent. The underscore is optional, 
  13945.  and is accepted for compatibility with C/2 cdecl linkage declarations. 
  13946.  Similarly, pascal and _pascal are equivalent, and specify C/2 pascal linkage; 
  13947.  fastcall and _fastcall specify Microsoft** _fastcall linkage. If far16 is 
  13948.  specified without a parameter, __cdecl linkage is used. 
  13949.  
  13950.  You can use compiler options to explicitly set the calling convention to 
  13951.  _Optlink (/Mp) or to change the default to _System linkage (/Ms). A linkage 
  13952.  keyword or #pragma linkage directive overrides the compiler option. 
  13953.  
  13954.  For more information about calling conventions, see the IBM VisualAge C++ for 
  13955.  OS/2 Programming Guide. 
  13956.  
  13957.  Related Information 
  13958.  
  13959.      /Mp, /Ms options 
  13960.      Linkage Keywords 
  13961.      typedef 
  13962.      Pragma Directives (#pragma) 
  13963.      Preprocessor Directives 
  13964.  
  13965.  
  13966. ΓòÉΓòÉΓòÉ 9.13.19. map ΓòÉΓòÉΓòÉ
  13967.  
  13968. The #pragma map directive tells the compiler that all references to an 
  13969. identifier are to be converted to "name". 
  13970.  
  13971. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇmapΓöÇΓöÇ>
  13972. >ΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ,ΓöÇΓöÇ"name"ΓöÇΓöÇ)ΓöÇΓöÇ><
  13973.    ΓööΓöÇfunc_or_op_identifierΓöÇΓöÇ(ΓöÇΓöÇargument_listΓöÇΓöÇ)ΓöÇΓöÿ
  13974.  
  13975.  identifier             a name of a data object or a nonoverloaded function 
  13976.                         with external linkage. 
  13977.  
  13978.  func_or_op_identifier  a name of a function or operator with internal linkage. 
  13979.                         The name can be qualified. 
  13980.  
  13981.  argument_list          a prototype list for the named function or operator. 
  13982.  
  13983.  name                   the external name that is to be bound to the given 
  13984.                         object, function or operator. 
  13985.  
  13986.  The directive can appear anywhere in the source file within a single 
  13987.  compilation unit. It can appear before any declaration or definition of the 
  13988.  named object, function, or operator. The identifers appearing in the 
  13989.  directive, including any type names used in the prototype argument list, are 
  13990.  resolved as though the directive had appeared at file scope, independent of 
  13991.  its actual point of occurrence. 
  13992.  
  13993.  For example: 
  13994.  
  13995.   int func(int);
  13996.  
  13997.   class X
  13998.   {
  13999.   public:
  14000.         void func(void);
  14001.   #pragma map(func, "funcname1")    // maps ::func
  14002.   #pragma map(X::func, "funcname2") // maps X::func
  14003.   };
  14004.  
  14005.  You should not use #pragma map to map member functions, overloaded functions, 
  14006.  or objects generated from templates. Such mappings override the 
  14007.  compiler-generated mangled names, which could cause binder errors. If mangled 
  14008.  names are overridden with #pragma map, the compiler issues a warning message. 
  14009.  
  14010.  Related Information 
  14011.  
  14012.      Pragma Directives (#pragma) 
  14013.      Preprocessor Directives 
  14014.  
  14015.  
  14016. ΓòÉΓòÉΓòÉ 9.13.20. margins ΓòÉΓòÉΓòÉ
  14017.  
  14018. The #pragma margins directive specifies the columns in the input line that are 
  14019. to be scanned for input to the compiler. 
  14020.  
  14021. Note:  This directive is valid for C programs only. 
  14022.  
  14023.          ΓöîΓöÇnomarginsΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14024. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇΓö┤ΓöÇmarginsΓöÇΓöÇ(ΓöÇΓöÇleftΓöÇΓöÇ,ΓöÇΓöÇrightΓöÇΓöÇ)ΓöÇΓö┤ΓöÇΓöÇ><
  14025.  
  14026. Use the #pragma margins directive if you want to have characters outside 
  14027. certain columns ignored in your source file. The compiler ignores any text in 
  14028. the source input that does not fall within the range specified in the 
  14029. directive. 
  14030.  
  14031. The variable left specifies the first column of the source input that is to be 
  14032. scanned, and must be between 1 and 65535, inclusive. The variable right 
  14033. specifies the last column of the source input that is to be scanned. It must be 
  14034. greater than or equal to left and less than or equal to 65535. An asterisk (*) 
  14035. can be assigned to right to indicate the last column of input. 
  14036.  
  14037. By default, the left margin is set to 1, and the right margin is set to 
  14038. infinity. The default for this directive is #pragma margins(), which has the 
  14039. effect of setting the right margin to infinity. 
  14040.  
  14041. The #pragma margins directive can be used with the #pragma sequence directive 
  14042. to specify the columns that are not to be scanned for sequence numbers. If the 
  14043. #pragma sequence settings do not fall within the #pragma margins settings, the 
  14044. #pragma sequence directive has no effect. 
  14045.  
  14046. You can also set margins using the /Sg option. 
  14047.  
  14048. Related Information 
  14049.  
  14050.      /Sg option 
  14051.      #pragma sequence 
  14052.      Pragma Directives (#pragma) 
  14053.      Preprocessor Directives 
  14054.  
  14055.  
  14056. ΓòÉΓòÉΓòÉ 9.13.21. pack ΓòÉΓòÉΓòÉ
  14057.  
  14058. The #pragma pack directive specifies the alignment rules to use for the 
  14059. structures, unions, and classes that follow it. In C++, packing is performed on 
  14060. declarations or types. This is different from C, where packing is also 
  14061. performed on definitions. 
  14062.  
  14063. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇpackΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14064.             Γö£ΓöÇ1ΓöÇΓöñ
  14065.             Γö£ΓöÇ2ΓöÇΓöñ
  14066.             ΓööΓöÇ4ΓöÇΓöÿ
  14067.  
  14068. The #pragma pack directive causes all structures, unions and classes that 
  14069. follow it in the program to be packed along a 1-byte, 2-byte, or 4-byte 
  14070. boundary, according to the value specified in the directive, until another 
  14071. #pragma pack directive changes the packing boundary. 
  14072.  
  14073. Packing along a 4-byte boundary is the system default. 
  14074.  
  14075. If no value is specified, packing is performed along the system default 
  14076. boundary unless the /Sp compiler option was used. If it is used, #pragma pack() 
  14077. causes packing to be performed along the boundary specified by /Sp. 
  14078.  
  14079. For example: 
  14080.  
  14081.    #pragma pack(1)
  14082.  
  14083.    struct hester{       /* this structure is packed */
  14084.      char philip;       /*    along 1-byte boundaries    */
  14085.      int mark;
  14086.    };
  14087.    .
  14088.    .
  14089.    .
  14090.    #pragma pack(2)
  14091.  
  14092.    struct jeff{         /* this structure is packed */
  14093.      float bill;        /*    along 2-byte boundaries    */
  14094.      int *chris;
  14095.    }
  14096.    .
  14097.    .
  14098.    .
  14099.    #pragma pack()
  14100.  
  14101.    struct dor{          /* this structure is packed  */
  14102.      double stephen;    /* along the default boundaries   */
  14103.      long alex;
  14104.    }
  14105.  
  14106.  
  14107. Note:  If data types are by default packed along boundaries smaller than those 
  14108. specified by #pragma pack, they are still aligned along the smaller boundaries. 
  14109. For example, type char is always aligned along a 1-byte boundary, regardless of 
  14110. the value of #pragma pack. 
  14111.  
  14112. The following table describes how each data type is packed for each of the 
  14113. #pragma pack options: 
  14114.  
  14115. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14116. Γöé   DATA TYPE   Γöé    #PRAGMA PACK VALUE   Γöé
  14117. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14118. Γöé         Γöé   1   Γöé   2   Γöé   4   Γöé
  14119. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14120. Γöé char       Γöé   1   Γöé   1   Γöé   1   Γöé
  14121. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14122. Γöé short      Γöé   1   Γöé   2   Γöé   2   Γöé
  14123. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14124. Γöé int, long    Γöé   1   Γöé   2   Γöé   4   Γöé
  14125. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14126. Γöé float, double,  Γöé   1   Γöé   2   Γöé   4   Γöé
  14127. Γöé long double   Γöé     Γöé     Γöé     Γöé
  14128. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  14129. Γöé pointer     Γöé   1   Γöé   2   Γöé   4   Γöé
  14130. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  14131.  
  14132. Note:  If more than one #pragma pack directive appears in a structure defined 
  14133. in an inline function, the #pragma pack directive effective at the beginning of 
  14134. the class takes precedence. 
  14135.  
  14136. For more information on the alignment of data types in structures, see the IBM 
  14137. VisualAge C++ for OS/2 Programming Guide. 
  14138.  
  14139. Related Information 
  14140.  
  14141.      /Sp option 
  14142.      _Packed Qualifier 
  14143.      Structures 
  14144.      Type Specifiers 
  14145.      Pragma Directives (#pragma) 
  14146.      Preprocessor Directives 
  14147.  
  14148.  
  14149. ΓòÉΓòÉΓòÉ 9.13.22. page ΓòÉΓòÉΓòÉ
  14150.  
  14151. The #pragma page directive skips the number of pages specified by pages of the 
  14152. generated source listing. If pages is not specified, the next page is started. 
  14153.  
  14154. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇpageΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14155.             ΓööΓöÇpagesΓöÇΓöÿ
  14156.  
  14157. Related Information 
  14158.  
  14159.      Pragma Directives (#pragma) 
  14160.      Preprocessor Directives 
  14161.  
  14162.  
  14163. ΓòÉΓòÉΓòÉ 9.13.23. pagesize ΓòÉΓòÉΓòÉ
  14164.  
  14165. The #pragma pagesize directive sets the number of lines per page to lines for 
  14166. the generated source listing. 
  14167.  
  14168. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇpagesizeΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14169.                ΓööΓöÇlinesΓöÇΓöÿ
  14170.  
  14171. The value of lines must be between 16 and 32767, inclusive. The default page 
  14172. length is 66 lines. 
  14173.  
  14174. You can also use the /Lp compiler option to set the listing page size. 
  14175.  
  14176. Related Information 
  14177.  
  14178.      /Lp option 
  14179.      Pragma Directives (#pragma) 
  14180.      Preprocessor Directives 
  14181.  
  14182.  
  14183. ΓòÉΓòÉΓòÉ 9.13.24. priority ΓòÉΓòÉΓòÉ
  14184.  
  14185. The #pragma priority directive specifies the order in which static objects are 
  14186. to be initialized at run time. 
  14187.  
  14188. Note:  This directive is valid for C++ programs only. 
  14189.  
  14190. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇpriorityΓöÇΓöÇ(ΓöÇΓöÇnΓöÇΓöÇ)ΓöÇΓöÇ><
  14191.  
  14192. Where n is an integer literal in the range of INT_MIN to INT_MAX. The default 
  14193. value is 0. A negative value indicates a higher priority; a positive value 
  14194. indicates a lower priority. 
  14195.  
  14196. The first 1024 priorities (INT_MIN to INT_MIN + 1023) are reserved for use by 
  14197. the compiler and its libraries. The priority value specified applies to all 
  14198. runtime static initialization in the current compilation unit. 
  14199.  
  14200. Any global object declared before another object in a file is constructed 
  14201. first. Use #pragma priority to specify the construction order of objects across 
  14202. files. 
  14203.  
  14204. To ensure that the objects are always constructed from top to bottom in a file, 
  14205. the compiler enforces the restriction that the priority specified all objects 
  14206. before and all objects after it until the next #pragma is at that priority. 
  14207.  
  14208. Related Information 
  14209.  
  14210.      Pragma Directives (#pragma) 
  14211.      Preprocessor Directives 
  14212.  
  14213.  
  14214. ΓòÉΓòÉΓòÉ 9.13.25. seg16 ΓòÉΓòÉΓòÉ
  14215.  
  14216. The #pragma seg16 directive specifies that a data object will be shared between 
  14217. 16-bit and 32-bit processes. 
  14218.  
  14219. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇseg16ΓöÇΓöÇ(ΓöÇΓöÇidentifierΓöÇΓöÇ)ΓöÇΓöÇ><
  14220.  
  14221. It causes the compiler to lay out the identifier in memory so that it does not 
  14222. cross a 64K boundary. The identifier can then be used in a 16-bit program. 
  14223.  
  14224. The identifier can be a typedef or a data object. For example: 
  14225.  
  14226.    typedef struct foo foostr;
  14227.    #pragma seg16(foostr)
  14228.    foostr  quux;
  14229.  
  14230. uses the typedef foostr to declare quux as an object addressable by a 16-bit 
  14231. program. 
  14232.  
  14233. You can also use the /Gt compiler option to perform the equivalent of a #pragma 
  14234. seg16 for all variables in the program. 
  14235.  
  14236. Note:  If #pragma seg16 is used on variables of a structure type, the pointers 
  14237. inside that structure are not automatically qualified as usable by 16-bit 
  14238. programs. If you want the pointers in the structure qualified as such, you must 
  14239. declare them using the _Seg16 type qualifier. 
  14240.  
  14241. See _Seg16 Type Qualifier for more information about _Seg16. For more 
  14242. information on calling 16-bit programs, see the IBM VisualAge C++ for OS/2 
  14243. Programming Guide. 
  14244.  
  14245. Related Information 
  14246.  
  14247.      /Gt option 
  14248.      _Seg16 Type Qualifier 
  14249.      Structures 
  14250.      typedef 
  14251.      Pragma Directives (#pragma) 
  14252.      Preprocessor Directives 
  14253.  
  14254.  
  14255. ΓòÉΓòÉΓòÉ 9.13.26. sequence ΓòÉΓòÉΓòÉ
  14256.  
  14257. The #pragma sequence directive defines the section of the input line that is to 
  14258. contain sequence numbers. 
  14259.  
  14260. Note:  This directive is valid for C programs only. 
  14261.  
  14262.          ΓöîΓöÇnosequenceΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  14263. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇΓö┤ΓöÇsequenceΓöÇΓöÇ(ΓöÇΓöÇleftΓöÇΓöÇ,ΓöÇΓöÇrightΓöÇΓöÇ)ΓöÇΓö┤ΓöÇΓöÇ><
  14264.  
  14265. If you are using a source file produced on a system that uses sequence numbers, 
  14266. you can use this option to have the sequence numbers ignored. 
  14267.  
  14268. The variable left specifies the column number of the left-hand margin. The 
  14269. value of left must be between 1 and 65535 inclusive, and must also be less than 
  14270. or equal to the value of right. The variable right specifies the column number 
  14271. of the right-hand margin. The value of right must be greater than or equal to 
  14272. left and less than or equal to 65535. An asterisk (*) can be assigned to right 
  14273. to indicate the last column of the line. 
  14274.  
  14275. The default for this directive is nosequence, which specifies there are no 
  14276. sequence numbers. 
  14277.  
  14278. The #pragma sequence directive can be used with the #pragma margins directive 
  14279. to specify the columns that are not to be scanned. If the #pragma sequence 
  14280. settings do not fall within the #pragma margins settings, the sequence 
  14281. directive has no effect. 
  14282.  
  14283. You can also set sequence numbers using the /Sq option. 
  14284.  
  14285. Related Information 
  14286.  
  14287.      /Sq option 
  14288.      #pragma margins 
  14289.      Pragma Directives (#pragma) 
  14290.      Preprocessor Directives 
  14291.  
  14292.  
  14293. ΓòÉΓòÉΓòÉ 9.13.27. skip ΓòÉΓòÉΓòÉ
  14294.  
  14295. The #pragma skip directive skips the specified number of lines of the generated 
  14296. source listing. The value of lines must be a positive integer less than 255. If 
  14297. lines is omitted, one line is skipped. 
  14298.  
  14299. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇskipΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14300.             ΓööΓöÇlinesΓöÇΓöÿ
  14301.  
  14302. Related Information 
  14303.  
  14304.      Pragma Directives (#pragma) 
  14305.      Preprocessor Directives 
  14306.      /L options 
  14307.  
  14308.  
  14309. ΓòÉΓòÉΓòÉ 9.13.28. sourcedir ΓòÉΓòÉΓòÉ
  14310.  
  14311. The #pragma sourcedir directive defines a new path to the directory containing 
  14312. the original source from which the compiler generates files in the TEMPINC 
  14313. directory. 
  14314.  
  14315. Note:  This directive is valid for C++ programs only. 
  14316.  
  14317. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇsourcedirΓöÇΓöÇ(ΓöÇΓöÇpathΓöÇΓöÇ)ΓöÇΓöÇ><
  14318.  
  14319. Instead of searching the TEMPINC directory first for the original source of the 
  14320. include file, the pragma directs the compiler to the directory specified by the 
  14321. supplied path. The compiler automatically inserts the necessary #pragma 
  14322. sourcedir directives into the source files it generates in the TEMPINC 
  14323. directory. 
  14324.  
  14325. Related Information 
  14326.  
  14327.      Pragma Directives (#pragma) 
  14328.      Preprocessor Directives 
  14329.  
  14330.  
  14331. ΓòÉΓòÉΓòÉ 9.13.29. stack16 ΓòÉΓòÉΓòÉ
  14332.  
  14333. The #pragma stack16 directive specifies the size of the stack to be allocated 
  14334. for calls to 16-bit routines. 
  14335.  
  14336. >>ΓöÇΓöÇΓöÇ#ΓöÇΓöÇΓöÇpragmaΓöÇΓöÇstack16ΓöÇΓöÇ(ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ><
  14337.                ΓööΓöÇsizeΓöÇΓöÿ
  14338.  
  14339. The variable size is the size of the stack in bytes, and has a value between 
  14340. 512 and 65532. The size specified applies to any 16-bit functions called from 
  14341. that point until the end of the compilation unit, or until another #pragma 
  14342. stack16 directive is given. 
  14343.  
  14344. The default value is 4096 bytes (4K). Note that the 16-bit stack is taken from 
  14345. the 32-bit stack allocated for the thread calling the 16-bit code. The 32-bit 
  14346. stack is therefore reduced by the amount you specify with #pragma stack16. Make 
  14347. sure your 32-bit stack is large enough for both your 32-bit and 16-bit code. 
  14348.  
  14349. If the sum of the size, the number of bytes for parameters, and the number of 
  14350. local bytes in the function calling the 16-bit routine is greater than 65532, 
  14351. the actual stack size will be 65532 bytes less the number of parameter and 
  14352. local bytes. If the sum of the parameter bytes and local bytes alone is greater 
  14353. than 65532, no bytes will be allocated for calls to 16-bit routines. 
  14354.  
  14355. Related Information 
  14356.  
  14357.      Pragma Directives (#pragma) 
  14358.      Preprocessor Directives 
  14359.  
  14360.  
  14361. ΓòÉΓòÉΓòÉ 9.13.30. strings ΓòÉΓòÉΓòÉ
  14362.  
  14363. The #pragma strings directive sets the storage type for strings. It specifies 
  14364. that the compiler can place strings into read-only memory or must place strings 
  14365. into read/write memory. 
  14366.  
  14367.               ΓöîΓöÇwriteableΓöÇΓöÉ
  14368. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇstringsΓöÇΓöÇ(ΓöÇΓöÇΓö┤ΓöÇreadonlyΓöÇΓöÇΓö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  14369.  
  14370. C strings are read/write by default. C++ strings are readonly by default. This 
  14371. pragma must appear before any C or C++ code in a file. 
  14372.  
  14373. Related Information 
  14374.  
  14375.      String Literals 
  14376.      Pragma Directives (#pragma) 
  14377.      Preprocessor Directives 
  14378.  
  14379.  
  14380. ΓòÉΓòÉΓòÉ 9.13.31. subtitle ΓòÉΓòÉΓòÉ
  14381.  
  14382. The #pragma subtitle directive places the text specified by subtitle on all 
  14383. subsequent pages of the generated source listing. 
  14384.  
  14385. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇsubtitleΓöÇΓöÇ(ΓöÇΓöÇ"subtitle"ΓöÇΓöÇ)ΓöÇΓöÇ><
  14386.  
  14387. The string subtitle must be less than 255 characters. 
  14388.  
  14389. You can also use the /Lu compiler option to specify the listing subtitle. 
  14390.  
  14391. Related Information 
  14392.  
  14393.      /Lu option 
  14394.      #pragma title 
  14395.      Pragma Directives (#pragma) 
  14396.      Preprocessor Directives 
  14397.  
  14398.  
  14399. ΓòÉΓòÉΓòÉ 9.13.32. title ΓòÉΓòÉΓòÉ
  14400.  
  14401. The #pragma title directive places the text specified by title on all 
  14402. subsequent pages of the generated source listing. 
  14403.  
  14404. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇtitleΓöÇΓöÇ(ΓöÇΓöÇ"title"ΓöÇΓöÇ)ΓöÇΓöÇ><
  14405.  
  14406. The string title must be less than 255 characters. 
  14407.  
  14408. You can also use the /Lt compiler option to specify the listing title. 
  14409.  
  14410. Related Information 
  14411.  
  14412.      /Lt option 
  14413.      #pragma subtitle 
  14414.      Pragma Directives (#pragma) 
  14415.      Preprocessor Directives 
  14416.  
  14417.  
  14418. ΓòÉΓòÉΓòÉ 9.13.33. undeclared ΓòÉΓòÉΓòÉ
  14419.  
  14420. The #pragma undeclared directive is used only by the compiler and only in 
  14421. template-include files. It is valid for C++ programs only. 
  14422.  
  14423. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇundeclaredΓöÇΓöÇ><
  14424.  
  14425. In the template-include file, template functions that were explicitly declared 
  14426. in at least one compilation unit appear before this line. Template functions 
  14427. that were called, but never declared, appear after this line. 
  14428.  
  14429. For more information on template-include files, see "Using Templates in C++ 
  14430. Programs" in the Programming Guide. 
  14431.  
  14432. Related Information 
  14433.  
  14434.      Pragma Directives (#pragma) 
  14435.      Preprocessor Directives 
  14436.  
  14437.  
  14438. ΓòÉΓòÉΓòÉ 9.13.34. weak ΓòÉΓòÉΓòÉ
  14439.  
  14440. The #pragma weak directive adds an alternate function name with weak binding 
  14441. for the function function_name. 
  14442.  
  14443. >>ΓöÇΓöÇ#ΓöÇΓöÇpragmaΓöÇΓöÇweakΓöÇΓöÇ(ΓöÇΓöÇfunction_nameΓöÇΓöÇ,ΓöÇΓöÇbackup_function_nameΓöÇΓöÇ)ΓöÇΓöÇ><
  14444.  
  14445. If the definition for the function function_name is not found, the linker 
  14446. resolves the function call to the definition for the function 
  14447. backup_function_name. If the definition for function_name is found, the linker 
  14448. resolves the function call to the definition for function_name. 
  14449.  
  14450. If function_name is not referenced, neither function_name nor 
  14451. backup_function_name. needs to be declared. 
  14452.  
  14453. If function_name is referenced, both function_name and backup_function_name. 
  14454. must be declared. 
  14455.  
  14456. Note:  Both functions must have full prototypes within the compilation unit. 
  14457. Neither function can be a C++ member function. 
  14458.  
  14459. In the following example, after the program is linked, the call to 
  14460. specialization resolves to the definition of generalization because no 
  14461. definition of specialization exists. 
  14462.  
  14463. #include <stdio.h>
  14464. int generalization(int i) {
  14465.   printf("in generalization\n");
  14466. }
  14467. #pragma weak (specialization, generalization)
  14468.  
  14469. int main() {
  14470.   printf("in main\n");
  14471.   return specialization(6);
  14472. }
  14473.  
  14474. Related Information 
  14475.  
  14476.      Pragma Directives (#pragma) 
  14477.      Preprocessor Directives 
  14478.  
  14479.  
  14480. ΓòÉΓòÉΓòÉ 10. C++ Classes ΓòÉΓòÉΓòÉ
  14481.  
  14482. A C++ class is a mechanism for creating user-defined data types. It is similar 
  14483. to the C-language structure data type. In C, a structure is composed of a set 
  14484. of data members. In C++, a class type is like a C structure, except that a 
  14485. class is composed of a set of data members and an optional set of operations 
  14486. that can be performed on the class. 
  14487.  
  14488. In C++, a class type can be declared with the keywords union, struct, or class. 
  14489. A union object can hold any one of a set of named members. Structure and class 
  14490. objects hold a complete set of members. Each class type represents a unique set 
  14491. of class members including data members, member functions, and other type 
  14492. names. The default access for members depends on the class key: 
  14493.  
  14494.      The members of a class declared with the class key class are private by 
  14495.       default. A class is inherited privately by default. 
  14496.      The members of a class declared with the class key struct are public be 
  14497.       default. A structure is inherited publicly by default. 
  14498.      The members of a union (declared with the class key union) are public by 
  14499.       default. A union cannot be used as a base class in derivation. Base 
  14500.       classes and derivation are described in C++ Inheritance. 
  14501.  
  14502.  Once you create a class type, you can declare one or more objects of that 
  14503.  class type. 
  14504.  
  14505.  For example: 
  14506.  
  14507.   class X
  14508.   { /* define class members here */ };
  14509.   void main()
  14510.   {
  14511.         X xobject1;       // create an object of class type X
  14512.         X xobject2;       // create another object of class type X
  14513.   }
  14514.  
  14515.  This chapter discusses the following topics: 
  14516.  
  14517.      Declaring Class Objects 
  14518.      Scope of Class Names 
  14519.  
  14520.  Classes are also used in C++ to support polymorphic functions through 
  14521.  overloaded functions (static compile time binding) and virtual functions 
  14522.  (dynamic binding). C++ allows you to redefine standard operators and functions 
  14523.  through the concept of overloading. Operator overloading facilitates data 
  14524.  abstraction by allowing you to use classes as easily as built-in types. 
  14525.  
  14526.  Related Information 
  14527.  
  14528.      C++ Class Members and Friends 
  14529.      C++ Inheritance 
  14530.      C++ Overloading 
  14531.      Virtual Functions 
  14532.      Structures 
  14533.      Unions 
  14534.  
  14535.  
  14536. ΓòÉΓòÉΓòÉ 10.1. Classes and Structures ΓòÉΓòÉΓòÉ
  14537.  
  14538. The C++ class is an extension of the C-language structure. Because the only 
  14539. difference between a structure and a class is that structure members have 
  14540. public access by default and a class members have private access by default, 
  14541. you can use the keywords class or struct to define equivalent classes. 
  14542.  
  14543. For example, in the following code fragment, the class X is equivalent to the 
  14544. structure Y: 
  14545.  
  14546. // In this example, class X is equivalent to struct Y
  14547.  
  14548. class X
  14549. {
  14550. int a; // private by default
  14551. public:
  14552.       int f() { return a = 5; }; // public member function
  14553. };
  14554. struct Y
  14555. {
  14556. int f() { return a = 5; };       // public by default
  14557. private:
  14558.       int a; // private data member
  14559. };
  14560.  
  14561. If you define a structure and then declare an object of that structure using 
  14562. the keyword class, the members of the object are still public by default. 
  14563.  
  14564. Example of Access for Classes and Structures 
  14565.  
  14566. An aggregate class is a class that has no user-defined constructors, no private 
  14567. or protected members, no  base classes, and no virtual functions. 
  14568.  
  14569. Initialization of aggregate classes is described in Initializers. 
  14570.  
  14571. Related Information 
  14572.  
  14573.      Structures 
  14574.      Declaring Class Objects 
  14575.      Scope of Class Names 
  14576.  
  14577.  
  14578. ΓòÉΓòÉΓòÉ <hidden> Example of Access for Classes and Structures ΓòÉΓòÉΓòÉ
  14579.  
  14580. /************************************************************************
  14581. *
  14582.  
  14583. In the following example, main() has access to the members of X even though X 
  14584. is declared as using the keyword class: 
  14585.  
  14586.                                                                         *
  14587. ************************************************************************/
  14588.  
  14589. // This example declares a structure, then declares a class
  14590. // that is an object of the structure.
  14591.  
  14592. #include <iostream.h>
  14593.  
  14594. struct x {
  14595.       int a;
  14596.       int b;
  14597.       } ;
  14598.  
  14599. class x X;
  14600.  
  14601. void main() {
  14602.       X.a = 0;
  14603.       X.b = 1;
  14604.       cout << "Here are e and f " << X.a << " " << X.b << endl;
  14605.       }
  14606.  
  14607.  
  14608. ΓòÉΓòÉΓòÉ 10.2. Declaring Class Objects ΓòÉΓòÉΓòÉ
  14609.  
  14610. A class declaration creates a unique type class name. 
  14611.  
  14612. A class specifier is used to declare a class. Once a class specifier has been 
  14613. seen and its members declared, a class is considered to be defined even if the 
  14614. member functions of that class are not yet defined. A class specifier has the 
  14615. following form: 
  14616.  
  14617. >>ΓöÇΓöÇΓö¼ΓöÇclassΓöÇΓöÇΓö¼ΓöÇΓöÇclass_nameΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ{ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ}ΓöÇΓöÇ><
  14618.   Γö£ΓöÇstructΓöÇΓöñ        ΓööΓöÇ:base_classΓöÇΓöÿ   ΓööΓöÇmember_listΓöÇΓöÿ
  14619.   ΓööΓöÇunionΓöÇΓöÇΓöÿ
  14620.  
  14621. The member_list is optional. It specifies the class members, both data and 
  14622. functions, of the class class_name. If the member_list of a class is empty, 
  14623. objects of that class have a nonzero size. You can use a class_name within the 
  14624. member_list of the class specifier itself as long as the size of the class is 
  14625. not required. For more information, see Class Member Lists. 
  14626.  
  14627. The base_class is optional. It specifies the base class or classes from which 
  14628. the class class_name inherits members. If the base_class is not empty, the 
  14629. class class_name is called a derived class. 
  14630.  
  14631. The declarator for a class variable declared with the class, struct, or union 
  14632. keyword is an identifier. If the symbol * precedes the identifier, the 
  14633. identifier names a pointer to a class of the specified data type. If ** 
  14634. precedes the identifier, the identifier names a pointer to a pointer to a class 
  14635. of the specified data type. 
  14636.  
  14637. If a constant expression enclosed in [ ] (brackets) follows the identifier, the 
  14638. identifier names an array of classes of the specified data type. If * precedes 
  14639. the identifier and a constant expression enclosed in [ ] follows the 
  14640. identifier, the identifier names an array of pointers to classes of the 
  14641. specified data type. 
  14642.  
  14643. Related Information 
  14644.  
  14645.      Class Names 
  14646.      Scope of Class Names 
  14647.      Class Member Lists 
  14648.      Derivation 
  14649.  
  14650.  
  14651. ΓòÉΓòÉΓòÉ 10.2.1. Class Names ΓòÉΓòÉΓòÉ
  14652.  
  14653. A class name is a unique identifier that becomes a reserved word within its 
  14654. scope. Once a class name is declared, it hides other declarations of the same 
  14655. name within the enclosing scope. 
  14656.  
  14657. If a class name is declared in the same scope as a function, enumerator, or 
  14658. object with the same name, that class can be referred to by using an elaborated 
  14659. type specifier. In the following example, the elaborated type specifier is used 
  14660. to refer to the class print that is hidden by the later definition of the 
  14661. function print(): 
  14662.  
  14663. class print
  14664. {
  14665.       /* definition of class print */
  14666. };
  14667. void print (class print*);       // redefine print as a function
  14668. //      .                        // prefix class-name by class-key
  14669. //      .                        // to refer to class print
  14670. //      .
  14671. void main ()
  14672. {
  14673.       class print* paper;        // prefix class-name by class-key
  14674.                                  // to refer to class print
  14675.       print(paper);              // call function print
  14676. }
  14677.  
  14678. You can use an elaborated type specifier with a class name to declare a class. 
  14679.  
  14680. For more information on elaborated type specifiers, see Incomplete Class 
  14681. Declarations. 
  14682.  
  14683. You can also qualify type names to refer to hidden type names in the current 
  14684. scope. You can reduce complex class name syntax by using a typedef to represent 
  14685. a nested class name. 
  14686.  
  14687. Example of Using a typedef for a Class Name 
  14688.  
  14689. Related Information 
  14690.  
  14691.      Declaring Class Objects 
  14692.      Scope of Class Names 
  14693.      Nested Classes 
  14694.  
  14695.  
  14696. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Nested Class Specifier ΓòÉΓòÉΓòÉ
  14697.  
  14698. The syntax of a nested class specifier is: 
  14699.  
  14700. >>ΓöÇΓöÇclass_nameΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  14701.         ΓööΓöÇ::nested_classΓöÇΓöÿ
  14702.  
  14703. where class_name specifies the name of the enclosing class and nested-class 
  14704. specifies the name of the nested class. For more information, see Nested 
  14705. Classes. 
  14706.  
  14707.  
  14708. ΓòÉΓòÉΓòÉ <hidden> Example of Using a typedef for a Class Name ΓòÉΓòÉΓòÉ
  14709.  
  14710. /************************************************************************
  14711. *
  14712.  
  14713. In the following example, a typedef is used so that the simple name nested can 
  14714. be used in place of outside::middle::inside. 
  14715.  
  14716. *
  14717. ************************************************************************/
  14718.  
  14719. // This example illustrates a typedef used to simplify
  14720. // a nested class name.
  14721.  
  14722. #include <iostream.h>
  14723.  
  14724. class outside {
  14725. public:
  14726.       class middle {
  14727.       public:
  14728.             class inside {
  14729.                   private:
  14730.                         int a;
  14731.                   public:
  14732.                         inside(int a_init = 0): a(a_init) {}
  14733.                         void printa();
  14734.             };
  14735.       };
  14736. };
  14737.  
  14738. typedef outside::middle::inside nested;
  14739.  
  14740. void nested::printa() {
  14741.       cout << "Here is a " << this->a << endl;
  14742.       }
  14743.  
  14744. void main() {
  14745.       nested n(9);
  14746.       n.printa();
  14747. }
  14748.  
  14749.  
  14750. ΓòÉΓòÉΓòÉ 10.2.2. Using Class Objects ΓòÉΓòÉΓòÉ
  14751.  
  14752. You can use a class type to create instances or objects of that class type. For 
  14753. example, you can declare a class, structure, and union with class names X, Y, 
  14754. and Z respectively: 
  14755.  
  14756. class X {       /* definition of class X */ };
  14757. struct Y {      /* definition of struct Y */ };
  14758. union Z {       /* definition of union Z */ };
  14759.  
  14760. You can then declare objects of each of these class types. Remember that 
  14761. classes, structures, and unions are all types of C++ classes. 
  14762.  
  14763. void main()
  14764. {
  14765.       X xobj;      // declare a class object of class type X
  14766.       Y yobj;      // declare a struct object of class type Y
  14767.       Z zobj;      // declare a union object of class type Z
  14768. }
  14769.  
  14770. In C++, unlike C, you do not need to precede declarations of class objects with 
  14771. the keywords union, struct, and class unless the name of the class is hidden. 
  14772. For more information on hidden names, see Scope of Class Names. 
  14773.  
  14774. When you declare more than one class object in a declaration, the declarators 
  14775. are treated as if declared individually. For example, if you declare two 
  14776. objects of class S in a single declaration: 
  14777.  
  14778. class S { /* ... */ };
  14779. void main()
  14780. {
  14781.       S S,T; // declare two objects of class type S
  14782. }
  14783.  
  14784. this declaration is equivalent to: 
  14785.  
  14786. class S { /* ... */ };
  14787. void main()
  14788. {
  14789.       S S;
  14790.       class S T;       // keyword class is required
  14791.                        // since variable S hides class type S
  14792. }
  14793.  
  14794. but is not equivalent to: 
  14795.  
  14796. class S { /* ... */ };
  14797. void main()
  14798. {
  14799.       S S;
  14800.       S T;             // error, S class type is hidden
  14801. }
  14802.  
  14803. You can also declare references to classes, pointers to classes, and arrays of 
  14804. classes. 
  14805.  
  14806. Examples of Declaring Class Objects 
  14807.  
  14808. Objects of class types that are not copy restricted can be assigned, passed as 
  14809. arguments to functions, and returned by functions. For more information, see 
  14810. Copying Class Objects. 
  14811.  
  14812. Related Information 
  14813.  
  14814.      Objects 
  14815.      Scope of Class Names 
  14816.      Initialization by Constructor 
  14817.      Copying Class Objects 
  14818.  
  14819.  
  14820. ΓòÉΓòÉΓòÉ <hidden> Examples of Declaring Class Objects ΓòÉΓòÉΓòÉ
  14821.  
  14822. /************************************************************************
  14823. *
  14824.  
  14825. In C++, unlike C, you do not need to precede declarations of class objects with 
  14826. the keywords union, struct, and class unless the name of the class is hidden. 
  14827. For example: 
  14828.  
  14829.                                                                         *
  14830. ************************************************************************/
  14831.  
  14832. struct Y { /* ... */ };
  14833. class X { /* ... */ };
  14834. void main ()
  14835. {
  14836.       int X;             // hides the class name X
  14837.       Y yobj;            // valid
  14838.       X xobj;            // error, class name X is hidden
  14839.       class X xobj;      // valid
  14840. }
  14841.  
  14842. /************************************************************************
  14843. *
  14844.  
  14845. The following example declares a reference, a pointer, and an array: 
  14846.  
  14847.                                                                         *
  14848. ************************************************************************/
  14849.  
  14850. class X { /* ... */ };
  14851. struct Y { /* ... */ };
  14852. union Z { /* ... */ };
  14853. void main()
  14854. {
  14855.       X xobj;
  14856.       X &xref = xobj;           // reference to class object of type X
  14857.       Y *yptr;                  // pointer to struct object of type Y
  14858.       Z zarray[10];             // array of 10 union objects of type Z
  14859. }
  14860.  
  14861.  
  14862. ΓòÉΓòÉΓòÉ 10.3. Scope of Class Names ΓòÉΓòÉΓòÉ
  14863.  
  14864. A class declaration introduces the class name into the scope where it is 
  14865. declared. Any class, object, function or other declaration of that name in an 
  14866. enclosing scope is hidden. If a class name is declared in a scope where an 
  14867. object, function, or enumerator of the same name is also declared, you can only 
  14868. refer to the class by using the elaborated type specifier. The class key 
  14869. (class, struct, or union) must precede the class name to identify it. 
  14870.  
  14871. For example: 
  14872.  
  14873. // This example shows the scope of class names.
  14874.  
  14875. class x { int a; };            // declare a class type class-name
  14876.  
  14877. x xobject;                     // declare object of class type x
  14878.  
  14879. int x(class x*)                // redefine x to be a function
  14880. {return 0;}                    // use class-key class to define
  14881.                                // a pointer to the class type x
  14882.                                // as the function argument
  14883.  
  14884. void main()
  14885. {
  14886.       class x* xptr;           // use class-key class to define
  14887.                                // a pointer to class type x
  14888.       xptr = &xobject;         // assign pointer
  14889.       x(xptr);                 // call function x with pointer to class x
  14890. }
  14891.  
  14892. An elaborated type specifier can be used in the declaration of objects and 
  14893. functions. See Class Names for an example. 
  14894.  
  14895. An elaborated type specifier can also be used in the incomplete declaration of 
  14896. a class type to reserve the name for a class type within the current scope. 
  14897.  
  14898. Related Information 
  14899.  
  14900.      Incomplete Class Declarations 
  14901.      Nested Classes 
  14902.      Local Classes 
  14903.      Local Type Names 
  14904.      Class Names 
  14905.      Declaring Class Objects 
  14906.      Scope in C 
  14907.  
  14908.  
  14909. ΓòÉΓòÉΓòÉ 10.3.1. Incomplete Class Declarations ΓòÉΓòÉΓòÉ
  14910.  
  14911. An incomplete class declaration is a class declaration that does not define any 
  14912. class members. You cannot declare any objects of the class type or refer to the 
  14913. members of a class until the declaration is complete. However, an incomplete 
  14914. declaration allows you to make specific references to a class prior to its 
  14915. definition as long as the size of the class is not required. 
  14916.  
  14917. For example, you can define a pointer to the structure first in the definition 
  14918. of the structure second. Structure first is declared in an incomplete class 
  14919. declaration prior to the definition of second, and the definition of oneptr in 
  14920. structure second does not require the size of first: 
  14921.  
  14922. struct first;           // incomplete declaration of struct first
  14923.  
  14924. struct second           // complete declaration of struct second
  14925. {
  14926.       first* oneptr;    // pointer to struct first refers to
  14927.                         // struct first prior to its complete
  14928.                         // declaration
  14929.  
  14930.       first one;        // error, you cannot declare an object of
  14931.                         // an incompletely declared class type
  14932.       int x, y;
  14933. };
  14934.  
  14935. struct first            // complete declaration of struct first
  14936. {
  14937.       second two;       // define an object of class type second
  14938.       int z;
  14939. };
  14940.  
  14941. If you declare a class with an empty member list, it is a complete class 
  14942. declaration. For example: 
  14943.  
  14944. class X;                // incomplete class declaration
  14945. class Z {};             // empty member list
  14946. class Y
  14947. {
  14948. public:
  14949.       X yobj;           // error, cannot create an object of an
  14950.                         // incomplete class type
  14951.       Z zobj;           // valid
  14952. };
  14953.  
  14954. Related Information 
  14955.  
  14956.      Declaring Class Objects 
  14957.      Class Member Lists 
  14958.      Scope of Class Names 
  14959.  
  14960.  
  14961. ΓòÉΓòÉΓòÉ 10.3.2. Nested Classes ΓòÉΓòÉΓòÉ
  14962.  
  14963. A nested class is declared within the scope of another class. The name of a 
  14964. nested class is local to its enclosing class.  Unless you use explicit 
  14965. pointers, references, or object names, declarations in a nested class can only 
  14966. use visible constructs, including type names, static members, and enumerators 
  14967. from the enclosing class and global variables. 
  14968.  
  14969. Member functions of a nested class follow regular access rules and have no 
  14970. special access privileges to members of their enclosing classes. Member 
  14971. functions of the enclosing class have no special access to members of a nested 
  14972. class. 
  14973.  
  14974. You can define member functions and static data members of a nested class in 
  14975. the global scope. For example, in the following code fragment, you can access 
  14976. the static members x and y and member functions f() and g() of the nested class 
  14977. nested by using a qualified type name. Qualified type names allow you to define 
  14978. a typedef to represent a qualified class name. You can then use the typedef 
  14979. with the :: (scope resolution) operator to refer to a nested class or class 
  14980. member, as shown in the following example: 
  14981.  
  14982. class outside
  14983. {
  14984. public:
  14985.       class nested
  14986.       {
  14987.       public:
  14988.             static int x;
  14989.             static int y;
  14990.             int f();
  14991.             int g();
  14992.       };
  14993. };
  14994. int outside::nested::x = 5;
  14995. int outside::nested::f() { return 0; };
  14996.  
  14997. typedef outside::nested outnest;       // define a typedef
  14998. int outnest::y = 10;                   // use typedef with ::
  14999. int outnest::g() { return 0; };
  15000. //      . . .
  15001.  
  15002. Related Information 
  15003.  
  15004.      Class Names 
  15005.      Declaring Class Objects 
  15006.      Scope of Class Names 
  15007.  
  15008.  
  15009. ΓòÉΓòÉΓòÉ 10.3.3. Local Classes ΓòÉΓòÉΓòÉ
  15010.  
  15011. A local class is declared within a function definition. The local class is in 
  15012. the scope of the enclosing function scope. Declarations in a local class can 
  15013. only use type names, enumerations, static variables from the enclosing scope, 
  15014. as well as external variables and functions. 
  15015.  
  15016. Examples of Local Classes 
  15017.  
  15018. Member functions of a local class have to be defined within their class 
  15019. definition. Member functions of a local class must be inline functions. Like 
  15020. all member functions, those defined within the scope of a local class do not 
  15021. need the keyword inline. 
  15022.  
  15023. A local class cannot have static data members. In the following example, an 
  15024. attempt to define a static member of a local class causes an error: 
  15025.  
  15026. void f()
  15027. {
  15028.     class local
  15029.     {
  15030.        int f();              // error, local class has noninline
  15031.                              // member function
  15032.        int g() {return 0;}   // valid, inline member function
  15033.        static int a;         // error, static is not allowed for
  15034.                              // local class
  15035.        int b;                // valid, nonstatic variable
  15036.     };
  15037. }
  15038. //      . . .
  15039.  
  15040. An enclosing function has no special access to members of the local class. 
  15041.  
  15042. Related Information 
  15043.  
  15044.      Scope of Class Names 
  15045.      Function Scope 
  15046.      Inline Member Functions 
  15047.      Inline Specifiers 
  15048.      Local Type Names 
  15049.  
  15050.  
  15051. ΓòÉΓòÉΓòÉ <hidden> Examples of Local Classes ΓòÉΓòÉΓòÉ
  15052.  
  15053. /************************************************************************
  15054. *
  15055.  
  15056. The following example uses local classes. 
  15057.  
  15058.                                                                         *
  15059. ************************************************************************/
  15060.  
  15061. int x;                         // global variable
  15062. void f()                       // function definition
  15063. {
  15064.       static int y;            // static variable y can be used by
  15065.                                // local class
  15066.       int x;                   // auto variable x cannot be used by
  15067.                                // local class
  15068.       extern int g();          // extern function g can be used by
  15069.                                // local class
  15070.  
  15071.       class local              // local class
  15072.       {
  15073.             int g() { return x; }      // error, local variable x
  15074.                                        // cannot be used by g
  15075.             int h() { return y; }      // valid,static variable y
  15076.             int k() { return ::x; }    // valid, global x
  15077.             int l() { return g(); }    // valid, extern function g
  15078.       };
  15079. }
  15080.  
  15081. void main()
  15082. {
  15083.       local* z;                // error, local is undefined
  15084. //      .
  15085. //      .
  15086. //      .
  15087. }
  15088.  
  15089.  
  15090. ΓòÉΓòÉΓòÉ 10.3.4. Local Type Names ΓòÉΓòÉΓòÉ
  15091.  
  15092. Local type names follow the same scope rules as other names. Scope rules are 
  15093. described in Scope in C++. Type names defined within a class declaration have 
  15094. class scope and cannot be used outside their class without qualification. 
  15095.  
  15096. If you use a class name, typedef name, or a constant name that is used in a 
  15097. type name, in a class declaration, you cannot redefine that name after it is 
  15098. used in the class declaration. 
  15099.  
  15100. For example: 
  15101.  
  15102. void main ()
  15103. {
  15104.       typedef double db;
  15105.       struct st
  15106.       {
  15107.             db x;
  15108.             typedef int db; // error
  15109.             db y;
  15110.       };
  15111. }
  15112.  
  15113. The following declarations are valid: 
  15114.  
  15115. typedef float T;
  15116. class s {
  15117.       typedef int T;
  15118.       void f(const T);
  15119. };
  15120.  
  15121. Here, function f() takes an argument of type s::T. However, the following 
  15122. declarations, where the order of the members of s has been reversed, cause an 
  15123. error: 
  15124.  
  15125. typedef float T;
  15126. class s {
  15127.       void f(const T);
  15128.       typedef int T;
  15129. };
  15130.  
  15131. In a class declaration, you cannot redefine a name that is not a class name, or 
  15132. a typedef name to a class name or typedef name once you have used that name in 
  15133. the class declaration. 
  15134.  
  15135. Related Information 
  15136.  
  15137.      Scope in C 
  15138.      Declaring Class Objects 
  15139.      Scope of Class Names 
  15140.      Local Classes 
  15141.      typedef 
  15142.  
  15143.  
  15144. ΓòÉΓòÉΓòÉ 11. C++ Class Members and Friends ΓòÉΓòÉΓòÉ
  15145.  
  15146. This chapter describes class members and friends, including the following 
  15147. topics: 
  15148.  
  15149.      Class Member Lists 
  15150.      Data Members 
  15151.      Class-Type Class Members 
  15152.      Member Functions 
  15153.      Member Scope 
  15154.      Pointers to Members 
  15155.      The this Pointer 
  15156.      Static Members 
  15157.      Member Access 
  15158.      Friends 
  15159.  
  15160.  Related Information 
  15161.  
  15162.      C++ Classes 
  15163.      C++ Inheritance 
  15164.      Special C++ Member Functions 
  15165.  
  15166.  
  15167. ΓòÉΓòÉΓòÉ 11.1. Class Member Lists ΓòÉΓòÉΓòÉ
  15168.  
  15169. An optional member list declares sub-objects called class members. Class 
  15170. members can be data, functions, classes, enumeration, bit fields, and typedef 
  15171. names. A member list is the only place you can declare class members. Friend 
  15172. declarations are not class members but must appear in member lists. 
  15173.  
  15174. The member list follows the class name and is placed between braces. It can 
  15175. contain access specifiers, member declarations, and member definitions. 
  15176.  
  15177. You can access members by using the class access . (dot) and -> (arrow) 
  15178. operators. 
  15179.  
  15180. An access specifier is one of public, private, or protected. 
  15181.  
  15182. A member declaration declares a class member for the class containing the 
  15183. declaration. For more information on declarations, see Declarations, and 
  15184. Declaring Class Objects. 
  15185.  
  15186. A member declaration that is a qualified name followed by a ; (semicolon) is 
  15187. used to restore access to members of base classes and is described in Access 
  15188. Declarations. 
  15189.  
  15190. A member declarator declares an object, function, or type within a declaration. 
  15191. It cannot contain an initializer. You can initialize a member by using a 
  15192. constructor or, if the member belongs to an aggregate class, by using a brace 
  15193. initializer list (a list surrounded by braces { }) in the declarator list. You 
  15194. must explicitly initialize a class containing constant or reference members 
  15195. with a brace initializer list or explicitly with a constructor. 
  15196.  
  15197. A member declarator of the form: 
  15198.  
  15199.       [identifier] : constant-expression
  15200.  
  15201. specifies a bit field. 
  15202.  
  15203. A pure specifier (= 0) indicates that a function has no definition. It is only 
  15204. used with virtual member functions and replaces the function definition of a 
  15205. member function in the member list. Pure specifiers are described in Virtual 
  15206. Functions. 
  15207.  
  15208. You can use the storage-class specifier static (but not extern, auto or 
  15209. register) in a member list. 
  15210.  
  15211. The order of mapping of class members in a member list is implementation 
  15212. dependent. For the VisualAge C++ compiler, class members are allocated in the 
  15213. order they are declared. For more information, see the IBM VisualAge C++ for 
  15214. OS/2 User's Guide and Reference. 
  15215.  
  15216. Related Information 
  15217.  
  15218.      Member Access 
  15219.      Dot Operator . 
  15220.      Arrow Operator -> 
  15221.      Declaring Class Objects 
  15222.      Access Declarations 
  15223.      Initialization by Constructor 
  15224.      Virtual Functions 
  15225.      Initializers 
  15226.      Storage Class Specifiers 
  15227.  
  15228.  
  15229. ΓòÉΓòÉΓòÉ 11.2. Data Members ΓòÉΓòÉΓòÉ
  15230.  
  15231. Data members include members that are declared with any of the fundamental 
  15232. types, as well as other types, including pointer, reference, array types, and 
  15233. user-defined types. You can declare a data member the same way as a variable, 
  15234. except that explicit initializers are not allowed inside the class definition. 
  15235.  
  15236. If an array is declared as a nonstatic class member, you must specify all of 
  15237. the dimensions of the array. 
  15238.  
  15239. Related Information 
  15240.  
  15241.      Type Specifiers 
  15242.      Class Member Lists 
  15243.      Class-Type Class Members 
  15244.      Static Members 
  15245.      Member Access 
  15246.  
  15247.  
  15248. ΓòÉΓòÉΓòÉ 11.3. Class-Type Class Members ΓòÉΓòÉΓòÉ
  15249.  
  15250. A class can have members that are of a class type or are pointers or references 
  15251. to a class type. Members that are of a class type must be of a class type that 
  15252. is previously declared. An incomplete class type can be used in a member 
  15253. declaration as long as the size of the class is not needed. For example, a 
  15254. member can be declared that is a pointer to an incomplete class type. 
  15255.  
  15256. A class X cannot have a member that is of type X, but it can contain pointers 
  15257. to X, references to X, and static objects of X. Member functions of X can take 
  15258. arguments of type X and have a return type of X. For example: 
  15259.  
  15260. class X
  15261. {
  15262.       X();
  15263.       X *xptr;
  15264.       X &xref;
  15265.       static X xcount;
  15266.       X xfunc(X);
  15267. };
  15268.  
  15269. The bodies of member functions are always processed after the definition of 
  15270. their class is complete. For this reason, the body of a member function can 
  15271. refer to the name of the class that owns it. even if this requires information 
  15272. about the class definition. 
  15273.  
  15274. The language allows member functions to refer to any class member even if the 
  15275. member function definition appears before the declaration of that member in the 
  15276. class member list. For example, 
  15277.  
  15278. class Y
  15279. {
  15280. public:
  15281.       int a;
  15282.       Y ();
  15283. private:
  15284.       int f() {return sizeof(Y);};
  15285.       void g(Y yobj);
  15286.       Y h(int a);
  15287. };
  15288.  
  15289. In this example, it is permitted for the inline function f() to make use of the 
  15290. size of class Y. 
  15291.  
  15292. Related Information 
  15293.  
  15294.      Incomplete Class Declarations 
  15295.      Member Functions 
  15296.      Inline Member Functions 
  15297.      C++ Classes 
  15298.      Class Member Lists 
  15299.  
  15300.  
  15301. ΓòÉΓòÉΓòÉ 11.4. Member Functions ΓòÉΓòÉΓòÉ
  15302.  
  15303. Member functions are operators and functions that are declared as members of a 
  15304. class. Member functions do not include operators and functions declared with 
  15305. the friend specifier. These are called friends of a class. 
  15306.  
  15307. The definition of a member function is within the scope of its enclosing class. 
  15308. The body of a member function is analyzed after the class declaration so that 
  15309. members of that class can be used in the member function body. When the 
  15310. function add() is called in the following example, the data variables a, b, and 
  15311. c can be used in the body of add(). 
  15312.  
  15313. class x
  15314. {
  15315. public:
  15316.       int add()             // inline member function add
  15317.       {return a+b+c;};
  15318. private:
  15319.       int a,b,c;
  15320. };
  15321.  
  15322. There are several kinds of member functions: 
  15323.  
  15324.      const and volatile member functions 
  15325.      Virtual member functions 
  15326.      Special member functions 
  15327.      Inline member functions 
  15328.      Member function templates 
  15329.  
  15330.  Related Information 
  15331.  
  15332.      Member Scope 
  15333.      Static Member Functions 
  15334.      Functions 
  15335.      Class Member Lists 
  15336.  
  15337.  
  15338. ΓòÉΓòÉΓòÉ <hidden> const and volatile Member Functions ΓòÉΓòÉΓòÉ
  15339.  
  15340. A member function declared with the const qualifier can be called for constant 
  15341. and nonconstant objects. A nonconstant member function can only be called for a 
  15342. nonconstant object. Similarly, a member function declared with the volatile 
  15343. qualifier can be called for volatile and nonvolatile objects. A nonvolatile 
  15344. member function can only be called for a nonvolatile object. 
  15345.  
  15346.  
  15347. ΓòÉΓòÉΓòÉ <hidden> Virtual Member Functions ΓòÉΓòÉΓòÉ
  15348.  
  15349. Virtual member functions are declared with the keyword virtual. They allow 
  15350. dynamic binding of member functions. Because all virtual functions must be 
  15351. member functions, virtual member functions are simply called virtual functions. 
  15352.  
  15353. If the definition of a virtual function is replaced by a pure specifier in the 
  15354. declaration of the function, the function is said to be declared pure. A class 
  15355. that has at least one pure virtual function is called an abstract class. 
  15356.  
  15357.  
  15358. ΓòÉΓòÉΓòÉ <hidden> Special Member Functions ΓòÉΓòÉΓòÉ
  15359.  
  15360. Special member functions are used to create, destroy, initialize, convert, and 
  15361. copy class objects. These include: 
  15362.  
  15363.      Constructors 
  15364.      Destructors 
  15365.      Conversion constructors 
  15366.      Conversion functions 
  15367.      Copy constructors 
  15368.  
  15369.  
  15370. ΓòÉΓòÉΓòÉ <hidden> Inline Member Functions ΓòÉΓòÉΓòÉ
  15371.  
  15372. A member function that is both declared and defined in the class member list is 
  15373. called an inline member function. Member functions containing a few lines of 
  15374. code are usually declared inline. 
  15375.  
  15376. An equivalent way to declare an inline member function is to declare it outside 
  15377. of the class declaration using the keyword inline and the :: (scope resolution) 
  15378. operator to identify the class the member function belongs to. For example: 
  15379.  
  15380. class Y
  15381. {
  15382.       char* a;
  15383. public:
  15384.       char* f() {return a;};
  15385. };
  15386.  
  15387. is equivalent to: 
  15388.  
  15389. class Z
  15390. {
  15391.       char* a;
  15392. public:
  15393.       char* f();
  15394. };
  15395. inline char* Z::f() {return a;}
  15396.  
  15397. When you declare an inline function without the inline keyword and do not 
  15398. define it in the class member list, you cannot call the function before you 
  15399. define it. In the above example, you cannot call f() until after its 
  15400. definition. 
  15401.  
  15402. Inline member functions have internal linkage. Noninline member functions have 
  15403. external linkage. 
  15404.  
  15405. For more information, see C++ Inline Functions. 
  15406.  
  15407.  
  15408. ΓòÉΓòÉΓòÉ <hidden> Member Function Templates ΓòÉΓòÉΓòÉ
  15409.  
  15410. Any member function (inlined or noninlined) declared within a class template is 
  15411. implicitly a function template. When a template class is declared, it 
  15412. implicitly generates template functions for each function defined in the class 
  15413. template. If a class template is instantiated, only the function templates 
  15414. whose instantiations will actually be used by the resulting template class are 
  15415. instantiated. 
  15416.  
  15417. For more information about member function templates, see Member Function 
  15418. Templates. 
  15419.  
  15420.  
  15421. ΓòÉΓòÉΓòÉ 11.5. Member Scope ΓòÉΓòÉΓòÉ
  15422.  
  15423. Member functions and static members can be defined outside their class 
  15424. declaration if they have already been declared, but not defined, in the class 
  15425. member list. Nonstatic data members are defined when their class is 
  15426. instantiated. The declaration of a static data member is not a definition. The 
  15427. declaration of a member function is a definition if the body of the function is 
  15428. also given. 
  15429.  
  15430. Whenever the definition of a class member appears outside of the class 
  15431. declaration, the member name must be qualified by the class name using the :: 
  15432. (scope resolution) operator. 
  15433.  
  15434. Example of Defining a Member outside of the Class 
  15435.  
  15436. All member functions are in class scope even if they are defined outside their 
  15437. class declaration. 
  15438.  
  15439. The name of a class member is local to its class. Unless you use one of the 
  15440. class access operators, . (dot), or -> (arrow), or :: (scope resolution) 
  15441. operator, you can only use a class member in a member function of its class and 
  15442. in nested classes. You can only use types, enumerations and static members in a 
  15443. nested class without qualification with the :: operator. 
  15444.  
  15445. The order of search for a name in a member function body is: 
  15446.  
  15447.    1. Within the member function body itself 
  15448.    2. Within all the enclosing classes, including inherited members of those 
  15449.       classes 
  15450.    3. Within the lexical scope of the body declaration 
  15451.  
  15452.  Example of Member Function Search Path 
  15453.  
  15454.  Note:  When the containing classes are being searched, only the definitions of 
  15455.  the containing classes and their base classes are searched. The scope 
  15456.  containing the base class definitions (global scope, in this example) is not 
  15457.  searched. 
  15458.  
  15459.  Related Information 
  15460.  
  15461.      Scope in C++ 
  15462.      Scope Resolution Operator :: 
  15463.      Member Functions 
  15464.      Dot Operator . 
  15465.      Arrow Operator -> 
  15466.      Member Access 
  15467.  
  15468.  
  15469. ΓòÉΓòÉΓòÉ <hidden> Example of Defining a Member ΓòÉΓòÉΓòÉ
  15470.  
  15471. /************************************************************************
  15472. *
  15473.  
  15474. The following example defines a member function outside of its class 
  15475. declaration. 
  15476.  
  15477.                                                                         *
  15478. ************************************************************************/
  15479.  
  15480. // This example illustrates member scope.
  15481.  
  15482. #include <iostream.h>
  15483. class X
  15484. {
  15485. public:
  15486.       int a, b ;      // public data members
  15487.       int add();      // member function declaration only
  15488. };
  15489. int a  = 10;          // global variable
  15490. // define member function outside its class declaration
  15491. int X::add() {return a + b;};
  15492. //      .
  15493. //      .
  15494. //      .
  15495. void main()
  15496. {
  15497.     int answer;
  15498.     X xobject;
  15499.     xobject.a = 1;
  15500.     xobject.b = 2;
  15501.     answer = xobject.add();
  15502.     cout << xobject.a << " + " << xobject.b << " = " << answer;
  15503. }
  15504.  
  15505. /************************************************************************
  15506. *
  15507.  
  15508. The output for this example is: 1 + 2 = 3 
  15509.  
  15510. Note:  All member functions are in class scope even if they are defined outside 
  15511. their class declaration. In the above example, the member function add() 
  15512. returns the data member a, not the global variable a. 
  15513.  
  15514.                                                                         *
  15515. ************************************************************************/
  15516.  
  15517.  
  15518. ΓòÉΓòÉΓòÉ <hidden> Example of Member Function Search Path ΓòÉΓòÉΓòÉ
  15519.  
  15520. /************************************************************************
  15521. *
  15522.  
  15523. The search of the enclosing classes, including inherited members, is 
  15524. demonstrated in the following example: 
  15525.  
  15526.                                                                         *
  15527. ************************************************************************/
  15528.  
  15529. class A { /* ... */ };
  15530. class B { /* ... */ };
  15531. class C { /* ... */ };
  15532. class Z : A {
  15533.       class Y : B {
  15534.             class X : C { int f(); /* ... */ };
  15535.       };
  15536. };
  15537. int Z::Y::X f()
  15538. {
  15539.    // ...
  15540.       j();
  15541.    // ...
  15542. }
  15543.  
  15544. /************************************************************************
  15545. *
  15546.  
  15547. In this example, the search for the name j in the definition of the function f 
  15548. follows this order: 
  15549.  
  15550.    1. In the body of the function f 
  15551.    2. In X and in its base class C 
  15552.    3. In Y and in its base class B 
  15553.    4. In Z and in its base class A 
  15554.    5. In the lexical scope of the body of f. In this case, this is global 
  15555.       scope. 
  15556.  
  15557.                                                                           *
  15558.   ************************************************************************/
  15559.  
  15560.  
  15561. ΓòÉΓòÉΓòÉ 11.6. Pointers to Members ΓòÉΓòÉΓòÉ
  15562.  
  15563. Pointers to members allow you to refer to nonstatic members of class objects. 
  15564. You cannot use a pointer to member to point to a static class member because 
  15565. the address of a static member is not associated with any particular object. To 
  15566. point to a static class member, you must use a normal pointer. 
  15567.  
  15568. You can use pointers to member functions in the same manner as pointers to 
  15569. functions. You can compare pointers to member functions, assign values to them, 
  15570. and use them to call member functions. Note that a member function does not 
  15571. have the same type as a nonmember function that has the same number and type of 
  15572. arguments and the same return type. 
  15573.  
  15574. Example of Pointers to Members 
  15575.  
  15576. To reduce complex syntax, you can declare a typedef to be a pointer to a 
  15577. member. A pointer to a member can be declared and used as shown in the 
  15578. following code fragment: 
  15579.  
  15580. typedef void (X::*ptfptr) (int);      // declare typedef
  15581. void main ()
  15582. {
  15583. // ...
  15584. ptfptr ptf = &X::f;                   // use typedef
  15585. X xobject;
  15586. (xobject.*ptf) (20);                  // call function
  15587. }
  15588.  
  15589. The pointer to member operators .* and ->* are used to bind a pointer to a 
  15590. member of a specific class object. Because the precedence of () (function call 
  15591. operator) is higher than .* and ->*, you must use parentheses to call the 
  15592. function pointed to by ptf. 
  15593.  
  15594. Related Information 
  15595.  
  15596.      Pointer to Member Operators .* ->* 
  15597.      Pointers 
  15598.      Static Members 
  15599.      The this Pointer 
  15600.  
  15601.  
  15602. ΓòÉΓòÉΓòÉ <hidden> Example of Pointers to Members ΓòÉΓòÉΓòÉ
  15603.  
  15604. /************************************************************************
  15605. *
  15606.  
  15607. Pointers to members can be declared and used as shown in the following example: 
  15608.  
  15609.                                                                         *
  15610. ************************************************************************/
  15611.  
  15612. // This example illustrates pointers to members.
  15613.  
  15614. #include <iostream.h>
  15615. class X
  15616. {
  15617. public:
  15618.       int a;
  15619.       void f(int b)
  15620.       {
  15621.              cout << "The value of b is "<< b << endl;
  15622.       }
  15623. };
  15624. //      .
  15625. //      .
  15626. //      .
  15627. void main ()
  15628. {
  15629.       // declare pointer to data member
  15630.       int X::*ptiptr = &X::a;
  15631.  
  15632.       // declare a pointer to member function
  15633.       void (X::* ptfptr) (int) = &X::f;
  15634.  
  15635.       X xobject;                  // create an object of class type X
  15636.       xobject.*ptiptr = 10;       // initialize data member
  15637.  
  15638.       cout << "The value of a is " << xobject.*ptiptr << endl;
  15639.       (xobject.*ptfptr) (20);     // call member function
  15640. }
  15641.  
  15642. /************************************************************************
  15643. *
  15644.  
  15645. The output for this example is: 
  15646.  
  15647. The value of a is 10
  15648. The value of b is 20
  15649.  
  15650.                                                                         *
  15651. ************************************************************************/
  15652.  
  15653.  
  15654. ΓòÉΓòÉΓòÉ 11.7. The this Pointer ΓòÉΓòÉΓòÉ
  15655.  
  15656. The keyword this identifies a special type of pointer. When a nonstatic member 
  15657. function is called, the this pointer identifies the class object which the 
  15658. member function is operating on. You cannot declare the this pointer or make 
  15659. assignments to it. 
  15660.  
  15661. The type of the this pointer for a member function of a class type X, is X* 
  15662. const. If the member function is declared with the constant qualifier, the type 
  15663. of the this pointer for that member function for class X, is const X* const. If 
  15664. the member function is declared with the volatile qualifier, the type of the 
  15665. this pointer for that member function for class X is volatile X* const. 
  15666.  
  15667. this is passed as a hidden argument to all nonstatic member function calls and 
  15668. is available as a local variable within the body of all nonstatic functions. 
  15669.  
  15670. For example, you can refer to the particular class object that a member 
  15671. function is called for by using the this pointer in the body of the member 
  15672. function. The following code example produces the output a =  5: 
  15673.  
  15674. // This example illustrates the this pointer
  15675.  
  15676. #include <iostream.h>
  15677. class X
  15678. {
  15679.       int a;
  15680. public:
  15681.       // The 'this' pointer is used to retrieve 'xobj.a' hidden by
  15682.       // the automatic variable 'a'
  15683.       void Set_a(int a) { this->a = a; }
  15684.       void Print_a() { cout << "a = " << a << endl; }
  15685. };
  15686. void main()
  15687. {
  15688.       X xobj;
  15689.       int a = 5;
  15690.       xobj.Set_a(a);
  15691.       xobj.Print_a();
  15692. }
  15693.  
  15694. Unless a class member name is hidden, using the class member name is equivalent 
  15695. to using the class member name qualified with the this pointer. 
  15696.  
  15697. Example of the this Pointer 
  15698.  
  15699. Related Information 
  15700.  
  15701.      Pointers 
  15702.      Member Functions 
  15703.      Pointers to Members 
  15704.      C++ Classes 
  15705.  
  15706.  
  15707. ΓòÉΓòÉΓòÉ <hidden> Example of the this Pointer ΓòÉΓòÉΓòÉ
  15708.  
  15709. /************************************************************************
  15710. *
  15711.  
  15712. The following example shows code using class members without the this pointer. 
  15713. The comments on each line show the equivalent code with the hidden use of the 
  15714. this pointer. 
  15715.  
  15716.                                                                         *
  15717. ************************************************************************/
  15718.  
  15719. // This example uses class members without the this pointer.
  15720.  
  15721. #include <string.h>
  15722. #include <iostream.h>
  15723. class X
  15724. {
  15725.       int len;
  15726.        char *ptr;
  15727. public:
  15728.       int GetLen()          // int GetLen (X* const this)
  15729.       { return len; }       // { return this->len; }
  15730.       char * GetPtr()       // char * GetPtr (X* const this)
  15731.       { return ptr; }       // { return this->ptr; }
  15732.       X& Set(char *);
  15733.       X& Cat(char *);
  15734.       X& Copy(X&);
  15735.       void Print();
  15736. };
  15737.  
  15738. X& X::Set(char *pc)         // X& X::Set(X* const this, char *pc)
  15739. {
  15740.       len = strlen(pc);     // this->len = strlen(pc);
  15741.       ptr = new char[len];  // this->ptr =
  15742.                             //   new char[this->len];
  15743.       strcpy(ptr, pc);      // strcpy(this->ptr, pc);
  15744.       return *this;
  15745. }
  15746.  
  15747. X& X::Cat(char *pc)         // X& X::Cat(X* const this, char *pc)
  15748. {
  15749.       len += strlen(pc);    // this->len += strlen(pc);
  15750.       strcat(ptr,pc);       // strcat(this->ptr,pc);
  15751.       return *this;
  15752. }
  15753.  
  15754. X& X::Copy(X& x)            // X& X::Copy(X* const this, X& x)
  15755. {
  15756.       Set(x.GetPtr());      // this->Set(x.GetPtr(&x));
  15757.       return *this;
  15758. }
  15759.  
  15760. void X::Print()             // void X::Print(X* const this)
  15761. {
  15762.       cout << ptr << endl;  // cout << this->ptr << endl;
  15763. }
  15764. void main()
  15765. {
  15766.       X xobj1;
  15767.       xobj1.Set("abcd").Cat("efgh");
  15768.       // xobj1.Set(&xobj1, "abcd").Cat(&xobj1, "efgh");
  15769.  
  15770.       xobj1.Print();        // xobj1.Print(&xobj1);
  15771.       X xobj2;
  15772.       xobj2.Copy(xobj1).Cat("ijkl");
  15773.       // xobj2.Copy(&xobj2, xobj1).Cat(&xobj2, "ijkl");
  15774.  
  15775.       xobj2.Print();        // xobj2.Print(&xobj2);
  15776. }
  15777.  
  15778. /************************************************************************
  15779. *
  15780.  
  15781. This example produces the following output: 
  15782.  
  15783. abcdefgh
  15784. abcdefghijkl
  15785.  
  15786.                                                                         *
  15787. ************************************************************************/
  15788.  
  15789.  
  15790. ΓòÉΓòÉΓòÉ 11.8. Static Members ΓòÉΓòÉΓòÉ
  15791.  
  15792. Class members can be declared using the storage-class specifier static in the 
  15793. class member list. Only one copy of the static member is shared by all objects 
  15794. of a class in a program. When you declare an object of a class having a static 
  15795. member, the static member is not part of the class object. 
  15796.  
  15797. A typical use of static members is for recording data common to all objects of 
  15798. a class. For example, you can use a static data member as a counter to store 
  15799. the number of objects of a particular class type that are created. Each time a 
  15800. new object is created, this static data member can be incremented to keep track 
  15801. of the total number of objects. 
  15802.  
  15803. The declaration of a static member in the member list of a class is not a 
  15804. definition. The definition of a static member is equivalent to an external 
  15805. variable definition. You must define the static member outside of the class 
  15806. declaration. 
  15807.  
  15808. For example: 
  15809.  
  15810. class X
  15811. {
  15812. public:
  15813.       static int i;
  15814. }
  15815. int X::i = 0; // definition outside class declaration
  15816. //      .
  15817. //      .
  15818. //      .
  15819.  
  15820. A static member can be accessed from outside of its class only if it is 
  15821. declared with the keyword public. You can then access the static member by 
  15822. qualifying the class name using the :: (scope resolution) operator. In the 
  15823. following example: 
  15824.  
  15825. class X
  15826. {
  15827. public:
  15828.       static int f();
  15829. };
  15830. void main ()
  15831. {
  15832.       X::f();
  15833. }
  15834.  
  15835. you can refer to the static member f() of class type X as X::f(). 
  15836.  
  15837. Related Information 
  15838.  
  15839.      static Storage Class Specifier 
  15840.      Using the Class Access Operators with Static Members 
  15841.      Static Data Members 
  15842.      Static Member Functions 
  15843.  
  15844.  
  15845. ΓòÉΓòÉΓòÉ 11.8.1. Using the Class Access Operators with Static Members ΓòÉΓòÉΓòÉ
  15846.  
  15847. You can also access a static member from a class object by using the class 
  15848. access operators . (dot) and -> (arrow). When a static member is accessed 
  15849. through a class access operator, the expression on the left of the . or -> 
  15850. operator is not evaluated. 
  15851.  
  15852. Example of Accessing Static Members 
  15853.  
  15854. A static member can be referred to independently of any association with a 
  15855. class object because there is only one static member shared by all objects of a 
  15856. class. A static member can exist even if no objects of its class have been 
  15857. declared. 
  15858.  
  15859. When you access a static member, the expression that you use to access it is 
  15860. not evaluated. In the following example, the external function f() returns 
  15861. class type X. The function f() can be used to access the static member i of 
  15862. class X. The function f() itself is not called. 
  15863.  
  15864. // This example shows that the expression used to
  15865. // access a static member is not evaluated.
  15866.  
  15867. class X
  15868. {
  15869. public:
  15870.       static int i;
  15871. };
  15872. int X::i = 10;
  15873. X f() { /* ... */ }
  15874. void main ()
  15875. {
  15876.       int a;
  15877.       a = f().i;       // f().i does not call f()
  15878. }
  15879.  
  15880. Related Information 
  15881.  
  15882.      Static Members 
  15883.      Dot Operator . 
  15884.      Arrow Operator -> 
  15885.      Static Data Members 
  15886.      Static Member Functions 
  15887.  
  15888.  
  15889. ΓòÉΓòÉΓòÉ <hidden> Example of Accessing Static Members ΓòÉΓòÉΓòÉ
  15890.  
  15891. /************************************************************************
  15892. *
  15893.  
  15894. The following example uses the class access operators to access static members. 
  15895.  
  15896.                                                                         *
  15897. ************************************************************************/
  15898.  
  15899. // This example illustrates access to static
  15900. // members with class access operators.
  15901.  
  15902. #include <iostream.h>
  15903. class X
  15904. {
  15905.       static int cnt;
  15906. public:
  15907.       // The following routines all set X's static variable cnt
  15908.       // and print its value.
  15909.       void Set_Show (int i)
  15910.       {      X::cnt = i;
  15911.          cout << "X::cnt = " << X::cnt << endl; }
  15912.       void Set_Show (int i, int j )
  15913.       {       this->cnt = i+j;
  15914.          cout << "X::cnt = " << X::cnt << endl; }
  15915.       void Set_Show (X& x, int i)
  15916.       {       x.cnt = i;
  15917.          cout << "X::cnt = " << X::cnt << endl; }
  15918. };
  15919. int X::cnt;
  15920. void main()
  15921. {
  15922.       X xobj1, xobj2;
  15923.       xobj1.Set_Show(11);
  15924.       xobj1.Set_Show(11,22);
  15925.       xobj1.Set_Show(xobj2, 44);
  15926. }
  15927.  
  15928. /************************************************************************
  15929. *
  15930.  
  15931. The above example produces the following output: 
  15932.  
  15933. X::cnt = 11
  15934. X::cnt = 33
  15935. X::cnt = 44
  15936.  
  15937.                                                                         *
  15938. ************************************************************************/
  15939.  
  15940.  
  15941. ΓòÉΓòÉΓòÉ 11.8.2. Static Data Members ΓòÉΓòÉΓòÉ
  15942.  
  15943. Static data members of global classes have external linkage and can be 
  15944. initialized in file scope like other global objects. Static data members follow 
  15945. the usual class access rules, except that they can be initialized in file 
  15946. scope. Static data members and their initializers can access other static 
  15947. private and protected members of their class. The initializer for a static data 
  15948. member is in the scope of the class declaring the member. 
  15949.  
  15950. The following example shows how you can initialize static members using other 
  15951. static members, even though these members are private: 
  15952.  
  15953. class C {
  15954.       static int i;
  15955.       static int j;
  15956.       static int k;
  15957.       static int l;
  15958.       static int m;
  15959.       static int n;
  15960.       static int p;
  15961.       static int q;
  15962.       static int r;
  15963.       static int s;
  15964.       static int f() { return 0; }
  15965.       int a;
  15966. public:
  15967.       C() { a = 0; }
  15968.       };
  15969.  
  15970. C c;
  15971. int C::i = C::f();    // initialize with static member function
  15972. int C::j = C::i;      // initialize with another static data member
  15973. int C::k = c.f();     // initialize with member function from an object
  15974. int C::l = c.j;       // initialize with data member from an object
  15975. int C::s = c.a;       // initialize with nonstatic data member
  15976. int C::r = 1;         // initialize with a constant value
  15977.  
  15978. class Y : private C {} y;
  15979.  
  15980. int C::m = Y::f();
  15981. int C::n = Y::r;
  15982. int C::p = y.r;       // error
  15983. int C::q = y.f();     // error
  15984.  
  15985. The initializations of C::p and C::x cause errors because y is an object of a 
  15986. class that is derived privately from C, and its members are not accessible to 
  15987. members of C. 
  15988.  
  15989. You can only have one definition of a static member in a program. If a static 
  15990. data member is not initialized, it is assigned a zero default value. Local 
  15991. classes cannot have static data members. 
  15992.  
  15993. Example of Static Data Members 
  15994.  
  15995. Related Information 
  15996.  
  15997.      Static Member Functions 
  15998.      Static Members 
  15999.      Using the Class Access Operators with Static Members 
  16000.      External Linkage 
  16001.      Member Access 
  16002.      Local Classes 
  16003.  
  16004.  
  16005. ΓòÉΓòÉΓòÉ <hidden> Example of Static Data Members ΓòÉΓòÉΓòÉ
  16006.  
  16007. /************************************************************************
  16008. *
  16009.  
  16010. The following example shows the declaration, initialization, use, and scope of 
  16011. the static data member si and static member functions Set_si(int) and 
  16012. Print_si(). 
  16013.  
  16014.                                                                         *
  16015. ************************************************************************/
  16016.  
  16017. // This example shows the declaration, initialization,
  16018. // use, and scope of a static data member.
  16019.  
  16020. #include <iostream.h>
  16021. class X
  16022. {
  16023.       int i;
  16024.       static int si;
  16025. public:
  16026.       void Set_i(int i) { this->i = i; }
  16027.       void Print_i() { cout << "i = " << i << endl; }
  16028.       // Equivalent to:
  16029.       // void Print_i(X* this)
  16030.       // { cout << "X::i = " << this->i << endl; }
  16031.       static void Set_si(int si) { X::si = si; }
  16032.  
  16033.       static void Print_si()
  16034.       {
  16035.             cout << "X::si = " << X::si << endl;
  16036.       }
  16037.       // Print_si doesn't have a 'this' pointer
  16038. };
  16039. int X::si = 77;       // Initialize static data member
  16040.  
  16041. void main()
  16042. {
  16043.       X xobj;
  16044.       // Non-static data members and functions belong to specific
  16045.       // instances (here xobj) of class X
  16046.       xobj.Set_i(11);
  16047.       xobj.Print_i();
  16048.  
  16049.       // static data members and functions belong to the class and
  16050.       // can be accessed without using an instance of class X
  16051.       X::Print_si();
  16052.       X::Set_si(22);
  16053.       X::Print_si();
  16054. }
  16055.  
  16056. /************************************************************************
  16057. *
  16058.  
  16059. This example produces the following output: 
  16060.  
  16061. i = 11
  16062. X::si = 77
  16063. X::si = 22
  16064.  
  16065.                                                                         *
  16066. ************************************************************************/
  16067.  
  16068.  
  16069. ΓòÉΓòÉΓòÉ 11.8.3. Static Member Functions ΓòÉΓòÉΓòÉ
  16070.  
  16071. You cannot have static and nonstatic member functions with the same names and 
  16072. the same number and type of arguments. 
  16073.  
  16074. A static member function does not have a this pointer. You can call a static 
  16075. member function using the this pointer of a nonstatic member function. In the 
  16076. following example, the nonstatic member function printall() calls the static 
  16077. member function f() using the this pointer: 
  16078.  
  16079. // This example illustrates a static member function f().
  16080.  
  16081. #include <iostream.h>
  16082. class c {
  16083.             static void f() { cout << "Here is i"
  16084.                                         << i << endl;}
  16085.             static int i;
  16086.             int j;
  16087.       public:
  16088.             c(int firstj): j(firstj) {}
  16089.             void printall();
  16090.             };
  16091. void c::printall() {
  16092.       cout << "Here is j " << this->j << endl;
  16093.       this->f();
  16094.       }
  16095. int c::i = 3;
  16096. void main() {
  16097.       class c C(0);
  16098.       C.printall();
  16099.       }
  16100.  
  16101. A static member function cannot be declared with the keyword virtual. 
  16102.  
  16103. A static member function can access only the names of static members, 
  16104. enumerators, and nested types of the class in which it is declared. 
  16105.  
  16106. Related Information 
  16107.  
  16108.      Member Functions 
  16109.      Using the Class Access Operators with Static Members 
  16110.      Static Data Members 
  16111.      Static Members 
  16112.      The this Pointer 
  16113.      Virtual Functions 
  16114.  
  16115.  
  16116. ΓòÉΓòÉΓòÉ 11.9. Member Access ΓòÉΓòÉΓòÉ
  16117.  
  16118. Member access determines if a class member is accessible in an expression or 
  16119. declaration. Note that accessibility and visibility are independent. Visibility 
  16120. is based on the scoping rules of C++. A class member can be visible and 
  16121. inaccessible at the same time. This section describes how you control the 
  16122. access to the individual nonderived class members by using access specifiers 
  16123. when you declare class members in a member list. 
  16124.  
  16125. Related Information 
  16126.  
  16127.      Access Declarations 
  16128.      Inherited Member Access 
  16129.      Class Member Lists 
  16130.      Classes and Access Control 
  16131.      Access Specifiers 
  16132.      C++ Classes 
  16133.  
  16134.  
  16135. ΓòÉΓòÉΓòÉ 11.9.1. Classes and Access Control ΓòÉΓòÉΓòÉ
  16136.  
  16137. C++ facilitates data abstraction and encapsulation by providing access control 
  16138. for members of class types. 
  16139.  
  16140. For example, if you declare private data members and public member functions, a 
  16141. client program can only access the private members through the public member 
  16142. functions and friends of that class. Such a class would have data hiding 
  16143. because client programs do not have access to implementation details and are 
  16144. forced to use a public interface to manipulate objects of the class. 
  16145.  
  16146. You can control access to class members by using access specifiers. In the 
  16147. following example, the class abc has three private data members a, b, and c, 
  16148. and three public member functions add(), mult(), and the constructor abc(). The 
  16149. main() function creates an object danforth of the abc class and then attempts 
  16150. to print the value of the member a for this object: 
  16151.  
  16152. // This example illustrates class member access specifiers
  16153.  
  16154. #include <iostream.h>
  16155.  
  16156. class abc
  16157. {
  16158. private:
  16159.       int a, b, c;
  16160. public:
  16161.       abc(int p1, int p2, int p3): a(p1), b(p2), c(p3) {}
  16162.       int add() { return a + b + c ; }
  16163.       int mult() { return a * b * c; }
  16164. };
  16165.  
  16166. void main() {
  16167.       abc danforth(1,2,3);
  16168.       cout << "Here is the value of a " << danforth.a << endl;
  16169.                   // This causes an error because a is not
  16170.                   // a public member and cannot be accessed
  16171.                   // directly
  16172.       }
  16173.  
  16174. Because class members are private by default, you can omit the keyword private 
  16175. in the definition of abc. Because a is not a public member, the attempt to 
  16176. access its value directly causes an error. 
  16177.  
  16178. Related Information 
  16179.  
  16180.      Access Declarations 
  16181.      Inherited Member Access 
  16182.      Class Member Lists 
  16183.      Member Access 
  16184.      Access Specifiers 
  16185.      C++ Classes 
  16186.  
  16187.  
  16188. ΓòÉΓòÉΓòÉ 11.9.2. Access Specifiers ΓòÉΓòÉΓòÉ
  16189.  
  16190. The three class member access specifiers have the following effect: 
  16191.  
  16192.  public class members 
  16193.            can be accessed by any function, file or class. 
  16194.  
  16195.  private class members 
  16196.            can be accessed only by member functions and friends of the class in 
  16197.            which the member is declared. 
  16198.  
  16199.  protected class members 
  16200.            can be accessed only by member functions and friends of the class in 
  16201.            which they are declared and by member functions and friends of 
  16202.            classes derived with public or protected access from the class in 
  16203.            which the protected members are declared. The access specifier 
  16204.            protected can be used for nonbase class members, but it is 
  16205.            equivalent to private unless it is used in a base class member 
  16206.            declaration or in a base list. 
  16207.  
  16208.  The default access for an individual class member depends on the class key 
  16209.  used in the class declaration. Members of classes declared with the keyword 
  16210.  class are private by default. Members of classes declared with the keyword 
  16211.  struct or union are public by default. 
  16212.  
  16213.  The access specifier protected is meaningful only in the context of 
  16214.  derivation. You can control the access to inherited members (that is, base 
  16215.  class members) by including access specifiers in the base list of the derived 
  16216.  class declaration. You can also restore the access to an inherited member from 
  16217.  a derived class by using an access declaration. 
  16218.  
  16219.  Access for inherited members is described in Inherited Member Access. 
  16220.  
  16221.  Member lists can include access specifiers as labels. Members declared after 
  16222.  these labels have access as specified by the label they follow. An access 
  16223.  specifier determines the access for members until another access specifier is 
  16224.  used or until the end of the class declaration. You can use any number of 
  16225.  access specifiers in any order. 
  16226.  
  16227.  Examples of Access Specifiers 
  16228.  
  16229.  Related Information 
  16230.  
  16231.      Access Declarations 
  16232.      Inherited Member Access 
  16233.      Class Member Lists 
  16234.      Member Access 
  16235.      Classes and Access Control 
  16236.      C++ Classes 
  16237.  
  16238.  
  16239. ΓòÉΓòÉΓòÉ <hidden> Examples of Access Specifiers ΓòÉΓòÉΓòÉ
  16240.  
  16241. /************************************************************************
  16242. *
  16243.  
  16244. The following example shows access specifiers in member lists. 
  16245.  
  16246.                                                                         *
  16247. ************************************************************************/
  16248.  
  16249. class X
  16250. {
  16251.       int a;             // private data by default
  16252. public:
  16253.       void f(int);       // public function
  16254.       int b;             // public data
  16255. private:
  16256.       int c;             // private data
  16257. protected:
  16258.       void g(int);       // protected function
  16259. };
  16260. struct Y
  16261. {
  16262.       int a;             // public data by default
  16263. public:
  16264.       int b;             // public data
  16265. private:
  16266.       void g(int);       // private function
  16267.       int c;             // private data
  16268. };
  16269.  
  16270.  
  16271. ΓòÉΓòÉΓòÉ 11.10. Friends ΓòÉΓòÉΓòÉ
  16272.  
  16273. A friend of a class X is a function or class that is granted the same access to 
  16274. X as the members of X. Functions declared with the friend specifier in a class 
  16275. member list are called friend functions of that class. Classes declared with 
  16276. the friend specifier in the member list of another class are called friend 
  16277. classes of that class. 
  16278.  
  16279. A class Y must be defined before any member of Y can be declared a friend of 
  16280. another class. 
  16281.  
  16282. You can declare an entire class as a friend. 
  16283.  
  16284. If the class has not been previously declared, use an elaborated type specifier 
  16285. and a qualified type specifier to specify the class name. 
  16286.  
  16287. If the friend class has been previously declared, you can omit the keyword 
  16288. class, as shown in the following example: 
  16289.  
  16290. class F;
  16291. class X
  16292. {
  16293. public:
  16294.  
  16295.       X() {a=1; b=2;}
  16296. private:
  16297.       int a, b;
  16298.       friend F; // elaborated-type-specifier not required
  16299. };
  16300.  
  16301. Examples of Friends 
  16302.  
  16303. Related Information 
  16304.  
  16305.      Friend Scope 
  16306.      Friend Access 
  16307.      C++ Classes 
  16308.      Member Functions 
  16309.  
  16310.  
  16311. ΓòÉΓòÉΓòÉ <hidden> Example of a friend Function ΓòÉΓòÉΓòÉ
  16312.  
  16313. /************************************************************************
  16314. *
  16315.  
  16316. In the following example, the friend function print is a member of class Y and 
  16317. accesses the private data members a and b of class X. 
  16318.  
  16319.                                                                         *
  16320. ************************************************************************/
  16321.  
  16322. // This example illustrates a friend function.
  16323.  
  16324. #include <iostream.h>
  16325. class X;
  16326. class Y
  16327. {
  16328. public:
  16329.       void print(X& x);
  16330. };
  16331. class X
  16332. {
  16333. public:
  16334.       X() {a=1; b=2;}
  16335. private:
  16336.       int a, b;
  16337.       friend void Y::print(X& x);
  16338. };
  16339. void Y::print(X& x)
  16340. {
  16341.       cout << "A is "<< x.a << endl;
  16342.       cout << "B is " << x.b << endl;
  16343. }
  16344. void main ()
  16345. {
  16346.       X xobj;
  16347.       Y yobj;
  16348.       yobj.print(xobj);
  16349. }
  16350.  
  16351. /************************************************************************
  16352. *
  16353.  
  16354. In the following example, the friend class F has a member function print that 
  16355. accesses the private data members a and b of class X and performs the same task 
  16356. as the friend function print in the above example. Any other members declared 
  16357. in class F also have access to all members of class X. In the example, the 
  16358. friend class F has not been previously declared, so an elaborated type 
  16359. specifier and a qualified type specifier are used to specify the class name. 
  16360.  
  16361.                                                                         *
  16362. ************************************************************************/
  16363.  
  16364. // This example illustrates a friend class.
  16365.  
  16366. #include <iostream.h>
  16367. class X
  16368. {
  16369. public:
  16370.  
  16371.       X() {a=1; b=2;}           // constructor
  16372. private:
  16373.       int a, b;
  16374.       friend class F;           // friend class
  16375. };
  16376. class F
  16377. {
  16378. public:
  16379.       void print(X& x)
  16380.       {
  16381.             cout << "A is " << x.a << endl;
  16382.             cout << "B is " << x.b << endl;
  16383.       }
  16384. };
  16385. void main ()
  16386. {
  16387.       X xobj;
  16388.       F fobj;
  16389.       fobj.print(xobj);
  16390. }
  16391.  
  16392. /************************************************************************
  16393. *
  16394.  
  16395. Both the above examples produce the following output: 
  16396.  
  16397. A is 1
  16398. B is 2
  16399.  
  16400.                                                                         *
  16401. ************************************************************************/
  16402.  
  16403.  
  16404. ΓòÉΓòÉΓòÉ 11.10.1. Friend Scope ΓòÉΓòÉΓòÉ
  16405.  
  16406. The name of a friend function or class first introduced in a friend declaration 
  16407. is not in the scope of the class granting friendship (also called the enclosing 
  16408. class) and is not a member of the class granting friendship. 
  16409.  
  16410. The name of a function first introduced in a friend declaration is in the scope 
  16411. of the first nonclass scope that contains the enclosing class. The body of a 
  16412. function provided in a friend declaration is handled in the same way as a 
  16413. member function defined within a class. Processing of the definition does not 
  16414. start until the end of the outermost enclosing class. In addition, unqualified 
  16415. names in the body of the function definition are searched for starting from the 
  16416. class containing the function definition. 
  16417.  
  16418. A class that is first declared in a friend declaration is equivalent to an 
  16419. extern declaration. For example: 
  16420.  
  16421. class B {};
  16422. class A
  16423. {
  16424.       friend class B; // global class B is a friend of A
  16425. };
  16426.  
  16427. If the name of a friend class has been introduced before the friend 
  16428. declaration, the compiler searches for a class name that matches the name of 
  16429. the friend class beginning at the scope of the friend declaration. If the 
  16430. declaration of a nested class is followed by the declaration of a friend class 
  16431. with the same name, the nested class is a friend of the enclosing class. 
  16432.  
  16433. The scope of a friend class name is the first nonclass enclosing scope. For 
  16434. example: 
  16435.  
  16436. class A {
  16437.    class B { // arbitrary nested class definitions
  16438.       friend class C;
  16439.    };
  16440. };
  16441.  
  16442. is equivalent to: 
  16443.  
  16444. class C;
  16445. class A {
  16446.    class B { // arbitrary nested class definitions
  16447.       friend class C;
  16448.    };
  16449. };
  16450.  
  16451. If the friend function is a member of another class, you need to use the class 
  16452. member access operators. For example: 
  16453.  
  16454. class A
  16455. {
  16456. public:
  16457.       int f() { /* ... */ }
  16458. };
  16459. class B
  16460. {
  16461.       friend int A::f();
  16462. };
  16463.  
  16464. Friends of a base class are not inherited by any classes derived from that base 
  16465. class. 
  16466.  
  16467. Related Information 
  16468.  
  16469.      Scope of Class Names 
  16470.      Friend Access 
  16471.      Friends 
  16472.      Nested Classes 
  16473.      Derivation 
  16474.  
  16475.  
  16476. ΓòÉΓòÉΓòÉ 11.10.2. Friend Access ΓòÉΓòÉΓòÉ
  16477.  
  16478. A friend of a class can access the private and protected members of that class. 
  16479. Normally, you can only access the private members of a class through member 
  16480. functions of that class, and you can only access the protected members of a 
  16481. class through member functions of a class or classes derived from that class. 
  16482.  
  16483. Friend declarations are not affected by access specifiers. 
  16484.  
  16485. Related Information 
  16486.  
  16487.      Member Access 
  16488.      Friend Scope 
  16489.      Friends 
  16490.  
  16491.  
  16492. ΓòÉΓòÉΓòÉ 12. C++ Overloading ΓòÉΓòÉΓòÉ
  16493.  
  16494. Overloading enables you to redefine functions and most standard C++ operators. 
  16495. Typically, you overload a function or operator if you want to extend the 
  16496. operations the function or operator performs to different data types. 
  16497.  
  16498. This section discusses: 
  16499.  
  16500.      Overloading Functions 
  16501.      Argument Matching in Overloaded Functions 
  16502.      Overloading Operators 
  16503.      Overloading Unary Operators 
  16504.      Overloading Binary Operators 
  16505.      Special Overloaded Operators 
  16506.  
  16507.  Related Information 
  16508.  
  16509.      Expressions and Operators 
  16510.      Functions 
  16511.      C++ Classes 
  16512.  
  16513.  
  16514. ΓòÉΓòÉΓòÉ 12.1. Overloading Functions ΓòÉΓòÉΓòÉ
  16515.  
  16516. You can overload a function by having multiple declarations of the same 
  16517. function name in the same scope. The declarations differ in the type and number 
  16518. of arguments in the argument list. When an overloaded function is called, the 
  16519. correct function is selected by comparing the types of the actual arguments 
  16520. with the types of the formal arguments. 
  16521.  
  16522. Consider a function print, which displays an int. As shown in the following 
  16523. example, you can overload the function print to display other types, for 
  16524. example, double and char*. You can have three functions with the same name, 
  16525. each performing a similar operation on a different data type. 
  16526.  
  16527. // This example illustrates function overloading.
  16528.  
  16529. #include <iostream.h>
  16530.  
  16531. void print(int i) { cout << " Here is int " << i << endl; }
  16532. void print(double  f) { cout << " Here is float "
  16533.                                   << f << endl; }
  16534. void print(char* c) { cout << " Here is char* " << c << endl; }
  16535. void main() {
  16536.       print(10);            // calls print(int)
  16537.       print(10.10);         // calls print(double)
  16538.       print("ten");         // calls print(char*)
  16539. }
  16540.  
  16541. Two function declarations are identical if all of the following are true: 
  16542.  
  16543.      They have the same function name 
  16544.      They are declared in the same scope 
  16545.      They have identical argument lists 
  16546.  
  16547.  When you declare a function name more than once in the same scope, the second 
  16548.  declaration of the function name is interpreted by the compiler as follows: 
  16549.  
  16550.      If the return type, argument types, and number of arguments of the two 
  16551.       declarations are identical, the second declaration is considered a 
  16552.       declaration of the same function as the first. 
  16553.      If only the return types of the two function declarations differ, the 
  16554.       second declaration is an error. 
  16555.      If either the argument types or number of arguments of the two 
  16556.       declarations differ, the function is considered to be overloaded. 
  16557.  
  16558.  Restrictions on Overloaded Functions 
  16559.  
  16560.  Related Information 
  16561.  
  16562.      Functions 
  16563.      Function Declarations 
  16564.      Scope in C++ 
  16565.      Argument Matching in Overloaded Functions 
  16566.      Member Functions 
  16567.      C++ Inheritance 
  16568.  
  16569.  
  16570. ΓòÉΓòÉΓòÉ <hidden> Restrictions on Overloaded Functions ΓòÉΓòÉΓòÉ
  16571.  
  16572.      Functions that differ only in return type cannot have the same name. 
  16573.  
  16574.      Two member functions that differ only in that one is declared with the 
  16575.       keyword static cannot have the same name. 
  16576.  
  16577.      A typedef is a synonym for another type, not a separate type. The 
  16578.       following two declarations of spadina() are declarations of the same 
  16579.       function: 
  16580.  
  16581.                   typedef int I;
  16582.                   void spadina(float, int);
  16583.                   void spadina(float, I);
  16584.  
  16585.      A member function of a derived class is not in the same scope as a member 
  16586.       function in a base class with the same name. A derived class member hides 
  16587.       a base class member with the same name. 
  16588.  
  16589.      Argument types that differ only in that one is a pointer * and the other 
  16590.       is an array [] are identical. The following two declarations are 
  16591.       equivalent: 
  16592.  
  16593.                   f(char*);
  16594.                   f(char[10]);
  16595.  
  16596.  
  16597. ΓòÉΓòÉΓòÉ 12.2. Argument Matching in Overloaded Functions ΓòÉΓòÉΓòÉ
  16598.  
  16599. When an overloaded function or overloaded operator is called, the compiler 
  16600. chooses the function declaration with the best match on all arguments from all 
  16601. the function declarations that are visible. The compiler compares the actual 
  16602. arguments of a function call with the formal arguments of all declarations of 
  16603. the function that are visible. For a best match to occur, the compiler must be 
  16604. able to distinguish a function that: 
  16605.  
  16606.      Has at least as good a match on all arguments as any other function with 
  16607.       the same name 
  16608.      Has at least one better argument match than any other function with the 
  16609.       same name 
  16610.  
  16611.  If no such function exists, the call is not allowed. A call to an overloaded 
  16612.  function has three possible outcomes. The compiler can find: 
  16613.  
  16614.      An exact match 
  16615.      No match 
  16616.      An ambiguous match 
  16617.  
  16618.  An ambiguous match occurs when the actual arguments of the function call match 
  16619.  more than one overloaded function. 
  16620.  
  16621.  Argument matching can include performing standard and user-defined conversions 
  16622.  on the arguments to match the actual arguments with the formal arguments. Only 
  16623.  a single user-defined conversion is performed in a sequence of conversions on 
  16624.  an actual argument. In addition, the best-matching sequence of standard 
  16625.  conversions is performed on an actual argument. The best-matching sequence is 
  16626.  the shortest sequence of conversions between two standard types. For example, 
  16627.  the conversion: 
  16628.  
  16629.   int -> float -> double
  16630.  
  16631.  can be shortened to the best-matching conversion sequence: 
  16632.  
  16633.   int -> double
  16634.  
  16635.  because the conversion from int to double is allowed. 
  16636.  
  16637.  Trivial Conversions do not affect the choice of conversion sequence. 
  16638.  Conversion sequences are described in Sequence of Argument Conversions. 
  16639.  
  16640.  Related Information 
  16641.  
  16642.      Sequence of Argument Conversions 
  16643.      Trivial Conversions 
  16644.      Overloading Functions 
  16645.      Overloading Operators 
  16646.  
  16647.  
  16648. ΓòÉΓòÉΓòÉ 12.2.1. Sequence of Argument Conversions ΓòÉΓòÉΓòÉ
  16649.  
  16650. Argument-matching conversions occur in the following order: 
  16651.  
  16652.    1. An exact match in which the actual arguments match exactly (including a 
  16653.       match with one or more trivial conversions) with the type and number of 
  16654.       formal arguments of one declaration of the overloaded function 
  16655.  
  16656.    2. A match with promotions in which a match is found when one or more of the 
  16657.       actual arguments is promoted 
  16658.  
  16659.    3. A match with standard conversions in which a match is found when one or 
  16660.       more of the actual arguments is converted by a standard conversion 
  16661.  
  16662.    4. A match with user-defined conversions in which a match is found when one 
  16663.       or more of the actual arguments is converted by a user-defined conversion 
  16664.  
  16665.    5. A match with ellipses 
  16666.  
  16667.  Match through promotion follows the rules for Integral Promotions and Standard 
  16668.  Type Conversions. 
  16669.  
  16670.  You can override an exact match by using an explicit cast. In the following 
  16671.  example, the second call to f() matches with f(void*): 
  16672.  
  16673.   void f(int);
  16674.   void f(void*);
  16675.   void main()
  16676.   {
  16677.         f(0xaabb);            // matches f(int);
  16678.         f((void*) 0xaabb);    // matches f(void*)
  16679.   }
  16680.  
  16681.  The implicit first argument for a nonstatic member function or operator is the 
  16682.  this pointer. It refers to the class object for which the member function is 
  16683.  called. When you overload a nonstatic member function, the first implicit 
  16684.  argument, the this pointer, is matched with the object or pointer used in the 
  16685.  call to the member function. User-defined conversions are not applied in this 
  16686.  type of argument matching for overloaded functions or operators. 
  16687.  
  16688.  When you call an overloaded member function of class X using the . (dot) or -> 
  16689.  (arrow) operator, the this pointer has type X* const. The type of the this 
  16690.  pointer for a constant object is const X* const. The type of the this pointer 
  16691.  for a volatile object is volatile X* const. 
  16692.  
  16693.  Related Information 
  16694.  
  16695.      Argument Matching in Overloaded Functions 
  16696.      Trivial Conversions 
  16697.      Implicit Type Conversions 
  16698.      User-Defined Conversions 
  16699.      The this Pointer 
  16700.      Overloading Functions 
  16701.      Overloading Operators 
  16702.      Dot Operator . 
  16703.      Arrow Operator -> 
  16704.  
  16705.  
  16706. ΓòÉΓòÉΓòÉ 12.2.2. Trivial Conversions ΓòÉΓòÉΓòÉ
  16707.  
  16708. Functions cannot be distinguished if they have the same name and have arguments 
  16709. that differ only in that one is declared as a reference to a type and the other 
  16710. is that type. You cannot have two functions with the same name and with 
  16711. arguments differing only in this respect. Because the following two 
  16712. declarations cannot be distinguished, the second one causes an error: 
  16713.  
  16714. double f(double i);  // declaration
  16715.  
  16716. double f(double &i); // error
  16717.  
  16718. However, functions with the same name having arguments that differ only in that 
  16719. one is a pointer or reference and the other is a pointer to const or const 
  16720. reference can be distinguished. Functions with the same name having arguments 
  16721. that differ only in that one is a pointer or reference and the other is a 
  16722. pointer to volatile or volatile reference can also be distinguished. For the 
  16723. purpose of finding a best match of arguments, functions that have a volatile or 
  16724. const match (not requiring a trivial conversion) are better than those that 
  16725. have a volatile or const mismatch. 
  16726.  
  16727. Related Information 
  16728.  
  16729.      Argument Matching in Overloaded Functions 
  16730.      Sequence of Argument Conversions 
  16731.      Implicit Type Conversions 
  16732.      User-Defined Conversions 
  16733.      Overloading Functions 
  16734.      Overloading Operators 
  16735.  
  16736.  
  16737. ΓòÉΓòÉΓòÉ 12.3. Overloading Operators ΓòÉΓòÉΓòÉ
  16738.  
  16739. You can overload one of the standard C++ operators by redefining it to perform 
  16740. a particular operation when it is applied to an object of a particular class. 
  16741. Overloaded operators must have at least one argument that has class type. An 
  16742. overloaded operator is called an operator function and is declared with the 
  16743. keyword operator preceding the operator. Overloaded operators are distinct from 
  16744. overloaded functions, but, like overloaded functions, they are distinguished by 
  16745. the number and types of operands used with the operator. 
  16746.  
  16747. You can overload any of the following operators: 
  16748.  
  16749. +     -     *     /     %     ^     &     |     ~
  16750. !     =     <     >     +=    -=    *=    /=    %=
  16751. ^=    &=    |=    <<    >>    <<=   >>=   ==    !=
  16752. <=    >=    &&    ||    ++    --    ,     ->*   ->
  16753. ()    []    new   delete
  16754.  
  16755. where () is the function call operator and [] is the subscript operator. 
  16756.  
  16757. Consider the standard + (plus) operator. When this operator is used with 
  16758. operands of different standard types, the operators have slightly different 
  16759. meanings. For example, the addition of two integers is not implemented in the 
  16760. same way as the addition of two floating-point numbers. C++ allows you to 
  16761. define your own meanings for the standard C++ operators when they are applied 
  16762. to class types. 
  16763.  
  16764. Example of an Overloaded Operator 
  16765.  
  16766. You can overload both the unary and binary forms of: 
  16767.  
  16768.       +      -      *      &
  16769.  
  16770. When an overloaded operator is a member function, the first operand is matched 
  16771. against the class type of the overloaded operator. The second operand, if one 
  16772. exists, is matched against the argument in the overloaded operator call. 
  16773.  
  16774. When an overloaded operator is a nonmember function, at least one operand must 
  16775. have class or enumeration type. The first operand is matched against the first 
  16776. argument in the overloaded operator call. The second operand, if one exists, is 
  16777. matched against the second argument in the overloaded operator call. 
  16778.  
  16779. The argument-matching conventions and rules described in Argument Matching in 
  16780. Overloaded Functions apply to overloaded operators. 
  16781.  
  16782. An overloaded operator must be either a member function, as shown in the 
  16783. following example: 
  16784.  
  16785. class X
  16786. {
  16787. public:
  16788.       X operator!();
  16789.       X& operator =(X&);
  16790.       X operator+(X&);
  16791. };
  16792. X X::operator!() { /* ... */ }
  16793. X& X::operator=(X& x) { /* ... */ }
  16794. X X::operator+(X& x) { /* ... */ }
  16795.  
  16796. or take at least one argument of class, a reference to a class, an enumeration, 
  16797. or a reference to an enumeration, as shown below: 
  16798.  
  16799. class Y;
  16800. {
  16801. //      .
  16802. };
  16803. class Z;
  16804. {
  16805. //      .
  16806. };
  16807. Y operator!(Y& y);
  16808. Z operator+(Z& z, int);
  16809.  
  16810. Usually, overloaded operators are invoked using the normal operator syntax. You 
  16811. can also call overloaded operators explicitly by qualifying the operator name. 
  16812.  
  16813. Restrictions on Overloaded Operators 
  16814.  
  16815. Related Information 
  16816.  
  16817.      Overloading Unary Operators 
  16818.      Overloading Binary Operators 
  16819.      Special Overloaded Operators 
  16820.      Argument Matching in Overloaded Functions 
  16821.      Overloading Functions 
  16822.      Expressions and Operators 
  16823.  
  16824.  
  16825. ΓòÉΓòÉΓòÉ <hidden> Example of an Overloaded Operator ΓòÉΓòÉΓòÉ
  16826.  
  16827. /************************************************************************
  16828. *
  16829.  
  16830. In the following example, a class called complx is defined to model complex 
  16831. numbers, and the + (plus) operator is redefined in this class to add two 
  16832. complex numbers. 
  16833.  
  16834.                                                                         *
  16835. ************************************************************************/
  16836.  
  16837. // This example illustrates overloading the plus (+) operator.
  16838.  
  16839. #include <iostream.h>
  16840. class complx
  16841. {
  16842.       double real,
  16843.              imag;
  16844. public:
  16845.       complx( double real = 0., double imag = 0.); // constructor
  16846.       complx operator+(const complx&) const;       // operator+()
  16847. };
  16848. // define constructor
  16849. complx::complx( double r, double i )
  16850. {
  16851.       real = r; imag = i;
  16852. }
  16853. // define overloaded + (plus) operator
  16854. complx complx::operator+ (const complx& c) const
  16855. {
  16856.       complx result;
  16857.       result.real = (this->real + c.real);
  16858.       result.imag = (this->imag + c.imag);
  16859.       return result;
  16860. }
  16861. void main()
  16862. {
  16863.       complx x(4,4);
  16864.       complx y(6,6);
  16865.       complx z = x + y; // calls complx::operator+()
  16866. }
  16867.  
  16868. /************************************************************************
  16869. *
  16870.  
  16871. For the class complx, described above, you can call the overloaded + (plus) 
  16872. operator either implicitly or explicitly as shown below. 
  16873.  
  16874.                                                                         *
  16875. ************************************************************************/
  16876.  
  16877. // This example shows implicit and explicit calls
  16878. // to an overloaded plus (+) operator.
  16879.  
  16880. class complx
  16881. {
  16882.       double real,
  16883.              imag;
  16884. public:
  16885.       complx( double real = 0., double imag = 0.);
  16886.       complx operator+(const complx&) const;
  16887. };
  16888. //      .
  16889. //      .
  16890. //      .
  16891. void main()
  16892. {
  16893.       complx x(4,4);
  16894.       complx y(6,6);
  16895.       complx u = x.operator+(y); // explicit call
  16896.       complx z = x + y;          // implicit call to complx::operator+()
  16897. }
  16898.  
  16899.  
  16900. ΓòÉΓòÉΓòÉ 12.3.1. Restrictions on Overloaded Operators ΓòÉΓòÉΓòÉ
  16901.  
  16902.      The following C++ operators cannot be overloaded: 
  16903.  
  16904.                   .      .*      ::      ?:
  16905.  
  16906.      You cannot overload the preprocessing symbols # and ##. 
  16907.  
  16908.      You cannot change the precedence, grouping, or number of operands of the 
  16909.       standard C++ operators. 
  16910.  
  16911.      An overloaded operator (except for the function call operator) cannot 
  16912.       have default arguments or an ellipsis in the argument list. 
  16913.  
  16914.      You must declare the overloaded =, [], () and -> operators as nonstatic 
  16915.       member functions to ensure that they receive lvalues as their first 
  16916.       operands. 
  16917.  
  16918.      The operators new and delete do not follow the general rules described in 
  16919.       this section. Overloading new and delete is described in Overloaded new 
  16920.       and delete. 
  16921.  
  16922.      All operators except the = operator are inherited. Copy by Assignment 
  16923.       describes the behavior of the assignment operator. 
  16924.  
  16925.      Unless they are explicitly mentioned in Special Overloaded Operators, 
  16926.       overloaded unary and binary operators follow the rules outlined in 
  16927.       Overloading Unary Operators and Overloading Binary Operators. 
  16928.  
  16929.  For more information on standard C and C++ operators, see Expressions and 
  16930.  Operators. 
  16931.  
  16932.  
  16933. ΓòÉΓòÉΓòÉ 12.3.2. Overloading Unary Operators ΓòÉΓòÉΓòÉ
  16934.  
  16935. You can overload a prefix unary operator by declaring a nonmember function 
  16936. taking one argument or a nonstatic member function taking no arguments. 
  16937.  
  16938. When you prefix a class object with an overloaded unary operator, for example: 
  16939.  
  16940. class X
  16941. {
  16942. // ...
  16943. };
  16944. void main ()
  16945. {
  16946.       X x;
  16947.       !x;       // overloaded unary operator
  16948. }
  16949.  
  16950. the operator function call !x can be interpreted as:  x.operator!()  or 
  16951. operator!(x) . depending on the declarations of the operator function. If both 
  16952. forms of the operator function have been declared, argument matching determines 
  16953. which interpretation is used. 
  16954.  
  16955. Related Information 
  16956.  
  16957.      Overloading Binary Operators 
  16958.      Overloading Operators 
  16959.      Special Overloaded Operators 
  16960.      Restrictions on Overloaded Operators 
  16961.      Unary Expressions 
  16962.  
  16963.  
  16964. ΓòÉΓòÉΓòÉ 12.3.3. Overloading Binary Operators ΓòÉΓòÉΓòÉ
  16965.  
  16966. You can overload a binary operator by declaring a nonmember function taking two 
  16967. arguments or a nonstatic member function taking one argument. 
  16968.  
  16969. When you use a class object with an overloaded binary operator, for example: 
  16970.  
  16971. class X
  16972. {
  16973. // ...
  16974. };
  16975. void main ()
  16976. {
  16977.       X x;
  16978.       int y=10;
  16979.       x*y;       // overloaded binary operator
  16980. }
  16981.  
  16982. the operator function call x*y can be interpreted as:  x.operator*(y)  or 
  16983. operator*(x,y)  depending on the declarations of the operator function. If both 
  16984. forms of the operator function have been declared, argument matching determines 
  16985. which interpretation is used. 
  16986.  
  16987. Related Information 
  16988.  
  16989.      Overloading Unary Operators 
  16990.      Overloading Operators 
  16991.      Special Overloaded Operators 
  16992.      Restrictions on Overloaded Operators 
  16993.      Binary Expressions 
  16994.  
  16995.  
  16996. ΓòÉΓòÉΓòÉ 12.4. Special Overloaded Operators ΓòÉΓòÉΓòÉ
  16997.  
  16998. The following overloaded operators do not fully follow the rules for unary or 
  16999. binary overloaded operators: 
  17000.  
  17001.      Assignment 
  17002.      Function Call 
  17003.      Subscripting 
  17004.      Class Member Access 
  17005.      Increment and Decrement 
  17006.      new and delete 
  17007.  
  17008.  Related Information 
  17009.  
  17010.      Overloading Unary Operators 
  17011.      Overloading Binary Operators 
  17012.      Overloading Operators 
  17013.      Restrictions on Overloaded Operators 
  17014.      Member Functions 
  17015.  
  17016.  
  17017. ΓòÉΓòÉΓòÉ 12.4.1. Overloaded Assignment ΓòÉΓòÉΓòÉ
  17018.  
  17019. You can only overload an assignment operator by declaring a nonstatic member 
  17020. function. The following example shows how you can overload the assignment 
  17021. operator for a particular class: 
  17022.  
  17023. class X
  17024. {
  17025. public:
  17026.       X();
  17027.       X& operator=(X&);
  17028.       X& operator=(int);
  17029.  
  17030. };
  17031. X& X::operator=(X& x) { /* ... */ }
  17032. X& X::operator=(int i) { /* ... */ }
  17033.  
  17034. void main()
  17035. {
  17036.       X x1, x2;
  17037.       x1 = x2;      // call x1.operator=(x2)
  17038.       x1 = 5;       // call x1.operator=(5)
  17039. }
  17040.  
  17041. You cannot declare an overloaded assignment operator that is a nonmember 
  17042. function. Overloaded assignment operators are not inherited. 
  17043.  
  17044. If a copy assignment operator function is not defined for a class, the copy 
  17045. assignment operator function is defined by default as a memberwise assignment 
  17046. of the class members. If assignment operator functions exist for base classes 
  17047. or class members, these operators are used when the compiler generates default 
  17048. copy assignment operators. See Copy by Assignment for more information. 
  17049.  
  17050. For more information on standard assignment operators, see Assignment 
  17051. Expressions. 
  17052.  
  17053.  
  17054. ΓòÉΓòÉΓòÉ 12.4.2. Overloaded Function Calls ΓòÉΓòÉΓòÉ
  17055.  
  17056. The operands are function_name and an optional expression_list. The operator 
  17057. function operator() must be defined as a nonstatic member function. You cannot 
  17058. declare an overloaded function call operator that is a nonmember function. 
  17059.  
  17060. If you make the following call for the class object x: 
  17061.  
  17062. x (arg1, arg2, arg3)
  17063.  
  17064. it is interpreted as 
  17065.  
  17066. x.operator()(arg1, arg2, arg3)
  17067.  
  17068. Unlike all other overloaded operators, you can provide default arguments and 
  17069. ellipses in the argument list for the function call operator. For example: 
  17070.  
  17071. class X
  17072. {
  17073. public:
  17074.       X& operator() (int = 5);
  17075. };
  17076.  
  17077. For more information on the standard function call operator, see Function 
  17078. Calls ( ). 
  17079.  
  17080.  
  17081. ΓòÉΓòÉΓòÉ 12.4.3. Overloaded Subscripting ΓòÉΓòÉΓòÉ
  17082.  
  17083. An expression containing the subscripting operator has syntax of the form: 
  17084.  
  17085.       identifier [ expression ]
  17086.  
  17087. and is considered a binary operator. The operands are identifier and 
  17088. expression. The operator function operator[] must be defined as a nonstatic 
  17089. member function. You cannot declare an overloaded subscript operator that is a 
  17090. nonmember function. 
  17091.  
  17092. A subscripting expression for the class object x: 
  17093.  
  17094. x [y]
  17095.  
  17096. is interpreted as x.operator[](y). It is not interpreted as operator[](x,y) 
  17097. because it is defined as a nonstatic member function. 
  17098.  
  17099. For more information on the standard subscripting operator, see Array 
  17100. Subscript[ ]. 
  17101.  
  17102.  
  17103. ΓòÉΓòÉΓòÉ 12.4.4. Overloaded Class Member Access ΓòÉΓòÉΓòÉ
  17104.  
  17105. An expression containing the class member access -> (arrow) operator has syntax 
  17106. of the form: 
  17107.  
  17108.       identifier -> name-expression
  17109.  
  17110. and is considered a unary operator. The operator function operator->() must be 
  17111. defined as a nonstatic member function. 
  17112.  
  17113. The following restrictions apply to class member access operators: 
  17114.  
  17115.      You cannot declare an overloaded arrow operator that is a nonmember 
  17116.       function. 
  17117.      You cannot overload the class member access . (dot) operator. 
  17118.  
  17119.  Consider the following example of overloading the -> (arrow) operator: 
  17120.  
  17121.   class Y
  17122.   {
  17123.   public:
  17124.         void f();
  17125.   };
  17126.   class X
  17127.   {
  17128.   public:
  17129.         Y* operator->();
  17130.   };
  17131.   X x;
  17132.   x->f();
  17133.  
  17134.  Here x->f() is interpreted as:  ( x.operator->() )-> f() . 
  17135.  
  17136.  x.operator->() must return either a reference to a class object or a class 
  17137.  object for which the overloaded operator-> function is defined or a pointer to 
  17138.  any class. If the overloaded operator-> function returns a class type, the 
  17139.  class type must not be the same as the class declaring the function, and the 
  17140.  class type returned must contain its own definition of an overloaded -> 
  17141.  operator function. 
  17142.  
  17143.  For more information on the standard class member access arrow operator, see 
  17144.  Arrow Operator ->. 
  17145.  
  17146.  
  17147. ΓòÉΓòÉΓòÉ 12.4.5. Overloaded Increment and Decrement ΓòÉΓòÉΓòÉ
  17148.  
  17149. The prefix increment operator ++ can be overloaded for a class type by 
  17150. declaring a nonmember function operator with one argument of class type or a 
  17151. reference to class type, or by declaring a member function operator with no 
  17152. arguments. 
  17153.  
  17154. In the following example, the increment operator is overloaded in both ways: 
  17155.  
  17156. // This example illustrates an overloaded prefix increment operator.
  17157.  
  17158. class X
  17159. {
  17160.       int a;
  17161. public:
  17162.       operator++();      // member prefix increment operator
  17163. };
  17164. class Y { /* ... */ };
  17165. operator++(Y& y);        // nonmember prefix increment operator
  17166.  
  17167. // Definitions of prefix increment operator functions
  17168. // ...
  17169.  
  17170. void main()
  17171. {
  17172.       X x;
  17173.       Y y;
  17174.       ++x;               // x.operator++
  17175.       x.operator++();    // x.operator++
  17176.       operator++(y);     // nonmember operator++
  17177.       ++y;               // nonmember operator++
  17178. }
  17179.  
  17180. The postfix increment operator ++ can be overloaded for a class type by 
  17181. declaring a nonmember function operator operator++() with two arguments, the 
  17182. first having class type and the second having type int. Alternatively, you can 
  17183. declare a member function operator operator++() with one argument having type 
  17184. int. The compiler uses the int argument to distinguish between the prefix and 
  17185. postfix increment operators. For implicit calls, the default value is zero. 
  17186.  
  17187. For example: 
  17188.  
  17189. // This example illustrates an overloaded postfix increment operator.
  17190.  
  17191. class X
  17192. {
  17193.       int a;
  17194. public:
  17195.       operator++(int);   // member postfix increment operator
  17196. };
  17197. operator++(X x, int i);  // nonmember postfix increment operator
  17198.  
  17199. // Definitions of postfix increment operator functions
  17200. // ...
  17201.  
  17202. void main()
  17203. {
  17204.       X x;
  17205.       x++;               // x.operator++
  17206.                          // default zero is supplied by compiler
  17207.       x.operator++(0);   // x.operator++
  17208.       operator++(x,0);   // nonmember operator++
  17209. }
  17210.  
  17211. The prefix and postfix decrement operators follow the same rules as their 
  17212. increment counterparts. 
  17213.  
  17214. For more information on the standard postfix and prefix increment operators, 
  17215. see Increment  ++. For more information on the standard postfix and prefix 
  17216. decrement operators, see Decrement  - -. 
  17217.  
  17218.  
  17219. ΓòÉΓòÉΓòÉ 12.4.6. Overloaded new and delete ΓòÉΓòÉΓòÉ
  17220.  
  17221. You can implement your own memory management scheme for a class by overloading 
  17222. the operators new and delete. The overloaded operator new must return a void*, 
  17223. and its first argument must have type size_t. The overloaded operator delete 
  17224. must return a void type, and its first argument must be void*. The second 
  17225. argument for the overloaded delete operator is optional and, if present, it 
  17226. must have type size_t. You can only define one delete operator function for a 
  17227. class. 
  17228.  
  17229. Type size_t is an implementation dependent unsigned integral type defined in 
  17230. <stddef.h>. For more information about size_t, see the IBM VisualAge C++ for 
  17231. OS/2 User's Guide and Reference. 
  17232.  
  17233. The size argument is required because a class can inherit an overloaded new 
  17234. operator. The derived class can be a different size than the base class. The 
  17235. size argument ensures that the correct amount of storage space is allocated or 
  17236. deallocated for the object. 
  17237.  
  17238. When new and delete are overloaded within a class declaration, they are static 
  17239. member functions whether they are declared with the keyword static or not. They 
  17240. cannot be virtual functions. 
  17241.  
  17242. You can access the standard, nonoverloaded versions of new and delete within a 
  17243. class scope containing the overloading new and delete operators by using the :: 
  17244. (scope resolution) operator to provide global access. 
  17245.  
  17246. For more information on the class member operators new and delete, see Free 
  17247. Store. For more information on the standard new and delete operators, see new 
  17248. Operator and delete Operator. 
  17249.  
  17250.  
  17251. ΓòÉΓòÉΓòÉ 13. Special C++ Member Functions ΓòÉΓòÉΓòÉ
  17252.  
  17253. This chapter introduces the special member functions that are used to create, 
  17254. destroy, convert, initialize, and copy class objects. This chapter discusses: 
  17255.  
  17256.      Constructors 
  17257.      Destructors 
  17258.      Free Store 
  17259.      Temporary Objects 
  17260.      User-Defined Conversions 
  17261.      Initialization by Constructor 
  17262.      Copying Class Objects 
  17263.  
  17264.  Related Information 
  17265.  
  17266.      Functions 
  17267.      C++ Classes 
  17268.      C++ Class Members and Friends 
  17269.      C++ Overloading 
  17270.      C++ Inheritance 
  17271.  
  17272.  
  17273. ΓòÉΓòÉΓòÉ 13.1. Constructors and Destructors Overview ΓòÉΓòÉΓòÉ
  17274.  
  17275. Because classes have complicated internal structures, including data and 
  17276. functions, object initialization and cleanup for classes is much more 
  17277. complicated than it is for simple data structures. Constructors and destructors 
  17278. are special member functions of classes that are used to construct and destroy 
  17279. class objects. Construction may involve memory allocation and initialization 
  17280. for objects. Destruction may involve cleanup and deallocation of memory for 
  17281. objects. 
  17282.  
  17283. Like other member functions, constructors and destructors are declared within a 
  17284. class declaration. They can be defined inline or external to the class 
  17285. declaration. Constructors can have default arguments. Unlike other member 
  17286. functions, constructors can have member initialization lists. The following 
  17287. restrictions apply to constructors and destructors: 
  17288.  
  17289.      Constructors and destructors do not have return types nor can they return 
  17290.       values. 
  17291.      References and pointers cannot be used on constructors and destructors 
  17292.       because their addresses cannot be taken. 
  17293.      Constructors cannot be declared with the keyword virtual. 
  17294.      Constructors and destructors cannot be declared static, const, or 
  17295.       volatile. 
  17296.      Unions cannot contain class objects that have constructors or 
  17297.       destructors. 
  17298.  
  17299.  Constructors and destructors obey the same access rules as member functions. 
  17300.  For example, if a constructor is declared with the keyword protected, only 
  17301.  derived classes and friends can use it to create class objects. Class member 
  17302.  access is described in Member Access. 
  17303.  
  17304.  The compiler automatically calls constructors when defining class objects and 
  17305.  calls destructors when class objects go out of scope. A constructor does not 
  17306.  allocate memory for the class object its this pointer refers to, but may 
  17307.  allocate storage for more objects that its class object refers to. If memory 
  17308.  allocation is required for objects, constructors can explicitly call the new 
  17309.  operator. During cleanup, a destructor may release objects allocated by the 
  17310.  corresponding constructor. To release objects, use the delete operator. 
  17311.  
  17312.  Derived classes do not inherit constructors or destructors from their base 
  17313.  classes, but they do call the constructor and destructor of base classes. 
  17314.  Destructors can be declared with the keyword virtual. 
  17315.  
  17316.  Constructors are also called when local or temporary class objects are 
  17317.  created, and destructors are called when local or temporary objects go out of 
  17318.  scope. 
  17319.  
  17320.  You can call member functions from constructors or destructors. You can call a 
  17321.  virtual function, either directly or indirectly, from a constructor or 
  17322.  destructor. In this case, the function called is the one defined in the class 
  17323.  or base class containing the constructor (or destructor), but not a function 
  17324.  defined in any class derived from the class being constructed. This avoids the 
  17325.  possibility of accessing an unconstructed object from a constructor or 
  17326.  destructor. 
  17327.  
  17328.  Related Information 
  17329.  
  17330.      Constructors 
  17331.      Destructors 
  17332.      Virtual Functions 
  17333.      Member Access 
  17334.      new Operator 
  17335.      delete Operator 
  17336.  
  17337.  
  17338. ΓòÉΓòÉΓòÉ 13.1.1. Constructors ΓòÉΓòÉΓòÉ
  17339.  
  17340. A constructor is a member function with the same name as its class. For 
  17341. example: 
  17342.  
  17343. class X
  17344. {
  17345. public:
  17346.       X();      // constructor for class X
  17347. };
  17348.  
  17349. Constructors are used to create, and can initialize, objects of their class 
  17350. type. Initialization of class objects using constructors is described in 
  17351. Initialization by Constructor. 
  17352.  
  17353. A default constructor is a constructor that either has no arguments, or, if it 
  17354. has arguments, all the arguments have default values. If no user-defined 
  17355. constructor exists for a class and one is needed, the compiler creates a 
  17356. default constructor, with public access, for that class. No default constructor 
  17357. is created for a class that has any constant or reference type members. 
  17358.  
  17359. Like all functions, a constructor can have default arguments. They are used to 
  17360. initialize member objects. If default values are supplied, the trailing 
  17361. arguments can be omitted in the expression list of the constructor. Note that 
  17362. if a constructor has any arguments that do not have default values, it is not a 
  17363. default constructor. 
  17364.  
  17365. A copy constructor is used to make a copy of one class object from another 
  17366. class object of the same class type. A copy constructor is called with a single 
  17367. argument that is a reference to its own class type. You cannot use a copy 
  17368. constructor with an argument of the same type as its class; you must use a 
  17369. reference. You can provide copy constructors with additional default arguments. 
  17370. If a user-defined copy constructor does not exist for a class and one is 
  17371. needed, the compiler creates a copy constructor, with public access, for that 
  17372. class. It is not created for a class if any of its members or base classes have 
  17373. an inaccessible copy constructor. 
  17374.  
  17375. If a class has a base class or members with constructors when it is 
  17376. constructed, the constructor for the base class is called, followed by any 
  17377. constructors for members. The constructor for the derived class is called last. 
  17378. Virtual base classes are constructed before nonvirtual base classes. When more 
  17379. than one base class exists, the base class constructors are called in the order 
  17380. that their classes appear in the base list. For more information, see 
  17381. Construction Order of Derived Class Objects. 
  17382.  
  17383. Examples of Constructors and Construction Order 
  17384.  
  17385. You cannot call constructors directly. You use a function style cast to 
  17386. explicitly construct an object of the specified type. 
  17387.  
  17388. Example of Explicitly Constructing an Object 
  17389.  
  17390. Related Information 
  17391.  
  17392.      Destructors 
  17393.      Constructors and Destructors Overview 
  17394.      Construction Order of Derived Class Objects 
  17395.      Default Arguments in C++ Functions 
  17396.      References 
  17397.  
  17398.  
  17399. ΓòÉΓòÉΓòÉ <hidden> Example of Explicitly Constructing an Object ΓòÉΓòÉΓòÉ
  17400.  
  17401. /************************************************************************
  17402. *
  17403.  
  17404. In the following example, a constructor is used as an initializer to create a 
  17405. named object. 
  17406.  
  17407.                                                                         *
  17408. ************************************************************************/
  17409.  
  17410. #include <iostream.h>
  17411. class X
  17412. {
  17413. public:
  17414.  
  17415.       X (int, int , int = 0);  // constructor with default argument
  17416. private:
  17417.       int a, b, c;
  17418.       int f();
  17419. };
  17420. X::X (int i, int j, int k) { a = i; b = j; c = k; }
  17421.  
  17422. void main ()
  17423. {
  17424. X xobject = X(1,2,3);    // explicitly create and initialize
  17425.                          // named object with constructor call
  17426. }
  17427.  
  17428.  
  17429. ΓòÉΓòÉΓòÉ <hidden> Examples of Constructors and Construction Order ΓòÉΓòÉΓòÉ
  17430.  
  17431. /************************************************************************
  17432. *
  17433.  
  17434. The following code fragment shows two classes with constructors, default 
  17435. constructors, and copy constructors: 
  17436.  
  17437. class X
  17438. {
  17439. public:
  17440.       X();                     // default constructor, no arguments
  17441.       X(int, int , int = 0);   // constructor
  17442.       X(const X&);             // copy constructor
  17443.       X(X);                    // error, incorrect argument type
  17444. };
  17445. class Y
  17446. {
  17447. public:
  17448.       Y( int = 0);            // default constructor with one
  17449.                               // default argument
  17450.       Y(const Y&, int = 0);   // copy constructor
  17451. };
  17452.  
  17453. When more than one base class exists, the base class constructors are called in 
  17454. the order that their classes appear in the base list, as shown in the following 
  17455. example: 
  17456.  
  17457.                                                                         *
  17458. ************************************************************************/
  17459.  
  17460. class B1 { public: B1(); };
  17461. class B2
  17462. {
  17463. public:
  17464.       B2();
  17465.       B1 b1obj;
  17466. };
  17467. class B3 { public: B3(); };
  17468. // ...
  17469. class D : public B1, public B2, public B3
  17470. {
  17471. public:
  17472.       D();
  17473.       ~D();
  17474. };
  17475.  
  17476. void main ()
  17477. {
  17478.       D object;
  17479. }
  17480.  
  17481. /************************************************************************
  17482. *
  17483.  
  17484. In the above example, the constructors for object are called in the following 
  17485. order: 
  17486.  
  17487. B1();      // first base constructor declared
  17488. B1();      // member constructor for B2::b1obj
  17489. B2();      // second base constructor declared
  17490. B3();      // last base constructor declared
  17491. D();       // derived constructor called last
  17492.  
  17493. Note that the construction of class D involves construction of the base classes 
  17494. B1, B2, and B3. The construction of base class B2 involves the construction of 
  17495. its class B1 member object. When class B2 is constructed, the constructor for 
  17496. class B1 is called in addition to B2's own constructor. 
  17497.  
  17498. As explained above, the second call to the constructor of B1 followed by the 
  17499. call to the constructor of B2 is part of the construction of B2. 
  17500.  
  17501.                                                                         *
  17502. ************************************************************************/
  17503.  
  17504.  
  17505. ΓòÉΓòÉΓòÉ 13.1.2. Destructors ΓòÉΓòÉΓòÉ
  17506.  
  17507. A destructor is a member function with the same name as its class prefixed by a 
  17508. ~ (tilde). 
  17509.  
  17510. For example: 
  17511.  
  17512. class X
  17513. {
  17514. public:
  17515.       X();       // constructor for class X
  17516.       ~X();      // destructor for class X
  17517. };
  17518.  
  17519. A destructor takes no arguments and has no return type. Its address cannot be 
  17520. taken. Destructors cannot be declared const, volatile, or static. A destructor 
  17521. can be declared virtual or pure virtual. A union cannot have as a member an 
  17522. object of a class with a destructor. 
  17523.  
  17524. Destructors are usually used to deallocate memory and do other cleanup for a 
  17525. class object and its class members when the object is destroyed. A destructor 
  17526. is called for a class object when that object passes out of scope or is 
  17527. explicitly deleted. 
  17528.  
  17529. Class members that are class types can have their own destructors. Both base 
  17530. and derived classes can have destructors, although destructors are not 
  17531. inherited. If a base class or a member of a base class has a destructor and a 
  17532. class derived from that base class does not declare a destructor, a default 
  17533. destructor is generated. The default destructor calls the destructors of the 
  17534. base class and members of the derived class. Default destructors are generated 
  17535. with default public access. 
  17536.  
  17537. Destructors are called in the reverse order to constructors: 
  17538.  
  17539.    1. The destructor for a class object is called before destructors for 
  17540.       members and bases are called. 
  17541.    2. Destructors for nonstatic members are called before destructors for base 
  17542.       classes are called. 
  17543.    3. Destructors for nonvirtual base classes are called before destructors for 
  17544.       virtual base classes are called. 
  17545.  
  17546.  When an exception is thrown for a class object with a destructor, the 
  17547.  destructor for the temporary object thrown is not called until control passes 
  17548.  out of the catch block. For more information, see Constructors and Destructors 
  17549.  in Exception Handling. 
  17550.  
  17551.  Destructors are implicitly called when an automatic or temporary object passes 
  17552.  out of scope. They are implicitly called at program termination for 
  17553.  constructed external and static objects. Destructors are invoked when you use 
  17554.  the delete operator for objects created with the new operator. 
  17555.  
  17556.  Example of Destructors 
  17557.  
  17558.  You can use a destructor explicitly to destroy objects, although this practice 
  17559.  is not recommended. If an object has been placed at a specific address by the 
  17560.  new operator, you can call the destructor of the object explicitly to destroy 
  17561.  it. An explicitly called destructor cannot delete storage. 
  17562.  
  17563.  Note:  You can only call destructors for class types. You cannot call 
  17564.  destructors for simple types. The call to the destructor in the following 
  17565.  example causes the compiler to issue a warning: 
  17566.  
  17567.         int * ptr;
  17568.         ptr -> int::~int(); // warning
  17569.  
  17570.  Related Information 
  17571.  
  17572.      Constructors and Destructors Overview 
  17573.      Constructors 
  17574.      Virtual Functions 
  17575.      Constructors and Destructors in Exception Handling 
  17576.      new Operator 
  17577.      delete Operator 
  17578.  
  17579.  
  17580. ΓòÉΓòÉΓòÉ <hidden> Example of Destructors ΓòÉΓòÉΓòÉ
  17581.  
  17582. /***********************************************************************
  17583. *
  17584.  
  17585. The following example shows the use of destructors: 
  17586.  
  17587.                                                                         *
  17588. ************************************************************************/
  17589.  
  17590. #include <string.h>
  17591. class Y
  17592. {
  17593. private:
  17594.       char * string;
  17595.       int number;
  17596. public:
  17597.       Y(const char* n,int a);   // constructor
  17598.       ~Y() { delete[] string; } // destructor
  17599. };
  17600. Y::Y(const char* n, int a)      // define class Y constructor
  17601. {
  17602.       string = strcpy(new char[strlen(n) + 1 ], n);
  17603.       number = a;
  17604. }
  17605. void main ()
  17606. {
  17607.       Y yobj = Y("somestring", 10); // create and initialize
  17608.                                     // object of class Y
  17609. // ...
  17610. // destructor ~Y is called before control returns from main()
  17611. }
  17612.  
  17613.  
  17614. ΓòÉΓòÉΓòÉ 13.2. Free Store ΓòÉΓòÉΓòÉ
  17615.  
  17616. Free store is used for dynamic allocation of memory. The new and delete 
  17617. operators are used to allocate and deallocate free store, respectively. You can 
  17618. define your own versions of new and delete for a class by overloading them. You 
  17619. can supply the new and delete operators with additional arguments. You can also 
  17620. use the /Tm option to enable the debug versions of these operators. See Debug 
  17621. Versions of new and delete for more information on these versions. When new and 
  17622. delete operate on class objects, the class member operator functions new and 
  17623. delete are called, if they have been declared. 
  17624.  
  17625. If you create a class object with the new operator, the operator function 
  17626. operator new() (if it has been declared) is called to create the object. An 
  17627. operator new() for a class is always a static class member, even if it is not 
  17628. declared with the keyword static. It has a return type void* and its first 
  17629. argument must be the size of the object type and have type size_t. It cannot be 
  17630. virtual. 
  17631.  
  17632. Type size_t is an implementation dependent unsigned integral type defined in 
  17633. <stddef.h>. For more information about size_t, see the IBM VisualAge C++ for 
  17634. OS/2 User's Guide and Reference. 
  17635.  
  17636. When you overload the new operator, you must declare it as a class member, 
  17637. returning type void*, with first argument size_t, as described above. You 
  17638. supply additional arguments in the declaration of operator new(). Use the 
  17639. placement syntax to specify values for these arguments in an allocation 
  17640. expression. 
  17641.  
  17642. The delete operator destroys an object created by the new operator. The operand 
  17643. of delete must be a pointer returned by new. If delete is called for an object 
  17644. with a destructor, the destructor is invoked before the object is deallocated. 
  17645.  
  17646. If you destroy a class object with the delete operator, the operator function 
  17647. operator delete() (if it has been declared) is called to destroy the object. An 
  17648. operator delete() for a class is always a static member, even if it is not 
  17649. declared with the keyword static. Its first argument must have type void*. 
  17650. Because operator delete() has a return type void, it cannot return a value. It 
  17651. cannot be virtual. 
  17652.  
  17653. When you overload the delete operator, you must declare it as class member, 
  17654. returning type void, with first argument having type void*, as described above. 
  17655. You can add a second argument of type size_t to the declaration. You can only 
  17656. have one operator delete() for a single class. 
  17657.  
  17658. Examples of operator new() and operator delete() 
  17659.  
  17660. The result of trying to access a deleted object is undefined because the value 
  17661. of the object can change after deletion. 
  17662.  
  17663. If new and delete are called for a class object that does not declare the 
  17664. operator functions new and delete, or they are called for a nonclass object, 
  17665. the global operators new and delete are used. The global operators new and 
  17666. delete are provided in the C++ library. The VisualAge C++ compiler does not 
  17667. support them. When you declare arrays of class objects, the global new and 
  17668. delete operators are used. 
  17669.  
  17670. Related Information 
  17671.  
  17672.      new Operator 
  17673.      delete Operator 
  17674.      Overloaded new and delete 
  17675.      Debug Versions of new and delete 
  17676.  
  17677.  
  17678. ΓòÉΓòÉΓòÉ <hidden> Examples of operators new() and delete() ΓòÉΓòÉΓòÉ
  17679.  
  17680. /************************************************************************
  17681. *
  17682.  
  17683. The following example shows two overloaded new operator functions. 
  17684.  
  17685.                                                                         *
  17686. ************************************************************************/
  17687.  
  17688. #include <stddef.h>
  17689. class X
  17690. {
  17691. public:
  17692.       void* operator new(size_t);
  17693.       void* operator new(size_t, int);
  17694. };
  17695.  
  17696. void main ()
  17697. {
  17698.       X* ptr1 = new X;        // calls X::operator new(sizeof(X))
  17699.       X* ptr2 = new(10) X;    // calls X::operator
  17700.                               // new(sizeof(X),10)
  17701. }
  17702.  
  17703. /************************************************************************
  17704. *
  17705.  
  17706. The following example shows the declaration and use of the operator functions 
  17707. operator new() and operator delete(): 
  17708.  
  17709.                                                                         *
  17710. ************************************************************************/
  17711.  
  17712. #include <stddef.h>
  17713. class X
  17714. {
  17715. public:
  17716.       void* operator new(size_t);
  17717.       void operator delete(void*);         // single argument
  17718. };
  17719. class Y
  17720. {
  17721. public:
  17722.       void operator delete(void*, size_t); // two arguments
  17723. };
  17724.  
  17725. void main ()
  17726. {
  17727.       X* ptr = new X;
  17728.       delete ptr;      // call X::operator delete(void*)
  17729.       Y* yptr;
  17730. // ...
  17731.       delete yptr;     // call Y::operator delete(void*, size_t)
  17732.                        // with size of Y as second argument
  17733. }
  17734.  
  17735.  
  17736. ΓòÉΓòÉΓòÉ <hidden> Debug Versions of new and delete ΓòÉΓòÉΓòÉ
  17737.  
  17738. VisualAge C++ provides special versions of new and delete to assist you in 
  17739. debugging memory management problems. These versions can help you find where 
  17740. memory is being incorrectly allocated, written to, or freed. 
  17741.  
  17742. To enable the debug memory management functions, use the /Tm option, which also 
  17743. defines the macro __DEBUG_ALLOC__. The debug versions of new and delete, as 
  17744. well as of the C library functions (malloc and so on), are automatically called 
  17745. in place of the regular functions in your code. Do not parenthesize any calls 
  17746. to these functions, because parentheses disable the definition of the function 
  17747. name to the debug function name. 
  17748.  
  17749. To each call to new, the compiler adds 2 parameters equivalent to the current 
  17750. __FILE__ and __LINE__ macros. They are inserted as the first two parameters in 
  17751. the placement syntax. As a result, the global and class-specific versions of 
  17752. operator new change from: 
  17753.  
  17754.    operator new(size_t);
  17755.    operator new(size_t , additional_parameters );
  17756. to: 
  17757.  
  17758.    operator new(size_t, const char *, size_t);
  17759.    operator new(size_t, const char *, size_t , additional_parameters );
  17760.  
  17761. The compiler adds the same parameters to each delete call, changing all global 
  17762. and class-specific versions of delete from: 
  17763.  
  17764.    operator delete(void *);
  17765.    operator delete(void * , size_t );
  17766. to: 
  17767.  
  17768.    operator delete(void *, const char *, size_t);
  17769.    operator delete(void *, const char *, size_t , size_t );
  17770.  
  17771. The debug versions also automatically call the C library function _heap_check. 
  17772. This function checks all memory blocks allocated or freed by debug memory 
  17773. management functions to make sure that no overwriting has occurred outside the 
  17774. bounds of allocated blocks or in a free memory block. You can also call 
  17775. _heap_check explicitly. 
  17776.  
  17777. You can also call the C library function _dump_allocated to print out 
  17778. information about each memory block currently allocated by the debug memory 
  17779. management functions. Both _heap_check and _dump_allocated are only available 
  17780. when the __DEBUG_ALLOC__ macro is defined. They are described in the IBM 
  17781. VisualAge C++ for OS/2 C Library Reference. 
  17782.  
  17783. All output from these functions is sent to the OS/2 file handle 2, which is 
  17784. usually associated with stderr. 
  17785.  
  17786. Note:  The information provided by these functions is Diagnosis, Modification, 
  17787.        and Tuning information only. It is not intended to be used as a 
  17788.        programming interface. 
  17789.  
  17790.  You may need to include the <new.h> header file to include the prototypes of 
  17791.  the debug malloc and free code that the debug versions of new and delete use. 
  17792.  
  17793.  Important  The changes described above take place for all occurrences of new 
  17794.  and delete whether global or specific to a class. If you have provided member 
  17795.  new or delete functions, you must make code changes before compiling with /Tm. 
  17796.  You can use the __DEBUG_ALLOC__ macro for conditional compilation. 
  17797.  
  17798.  For more information on debug memory management functions in the C library, 
  17799.  see the IBM VisualAge C++ for OS/2 C Library Reference. 
  17800.  
  17801.  
  17802. ΓòÉΓòÉΓòÉ 13.3. Temporary Objects ΓòÉΓòÉΓòÉ
  17803.  
  17804. It is sometimes necessary for the compiler to create temporary objects. They 
  17805. are used during reference initialization and during evaluation of expressions 
  17806. including standard type conversions, argument passing, function returns, and 
  17807. evaluation of the throw expression. 
  17808.  
  17809. When a temporary object is created to initialize a reference variable, the name 
  17810. of the temporary object has the same scope as that of the reference variable. 
  17811. When a temporary object is created during the evaluation of an expression, it 
  17812. exists until there is a break in the flow of control of the program. 
  17813.  
  17814. If a temporary object is created for a class with constructors, the compiler 
  17815. calls the appropriate (matching) constructor to create the temporary object. 
  17816.  
  17817. When a temporary object is destroyed and a destructor exists, the compiler 
  17818. calls the destructor to destroy the temporary object. When you exit from the 
  17819. scope in which the temporary object was created, it is destroyed. If a 
  17820. reference is bound to a temporary object, the temporary object is destroyed 
  17821. when the reference passes out of scope unless it is destroyed earlier by a 
  17822. break in the flow of control. For example, a temporary object created by a 
  17823. constructor initializer for a reference member is destroyed on leaving the 
  17824. contructor. 
  17825.  
  17826. Examples of Temporary Objects 
  17827.  
  17828. Use the /Wgnr option to flag the points where temporary objects are generated. 
  17829.  
  17830. Related Information 
  17831.  
  17832.      Constructors 
  17833.      Destructors 
  17834.      References 
  17835.      Initializing References 
  17836.      Expressions and Operators 
  17837.      Functions 
  17838.      Using Exception Handling 
  17839.  
  17840.  
  17841. ΓòÉΓòÉΓòÉ <hidden> Examples of Temporary Objects ΓòÉΓòÉΓòÉ
  17842.  
  17843. /************************************************************************
  17844. *
  17845.  
  17846. The following example shows two expressions in which temporary objects xre 
  17847. constructed: 
  17848.  
  17849.                                                                         *
  17850. ************************************************************************/
  17851.  
  17852. class Y
  17853. {
  17854. public:
  17855.       Y(int);
  17856.       Y(Y&);
  17857.       ~Y();
  17858. };
  17859. Y add(Y y) { /* ... */ }
  17860.  
  17861. void main ()
  17862. {
  17863.       Y obj1(10);
  17864.       Y obj2 = add(Y(5));       // one temporary created
  17865.       obj1 = add(obj1);         // two temporaries created
  17866. }
  17867.  
  17868. /************************************************************************
  17869. *
  17870.  
  17871. In the above example, a temporary object of class type Y is created to 
  17872. construct Y(5) before it is passed to the function add(). Because obj2 is being 
  17873. constructed, the function add() can construct its return value directly into 
  17874. obj2, so another temporary object is not created. A temporary object of class 
  17875. type Y is created when obj1 is passed to the function add(). Because obj1 has 
  17876. already been constructed, the function add() constructs its return value into a 
  17877. temporary object. This second temporary object is then assigned to obj1 using 
  17878. an assignment operator. 
  17879.  
  17880.                                                                         *
  17881. ************************************************************************/
  17882.  
  17883.  
  17884. ΓòÉΓòÉΓòÉ 13.4. User-Defined Conversions ΓòÉΓòÉΓòÉ
  17885.  
  17886. User-defined conversions allow you to specify object conversions with 
  17887. constructors or with conversion functions User-defined conversions are 
  17888. implicitly used in addition to standard conversions for conversion of 
  17889. initializers, functions arguments, function return values, expression operands, 
  17890. expressions controlling iteration, selection statements, and explicit type 
  17891. conversions. 
  17892.  
  17893. There are two types of user-defined conversions: 
  17894.  
  17895.      Conversion by constructor 
  17896.      Conversion functions. 
  17897.  
  17898.  Related Information 
  17899.  
  17900.      Implicit Type Conversions 
  17901.      Constructors and Destructors Overview 
  17902.      Constructors 
  17903.      C++ Classes 
  17904.      Functions 
  17905.  
  17906.  
  17907. ΓòÉΓòÉΓòÉ 13.4.1. Conversion by Constructor ΓòÉΓòÉΓòÉ
  17908.  
  17909. You can call a class constructor with a single argument to convert from the 
  17910. argument type to the type of the class. 
  17911.  
  17912. At most one user-defined conversion, either a constructor or conversion 
  17913. function, is implicitly applied to a class object. When you call a constructor 
  17914. with an argument and you have not defined a constructor accepting that argument 
  17915. type, only standard conversions are used to convert the argument to another 
  17916. argument type acceptable to a constructor for that class. Other constructors or 
  17917. conversions functions are not called to convert the argument to a type 
  17918. acceptable to a constructor defined for that class. 
  17919.  
  17920. Example of Conversion by Constructor 
  17921.  
  17922. Related Information 
  17923.  
  17924.      Conversion Functions 
  17925.      Constructors and Destructors Overview 
  17926.      Constructors 
  17927.      User-Defined Conversions 
  17928.      Implicit Type Conversions 
  17929.  
  17930.  
  17931. ΓòÉΓòÉΓòÉ <hidden> Example of Conversion by Constructor ΓòÉΓòÉΓòÉ
  17932.  
  17933. /************************************************************************
  17934. *
  17935.  
  17936. The following example shows conversion by constructor: 
  17937.  
  17938.                                                                         *
  17939. ************************************************************************/
  17940.  
  17941. class Y
  17942. {
  17943.       int a,b;
  17944.       char* name;
  17945. public:
  17946.       Y(int i);
  17947.       Y(const char* n, int j = 0);
  17948. };
  17949. void add(Y);
  17950. // ...
  17951. void main ()
  17952. {
  17953.       // code                     equivalent code
  17954.       Y obj1 = 2;              // obj1 = Y(2)
  17955.       Y obj2 = "somestring";   // obj2 = Y("somestring",0)
  17956.       obj1 = 10;               // obj1 = Y(10)
  17957.       add(5);                  // add(Y(5))
  17958. }
  17959.  
  17960.  
  17961. ΓòÉΓòÉΓòÉ 13.4.2. Conversion Functions ΓòÉΓòÉΓòÉ
  17962.  
  17963. You can define a member function of a class, called a conversion function, that 
  17964. converts from the type of its class to another specified type. 
  17965.  
  17966. Syntax of a Conversion Function 
  17967.  
  17968. The conversion function specifies a conversion from the class type the 
  17969. conversion function is a member of, to the type specified by the name of the 
  17970. conversion function. Classes, enumerations, and typedef names cannot be 
  17971. declared or defined as part of the function name. 
  17972.  
  17973. Conversion functions have no arguments, and the return type is implicitly the 
  17974. conversion type. Conversion functions can be inherited. You can have virtual 
  17975. conversion functions but not static ones. 
  17976.  
  17977. Only one user-defined conversion is implicitly applied to a single value. 
  17978. User-defined conversions must be unambiguous, or they are not called. 
  17979.  
  17980. If a conversion function is declared with the keyword const, the keyword has no 
  17981. affect on the function except for acting as a tie-breaker when there is more 
  17982. than one conversion function that could be applied. Specifically, if more than 
  17983. one conversion function could be applied, all of these functions are compared. 
  17984. If any of these functions is declared with the keyword const, const is ignored 
  17985. for the purposes of this comparison. If one of these functions is a best match, 
  17986. this function is applied. If there is no best match, the functions are compared 
  17987. again, but this time const is not ignored. 
  17988.  
  17989. Example of a Conversion Function 
  17990.  
  17991. Related Information 
  17992.  
  17993.      Conversion by Constructor 
  17994.      Functions 
  17995.      Implicit Type Conversions 
  17996.      volatile and const Qualifiers 
  17997.      Virtual Functions 
  17998.  
  17999.  
  18000. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Conversion Function ΓòÉΓòÉΓòÉ
  18001.  
  18002. >>ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇoperatorΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇconversion_typeΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ(ΓöÇΓöÇ)ΓöÇΓöÇ>
  18003.   ΓööΓöÇclass::ΓöÇΓöÿ       Γö£ΓöÇconstΓöÇΓöÇΓöÇΓöÇΓöñ          Γö£ΓöÇ*ΓöÇΓöñ
  18004.               ΓööΓöÇvolatileΓöÇΓöÿ          ΓööΓöÇ&ΓöÇΓöÿ
  18005. >ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  18006.   ΓööΓöÇ{ΓöÇΓöÇfunction_bodyΓöÇΓöÇ}ΓöÇΓöÿ
  18007.  
  18008.  
  18009. ΓòÉΓòÉΓòÉ <hidden> Example of a Conversion Function ΓòÉΓòÉΓòÉ
  18010.  
  18011. /************************************************************************
  18012. *
  18013.  
  18014. The following code fragment shows a conversion function called operator int(): 
  18015.  
  18016.                                                                         *
  18017. ************************************************************************/
  18018.  
  18019. class Y
  18020. {
  18021.       int b;
  18022. public:
  18023.       operator int();
  18024. };
  18025. Y::operator int() {return b;}
  18026.  
  18027. void f(Y obj )
  18028. {
  18029.       // each value assigned is converted by Y::operator int()
  18030.       int i = int(obj);
  18031.       int j = (int)obj;
  18032.       int k = i + obj;
  18033. }
  18034.  
  18035.  
  18036. ΓòÉΓòÉΓòÉ 13.5. Initialization by Constructor ΓòÉΓòÉΓòÉ
  18037.  
  18038. A class object with a constructor must be explicitly initialized or have a 
  18039. default constructor. Explicit initialization using a constructor is the only 
  18040. way, except for aggregate initialization, to initialize nonstatic constant and 
  18041. reference class members. 
  18042.  
  18043. A class object that has no constructors, no virtual functions, no private or 
  18044. protected members, and no base classes is called an aggregate. Aggregates are 
  18045. described in Structures and Unions. 
  18046.  
  18047. Class objects with constructors can be initialized with a parenthesized 
  18048. expression list. This list is used as an argument list for the call of a 
  18049. constructor that is used to initialize the class. You can also call a 
  18050. constructor with a single initialization value using the = operator. Because 
  18051. this type of expression is an initialization, not an assignment, the assignment 
  18052. operator function, if one exists, is not called. This value is used as a single 
  18053. argument for the call of a constructor. The type of the single argument must 
  18054. match the type of the first argument to the constructor. If the constructor has 
  18055. remaining arguments, these arguments must have default values. 
  18056.  
  18057. Syntax of an Explicit Initializer by Constructor 
  18058.  
  18059. Constructors can initialize their members in two different ways. A constructor 
  18060. can use the arguments passed to it to initialize member variables in the 
  18061. constructor definition: 
  18062.  
  18063. complx( double r, double i = 0.0) {re = r; im = i;}
  18064.  
  18065. Or a constructor can have an initializer list within the definition but prior 
  18066. to the function body: 
  18067.  
  18068. complx ( double r, double i = 0) : re(r), im(i) { /* ... */ }
  18069.  
  18070. Both methods assign the argument values to the appropriate data members of the 
  18071. class. The second method must be used to initialize base classes from within a 
  18072. derived class to initialize constant and reference members and members with 
  18073. constructors. 
  18074.  
  18075. Example of Explicit Initialization by Constructor 
  18076.  
  18077. Related Information 
  18078.  
  18079.      Initializing Base Classes and Members 
  18080.      Construction Order of Derived Class Objects 
  18081.      Constructors and Destructors Overview 
  18082.      Constructors 
  18083.      C++ Classes 
  18084.  
  18085.  
  18086. ΓòÉΓòÉΓòÉ <hidden> Syntax of an Explicit Initializer by Constructor ΓòÉΓòÉΓòÉ
  18087.  
  18088. The syntax for an initializer that explicitly initializes a class object with a 
  18089. constructor is: 
  18090.  
  18091. >>ΓöÇΓöÇΓö¼ΓöÇ(ΓöÇΓöÇexpressionΓöÇΓöÇ)ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  18092.   ΓööΓöÇ=ΓöÇΓöÇΓö¼ΓöÇexpressionΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  18093.      Γöé   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ      Γöé
  18094.      Γöé          Γöé      Γöé
  18095.      ΓööΓöÇ{ΓöÇΓöÇΓöÇΓöÇexpressionΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ}ΓöÇΓöÿ
  18096.                ΓööΓöÇ,ΓöÇΓöÿ
  18097.  
  18098.  
  18099. ΓòÉΓòÉΓòÉ <hidden> Example of Explicit Initialization by Constructor ΓòÉΓòÉΓòÉ
  18100.  
  18101. /************************************************************************
  18102. *
  18103.  
  18104. The following example shows the declaration and use of several constructors 
  18105. that explicitly initialize class objects: 
  18106.  
  18107.                                                                         *
  18108. ************************************************************************/
  18109.  
  18110. // This example illustrates explicit initialization
  18111. // by constructor.
  18112.  
  18113. #include <iostream.h>
  18114. class complx
  18115. {
  18116.       double re, im ;
  18117. public:
  18118.       complx();   // default constructor
  18119.       complx(const complx& c) {re = c.re; im = c.im;}
  18120.                   // copy constructor
  18121.       complx( double r, double i = 0.0) {re = r; im = i;}
  18122.                   // constructor with default trailing argument
  18123.       void display()
  18124.       {
  18125.             cout << "re = "<< re << " im = " << im << endl;
  18126.       }
  18127. };
  18128.  
  18129. void main ()
  18130. {
  18131.       complx one(1);      // initialize with complx(double, double)
  18132.       complx two = one;   // initialize with a copy of one
  18133.                           // using complx::complx(const complx&)
  18134.       complx three = complx(3,4);  // construct complx(3,4)
  18135.                                    // directly into three
  18136.       complx four;                 // initialize with default constructor
  18137.       complx five = 5;             // complx(double, double) & construct
  18138.                                    // directly into five
  18139.       one.display();
  18140.       two.display();
  18141.       three.display();
  18142.       four.display();
  18143.       five.display();
  18144. }
  18145.  
  18146. /************************************************************************
  18147. *
  18148.  
  18149. The above example produces the following output: 
  18150.  
  18151. re = 1 im = 0
  18152. re = 1 im = 0
  18153. re = 3 im = 4
  18154. re = 0 im = 0
  18155. re = 5 im = 0
  18156.  
  18157.                                                                         *
  18158. ************************************************************************/
  18159.  
  18160.  
  18161. ΓòÉΓòÉΓòÉ 13.5.1. Initializing Base Classes and Members ΓòÉΓòÉΓòÉ
  18162.  
  18163. You can initialize immediate base classes and derived class members that are 
  18164. not inherited from base classes by specifying initializers in the constructor 
  18165. definition prior to the function body. 
  18166.  
  18167. Syntax of a Constructor Initializer 
  18168.  
  18169. In a constructor that is not inline, include the initialization list as part of 
  18170. the function definition, not as part of the class declaration. 
  18171.  
  18172. For example: 
  18173.  
  18174. class B1
  18175. {
  18176.       int b;
  18177. public:
  18178.       B1();
  18179.       B1(int i) : b(i) { /* ... */ }      // inline constructor
  18180. };
  18181. class B2
  18182. {
  18183.       int b;
  18184. protected:
  18185.       B2();
  18186.       B2(int i);                        // noninline constructor
  18187. };
  18188. // B2 constructor definition including initialization list
  18189. B2::B2(int i) : b(i) { /* ...*/ }
  18190. // ...
  18191. class D : public B1, public B2
  18192. {
  18193.       int d1, d2;
  18194. public:
  18195.       D(int i, int j) : B1(i+1), B2(), d1(i) {d2 = j;}
  18196. };
  18197.  
  18198. If you do not explicitly initialize a base class or member that has 
  18199. constructors by calling a constructor, the compiler automatically initializes 
  18200. the base class or member with a default constructor. In the above example, if 
  18201. you leave out the call B2() in the constructor of class D (as shown below), a 
  18202. constructor initializer with an empty expression list is automatically created 
  18203. to initialize B2. The constructors for class D, shown above and below, result 
  18204. in the same construction of an object of class D. 
  18205.  
  18206. class D : public B1, public B2
  18207. {
  18208.       int d1, d2;
  18209. public:
  18210.       // call B2() generated by compiler
  18211.       D(int i, int j) : B1(i+1), d1(i) {d2 = j;}
  18212. };
  18213.  
  18214. Note:  You must declare base constructors with the access specifiers public or 
  18215. protected to enable a derived class to call them. 
  18216.  
  18217. Example of Base Constructors and Derivation 
  18218.  
  18219. Related Information 
  18220.  
  18221.      Construction Order of Derived Class Objects 
  18222.      Initialization by Constructor 
  18223.      Constructors and Destructors Overview 
  18224.      Constructors 
  18225.      Member Access 
  18226.  
  18227.  
  18228. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Constructor Initializer ΓòÉΓòÉΓòÉ
  18229.  
  18230. The syntax for a constructor initializer is: 
  18231.  
  18232.     ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  18233.     Γöé           ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ   Γöé
  18234.                             Γöé   Γöé
  18235. >>ΓöÇΓöÇ:ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇidentifierΓöÇΓö¼ΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓö┤ΓöÇΓöÇ><
  18236.      ΓööΓöÇclass_nameΓöÇΓöÿ    ΓööΓöÇassignment_expressionΓöÇΓöÿ
  18237.  
  18238.  
  18239. ΓòÉΓòÉΓòÉ <hidden> Example of Base Constructors and Derivation ΓòÉΓòÉΓòÉ
  18240.  
  18241. /************************************************************************
  18242. *
  18243.  
  18244. The following example shows how to call base constructors from derived classes: 
  18245.  
  18246.                                                                         *
  18247. ************************************************************************/
  18248.  
  18249. class B1
  18250. {
  18251.       int b;
  18252. public:
  18253.       B1();
  18254.       B1(int i) : b(i) { /* ... */ }
  18255. };
  18256. class B2
  18257. {
  18258.       int b;
  18259. protected:
  18260.       B2();
  18261.       B2(int i);
  18262. };
  18263. B2::B2(int i) : b(i) { /* ... */ }
  18264. class B4
  18265. {
  18266. public:
  18267.       B4();         // public constructor for B4
  18268.       int b;
  18269. private:
  18270.       B4(int);      // private constructor for B4
  18271. };
  18272. //      .
  18273. //      .
  18274. //      .
  18275.  
  18276. class D : public B1, public B2, public B4
  18277. {
  18278.       int d1, d2;
  18279. public:
  18280.       D(int i, int j) : B1(i+1), B2(i+2) ,
  18281.                         B4(i) {d1 = i; d2 = j; }
  18282.             // error, attempt to access private constructor B4()
  18283.       D(int i, int j) : B1(i+1), B2(i+2) {d1 = i; d2 = j;}
  18284.             // valid, calls public constructor for B4
  18285. };
  18286.  
  18287.  
  18288. ΓòÉΓòÉΓòÉ 13.5.2. Construction Order of Derived Class Objects ΓòÉΓòÉΓòÉ
  18289.  
  18290. When a derived class object is created using constructors, it is created in the 
  18291. following order: 
  18292.  
  18293.    1. Virtual base classes are initialized, in the order they appear in the 
  18294.       base list. 
  18295.    2. Nonvirtual base classes are initialized, in declaration order. 
  18296.    3. Class members are initialized in declaration order (regardless of their 
  18297.       order in the initialization list). 
  18298.    4. The body of the constructor is executed. 
  18299.  
  18300.  In the following code fragment, the constructor for class B1 is called before 
  18301.  the member d1 is initialized. The value passed to the constructor for class B1 
  18302.  is undefined. 
  18303.  
  18304.   class B1
  18305.   {
  18306.         int b;
  18307.   public:
  18308.         B1();
  18309.         B1(int i) {b = i;}
  18310.   };
  18311.   class D : public B1
  18312.   {
  18313.         int d1, d2;
  18314.   public:
  18315.         D(int i, int j) : d1(i), B1(d1) {d2 = j;}
  18316.         // d1 is not initialized in call B1::B1(d1)
  18317.   };
  18318.  
  18319.  Related Information 
  18320.  
  18321.      Initializing Base Classes and Members 
  18322.      Initialization by Constructor 
  18323.      Constructors and Destructors Overview 
  18324.      Constructors 
  18325.      Derivation 
  18326.  
  18327.  
  18328. ΓòÉΓòÉΓòÉ 13.6. Copying Class Objects ΓòÉΓòÉΓòÉ
  18329.  
  18330. You can copy one class object to another object of the same type by either 
  18331. assignment or initialization. 
  18332.  
  18333. Copy by assignment is implemented with an assignment operator function. If you 
  18334. do not define the assignment operator, it is defined as memberwise assignment. 
  18335.  
  18336. Copy by initialization is implemented with a copy constructor. If you do not 
  18337. define a copy constructor, it is defined as  memberwise initialization of 
  18338. members of its class. 
  18339.  
  18340. Memberwise assignment and memberwise initialization mean that, if a class has a 
  18341. member that is a class object, the assignment operator and copy constructor of 
  18342. that class object are used to implement assignment and initialization of the 
  18343. member. 
  18344.  
  18345. Restrictions: 
  18346.  
  18347. A default assignment operator cannot be generated for a class that has: 
  18348.  
  18349.      A nonstatic constant or reference data member 
  18350.      A nonstatic data member or base class whose assignment operator is not 
  18351.       accessible 
  18352.      A nonstatic data member or base class with no assignment operator and for 
  18353.       which a default assignment operator cannot be generated. 
  18354.  
  18355.  A default copy constructor cannot be generated for a class that has: 
  18356.  
  18357.      A nonstatic data member or base class whose copy constructor is not 
  18358.       accessible 
  18359.      A nonstatic data member or base class with no copy constructor and for 
  18360.       which a default copy constructor cannot be generated. 
  18361.  
  18362.  Related Information 
  18363.  
  18364.      Copy by Assignment 
  18365.      Copy by Initialization 
  18366.      Constructors and Destructors Overview 
  18367.      Constructors 
  18368.      Overloaded Assignment 
  18369.  
  18370.  
  18371. ΓòÉΓòÉΓòÉ 13.6.1. Copy by Assignment ΓòÉΓòÉΓòÉ
  18372.  
  18373. If you do not define an assignment operator and one is required, a default 
  18374. assignment operator is defined. If you do not define an assignment operator and 
  18375. one is not required, a default assignment operator is declared but not defined. 
  18376. If an assignment operator that takes a single argument of a class type exists 
  18377. for a class, a default assignment operator is not generated. 
  18378.  
  18379. Copy by assignment is used only in assignment. 
  18380.  
  18381. You can define an assignment operator for a class with a single argument that 
  18382. is a constant reference to that class type, only if all its base classes and 
  18383. members have assignment operators that accept constant arguments. 
  18384.  
  18385. For example: 
  18386.  
  18387. class B1
  18388. {
  18389. public:
  18390.       B1& operator=(const B1&);
  18391. };
  18392. class D: public B1
  18393. {
  18394. public:
  18395.       D& operator=(const D&);
  18396. };
  18397. D& D::operator=(const D& dobj) {D dobj2 = dobj;
  18398.                                        return dobj2;}
  18399.  
  18400. Otherwise, you can define an assignment operator for a class with a single 
  18401. argument that is a reference to that class type. For example: 
  18402.  
  18403. class Z
  18404. {
  18405. public:
  18406.       Z& operator=( Z&);
  18407. };
  18408. Z& Z::operator=(Z& zobj) {Z zobj2 = zobj;
  18409.                                         return zobj2;}
  18410.  
  18411. The default assignment operator for a class is a public class member. The 
  18412. return type is a reference to the class type it is a member of. 
  18413.  
  18414. Related Information 
  18415.  
  18416.      Assignment Expressions 
  18417.      Overloaded Assignment 
  18418.      Copy by Initialization 
  18419.      C++ Classes 
  18420.  
  18421.  
  18422. ΓòÉΓòÉΓòÉ 13.6.2. Copy by Initialization ΓòÉΓòÉΓòÉ
  18423.  
  18424. You can define a copy constructor for a class. If you do not define a copy 
  18425. constructor and one is required, a default copy constructor is defined. If you 
  18426. do not define a copy constructor, and one is not required, a default copy 
  18427. constructor is declared but not defined. If a class has a copy constructor 
  18428. defined, a default copy constructor is not generated. 
  18429.  
  18430. Copy by initialization is used only in initialization. 
  18431.  
  18432. You can define a copy constructor for a class with a single argument that is a 
  18433. constant reference to a class type only if all its base classes and members 
  18434. have copy constructors that accept constant arguments. For example: 
  18435.  
  18436. class B1
  18437. {
  18438. public:
  18439.       B1(const B1&) { /* ... */ }
  18440. };
  18441.  
  18442. class D: public B1
  18443. {
  18444. public:
  18445.       D(const D&);
  18446. };
  18447. D::D(const D& dobj):B1(dobj) { /* ... */ }
  18448.  
  18449. Otherwise, you can define a copy constructor with a single reference to a class 
  18450. type argument. For example: 
  18451.  
  18452. class Z
  18453. {
  18454. public:
  18455.       Z(Z&);
  18456. };
  18457. Z::Z(Z&) { /* ...*/ }
  18458.  
  18459. The default copy constructor for a class is a public class member. 
  18460.  
  18461. Related Information 
  18462.  
  18463.      Initialization by Constructor 
  18464.      Constructors 
  18465.      Copy by Assignment 
  18466.      C++ Classes 
  18467.  
  18468.  
  18469. ΓòÉΓòÉΓòÉ 14. C++ Inheritance ΓòÉΓòÉΓòÉ
  18470.  
  18471. In C++, you can create classes from existing classes using the object-oriented 
  18472. programming technique called inheritance. Inheritance allows you to define an 
  18473. is a relationship between classes. When members are inherited, they can be used 
  18474. as if they are members of the class that inherits them. 
  18475.  
  18476. This chapter discusses: 
  18477.  
  18478.      Derivation 
  18479.      Inherited Member Access 
  18480.      Multiple Inheritance 
  18481.      Virtual Functions 
  18482.      Abstract Classes 
  18483.  
  18484.  Related Information 
  18485.  
  18486.      Functions 
  18487.      C++ Classes 
  18488.      C++ Class Members and Friends 
  18489.  
  18490.  
  18491. ΓòÉΓòÉΓòÉ 14.1. Inheritance Overview ΓòÉΓòÉΓòÉ
  18492.  
  18493. C++ implements inheritance through the mechanism of derivation. Derivation 
  18494. allows you to reuse code by creating new classes, called derived classes, that 
  18495. inherit properties from one or more existing classes, called base classes. A 
  18496. derived class inherits the properties, including data and function members, of 
  18497. its base class. You can also add new data members and member functions to the 
  18498. derived class. You can modify the implementation of existing member functions 
  18499. or data by overriding base class member functions or data in the newly derived 
  18500. class. 
  18501.  
  18502. Multiple inheritance allows you to create a derived class that inherits 
  18503. properties from more than one base class. 
  18504.  
  18505. Because a derived class inherits members from all its base classes, ambiguities 
  18506. can result. For example, if two base classes have a member with the same name, 
  18507. the derived class cannot implicitly differentiate between the two members. Note 
  18508. that, when you are using multiple inheritance, the access to names of base 
  18509. classes may be ambiguous. 
  18510.  
  18511. Examples of Single and Multiple Inheritance 
  18512.  
  18513. Multiple inheritance allows you to have more than one base class for a single 
  18514. derived class. You can create an interconnected inheritance graph of inherited 
  18515. classes by using derived classes as base classes for other derived classes. You 
  18516. can build an inheritance graph through the process of specialization, in which 
  18517. derived classes are more specialized than their base classes. You can also work 
  18518. in the reverse direction and build an inheritance graph through generalization. 
  18519. If you have a number of related classes that share a group of properties, you 
  18520. can generalize and build a base class to embody them. The group of related 
  18521. classes becomes the derived classes of the new base class. 
  18522.  
  18523. A direct base class is a base class that appears directly as a base specifier 
  18524. in the declaration of its derived class. A direct base class is analogous to a 
  18525. parent in a hierarchical graph. 
  18526.  
  18527. An indirect base class is a base class that does not appear directly in the 
  18528. declaration of the derived class but is available to the derived class through 
  18529. one of its base classes. An indirect base class is analogous to a grandparent 
  18530. or great grandparent or great-great grandparent in a hierarchical graph. For a 
  18531. given class, all base classes that are not direct base classes are indirect 
  18532. base classes. 
  18533.  
  18534. Polymorphic functions are functions that can be applied to objects of more than 
  18535. one type. In C++, polymorphic functions are implemented in two ways: 
  18536.  
  18537.      Overloaded functions are statically bound at compile time, as discussed 
  18538.       in Overloading Functions. 
  18539.      C++ provides virtual functions. A virtual function is a function that can 
  18540.       be called for a number of different user-defined types that are related 
  18541.       through derivation. Virtual functions are bound dynamically at run time. 
  18542.  
  18543.  Typically, a base class has several derived classes, each requiring its own 
  18544.  customized version of a particular operation. It is difficult for a base class 
  18545.  to implement member functions that are useful for all of its derived classes. 
  18546.  A base class would have to determine which derived class an object belonged to 
  18547.  before it could execute the applicable code for that object. When a virtual 
  18548.  function is called, the compiler executes the function implementation 
  18549.  associated with the object that the function is called for. The implementation 
  18550.  of the base class is only a default that is used when the derived class does 
  18551.  not contain its own implementation. 
  18552.  
  18553.  Related Information 
  18554.  
  18555.      Derivation 
  18556.      Multiple Inheritance 
  18557.      Virtual Functions 
  18558.      C++ Classes 
  18559.      C++ Class Members and Friends 
  18560.  
  18561.  
  18562. ΓòÉΓòÉΓòÉ 14.2. Examples of Single and Multiple Inheritance ΓòÉΓòÉΓòÉ
  18563.  
  18564. Suppose you have defined a shape class to describe and operate on geometric 
  18565. shapes. Now suppose you want to define a circle class. Because you have 
  18566. existing code that operates on the shape class, you can use inheritance to 
  18567. create the circle class. You can redefine operations in the derived circle 
  18568. class that were originally defined in the shape base class. When you manipulate 
  18569. an object of the circle class, these redefined function implementations are 
  18570. used. 
  18571.  
  18572. For example: 
  18573.  
  18574. class shape
  18575. {
  18576.       char* name;
  18577.       int xpoint, ypoint;
  18578. public:
  18579.       virtual void rotate(int);
  18580.       virtual void draw();
  18581.       void display() const;
  18582. };
  18583.  
  18584. class circle: public shape      // derive class circle from
  18585. class shape
  18586. {
  18587.       int xorigin, yorigin;
  18588.       int radius;
  18589. public:
  18590.       void rotate(int);
  18591.       void draw();
  18592.       void display() const;
  18593. };
  18594.  
  18595. In the above example, class circle inherits the data members name, xpoint and 
  18596. ypoint, as well as the member functions display(), rotate(), and draw() from 
  18597. class shape. Because the member functions rotate() and draw() are declared in 
  18598. class shape with the keyword virtual, you can provide an alternative 
  18599. implementation for them in class circle. 
  18600.  
  18601. You can also provide an alternative implementation for the nonvirtual member 
  18602. function display() in class circle. When you manipulate an argument of type 
  18603. circle using a pointer to shape, and call a virtual member function, the member 
  18604. function defined in the derived class overrides the base-class member function. 
  18605. A similar call to a nonvirtual member function will call the member function 
  18606. defined in the base class. In addition to inheriting the members of class 
  18607. shape, class circle has declared its own data members, xorigin, yorigin, and 
  18608. radius. 
  18609.  
  18610. The key difference between virtual and nonvirtual member functions is that, 
  18611. when you treat the circle class as if it were a shape, the implementations of 
  18612. the virtual functions rotate() and draw() defined in class circle are used, 
  18613. rather than those originally defined in class shape. Because display() is a 
  18614. nonvirtual member function, the original implementation of display() defined in 
  18615. class shape is used. 
  18616.  
  18617. Multiple inheritance allows you to create a derived class that inherits 
  18618. properties from more than one base class. 
  18619.  
  18620. For example, in addition to the shape class, described above, you could also 
  18621. have a symbol class. Because a circle is both a shape and a symbol, you can use 
  18622. multiple inheritance to reflect this relationship. If the circle class is 
  18623. derived from both the shape and symbol classes, the circle class inherits 
  18624. properties from both classes. 
  18625.  
  18626. class symbol
  18627. {
  18628.       char* language;
  18629.       char letter;
  18630.       int number;
  18631. public:
  18632.       virtual void write();
  18633.       virtual void meaning();
  18634. };
  18635. class shape
  18636. {
  18637.       char* name;
  18638.       int xpoint, ypoint;
  18639. public:
  18640.       virtual void rotate(int);
  18641.       virtual void draw();
  18642.       void display() const;
  18643. };
  18644. class circle: public symbol, public shape
  18645. {
  18646.       int xorigin, yorigin;
  18647.       int radius;
  18648. public:
  18649.       void rotate(int);
  18650.       void draw ();
  18651.       void write();
  18652.       void meaning();
  18653.       void display() const;
  18654. };
  18655.  
  18656. In the above example, class circle inherits the members name, xpoint, ypoint, 
  18657. display(), rotate(), and draw() from class shape and also inherits the members 
  18658. language, letter, number, write(), and meaning() from class symbol. 
  18659.  
  18660.  
  18661. ΓòÉΓòÉΓòÉ 14.3. Derivation ΓòÉΓòÉΓòÉ
  18662.  
  18663. Inheritance is implemented in C++ through the mechanism of derivation. 
  18664. Derivation allows you to derive a class, called a derived class, from another 
  18665. class, called a base class. 
  18666.  
  18667. In the declaration of a derived class, you list the base classes of the derived 
  18668. class. The derived class inherits its members from these base classes. All 
  18669. classes that appear in the list of base classes must be previously defined 
  18670. classes. 
  18671.  
  18672. Syntax of a Derived Class 
  18673.  
  18674. Incompletely declared classes are not allowed in base lists. 
  18675.  
  18676. For example: 
  18677.  
  18678. class X; // incomplete declaration of class X
  18679. class Y: public X      // error
  18680. {
  18681. };
  18682.  
  18683. When you derive a class, the derived class inherits class members of the base 
  18684. class. You can refer to inherited members (base class members) as if they were 
  18685. members of the derived class. If you redefine base class members in the derived 
  18686. class, you can still refer to the base class members by using the :: (scope 
  18687. resolution) operator. 
  18688.  
  18689. You can manipulate a derived class object as if it were a base class object. 
  18690. You can use a pointer or a reference to a derived class object in place of a 
  18691. pointer or reference to its base class. For example, you can pass a pointer or 
  18692. reference to a derived class object D to a function expecting a pointer or 
  18693. reference to the base class of D. You do not need to use an explicit cast to 
  18694. achieve this; a standard conversion is performed. You can implicitly convert a 
  18695. pointer to a derived class to point to a base class. You can also implicitly 
  18696. convert a reference to a derived class to a reference to a base class. 
  18697.  
  18698. The reverse case is not allowed. You cannot implicitly convert a pointer or a 
  18699. reference to a base class object to a pointer or reference to a derived class. 
  18700.  
  18701. Examples of Derived Classes 
  18702.  
  18703. If a member of a derived class and a member of a base class have the same name, 
  18704. the base class member is hidden in the derived class. If a member of a derived 
  18705. class has the same name as a base class, the base class name is hidden in the 
  18706. derived class. In both cases, the name of the derived class member is called 
  18707. the dominant name. 
  18708.  
  18709. Related Information 
  18710.  
  18711.      Inheritance Overview 
  18712.      C++ Classes 
  18713.      Scope Resolution Operator :: 
  18714.      Multiple Inheritance 
  18715.  
  18716.  
  18717. ΓòÉΓòÉΓòÉ <hidden> Examples of Derived Classes ΓòÉΓòÉΓòÉ
  18718.  
  18719. /************************************************************************
  18720. *
  18721. You can refer to inherited members (base class members) as if they were members 
  18722. of the derived class: 
  18723.  
  18724.                                                                         *
  18725. ************************************************************************/
  18726.  
  18727. // This example illustrates references
  18728. // to base class members.
  18729.  
  18730. class base
  18731. {
  18732. public:
  18733.       int a,b;
  18734. };
  18735. class derived : public base
  18736. {
  18737. public:
  18738.       int c;
  18739. };
  18740. void main()
  18741. {
  18742.       derived d;
  18743.       d.a = 1;      // base::a
  18744.       d.b = 2;      // base::b
  18745.       d.c = 3;      // derived::c
  18746. }
  18747.  
  18748. /************************************************************************
  18749. *
  18750.  
  18751. The derived class can also add new class members and redefine existing base 
  18752. class members. In the above example, the two inherited members, a and b, of the 
  18753. derived class d, in addition to the derived class member c, are assigned 
  18754. values. 
  18755.  
  18756. For example: 
  18757.  
  18758.                                                                         *
  18759. ************************************************************************/
  18760.  
  18761. // This example illustrates references to base class
  18762. // members with the scope resolution (::) operator.
  18763.  
  18764. #include <iostream.h>
  18765. class base
  18766. {
  18767. public:
  18768.       char* name;
  18769.       void display(char* i) {cout << i << endl;}
  18770. };
  18771. class derived : public base
  18772. {
  18773. public:
  18774.       char* name;
  18775.       void display(char* i){cout << i << endl;}
  18776. };
  18777. void main()
  18778. {
  18779.       derived d;                    // create derived class object
  18780.       d.name = "Derived Class";     // assignment to derived::name
  18781.       d.base::name = "Base Class";  // assignment to base::name
  18782.  
  18783.       // call derived::display(derived::name)
  18784.       d.display(d.name);
  18785.  
  18786.       // call base::display(base::name)
  18787.       d.base::display(d.base::name);
  18788. }
  18789.  
  18790. /************************************************************************
  18791. *
  18792.  
  18793. In the following example, d, a pointer to a derived class object is assigned to 
  18794. bptr, a pointer to a base class object. A call is made to display() using bptr. 
  18795. Even though bptr has a type of pointer to base, in the body of display() the 
  18796. name member of derived is manipulated: 
  18797.  
  18798.                                                                         *
  18799. ************************************************************************/
  18800.  
  18801. // This example illustrates how to make a pointer
  18802. // to a derived class point to a base class.
  18803.  
  18804. #include <iostream.h>
  18805. class base
  18806. {
  18807. public:
  18808.       char* name;
  18809.       void display(char* i) {cout << i << endl;}
  18810. };
  18811. class derived : public base
  18812. {
  18813. public:
  18814.       char* name;
  18815.       void display(char* i){cout << i << endl;}
  18816. };
  18817. void main()
  18818. {
  18819.       derived d;
  18820.  
  18821.       // standard conversion from derived* to base*
  18822.       base* bptr = &d;
  18823.  
  18824.       // call base::display(base::name)
  18825.       bptr->display(bptr->name);
  18826. }
  18827.  
  18828.  
  18829. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Derived Class Declaration ΓòÉΓòÉΓòÉ
  18830.  
  18831. The syntax for the list of base classes is: 
  18832.  
  18833. >>ΓöÇΓöÇderived_classΓöÇΓöÇ:ΓöÇΓöÇ>
  18834.   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  18835.                                 Γöé
  18836. >ΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇqualified_class_specifierΓöÇΓö┤ΓöÇΓöÇ><
  18837.    Γö£ΓöÇvirtualΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  18838.    Γöé      Γö£ΓöÇpublicΓöÇΓöÇΓöÇΓöÇΓöñ   Γöé
  18839.    Γöé      Γö£ΓöÇprivateΓöÇΓöÇΓöÇΓöñ   Γöé
  18840.    Γöé      ΓööΓöÇprotectedΓöÇΓöÿ   Γöé
  18841.    ΓööΓöÇΓö¼ΓöÇpublicΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  18842.     Γö£ΓöÇprivateΓöÇΓöÇΓöÇΓöñ  ΓööΓöÇvirtualΓöÇΓöÿ
  18843.     ΓööΓöÇprotectedΓöÇΓöÿ
  18844.  
  18845. The qualified class specifier must be a class that has been previously declared 
  18846. in a class declaration as described in Class Names. The access specifiers 
  18847. (public, private, and protected) are described in Member Access. 
  18848.  
  18849. The virtual keyword can be used to declare virtual base classes. 
  18850.  
  18851. The following example shows the declaration of the derived class D and the base 
  18852. classes V, B1, and B2. The class B1 is both a base class and a derived class 
  18853. because it is derived from class V and is a base class for D. 
  18854.  
  18855. class V { /* ... */ };
  18856. class B1 : virtual public V { /* ... */ };
  18857. class B2 { /* ... */ };
  18858. class D : public B1, private B2 { /* ... */ };
  18859.  
  18860.  
  18861. ΓòÉΓòÉΓòÉ 14.4. Inherited Member Access ΓòÉΓòÉΓòÉ
  18862.  
  18863. Access specifiers, as described in Member Access, control the level of access 
  18864. to noninherited class members. The access for an inherited member is controlled 
  18865. in three ways: 
  18866.  
  18867.      When you declare a member in a base class, you can specify a level of 
  18868.       access using the keywords public, private, and protected. 
  18869.      When you derive a class, you can specify the access level for the base 
  18870.       class in the base list. 
  18871.      You can also restore the access level of inherited members. See 
  18872.       Derivation Access of Base Classes for an example. 
  18873.  
  18874.  Resolution of member names does not depend on the level of access associated 
  18875.  with each class member. 
  18876.  
  18877.  Consider the following example: 
  18878.  
  18879.   class A {
  18880.         private:
  18881.               int a;
  18882.   };
  18883.   class B {
  18884.         public:
  18885.               int a;
  18886.   };
  18887.   class C : public A, public B {
  18888.         void f() { a = 0; }  // ambiguous - is it A::a or B::a?
  18889.   };
  18890.  
  18891.  In this example, class A has a private member a, and class B has a public 
  18892.  member a. Class C is derived from both A and B. C does not have access to 
  18893.  A::a, but a in the body of f() can still resolve to either A::a or B::a. For 
  18894.  this reason, a is ambiguous in the body of f(). 
  18895.  
  18896.  If a class is derived publicly from a base class, a protected static base 
  18897.  class member can be accessed by members and friends of any classes derived 
  18898.  from that base class. A protected nonstatic base class member can be accessed 
  18899.  by members and friends of any classes derived from that base class by using 
  18900.  one of the following: 
  18901.  
  18902.      A pointer to a directly or indirectly derived class 
  18903.      A reference to a directly or indirectly derived class 
  18904.      An object of a directly or indirectly derived class 
  18905.  
  18906.  If a class is derived privately from a base class, all protected base class 
  18907.  members become private members of the derived class. 
  18908.  
  18909.  Examples of Inherited Member Access Rules 
  18910.  
  18911.  Related Information 
  18912.  
  18913.      Derivation Access of Base Classes 
  18914.      Access Declarations 
  18915.      Access Resolution 
  18916.      Member Access 
  18917.      Derivation 
  18918.      C++ Classes 
  18919.  
  18920.  
  18921. ΓòÉΓòÉΓòÉ 14.4.1. Derivation Access of Base Classes ΓòÉΓòÉΓòÉ
  18922.  
  18923. When you declare a derived class, an access specifier can precede each base 
  18924. class in the base list of the derived class. This does not alter the access 
  18925. attributes of the individual members of a base class as seen by the base class, 
  18926. but allows the derived class to restore the access attributes of the members of 
  18927. a base class. 
  18928.  
  18929. You can derive classes using any of the three access specifiers: 
  18930.  
  18931.      In a public base class, public and protected members of the base class 
  18932.       remain public and protected members of the derived class. 
  18933.      In a private base class, public and protected members of the base class 
  18934.       become private members of the derived class. 
  18935.      In a protected base class, public and protected members of the base class 
  18936.       are protected members of the derived class. 
  18937.  
  18938.  In all cases, private members of the base class remain private. Private 
  18939.  members of the base class cannot be used by the derived class unless friend 
  18940.  declarations within the base class explicitly grant access to them. 
  18941.  
  18942.  You can use both a structure and a class as base classes in the base list of a 
  18943.  derived class declaration. If the base class is declared with the keyword 
  18944.  class, its default access specifier in the base list of a derived class is 
  18945.  private. If the base class is declared with the keyword struct, its default 
  18946.  access specifier in the base list of a derived class is public. 
  18947.  
  18948.  Examples of Public and Private Derivation 
  18949.  
  18950.  Members and friends of a class can implicitly convert a pointer to an object 
  18951.  of that class to a pointer to either: 
  18952.  
  18953.      A direct private base class 
  18954.      A protected base class (either direct or indirect) 
  18955.  
  18956.  Related Information 
  18957.  
  18958.      Access Declarations 
  18959.      Access Resolution 
  18960.      Member Access 
  18961.      Derivation 
  18962.      C++ Classes 
  18963.  
  18964.  
  18965. ΓòÉΓòÉΓòÉ <hidden> Examples of Public and Private Derivation ΓòÉΓòÉΓòÉ
  18966.  
  18967. In the following example, class d is derived publicly from class b. Class b is 
  18968. declared a public base class by this declaration. 
  18969.  
  18970. class b
  18971. {
  18972. // ...
  18973. };
  18974. class d : public b // public derivation
  18975. {
  18976. // ...
  18977. };
  18978.  
  18979. In the following example, private derivation is used by default because no 
  18980. access specifier is used in the base list: 
  18981.  
  18982. struct bb
  18983. {
  18984. // ...
  18985. };
  18986. class dd : bb // private derivation
  18987. {
  18988. // ...
  18989. };
  18990.  
  18991.  
  18992. ΓòÉΓòÉΓòÉ 14.4.2. Access Declarations ΓòÉΓòÉΓòÉ
  18993.  
  18994. You can restore access to members of a base class using an access declaration. 
  18995. It allows you to change the access of a public member of a private or protected 
  18996. base class back to public. You can also change the access of a protected member 
  18997. of a private base class back to protected. Access is adjusted by using the base 
  18998. class member qualified name in the public or protected declarations of the 
  18999. derived class. 
  19000.  
  19001. You only use access declarations to restore base class access. You cannot 
  19002. change the access to a member to give it more access than it was originally 
  19003. declared with. You cannot change the access of a private member to public or to 
  19004. protected. You cannot change the access of a protected member to public. 
  19005.  
  19006. An access declaration cannot be used to restrict access to a member that is 
  19007. accessible in a base class. 
  19008.  
  19009. It is redundant to use an access declaration to change the access to a public 
  19010. member of a public base class to public, or to change the access to a protected 
  19011. member of a protected base class to protected. 
  19012.  
  19013. Examples of Access Declarations 
  19014.  
  19015. Access declarations can only be used to adjust the access of a member of a base 
  19016. class. The base class that an access declaration appears in can be directly or 
  19017. indirectly inherited by the derived class. 
  19018.  
  19019. You cannot adjust the access to a base class member if a member with the same 
  19020. name exists in a class derived from that base class. 
  19021.  
  19022. If you use an access declaration to adjust the access to an overloaded 
  19023. function, the access is adjusted for all functions with that name in the base 
  19024. class. 
  19025.  
  19026. Related Information 
  19027.  
  19028.      Derivation Access of Base Classes 
  19029.      Access Resolution 
  19030.      Member Access 
  19031.      Derivation 
  19032.      Overloading Functions 
  19033.      C++ Classes 
  19034.  
  19035.  
  19036. ΓòÉΓòÉΓòÉ <hidden> Examples of Access Declarations ΓòÉΓòÉΓòÉ
  19037.  
  19038. /************************************************************************
  19039. *
  19040.  
  19041. In the following example, the member b of the base class base is declared 
  19042. public in its base class declaration. Class derived is derived privately from 
  19043. class base. The access declaration in the public section of class derived 
  19044. restores the access level of the member b back to public. 
  19045.  
  19046.                                                                         *
  19047. ************************************************************************/
  19048.  
  19049. // This example illustrates using access declarations
  19050. // to restore base class access.
  19051.  
  19052. #include <iostream.h>
  19053. class base
  19054. {
  19055.       char a;
  19056. public:
  19057.       char c, b;
  19058.       void bprint();
  19059. };
  19060.  
  19061. class derived: private base
  19062. {
  19063.       char d;
  19064. public:
  19065.       char e;
  19066.       base::b;            // restore access to b in derived
  19067.       void dprint();
  19068.       derived(char ch) { base::b = ch; }
  19069. };
  19070.  
  19071. void print(derived& d)
  19072. {
  19073.       cout << " Here is d " << d.b << endl;
  19074. }
  19075.  
  19076. void main()
  19077. {
  19078.       derived obj('c');
  19079.       print(obj);
  19080. }
  19081.  
  19082. /************************************************************************
  19083. *
  19084.  
  19085. The external function print(derived&) can use the member b of base because the 
  19086. access of b has been restored to public. The external function print(derived&) 
  19087. can also use the members e and dprint() because they are declared with the 
  19088. keyword public in the derived class. The derived class member dprint() can use 
  19089. the members of its own class, d and e, in addition to the inherited members, b, 
  19090. c, and bprint(), that are declared with the keyword public in the base class. 
  19091. The base class member bprint() can use all the members of its own class, a, b, 
  19092. and c. 
  19093.  
  19094. You can also use an access declaration in a nested class. For example: 
  19095.  
  19096. class B
  19097. {
  19098. public:
  19099.       class N          // nested class
  19100.       {
  19101.       public:
  19102.             int i;     // public member
  19103.       };
  19104. };
  19105. class D: private B::N  // derive privately
  19106. {
  19107. public:
  19108.       B::N::i;         // restores access to public
  19109. };
  19110.  
  19111. You cannot convert a pointer to a derived class object to a pointer to a base 
  19112. class object if the base class is private or protected. For example: 
  19113.  
  19114. class B { /* ... */ };
  19115. class D : private B { /* ... */ };      // private base class
  19116.  
  19117. void main ()
  19118. {
  19119.       D d;
  19120.       B* ptr;
  19121.       ptr = &d;      // error
  19122. }
  19123.  
  19124.                                                                         *
  19125. ************************************************************************/
  19126.  
  19127.  
  19128. ΓòÉΓòÉΓòÉ 14.4.3. Access Resolution ΓòÉΓòÉΓòÉ
  19129.  
  19130. Access resolution is the process by which the accessibility of a particular 
  19131. class member is determined. Accessibility is dependent on the context. For 
  19132. example, a class member can be accessible in a member function but inaccessible 
  19133. at file scope. The following describes the access resolution procedure used by 
  19134. the compiler. 
  19135.  
  19136. In general, two scopes must be established before access resolution is applied. 
  19137. These scopes reduce an expression or declaration into a simplified construct to 
  19138. which the access rules are applied. Access rules are described in Member 
  19139. Access. These scopes are: 
  19140.  
  19141.  Call scope         The scope that encloses the expression or declaration that 
  19142.                     uses the class member. 
  19143.  
  19144.  Reference scope    The scope that identifies the class. 
  19145.  
  19146.  For example, in the following code: 
  19147.  
  19148.   // This example illustrates access resolution.
  19149.  
  19150.   class B { public: int member; };        // declaration
  19151.   class A : B {}                          // declaration
  19152.   void main()
  19153.   {
  19154.         A aobject;                         // declaration
  19155.         aobject.member = 10;               // expression
  19156.   }
  19157.  
  19158.  the reference scope for member is the type of aobject, that is class type  A. 
  19159.  
  19160.  Reference scope is chosen by simplifying the expression (or declaration) 
  19161.  containing the member. An expression can be thought of as being reduced to a 
  19162.  simple expression of the form obj.member where obj is the reference scope. 
  19163.  Reference scope is selected as follows: 
  19164.  
  19165.      If the member is qualified with . (dot) or -> (arrow), the reference 
  19166.       scope is the type of the object that is immediately to the left of the . 
  19167.       or -> operator closest to the member. Unqualified members are treated as 
  19168.       if they are qualified with this->. 
  19169.  
  19170.      If the member is a type member or a static member and is qualified with 
  19171.       :: (the scope resolution operator), the reference scope is the type 
  19172.       immediately to the left of the :: operator closest to the member. 
  19173.  
  19174.      Otherwise, the reference scope is the call scope. 
  19175.  
  19176.  The call scope and the reference scope determine the accessibility of a class 
  19177.  member. Once these scopes are resolved, the effective access of the member is 
  19178.  determined. Effective access is the access of the member as it is seen from 
  19179.  the reference scope. It is determined by taking the original access of the 
  19180.  member in its scope as the effective access and changing it as the class 
  19181.  hierarchy is traversed from the member's class to the reference scope. 
  19182.  Effective access is altered as the class hierarchy is traversed for each 
  19183.  derivation by the following: 
  19184.  
  19185.      The derivation access of a base class (see Derivation Access of Base 
  19186.       Classes) 
  19187.      Access declarations that are applied to the members (see Access 
  19188.       Declarations) 
  19189.      Friendships that are granted to the call scope (see Member Access) 
  19190.  
  19191.  After effective access is determined for a member, the access rules are 
  19192.  applied as if the effective access were the original access of the member. A 
  19193.  member is only accessible if the access rules say that it is. 
  19194.  
  19195.  Example of Access Resolution 
  19196.  
  19197.  Related Information 
  19198.  
  19199.      Derivation Access of Base Classes 
  19200.      Access Declarations 
  19201.      Member Access 
  19202.      Derivation 
  19203.      Overloading Functions 
  19204.      Scope Resolution Operator :: 
  19205.      C++ Classes 
  19206.  
  19207.  
  19208. ΓòÉΓòÉΓòÉ <hidden> Example of Access Resolution ΓòÉΓòÉΓòÉ
  19209.  
  19210. The following example demonstrates the access resolution procedure. 
  19211.  
  19212. class A
  19213. {
  19214. public:
  19215.       int a;
  19216. };
  19217. class B : private A
  19218. {
  19219.       friend void f (B*);
  19220. };
  19221. void f(B* b)
  19222. {
  19223.       b->a = 10; // is 'a' accessible to f(B*) ?
  19224. }
  19225. // ...
  19226.  
  19227. The following steps occur to determine the accessibility of A::a in f(B*): 
  19228.  
  19229.    1. The call scope and reference scope of the expression b->a are determined: 
  19230.  
  19231.         a. The call scope is the function f(B*). 
  19232.         b. The reference scope is class B. 
  19233.  
  19234.    2. The effective access of member a is determined: 
  19235.  
  19236.         a. Because the original access of the member a is public in class A, 
  19237.            the initial effective access of a is public. 
  19238.         b. Because B inherits from A privately, the effective access of a 
  19239.            inside class B is private. 
  19240.         c. Because class B is the reference scope, the effective access 
  19241.            procedure stops here. The effective access of a is private. 
  19242.  
  19243.    3. The access rules are applied. The rules state that a private member can 
  19244.       be accessed by a friend or a member of the member's class. Because f(B*) 
  19245.       is a friend of class B, f(B*) can access the private member a. 
  19246.  
  19247.  
  19248. ΓòÉΓòÉΓòÉ <hidden> Examples of Inherited Member Access Rules ΓòÉΓòÉΓòÉ
  19249.  
  19250. /************************************************************************
  19251. *
  19252.  
  19253. The following example demonstrates inherited member access rules. 
  19254.  
  19255.                                                                         *
  19256. ************************************************************************/
  19257.  
  19258. // This example illustrates inherited member access rules.
  19259.  
  19260. class B
  19261. {
  19262.       int a;
  19263. public:
  19264.       int b,c;
  19265.       void f(int) {}
  19266. protected:
  19267.       int d;
  19268.       void g(int) {}
  19269. };
  19270.  
  19271. class D1 : public B
  19272. {
  19273.       int a;
  19274. public:
  19275.       int b;
  19276.       void h(int i )
  19277.       {
  19278.             g(i);              // valid, protected B::g(int)
  19279.             B::b = 10;         // valid, B::b (not local b)
  19280.             d = 5 ;            // valid, protected B::d
  19281.       }
  19282. };
  19283.  
  19284. class D2 : private B
  19285. {
  19286.       int e;
  19287. public:
  19288.       B::c;                         // modify access to B::c
  19289.       void h(int i) { d = 5; }      // valid,protected B::d
  19290. };
  19291.  
  19292. void main( )
  19293. {
  19294.  
  19295.       int i= 1;      // declare and initialize local variable
  19296.       D1 d1;         // create object of class d1
  19297.       D2 d2;         // create object of class d2
  19298.  
  19299.       d1.a = 5;      // error, D1::a is private in class D1
  19300.       d2.b = 10;     // error, B::b is inherited private to
  19301.                      // derived class D2
  19302.       d2.c = 5;      // valid, modified access from private to public
  19303.       d2.B::c = 5;   // valid, public B::c
  19304.       d1.c = 5;      // valid, B::c is inherited publicly
  19305.       d1.d = 5;      // error, B::d is protected in base class
  19306.       d2.e = 10;     // error, private D2::e
  19307.       d1.g(i);       // error, g(int) is protected in base class
  19308.       d1.h(i);       // valid
  19309.       d2.h(i);       // valid
  19310. }
  19311.  
  19312. /************************************************************************
  19313. *
  19314.  
  19315.                                                                         *
  19316. ************************************************************************/
  19317.  
  19318.  
  19319. ΓòÉΓòÉΓòÉ 14.5. Multiple Inheritance ΓòÉΓòÉΓòÉ
  19320.  
  19321. You can derive a class from more than one base class. Deriving a class from 
  19322. more than one direct base class is called multiple inheritance. 
  19323.  
  19324. In the following example, classes A, B, and C are direct base classes for the 
  19325. derived class X: 
  19326.  
  19327. class A { /* ... */ };
  19328. class B { /* ... */ };
  19329. class C { /* ... */ };
  19330. class X : public A, private B, public C { /* ... */ };
  19331.  
  19332. The order of derivation is relevant only to determine the order of default 
  19333. initialization by constructors and cleanup by destructors. For more 
  19334. information, see Initialization by Constructor. 
  19335.  
  19336. A direct base class cannot appear in the base list of a derived class more than 
  19337. once: 
  19338.  
  19339. class B1 { /* ... */ };                   // direct base class
  19340. class D : public B1, private B1 { /* ... */ }; // error
  19341.  
  19342. However, a derived class can inherit an indirect base class more than once, as 
  19343. shown in the following example: 
  19344.  
  19345. class L { /* ... */ };                  // indirect base class
  19346. class B2 : public L { /* ... */ };
  19347. class B3 : public L { /* ... */ };
  19348. class D : public B2, public B3 { /* ... */ }; // valid
  19349.  
  19350. In the above example, class D inherits the indirect base class L once through 
  19351. class B2 and once through class B3. However, this may lead to ambiguities 
  19352. because two objects of class L exist, and both are accessible through class D. 
  19353. You can avoid this ambiguity by referring to class L using a qualified class 
  19354. name, for example,  B2::L  or  B3::L . 
  19355.  
  19356. You can also avoid this ambiguity by using the base specifier virtual to 
  19357. declare a base class. 
  19358.  
  19359. Examples of Single and Multiple Inheritance 
  19360.  
  19361. Related Information 
  19362.  
  19363.      Virtual Base Classes 
  19364.      Multiple Access 
  19365.      Inheritance Overview 
  19366.      Derivation 
  19367.      Initialization by Constructor 
  19368.      C++ Classes 
  19369.  
  19370.  
  19371. ΓòÉΓòÉΓòÉ 14.5.1. Virtual Base Classes ΓòÉΓòÉΓòÉ
  19372.  
  19373. If you have an inheritance graph in which two or more derived classes have a 
  19374. common base class, you can use a virtual base class to ensure that the two 
  19375. classes share a single instance of the base class. 
  19376.  
  19377. In the following example, an object of class D has two distinct objects of 
  19378. class L, one through class B1 and another through class B2. You can use the 
  19379. keyword virtual in front of the base class specifiers in the base lists of 
  19380. classes B1 and B2 to indicate that only one class L, shared by class B1 and 
  19381. class B2, exists. 
  19382.  
  19383. For example: 
  19384.  
  19385. class L { /* ... */ }; // indirect base class
  19386. class B1 : virtual public L { /* ... */ };
  19387. class B2 : virtual public L { /* ... */ };
  19388. class D : public B1, public B2 { /* ... */ }; // valid
  19389.  
  19390. Using the keyword virtual in this example ensures that an object of class D 
  19391. inherits only one object of class L. 
  19392.  
  19393. A derived class can have both virtual and nonvirtual base classes. For example: 
  19394.  
  19395. class V { /* ... */ };
  19396. class B1 : virtual public V { /* ... */ };
  19397. class B2 : virtual public V { /* ... */ };
  19398. class B3 : public V { /* ... */ };
  19399. class D : public B1, public B2, public B3 { /* ... */
  19400. };
  19401.  
  19402. In the above example, class D has two objects of class V, one that is shared by 
  19403. classes B1 and B2 and one through class B3. 
  19404.  
  19405. Related Information 
  19406.  
  19407.      Multiple Inheritance 
  19408.      Multiple Access 
  19409.      Inheritance Overview 
  19410.      Derivation 
  19411.      C++ Classes 
  19412.  
  19413.  
  19414. ΓòÉΓòÉΓòÉ 14.5.2. Multiple Access ΓòÉΓòÉΓòÉ
  19415.  
  19416. In an inheritance graph containing virtual base classes, a name that can be 
  19417. reached through more than one path is accessed through the path that gives the 
  19418. most access. 
  19419.  
  19420. For example: 
  19421.  
  19422. class L { public: void f(); };
  19423. class B1 : private virtual L { /* ... */ };
  19424. class B2 : public virtual L { /* ... */ };
  19425. class D : public B1, public B2
  19426. {
  19427. public:
  19428.       void f() {L::f();} // L::f() is accessed through B2
  19429.                                      // and is public
  19430. };
  19431.  
  19432. In the above example, the function f() is accessed through class B2. Because 
  19433. class B2 is inherited publicly and class B1 is inherited privately, class B2 
  19434. offers more access. 
  19435.  
  19436. An accessible base class is a publicly derived base class that is neither 
  19437. hidden nor ambiguous in the inheritance hierarchy. 
  19438.  
  19439. When you derive classes, ambiguities can result if base and derived classes 
  19440. have members with the same names. Access to a base class member is ambiguous if 
  19441. you use a name or qualified name that does not refer to a unique function, 
  19442. object, type, or enumerator. The declaration of a member with an ambiguous name 
  19443. in a derived class is not an error. The ambiguity is only flagged as an error 
  19444. if you use the ambiguous member name. 
  19445.  
  19446. For example, if two base classes have a member of the same name, an attempt to 
  19447. access the member by the derived class is ambiguous. You can resolve ambiguity 
  19448. by qualifying a member with its class name using the :: (scope resolution) 
  19449. operator. 
  19450.  
  19451. Example of Resolving Ambiguous Access 
  19452.  
  19453. The compiler checks for ambiguities at compile time. Because ambiguity checking 
  19454. occurs before access control or type checking, ambiguities may result even if 
  19455. only one of several members with the same name is accessible from the derived 
  19456. class. 
  19457.  
  19458. Conversions (either implicit or explicit) from a derived class pointer or 
  19459. reference to a base class pointer or reference must refer unambiguously to the 
  19460. same accessible base class object. For example: 
  19461.  
  19462. class W { /* ... */ };
  19463. class X : public W { /* ... */ };
  19464. class Y : public W { /* ... */ };
  19465. class Z : public X, public Y { /* ... */ };
  19466. void main ()
  19467. {
  19468.       Z z;
  19469.       X* xptr = &z;       // valid
  19470.       Y* yptr = &z;       // valid
  19471.       W* wptr = &z;       // error, ambiguous reference to class W
  19472.                           // X's W or Y's W ?
  19473. }
  19474.  
  19475. You can use virtual base classes to avoid ambiguous reference. For example: 
  19476.  
  19477. class W { /* ... */ };
  19478. class X : public virtual W { /* ... */ };
  19479. class Y : public virtual W { /* ... */ };
  19480. class Z : public X, public Y { /* ... */ };
  19481. void main ()
  19482. {
  19483.       Z z;
  19484.       X* xptr = &z;      // valid
  19485.       Y* yptr = &z;      // valid
  19486.       W* wptr = &z;      // valid, W is virtual therefore only one
  19487.                          // W subobject exists
  19488. }
  19489.  
  19490. Related Information 
  19491.  
  19492.      Virtual Base Classes 
  19493.      Multiple Inheritance 
  19494.      Scope Resolution Operator :: 
  19495.      Inheritance Overview 
  19496.      Derivation 
  19497.      Member Access 
  19498.  
  19499.  
  19500. ΓòÉΓòÉΓòÉ <hidden> Example of Resolving Ambiguous Access ΓòÉΓòÉΓòÉ
  19501.  
  19502. /************************************************************************
  19503. *
  19504.  
  19505. The following example uses the :: (scope resolution) operator to resolve an 
  19506. ambiguous reference. 
  19507.  
  19508.                                                                         *
  19509. ************************************************************************/
  19510.  
  19511. // This example illustrates ambiguous base classes.
  19512.  
  19513. class B1
  19514. {
  19515. public:
  19516.       int i;
  19517.       int j;
  19518.       int g( );
  19519. };
  19520. class B2
  19521. {
  19522. public:
  19523.       int j;
  19524.       int g( );
  19525. };
  19526. // ...
  19527. class D : public B1, public B2
  19528. {
  19529. public:
  19530.       int i;
  19531. };
  19532. void main ()
  19533. {
  19534.       D dobj;
  19535.       D *dptr = &dobj;
  19536.       dptr -> i = 5;        // valid, D::i
  19537.       dptr -> j = 10;       // error, ambiguous reference to j
  19538.       dptr->B1::j = 10;     // valid, B1::j
  19539.       dobj.g( );            // error, ambiguous reference to g( )
  19540.       dobj.B2::g( );        // valid, B2::g( )
  19541. }
  19542.  
  19543.  
  19544. ΓòÉΓòÉΓòÉ 14.6. Virtual Functions ΓòÉΓòÉΓòÉ
  19545.  
  19546. In C++, dynamic binding is supported by the mechanism of virtual functions. 
  19547. Virtual functions must be members of a class. Use virtual functions when you 
  19548. expect a class to be used as a base class in a derivation and when the 
  19549. implementation of the function may be overridden in the derived class. You can 
  19550. declare a member function with the keyword virtual in its class declaration. 
  19551. For example: 
  19552.  
  19553. class B
  19554. {
  19555.       int a,b,c;
  19556. public:
  19557.       virtual int f();
  19558. };
  19559.  
  19560. You can reimplement a virtual member function, like any member function, in any 
  19561. derived class. The implementation that is executed when you make a call to a 
  19562. virtual function depends on the type of the object for which it is called. If a 
  19563. virtual member function is called for a derived class object and the function 
  19564. is redefined in the derived class, the definition in the derived class is 
  19565. executed. In this case, the redefined derived class function is said to 
  19566. override the base class function. This occurs even if the access to the 
  19567. function is through a pointer or reference to the base class. 
  19568.  
  19569. If you call a virtual function with a pointer that has base class type but 
  19570. points to a derived class object, the member function of the derived class is 
  19571. called. However, if you call a nonvirtual function with a pointer that has base 
  19572. class type, the member function of the base class is called regardless of 
  19573. whether the pointer points to a derived class object. 
  19574.  
  19575. Example of Overriding Virtual Functions 
  19576.  
  19577. If the argument types or the number of arguments of the two functions are 
  19578. different, the functions are considered different, and the function in the 
  19579. derived class does not override the function in the base class. The function in 
  19580. the derived class hides the function in the base class. 
  19581.  
  19582. The return type of an overriding virtual function can differ from the return 
  19583. type of the overridden virtual function provided that: 
  19584.  
  19585.      The overridden function returns a pointer or a reference to a class T 
  19586.  
  19587.       AND 
  19588.  
  19589.      The overriding virtual function returns a pointer or a reference to a 
  19590.       class derived from T. 
  19591.  
  19592.  An error does result when a virtual function that returns D* overrides a 
  19593.  virtual function that returns B* where B is an ambiguous base class of D. The 
  19594.  reason is that two or more instances of class B will exist within class D, and 
  19595.  the compiler will not know which base B to return. For more information, see 
  19596.  Function Return Values. 
  19597.  
  19598.  A virtual function cannot be global or static because, by definition, a 
  19599.  virtual function is a member function of a base class and relies on a specific 
  19600.  object to determine which implementation of the function is called. You can 
  19601.  declare a virtual function to be a friend of another class. 
  19602.  
  19603.  If a function is declared virtual in its base class, it can still be accessed 
  19604.  directly using the :: (scope resolution) operator. In this case, the virtual 
  19605.  function call mechanism is suppressed and the function implementation defined 
  19606.  in the base class is used. In addition, if you do not redefine a virtual 
  19607.  member function in a derived class, a call to that function uses the function 
  19608.  implementation defined in the base class. 
  19609.  
  19610.  A virtual function must be one of the following: 
  19611.  
  19612.      Defined 
  19613.      Declared pure 
  19614.      Defined and declared pure 
  19615.  
  19616.  A base class containing one or more pure virtual member functions is called an 
  19617.  abstract class. 
  19618.  
  19619.  Related Information 
  19620.  
  19621.      Virtual Base Classes 
  19622.      Ambiguous Virtual Function Calls 
  19623.      Virtual Function Access 
  19624.      Abstract Classes 
  19625.      Function Return Values 
  19626.      Friends 
  19627.      Scope Resolution Operator :: 
  19628.      Inheritance Overview 
  19629.      Derivation 
  19630.  
  19631.  
  19632. ΓòÉΓòÉΓòÉ <hidden> Example of Overriding Virtual Functions ΓòÉΓòÉΓòÉ
  19633.  
  19634. /************************************************************************
  19635. *
  19636.  
  19637. The following example shows how virtual functions can be redefined. 
  19638.  
  19639.                                                                         *
  19640. ************************************************************************/
  19641.  
  19642. class B
  19643. {
  19644. public:
  19645.       virtual int f();
  19646.       virtual int g();
  19647.       int h();
  19648. };
  19649. class D : public B
  19650. {
  19651. public:
  19652.       int f();
  19653.       int g(char*);      // hides B::g()
  19654.       int h();
  19655. };
  19656. // ...
  19657. void main ()
  19658. {
  19659.       D d;
  19660.       B* bptr = &d;
  19661.  
  19662.       bptr->f();         // calls D::f() because f() is virtual
  19663.       bptr->h();         // calls B::h() because h() is nonvirtual
  19664.       bptr->g();         // calls B::g()
  19665.       d.g();             // error, wrong number and type of arguments
  19666.       d.g("string");     // calls D::g(char*)
  19667. }
  19668.  
  19669.  
  19670. ΓòÉΓòÉΓòÉ 14.6.1. Ambiguous Virtual Function Calls ΓòÉΓòÉΓòÉ
  19671.  
  19672. It is an error to override one virtual function with two or more ambiguous 
  19673. virtual functions. This can happen in a derived class that inherits from two 
  19674. nonvirtual bases that are derived from a virtual base class. 
  19675.  
  19676. Example of Ambiguous Virtual Functions 
  19677.  
  19678. A special case occurs when the ambiguous overriding virtual functions come from 
  19679. separate instances of the same class type. In the following example, there are 
  19680. two objects (instances) of class L. There are two data members L::count, one in 
  19681. class A and one in class B. If the declaration of class D is allowed, 
  19682. incrementing L::count in a call to L::f() with a pointer to class V is 
  19683. ambiguous. 
  19684.  
  19685. class V
  19686. {
  19687. public:
  19688.       virtual void f();
  19689. };
  19690. class L : virtual public V
  19691. {
  19692.       int count;
  19693.       void f();
  19694. };
  19695. void L::f() {++count;}
  19696. class A : public L
  19697. { /* ... */ };
  19698. class B : public L
  19699. { /* ... */ };
  19700. class D : public A, public B { /* ... */ }; // error
  19701. void main ()
  19702. {
  19703.       D d;
  19704.       V* vptr = &d;
  19705.       vptr->f();
  19706. }
  19707.  
  19708. In the above example, the function L::f() is expecting a pointer to an L 
  19709. object; that is, the this pointer for class L, as its first implicit argument. 
  19710. Because there are two objects of class L in a D object, there are two this 
  19711. pointers that could be passed to L::f(). Because the compiler cannot decide 
  19712. which this pointer to pass to L::f(), the declaration of class D is flagged as 
  19713. an error. 
  19714.  
  19715. Related Information 
  19716.  
  19717.      Virtual Functions 
  19718.      Virtual Function Access 
  19719.      Multiple Access 
  19720.      Scope Resolution Operator :: 
  19721.      Member Functions 
  19722.  
  19723.  
  19724. ΓòÉΓòÉΓòÉ <hidden> Example of Ambiguous Virtual Functions ΓòÉΓòÉΓòÉ
  19725.  
  19726. /************************************************************************
  19727. *
  19728.  
  19729. The following example shows a class that inherits from two nonvirtual bases 
  19730. that are derived from a virtual base class. 
  19731.  
  19732.                                                                         *
  19733. ************************************************************************/
  19734.  
  19735. class V
  19736. {
  19737. public:
  19738.       virtual void f() { /* ... */ };
  19739. };
  19740. class A : virtual public V
  19741. {
  19742.       void f() { /* ... */ };
  19743. };
  19744. class B : virtual public V
  19745. {
  19746.       void f() { /* ... */ };
  19747. };
  19748. class D : public B, public A { /* ... */ }; // error
  19749. void main ()
  19750. {
  19751.       D d;
  19752.       V* vptr = &d;
  19753.       vptr->f();            // which f(), A::f() or B::f()?
  19754. }
  19755.  
  19756. /************************************************************************
  19757. *
  19758.  
  19759. In class A, only A::f() will override V::f(). Similarly, in class B, only 
  19760. B::f() will override V::f(). However, in class D, both A::f() and B::f() will 
  19761. try to override V::f(). This attempt is not allowed because it is not possible 
  19762. to decide which function to call if a D object is referenced with a pointer to 
  19763. class V, as shown in the above example. Because only one function can override 
  19764. a virtual function, the compiler flags this situation as an error. 
  19765.  
  19766.                                                                         *
  19767. ************************************************************************/
  19768.  
  19769.  
  19770. ΓòÉΓòÉΓòÉ 14.6.2. Virtual Function Access ΓòÉΓòÉΓòÉ
  19771.  
  19772. The access for a virtual function is specified when it is declared. The access 
  19773. rules for a virtual function are not affected by the access rules for the 
  19774. function that later overrides the virtual function. In general, the access of 
  19775. the overriding member function is not known. 
  19776.  
  19777. If a virtual function is called with a pointer or reference to a class object, 
  19778. the type of the class object is not used to determine the access of the virtual 
  19779. function. Instead, the type of the pointer or reference to the class object is 
  19780. used. 
  19781.  
  19782. In the following example, when the function f() is called using a pointer 
  19783. having type B*, bptr is used to determine the access to the function f(). 
  19784. Although the definition of f() defined in class D is executed, the access of 
  19785. the member function f() in class B is used. When the function f() is called 
  19786. using a pointer having type D*, dptr is used to determine the access to the 
  19787. function f(). This call produces an error because f() is declared private in 
  19788. class D. 
  19789.  
  19790. class B
  19791. {
  19792. public:
  19793.       virtual void f();
  19794. };
  19795. class D : public B
  19796. {
  19797. private:
  19798.       void f();
  19799. };
  19800. void main ()
  19801. {
  19802.       D dobj;
  19803.       B *bptr = &dobj;
  19804.       D *dptr = &dobj;
  19805.       bptr->f();   // valid, virtual B::f() is public,
  19806.                    // D::f() is called
  19807.       dptr->f();   // error, D::f() is private
  19808. }
  19809.  
  19810. Related Information 
  19811.  
  19812.      Virtual Functions 
  19813.      Ambiguous Virtual Function Calls 
  19814.      Inherited Member Access 
  19815.  
  19816.  
  19817. ΓòÉΓòÉΓòÉ 14.7. Abstract Classes ΓòÉΓòÉΓòÉ
  19818.  
  19819. An abstract class is a class that is designed to be specifically used as a base 
  19820. class. An abstract class contains at least one pure virtual function. Pure 
  19821. virtual functions are inherited. You can declare a function to be pure by using 
  19822. a pure specifier in the declaration of the member function in the class 
  19823. declaration. 
  19824.  
  19825. For example: 
  19826.  
  19827. class AB             // abstract class
  19828. {
  19829. public:
  19830.       virtual void f()= 0; // pure virtual member function
  19831. };
  19832.  
  19833. A function that is declared pure typically has no definition and cannot be 
  19834. executed. Attempting to call a pure virtual function that has no implementation 
  19835. is undefined; however, such a call does not cause an error. No objects of an 
  19836. abstract class can be created. 
  19837.  
  19838. Note:  Because destructors are not inherited, a virtual destructor that is 
  19839. declared pure must have a definition. 
  19840.  
  19841. Virtual member functions are inherited. If a base class contains a pure virtual 
  19842. member function and a class derived from that base class does not redefine that 
  19843. pure virtual member function, the derived class itself is an abstract class. 
  19844. Any attempt to create an object of the derived class type produces an error. 
  19845.  
  19846. Examples of Errors using Abstract Classes 
  19847.  
  19848. You cannot use an abstract class as the type of an explicit conversion, as an 
  19849. argument type, or as the return type for a function. You can declare a pointer 
  19850. or reference to an abstract class. 
  19851.  
  19852. Related Information 
  19853.  
  19854.      Virtual Functions 
  19855.      Inheritance Overview 
  19856.      Derivation 
  19857.      C++ Classes 
  19858.  
  19859.  
  19860. ΓòÉΓòÉΓòÉ <hidden> Examples of Errors using Abstract Classes ΓòÉΓòÉΓòÉ
  19861.  
  19862. /************************************************************************
  19863. *
  19864.  
  19865. The following example shows an attempt to create an object of an abstract class 
  19866. type. 
  19867.  
  19868.                                                                         *
  19869. ************************************************************************/
  19870.  
  19871. class AB             // abstract class
  19872. {
  19873. public:
  19874.       virtual void f()= 0; // pure virtual member function
  19875. };
  19876. class D: public AB
  19877. {
  19878. public:
  19879.       void f();
  19880. };
  19881. // ...
  19882. void main ()
  19883. {
  19884.       D d;
  19885.       d.f() ;     // calls D::f()
  19886.       AB ab;      // error, cannot create an object of an
  19887.                   // abstract class type
  19888. }
  19889.  
  19890. /************************************************************************
  19891. *
  19892.  
  19893. The following example shows an attempt to create an object of a class derived 
  19894. from an abstract class, but that does not redefine the pure virtual function of 
  19895. that abstract class. 
  19896.  
  19897.                                                                         *
  19898. ************************************************************************/
  19899.  
  19900. For example: 
  19901.  
  19902. class AB // abstract class
  19903. {
  19904. public:
  19905.       virtual void f()= 0; // pure virtual member function
  19906. };
  19907. class D2: public AB
  19908. {
  19909.       int a,b,c;
  19910. public:
  19911.       void g();
  19912. };
  19913. // ...
  19914. void main ()
  19915. {
  19916.       D2 d;
  19917.       // error, cannot declare an object of abstract class D2
  19918. }
  19919.  
  19920. To avoid the error in the above example, provide a declaration of D2::f(). 
  19921.  
  19922.  
  19923. ΓòÉΓòÉΓòÉ 15. C++ Templates ΓòÉΓòÉΓòÉ
  19924.  
  19925. This chapter describes the C++ template facility. A template specifies how an 
  19926. individual class, function, or static data member can be constructed by 
  19927. providing a blueprint description of classes or functions within the template. 
  19928.  
  19929. Unlike an ordinary class or function definition, a template definition contains 
  19930. the template keyword, and uses a type argument, instead of a type, in one or 
  19931. more of the constructs used to define the class or function template. 
  19932. Individual classes or functions can then be generated simply by specifying the 
  19933. template name and by naming the type for the particular class or function as 
  19934. the type argument of the template. You can use templates to define a family of 
  19935. types or functions. 
  19936.  
  19937. This chapter discusses: 
  19938.  
  19939.      Template Syntax 
  19940.      Structuring Your Program Using Templates 
  19941.      Class Templates 
  19942.      Function Templates 
  19943.      Differences between Class and Function Templates 
  19944.      Member Function Templates 
  19945.      Friends and Templates 
  19946.      Static Data Members and Templates 
  19947.  
  19948.  Note:  C++ objects with templates can now be linked as a separate step with 
  19949.  the VisualAge C++ linker command. 
  19950.  
  19951.  Related Information 
  19952.  
  19953.      Functions 
  19954.      C++ Classes 
  19955.      Type Specifiers 
  19956.      define 
  19957.      implementation 
  19958.  
  19959.  See the IBM VisualAge C++ for OS/2 User's Guide and Reference for programming 
  19960.  hints on using templates in C++ programs. 
  19961.  
  19962.  
  19963. ΓòÉΓòÉΓòÉ 15.1. Template Syntax ΓòÉΓòÉΓòÉ
  19964.  
  19965. The syntax for a template is: 
  19966.  
  19967.          ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  19968. >>ΓöÇΓöÇtemplateΓöÇΓöÇΓöÉΓöÇΓöÇΓö┤Γö¼ΓöÇargument-declarationΓöÇΓö¼Γö┤ΓöÇΓöÇ>ΓöÇΓöÇ><
  19969.        Γöé  Γöé            Γöé
  19970.          ΓööΓöÇtypeΓöÇΓöÇidentifierΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  19971.  
  19972. The declaration in a template declaration must define or declare one of the 
  19973. following: 
  19974.  
  19975.      A class 
  19976.      A function 
  19977.      A static member of a template class 
  19978.  
  19979.  The identifier of a type is defined to be a type_name in the scope of the 
  19980.  template declaration. A template declaration can appear as a global 
  19981.  declaration only. 
  19982.  
  19983.  The template arguments (within the < and > delimitiers) specify the types and 
  19984.  the constants within the template that must be specified when the template is 
  19985.  instantiated. 
  19986.  
  19987.  Examples of Templates 
  19988.  
  19989.  Default intializers are permitted in template arguments, under the following 
  19990.  conditions: 
  19991.  
  19992.      They can only be applied to nontype template arguments. 
  19993.      Like functions, they can only be applied to trailing arguments. 
  19994.      Subsequent template declarations can add default initializers but cannot 
  19995.       redefine existing default initializers. 
  19996.      They can only be applied to class template declarations, not to function 
  19997.       template declarations. 
  19998.  
  19999.  Note:  A template that defines a member function of a class template is 
  20000.  treated as a function template. Such a template cannot have default 
  20001.  intializers. 
  20002.  
  20003.  Example of Default Initializers in Templates 
  20004.  
  20005.  Related Information 
  20006.  
  20007.      Structuring Your Program Using Templates 
  20008.      Class Templates 
  20009.      Function Templates 
  20010.      C++ Classes 
  20011.      Functions 
  20012.      Static Members 
  20013.  
  20014.  
  20015. ΓòÉΓòÉΓòÉ <hidden> Examples of Templates ΓòÉΓòÉΓòÉ
  20016.  
  20017. Given the following template: 
  20018.  
  20019. template<class L> class Key
  20020. {
  20021.    L k;
  20022.     L* kptr;
  20023.     int length;
  20024. public:
  20025.     Key(L);
  20026.     // ...
  20027. };
  20028.  
  20029. The following table shows what the classes Key<int>, Key<char*>, and 
  20030. Key<mytype> look like: 
  20031.  
  20032. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  20033. Γöé class Key<int> i;    Γöé class Key<char*> c;    Γöé class Key<mytype> m;   Γöé
  20034. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  20035. Γöé class Key<int> {     Γöé class Key<char*> {    Γöé class Key<mytype> {   Γöé
  20036. Γöé    int k;       Γöé    char* k;      Γöé    mytype k;     Γöé
  20037. Γöé    int * kptr;    Γöé    char** kptr;    Γöé    mytype* kptr;   Γöé
  20038. Γöé    int length;    Γöé    int length;     Γöé    int length;    Γöé
  20039. Γöé public:         Γöé public:          Γöé public:         Γöé
  20040. Γöé    Key(int);     Γöé    Key(char*);     Γöé    Key(mytype);    Γöé
  20041. Γöé    // ...  };     Γöé    // ...  };     Γöé    // ...  };     Γöé
  20042. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  20043.  
  20044. The declarations create the following objects: 
  20045.  
  20046.      i of type Key<int> 
  20047.      c of type Key<char*> 
  20048.      m of type Key<mytype> 
  20049.  
  20050.  Note that these three classes have different names. The types contained within 
  20051.  the angle braces are not arguments to the class names, but part of the class 
  20052.  names themselves. Key<int> and Key<char*> are class names. Within the context 
  20053.  of the example, a class called Key (with no template argument list) is 
  20054.  undefined. 
  20055.  
  20056.  
  20057. ΓòÉΓòÉΓòÉ <hidden> Example of Default Initializers in Templates ΓòÉΓòÉΓòÉ
  20058.  
  20059. /************************************************************************
  20060. *
  20061.  
  20062. The following example shows a valid template declaration with default 
  20063. initializers: 
  20064.  
  20065. *
  20066. ************************************************************************/
  20067.  
  20068. // This example shows a template declaration
  20069. // with default initializers.
  20070.  
  20071. #include <stdio.h>
  20072.  
  20073. template <class T, int i=1> class X
  20074. {
  20075. public:
  20076.      T s;
  20077.      X(int j=4);
  20078.      int val(T&)
  20079.      {
  20080.        return i;
  20081.      };
  20082. };
  20083.  
  20084. template <class T, int i> X<T,i>::X(int j):s(i){
  20085.   printf("i=%d   j=%d\n",i,j);
  20086. }
  20087.  
  20088. void main()
  20089. {
  20090.   X<int>   myX(2);
  20091.   X<int,3> myX2(4);
  20092. }
  20093.  
  20094.  
  20095. ΓòÉΓòÉΓòÉ 15.2. Structuring Your Program Using Templates ΓòÉΓòÉΓòÉ
  20096.  
  20097. You can structure your program three ways using templates: 
  20098.  
  20099.    1. Include the function template definition (both the .h and .c files) in 
  20100.       all files that may reference the corresponding template functions. 
  20101.  
  20102.    2. Include the function template declaration (the .h file only) in all files 
  20103.       that may reference the corresponding template functions, but include the 
  20104.       function definition (both the .h and .c files) in one file only. 
  20105.  
  20106.    3. Include the declaration of the function templates in a header file and 
  20107.       the definition in a source file that has the same name. When you include 
  20108.       the header file in your source, the compiler automatically generates the 
  20109.       template functions. Use the /Ft+ option to enable this method. 
  20110.  
  20111.  The following examples use two files to illustrate all three methods: stack.h 
  20112.  and stackdef.h 
  20113.  
  20114.  To instantiate a stack of 50 ints, you would declare the following in each 
  20115.  source file that requires it: 
  20116.  
  20117.   stack<int> intStack(50);
  20118.  
  20119.  For method 1, each source file using the template should include both stack.h 
  20120.  and stackdef.h. 
  20121.  
  20122.  For method 2, every source file should include stack.h, but only one of the 
  20123.  files needs to include stackdef.h. 
  20124.  
  20125.  For method 3, every source file should include stack.h. The compiler 
  20126.  automatically generates the template functions in the TEMPINC subdirectory 
  20127.  that is created in the current directory. To use this method, copy stackdef.h 
  20128.  to stack.c and use the /Ft+ option, which is the default. 
  20129.  
  20130.  Note:  C++ objects with templates can now be linked as a separate step with 
  20131.  the VisualAge C++ linker command. 
  20132.  
  20133.  Related Information 
  20134.  
  20135.      Template Syntax 
  20136.      Class Templates 
  20137.      Function Templates 
  20138.      Differences between Class and Function Templates 
  20139.      "Using Templates in C++ Programs" in the IBM VisualAge C++ for OS/2 
  20140.       Programming Guide. 
  20141.  
  20142.  
  20143. ΓòÉΓòÉΓòÉ <hidden> stack.h and stackdef.h ΓòÉΓòÉΓòÉ
  20144.  
  20145. /************************************************************************
  20146. *
  20147.  
  20148. stack.h 
  20149.  
  20150.                                                                         *
  20151. ************************************************************************/
  20152.  
  20153. #ifndef _STACK_TPL_H
  20154.       #define _STACK_TPL_H
  20155.  
  20156.       template<class T>
  20157.       class stack
  20158.       {
  20159.       private:
  20160.              T*  v;
  20161.              T*  p;
  20162.              int sz;
  20163.  
  20164.       public:
  20165.              stack( int );
  20166.               ~stack();
  20167.               void push( T );
  20168.       };
  20169. #endif
  20170.  
  20171. /************************************************************************
  20172. *
  20173.  
  20174. stackdef.h 
  20175.  
  20176.                                                                         *
  20177. ************************************************************************/
  20178.  
  20179. #include "stack.h"
  20180.  
  20181. template<class T> stack<T>::stack( int s )
  20182. {
  20183.       v = p = new T[sz=s];
  20184. }
  20185.  
  20186. template<class T> stack<T>::~stack()
  20187. {
  20188.       delete [] v;
  20189. }
  20190.  
  20191. template<class T> void stack<T>::push( T a )
  20192. {
  20193.       *p++ = a;
  20194. }
  20195.  
  20196.  
  20197. ΓòÉΓòÉΓòÉ 15.3. Class Templates ΓòÉΓòÉΓòÉ
  20198.  
  20199. The relationship between a class template and an individual class is like the 
  20200. relationship between a class and an individual object. An individual class 
  20201. defines how a group of objects can be constructed, while a class template 
  20202. defines how a group of classes can be generated. 
  20203.  
  20204. Note the distinction between the terms class template and template class: 
  20205.  
  20206.  Class template    is a template used to generate template classes. A class 
  20207.                    template can be only a declaration, or it can be a 
  20208.                    definition of the class. 
  20209.  
  20210.  Template class    is an instance of a class template. 
  20211.  
  20212.  A template definition is identical to any valid class definition that the 
  20213.  template might generate, except for the following: 
  20214.  
  20215.      The class template definition is preceded by  template < 
  20216.       template-argument-list >  where template-argument-list can include zero 
  20217.       or more arguments of user-defined type and zero or more argument 
  20218.       declarations. The template-argument-list must contain at least one 
  20219.       argument. 
  20220.  
  20221.      Types, variables, constants and objects within the class template can be 
  20222.       declared with arguments of user-defined type as well as with explicit 
  20223.       types (for example, int or char). 
  20224.  
  20225.      The template-argument-list can include argument-declarations (for 
  20226.       example, int a or char* b), which are generally used to define constant 
  20227.       values within the created class. 
  20228.  
  20229.  A class template can declare a class without defining it by using an 
  20230.  elaborated type specifier. For example: 
  20231.  
  20232.   template  <class L,class T> class key;
  20233.  
  20234.  This reserves the name as a class template name. All template declarations for 
  20235.  a class template must have the same types and number of template arguments. 
  20236.  Only one template declaration containing the class definition is allowed. 
  20237.  
  20238.  You can instantiate the class template by declaring a template class. If the 
  20239.  definitions of the member functions of the template class are not inlined, 
  20240.  then you have to define them. When you instantiate a template class, its 
  20241.  argument list must match the argument list in the class template declaration. 
  20242.  
  20243.  Syntax of a Template Class Instantiation 
  20244.  
  20245.  Note:  When you have nested template argument lists, you must have a 
  20246.  separating space between the > at the end of the inner list and the one at the 
  20247.  end of the outer list. Otherwise, there is an ambiguity between the output 
  20248.  operator >> and two template list delimiters >. 
  20249.  
  20250.   template  <class L,class T> class key
  20251.   {
  20252.   // ...
  20253.   };
  20254.   template <class L> class vector
  20255.   {
  20256.   // ...
  20257.   };
  20258.  
  20259.   void main ()
  20260.   {
  20261.   class key <int, vector<int> >; // instantiate template
  20262.   }
  20263.  
  20264.  Objects and functions of individual template classes can be accessed by any of 
  20265.  the techniques used to access ordinary class member objects and functions. 
  20266.  
  20267.  Examples of Accessing Class Template Members 
  20268.  
  20269.  Related Information 
  20270.  
  20271.      Class Template Declarations and Definitions 
  20272.      Nontype Template Arguments 
  20273.      Explicitly Defined Template Classes 
  20274.      Function Templates 
  20275.      Template Syntax 
  20276.      Structuring Your Program Using Templates 
  20277.      C++ Classes 
  20278.      Differences between Class and Function Templates 
  20279.  
  20280.  
  20281. ΓòÉΓòÉΓòÉ <hidden> Syntax of a Template Class Instantiation ΓòÉΓòÉΓòÉ
  20282.  
  20283. The syntax for instantiation of a template class is: 
  20284.  
  20285.            ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  20286. >>ΓöÇΓöÇtemplate-nameΓöÇΓöÇΓöÉΓöÇΓöÇΓö┤Γö¼ΓöÇtypeΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>ΓöÇΓöÇ><
  20287.           Γöé  Γöé            Γöé
  20288.             ΓööΓöÇassignment-expressionΓöÇΓöÿ
  20289.  
  20290.  
  20291. ΓòÉΓòÉΓòÉ <hidden> Examples of Accessing Class Template Members ΓòÉΓòÉΓòÉ
  20292.  
  20293. Given a class template: 
  20294.  
  20295. template<class T> class vehicle
  20296. {
  20297. public:
  20298.     vehicle() { /* ... */ }    // constructor
  20299.     ~vehicle() {};             // destructor
  20300.     T kind[16];
  20301.     T* drive();
  20302.     static void roadmap();
  20303.     // ...
  20304. };
  20305.  
  20306. and the declaration: 
  20307.  
  20308. vehicle<char> bicycle; // instantiates the template
  20309.  
  20310. the constructor, the constructed object, and the member function drive() can be 
  20311. accessed with any of the following (assuming the standard header file 
  20312. <string.h> is included in the program file): 
  20313.  
  20314. ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  20315. Γöé constructor          Γöé "vehicle<char> bicycle;            Γöé
  20316. Γöé                Γöé // constructor called automatically      Γöé
  20317. Γöé                Γöé // object bicycle created"          Γöé
  20318. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  20319. Γöé object "bicycle"        Γöé "strcpy (bicycle.kind, "10 speed");      Γöé
  20320. Γöé                Γöé bicycle.kind[0] = '2';"            Γöé
  20321. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  20322. Γöé function "drive()"       Γöé "char* n = bicycle.drive();"         Γöé
  20323. Γö£ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö╝ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  20324. Γöé function "roadmap()"      Γöé "vehicle<char>::roadmap();"          Γöé
  20325. ΓööΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö┤ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÿ
  20326.  
  20327.  
  20328. ΓòÉΓòÉΓòÉ 15.3.1. Class Template Declarations and Definitions ΓòÉΓòÉΓòÉ
  20329.  
  20330. A class template must be declared before any declaration of a corresponding 
  20331. template class. A class template definition can only appear once in any single 
  20332. compilation unit. A class template must be defined before any use of a template 
  20333. class that requires the size of the class or refers to members of the class. 
  20334.  
  20335. In the following example, the class template key is declared before it is 
  20336. defined. The declaration of the pointer keyiptr is valid because the size of 
  20337. the class is not needed. The declaration of keyi, however, causes an error. 
  20338.  
  20339. template  <class L> class key;      // class template declared,
  20340.                                     // not defined yet
  20341.                                     //
  20342. class key<int> *keyiptr;            // declaration of pointer
  20343.                                     //
  20344. class key<int> keyi;                // error, cannot declare keyi
  20345.                                     // without knowing size
  20346.                                     //
  20347. template <class L> class key        // now class template defined
  20348. {
  20349. // ...
  20350. };
  20351.  
  20352. If a template class is used before the corresponding class template is defined, 
  20353. the compiler issues an error. A class name with the appearance of a template 
  20354. class name is considered to be a template class. In other words, angle brackets 
  20355. are valid in a class name only if that class is a template class. 
  20356.  
  20357. The definition of a class template is not compiled until the definition of a 
  20358. template class is required. At that point, the class template definition is 
  20359. compiled using the argument list of the template class to instantiate the 
  20360. template arguments. Any errors in the class definition are flagged at this 
  20361. time. If the definition of a class template is never required, it is not 
  20362. compiled. In this case, some errors in the definition might not be flagged by 
  20363. the compiler. The /Wcls option can be used to find errors in class templates 
  20364. that are not compiled. 
  20365.  
  20366. A class template can only be defined once within a compilation unit, and the 
  20367. class template name cannot be declared to refer to any other template, class, 
  20368. object, function, value, or type in the same scope. 
  20369.  
  20370. Related Information 
  20371.  
  20372.      Class Templates 
  20373.      Nontype Template Arguments 
  20374.      Explicitly Defined Template Classes 
  20375.      /Wcls option 
  20376.      C++ Classes 
  20377.      Function Templates 
  20378.      Differences between Class and Function Templates 
  20379.  
  20380.  
  20381. ΓòÉΓòÉΓòÉ 15.3.2. Nontype Template Arguments ΓòÉΓòÉΓòÉ
  20382.  
  20383. A nontype template argument provided within a template argument list is an 
  20384. expression whose value can be determined at compile time. Such arguments must 
  20385. be constant expressions, addresses of functions or objects with external 
  20386. linkage, or addresses of static class members. Nontype template arguments are 
  20387. normally used to initialize a class or to specify the sizes of class members. 
  20388.  
  20389. For nontype integral arguments, the instance argument matches the corresponding 
  20390. template argument as long as the instance argument has a value and sign 
  20391. appropriate to the argument type. 
  20392.  
  20393. For nontype address arguments, the type of the instance argument must be of the 
  20394. form identifier or &identifier, and the type of the instance argument must 
  20395. match the template argument exactly, except that a function name is changed to 
  20396. a pointer to function type before matching. 
  20397.  
  20398. The resulting values of nontype template arguments within a template argument 
  20399. list form part of the template class's type. If two template class names have 
  20400. the same template name and if their arguments have identical values, they are 
  20401. the same class. 
  20402.  
  20403. Example of Nontype Template Arguments 
  20404.  
  20405. Note:  Arguments that contain the < symbol or the > symbol must be enclosed in 
  20406.        parentheses to prevent it from being parsed as a template argument list 
  20407.        delimiter when it is being used as a relational operator or a nested 
  20408.        template delimiter. For example, the arguments in the following 
  20409.        definition are valid: 
  20410.  
  20411.               myfilebuf<double, (20>10)> x;       // valid
  20412.  
  20413. The following definition, however, is not valid because the greater than 
  20414. operator (>) is interpreted as the closing delimiter of the template argument 
  20415. list: 
  20416.  
  20417. myfilebuf<double, 20>10> x;         // error
  20418.  
  20419.  If the template arguments do not evaluate identically, the objects created are 
  20420.  of different types: 
  20421.  
  20422.   myfilebuf<double,200> x;            // create object x of class
  20423.                                       // myfilebuf<double,200>
  20424.   myfilebuf<double,200.0> y;          // error, 200.0 is a double,
  20425.                                       // not an int
  20426.  
  20427.  The instantiation of y fails because the value 200.0 is of type double, and 
  20428.  the template argument is of type int. 
  20429.  
  20430.  The following two objects: 
  20431.  
  20432.         myfilebuf<double, 128> x
  20433.         myfilebuf<double, 512> y
  20434.  
  20435.  belong to separate template classes, and referencing either of these objects 
  20436.  later with myfilebuf<double> is an error. 
  20437.  
  20438.  A class template does not need to have a type argument if it has nontype 
  20439.  arguments. For example, the following template is a valid class template: 
  20440.  
  20441.   template<int i> class C
  20442.   {
  20443.         public:
  20444.               int k;
  20445.               C() { k = i; }
  20446.   };
  20447.  
  20448.  This class template can be instantiated by declarations such as: 
  20449.  
  20450.   class C<100>;
  20451.   class C<200>;
  20452.  
  20453.  Again, these two declarations refer to distinct classes because the values of 
  20454.  their nontype arguments differ. 
  20455.  
  20456.  Related Information 
  20457.  
  20458.      Class Templates 
  20459.      Class Template Declarations and Definitions 
  20460.      Explicitly Defined Template Classes 
  20461.      C++ Classes 
  20462.      Function Templates 
  20463.      Differences between Class and Function Templates 
  20464.  
  20465.  
  20466. ΓòÉΓòÉΓòÉ <hidden> Example of Nontype Template Arguments ΓòÉΓòÉΓòÉ
  20467.  
  20468. In the following example, a class template is defined that requires a nontype 
  20469. template int argument as well as the type argument: 
  20470.  
  20471. template<class T, int size> class myfilebuf
  20472. {
  20473.       T* filepos;
  20474.       static int array[size];
  20475. public:
  20476.       myfilebuf() { /* ... */ }
  20477.       ~myfilebuf();
  20478.       advance(); // function defined elsewhere in program
  20479. };
  20480.  
  20481. In this example, the template argument size becomes a part of the template 
  20482. class name. An object of such a template class is created with both the type 
  20483. arguments of the class and the values of any additional template arguments. 
  20484.  
  20485. An object x, and its corresponding template class with arguments double and 
  20486. size=200, can be created from this template with a value as its second template 
  20487. argument: 
  20488.  
  20489. myfilebuf<double,200> x;
  20490.  
  20491. x can also be created using an arithmetic expression: 
  20492.  
  20493. myfilebuf<double,10*20> x;
  20494.  
  20495. The objects created by these expressions are identical because the template 
  20496. arguments evaluate identically. The value 200 in the first expression could 
  20497. have been represented by an expression whose result at compile time is known to 
  20498. be equal to 200, as shown in the second construction. 
  20499.  
  20500.  
  20501. ΓòÉΓòÉΓòÉ 15.3.3. Explicitly Defined Template Classes ΓòÉΓòÉΓòÉ
  20502.  
  20503. You can override the definition of a class template of a particular template 
  20504. class by providing a class definition for the type of class required. For 
  20505. example, the following class template creates a class for each type for which 
  20506. it is referenced, but that class may be inappropriate for a particular type: 
  20507.  
  20508. template<class M> class portfolio
  20509. {
  20510.       double capital;
  20511.       M arr;
  20512.       // ...
  20513. } ;
  20514.  
  20515. The type for which the template class is inappropriate can be defined by using 
  20516. the applicable template class name. Assuming the inappropriately defined type 
  20517. is stocks, you can redefine the class portfolio<stocks> as follows: 
  20518.  
  20519. class portfolio<stocks>
  20520. {
  20521.       double capital;
  20522.       stocks yield;
  20523.       // ...
  20524. };
  20525.  
  20526. An explicit specialization of a template class can be defined before the class 
  20527. template is declared. In particular, a template class such as portfolio<stocks> 
  20528. can be defined before its class template has been defined. 
  20529.  
  20530. Related Information 
  20531.  
  20532.      Class Templates 
  20533.      Class Template Declarations and Definitions 
  20534.      Nontype Template Arguments 
  20535.      C++ Classes 
  20536.      Function Templates 
  20537.      Differences between Class and Function Templates 
  20538.  
  20539.  
  20540. ΓòÉΓòÉΓòÉ 15.4. Function Templates ΓòÉΓòÉΓòÉ
  20541.  
  20542. A function template allows you to define a group of functions that are the same 
  20543. except for the types of one or more of their arguments or objects. All type 
  20544. arguments in a function template must be used in the argument list or in the 
  20545. class qualifier for the function name. The type of a template function argument 
  20546. need not be explicitly specified when the template function is called. In this 
  20547. respect, a template function differs from a template class. 
  20548.  
  20549. Note the distinction between the terms function template and template function: 
  20550.  
  20551.  Function template   is a template used to generate template functions. A 
  20552.                      function template can be only a declaration, or it can 
  20553.                      define the function. 
  20554.  
  20555.  Template function   is a function generated by a function template. 
  20556.  
  20557.  Example of a Function Template 
  20558.  
  20559.  Because template functions can be generated in all compilation units that 
  20560.  contain function template definitions, you may want to group function template 
  20561.  definitions into one or two compilation units. Using templates in C++ programs 
  20562.  is described completely in the IBM VisualAge C++ for OS/2 Programming Guide. 
  20563.  
  20564.  Related Information 
  20565.  
  20566.      Overloading Resolution for Template Functions 
  20567.      Explicitly Defined Template Functions 
  20568.      Function Template Declarations and Definitions 
  20569.      Differences between Class and Function Templates 
  20570.      Functions 
  20571.      Class Templates 
  20572.  
  20573.  
  20574. ΓòÉΓòÉΓòÉ <hidden> Example of a Function Template ΓòÉΓòÉΓòÉ
  20575.  
  20576. If you want to create a function approximate(), which determines whether two 
  20577. values are within 5% of each other, you can define the following template: 
  20578.  
  20579.       #include <math.h>
  20580.       template <class T> int approximate (T first, T second)
  20581.       {
  20582.             double aptemp=double(first)/double(second);
  20583.             return int(abs(aptemp-1.0) <= .05);
  20584.       };
  20585.  
  20586. Assuming you have two values of type float you want to compare, you can use the 
  20587. approximate function template: 
  20588.  
  20589.       float a=3.24, b=3.35;
  20590.       if (approximate(a,b))
  20591.             cout << "a and b are pretty close" << endl;
  20592.  
  20593. A template function int approximate(float,float) is generated to resolve the 
  20594. call. 
  20595.  
  20596.  
  20597. ΓòÉΓòÉΓòÉ 15.4.1. Overloading Resolution for Template Functions ΓòÉΓòÉΓòÉ
  20598.  
  20599. Resolution of overloaded template functions is done in the following order: 
  20600.  
  20601.    1. Look for a function with an exact type match. This does not include 
  20602.       template functions, unless such functions were explicitly declared using 
  20603.       a function declaration. Trivial conversions are performed if they produce 
  20604.       an exact type match. 
  20605.  
  20606.    2. Look for a function template that allows generation of a function with an 
  20607.       exact type match. Trivial conversions are performed if they produce an 
  20608.       exact type match. 
  20609.  
  20610.    3. Try ordinary overloading resolution for functions already present. This 
  20611.       does not include template functions, unless such functions were 
  20612.       explicitly declared using a function declaration. 
  20613.  
  20614.  A call to a template function causes an error, and no overloading is done if 
  20615.  the following conditions are true: 
  20616.  
  20617.      The only available functions for a call are template functions. 
  20618.      These functions would require nontrivial conversions for the call to 
  20619.       succeed. 
  20620.      These functions have not been explicitly declared. 
  20621.  
  20622.  Example of Overloading a Template Function 
  20623.  
  20624.  Related Information 
  20625.  
  20626.      Trivial Conversions 
  20627.      Implicit Type Conversions 
  20628.      Function Templates 
  20629.      Explicitly Defined Template Functions 
  20630.      Function Template Declarations and Definitions 
  20631.      Functions 
  20632.      Differences between Class and Function Templates 
  20633.      Class Templates 
  20634.  
  20635.  
  20636. ΓòÉΓòÉΓòÉ <hidden> Example of Overloading a Template Function ΓòÉΓòÉΓòÉ
  20637.  
  20638. In the case of the approximate() function template: 
  20639.  
  20640.       #include <math.h>
  20641.       template <class T> int approximate (T first, T second)
  20642.       {
  20643.             double aptemp=double(first)/double(second);
  20644.             return int(abs(aptemp-1.0) <= .05);
  20645.       };
  20646.  
  20647. if the two input values are of different types, overloading resolution does not 
  20648. take place: 
  20649.  
  20650.       float a=3.24;
  20651.       double b=3.35;
  20652.       if (approximate(a,b))  // error, different types
  20653.       { /* ... */ }
  20654.  
  20655. The solution is to force a conversion to one of the available function types by 
  20656. explicitly declaring the function for the chosen type. To resolve the 
  20657. float/double example, include the following function declaration: 
  20658.  
  20659.       int approximate(double a, double b);
  20660.       // force conversion of the float to double
  20661.  
  20662. This declaration creates a function approximate() that expects two arguments of 
  20663. type double, so that when approximate(a,b) is called, the overloading is 
  20664. resolved by converting variable a to type double. 
  20665.  
  20666.  
  20667. ΓòÉΓòÉΓòÉ 15.4.2. Explicitly Defined Template Functions ΓòÉΓòÉΓòÉ
  20668.  
  20669. In some situations, a function template can define a group of functions in 
  20670. which, for one function type, the function definition would be inappropriate. 
  20671. For instance, the function template: 
  20672.  
  20673.     template<class T> int approximate(T first, T second);
  20674.  
  20675. determines whether two values are within 5% of each other. The algorithm used 
  20676. for this function template is appropriate for numerical values, but for char* 
  20677. values, it would indicate whether the pointers to two character strings are 
  20678. within 5% of one another, not whether the strings themselves are approximately 
  20679. equal. Whether two pointers are within 5% of each other is not useful 
  20680. information. You can define an explicit template function for char* values to 
  20681. compare the two strings themselves, character by character. 
  20682.  
  20683. Example of an Explicitly Defined Template Function 
  20684.  
  20685. Explicit definition has the same effect on template overloading resolution as 
  20686. explicit declaration (See Overloading Resolution for Template Functions for 
  20687. more information.) If a template function is explicitly defined for: 
  20688.  
  20689. int approximate(double a, double b) { /* ... */ }
  20690.  
  20691. then a call of: 
  20692.  
  20693. double a=3.54;
  20694. float b=3.5;
  20695. approximate(a,b);
  20696.  
  20697. resolves in a call to  approximate(double a, double b)  and variable b is 
  20698. converted to type double. 
  20699.  
  20700. Related Information 
  20701.  
  20702.      Function Templates 
  20703.      Overloading Resolution for Template Functions 
  20704.      Function Template Declarations and Definitions 
  20705.      Functions 
  20706.      Differences between Class and Function Templates 
  20707.      Class Templates 
  20708.  
  20709.  
  20710. ΓòÉΓòÉΓòÉ <hidden> Example of an Explicitly Defined Template Function ΓòÉΓòÉΓòÉ
  20711.  
  20712. The following explicitly defined template function compares two strings and 
  20713. returns a value indicating whether more than 5% of the characters differ 
  20714. between the two strings: 
  20715.  
  20716. #include <string.h>
  20717. int approximate(char *first, char *second)
  20718. {
  20719.       if (strcmp(first,second) == 0)
  20720.             return 1; // strings are identical
  20721.  
  20722.       double difct=0;
  20723.       int maxlen=0;
  20724.  
  20725.       if (strlen(first)>strlen(second))
  20726.             maxlen=strlen(first);
  20727.  
  20728.       else maxlen=strlen(second);
  20729.       for (int i=0; i<=maxlen ; ++i)
  20730.             if ( first[i] != second[i] ) difct++;
  20731.       return int((difct / maxlen) <= .05  );
  20732. }
  20733.  
  20734. Given this definition, the function call:  approximate("String A","String B"); 
  20735. invokes the explicitly defined function above, and no template function is 
  20736. generated. 
  20737.  
  20738.  
  20739. ΓòÉΓòÉΓòÉ 15.4.3. Function Template Declarations and Definitions ΓòÉΓòÉΓòÉ
  20740.  
  20741. When a template function is defined explicitly within a compilation unit, this 
  20742. definition is used in preference to any instantiation from the function 
  20743. template. For example, if one compilation unit contains the code: 
  20744.  
  20745. #include <iostream.h>
  20746. template <class T> T f(T i) {return i+1;}
  20747. void main()
  20748. {
  20749.       cout << f(2) << endl;
  20750. }
  20751.  
  20752. and another contains: 
  20753.  
  20754. int f(int i) {return i+2;}
  20755.  
  20756. when compiled and run, the program prints the number 4 to standard output, 
  20757. indicating that the explicitly defined function was used to resolve the call to 
  20758. f(). 
  20759.  
  20760. Each template, whether of a class or of a function, must be defined at most 
  20761. once within a compilation unit. The same applies to an explicitly defined 
  20762. template class or function. Function templates and class templates can be 
  20763. declared many times. 
  20764.  
  20765. A template class is considered declared if its name is used. A template 
  20766. function is considered declared if any of the following applies: 
  20767.  
  20768.      A function whose name matches a function template's name is declared, and 
  20769.       an appropriate template function can be generated. 
  20770.      A function whose name matches a function template's name is called, and 
  20771.       an appropriate template function can be generated. 
  20772.      A function whose name matches a function template's name is called, and 
  20773.       the template function has been explicitly defined. 
  20774.      The address of a template function is taken in such a way that 
  20775.       instantiation can occur. This means the pointer to function must supply a 
  20776.       return type and argument types that can be used to instantiate the 
  20777.       template function. 
  20778.  
  20779.  A template function is instantiated or generated if the function is referenced 
  20780.  in any of the following ways, provided that function is not explicitly defined 
  20781.  elsewhere in the program: 
  20782.  
  20783.      The function is declared. 
  20784.      A call to the function is made. 
  20785.      The address of the function is taken. 
  20786.  
  20787.  When a template function is instantiated, the body of the function template is 
  20788.  compiled using the template argument list of the template class to instantiate 
  20789.  the template arguments. Any errors in the function definition are flagged at 
  20790.  this time. If a template function is never generated from a function template, 
  20791.  it is not compiled. In this case, some errors in the function definition might 
  20792.  not be flagged by the compiler. 
  20793.  
  20794.  Related Information 
  20795.  
  20796.      Function Templates 
  20797.      Overloading Resolution for Template Functions 
  20798.      Explicitly Defined Template Functions 
  20799.      Functions 
  20800.      Differences between Class and Function Templates 
  20801.      Class Templates 
  20802.  
  20803.  
  20804. ΓòÉΓòÉΓòÉ 15.5. Differences between Class and Function Templates ΓòÉΓòÉΓòÉ
  20805.  
  20806. The name of a template class is a compound name consisting of the template name 
  20807. and the full template argument list enclosed in angle braces. Any references to 
  20808. a template class must use this complete name. For example: 
  20809.  
  20810. template <class T, int range> class ex
  20811. {
  20812.       T a;
  20813.        int r;
  20814.       // ...
  20815. };
  20816. //...
  20817. ex<double,20> obj1;     // valid
  20818. ex<double> obj2;        // error
  20819. ex obj3;                // error
  20820.  
  20821. C++ requires this explicit naming convention to ensure that the appropriate 
  20822. class can be generated. 
  20823.  
  20824. A template function, on the other hand, has the name of its function template 
  20825. and the particular function chosen to resolve a given template function call is 
  20826. determined by the type of the calling arguments. In the following example, the 
  20827. call min(a,b) is effectively a call to min(int a, int b), and the call min(af, 
  20828. bf) is effectively a call to min(float a, float b): 
  20829.  
  20830. // This example illustrates a template function.
  20831.  
  20832. template<class T> T min(T a, T b)
  20833. {
  20834.       if (a < b)
  20835.             return a;
  20836.       else
  20837.             return b;
  20838. }
  20839. void main()
  20840. {
  20841.       int a = 0;
  20842.       int b = 2;
  20843.       float af = 3.1;
  20844.       float bf = 2.9;
  20845.       cout << "Here is the smaller int " << min(a,b) << endl;
  20846.       cout << "Here is the smaller float " << min(af, bf) << endl;
  20847. }
  20848.  
  20849. Related Information 
  20850.  
  20851.      Class Templates 
  20852.      Function Templates 
  20853.      C++ Classes 
  20854.      Functions 
  20855.  
  20856.  
  20857. ΓòÉΓòÉΓòÉ 15.6. Member Function Templates ΓòÉΓòÉΓòÉ
  20858.  
  20859. In Function Templates, a function template was defined outside of any template 
  20860. class. However, functions in C++ are often member functions of a class. If you 
  20861. want to create a class template and a set of function templates to go with that 
  20862. class template, you do not have to create the function templates explicitly, as 
  20863. long as the function definitions are contained within the class template. Any 
  20864. member function (inlined or noninlined) declared within a class template is 
  20865. implicitly a function template. When a template class is declared, it 
  20866. implicitly generates template functions for each function defined in the class 
  20867. template. 
  20868.  
  20869. You can define template member functions three ways: 
  20870.  
  20871.    1. Explicitly at file scope for each type used to instantiate the template 
  20872.       class. 
  20873.    2. At file scope with the template arguments. 
  20874.    3. Inlined in the class template itself. 
  20875.  
  20876.  Examples of Defining Template Member Functions 
  20877.  
  20878.  Member function templates are used to instantiate any functions that are not 
  20879.  explicitly generated. If you have both a member function template and an 
  20880.  explicit definition, the explicit definition is used. 
  20881.  
  20882.  The template argument is not used in a constructor name. For example: 
  20883.  
  20884.   template<class L> class Key
  20885.   {
  20886.         Key();            // default constructor
  20887.         Key( L );         // constructor taking L by value
  20888.         Key<L>( L );      // error, <L> implicit within class template
  20889.   };
  20890.  
  20891.  The declaration Key<L>(L) is an error because the constructor does not use the 
  20892.  template argument. Assuming this class template was corrected by removing the 
  20893.  offending line, you can define a function template for the class template's 
  20894.  constructor: 
  20895.  
  20896.   // Constructor contained in function template:
  20897.   template<class L>
  20898.         Key<L>::Key(int) { /* ... */ }
  20899.         // valid, constructor template argument assumed template<class L>
  20900.  
  20901.         Key<L>::Key<L>(int) { /* ... */ }
  20902.         /* error, constructor template argument <L> implicit
  20903.            in class template argument */
  20904.  
  20905.  A template function name does not include the template argument. The template 
  20906.  argument does, however, appear in the template class name if a member function 
  20907.  of a template class is defined or declared outside of the class template. The 
  20908.  definition:   Key<L>::Key(int) { /* ... */ }   is valid because Key<L> (with 
  20909.  template argument) refers to the class, while Key(int) { /* ... */ } refers to 
  20910.  the member function. 
  20911.  
  20912.  Related Information 
  20913.  
  20914.      Class Templates 
  20915.      Function Templates 
  20916.      C++ Class Members and Friends 
  20917.  
  20918.  
  20919. ΓòÉΓòÉΓòÉ <hidden> Examples of Defining Template Member Functions ΓòÉΓòÉΓòÉ
  20920.  
  20921. /************************************************************************
  20922. *
  20923.  
  20924. The following three examples illustrate the three ways to define template 
  20925. member functions: 
  20926.  
  20927. Method 1 
  20928.  
  20929.                                                                         *
  20930. ************************************************************************/
  20931.  
  20932.       template <class T> class key
  20933.       {
  20934.       public:
  20935.             void f(T);
  20936.       };
  20937.       void key<char>::f(char) { /* ... */ }
  20938.       void key<int>::f(int ) { /* ... */ }
  20939.  
  20940.       void main()
  20941.       {
  20942.             int i = 9;
  20943.             key< int> keyobj;
  20944.             keyobj.f(i);
  20945.       }
  20946.  
  20947. /************************************************************************
  20948. *
  20949.  
  20950. Method 2 
  20951.  
  20952.                                                                         *
  20953. ************************************************************************/
  20954.  
  20955.       template <class T> class key
  20956.       {
  20957.       public:
  20958.             void f(T);
  20959.       };
  20960.       template <class T> void key <T>::f(T) { /* ... */ }
  20961.  
  20962.       void main()
  20963.       {
  20964.             int i = 9;
  20965.             key< int> keyobj;
  20966.             keyobj.f(i);
  20967.       }
  20968.  
  20969. /************************************************************************
  20970. *
  20971.  
  20972. Method 3 
  20973.  
  20974.                                                                         *
  20975. ************************************************************************/
  20976.  
  20977.       template <class T> class key
  20978.       {
  20979.       public:
  20980.             void f(T) { /* ... */ }
  20981.       };
  20982.  
  20983.       void main()
  20984.       {
  20985.             int i = 9;
  20986.             key< int> keyobj;
  20987.             keyobj.f(i);
  20988.       }
  20989.  
  20990.  
  20991. ΓòÉΓòÉΓòÉ 15.7. Friends and Templates ΓòÉΓòÉΓòÉ
  20992.  
  20993. A friend function can be declared in a class template either as a single 
  20994. function shared by all classes created by the template or as a template 
  20995. function that varies from class to class within the class template. For 
  20996. example: 
  20997.  
  20998. template<class T> class portfolio
  20999. {
  21000.       //...
  21001.       friend void taxes();
  21002.       friend void transact(T);
  21003.       friend portfolio<T>* invest(portfolio<T>*);
  21004.       friend portfolio* divest(portfolio*);        //error
  21005.       // ...
  21006. };
  21007.  
  21008. In this example, each declaration has the following characteristics: 
  21009.  
  21010.  taxes() 
  21011.      is a single function that can access private and protected members of any 
  21012.      template class generated by the class template. Note that taxes() is not a 
  21013.      template function. 
  21014.  
  21015.  transact(T) 
  21016.      is a function template that declares a distinct function for each class 
  21017.      generated by the class template. The only private and protected members 
  21018.      that can be accessed by functions generated from this template are the 
  21019.      private and protected members of their template class. 
  21020.  
  21021.  invest(portfolio<T>*) 
  21022.      is a function template whose return and argument types are pointers to 
  21023.      objects of type portfolio<T>. Each class generated by the class template 
  21024.      will have a friend function of this name, and each such function will have 
  21025.      a pointer to an object of its own class as both its return type and its 
  21026.      argument type. 
  21027.  
  21028.  divest(portfolio*) 
  21029.      is an error because portfolio* attempts to point to a class template. A 
  21030.      pointer to a class template is undefined and produces an error. This 
  21031.      statement can be corrected by using the syntax of the invest() function 
  21032.      template instead. 
  21033.  
  21034.  Because all friend functions in this example are declared but not defined, you 
  21035.  could create a set of function templates to define those functions that are 
  21036.  implicitly template functions (that is, all the valid functions except 
  21037.  taxes()). The function templates would then be used to instantiate the 
  21038.  template functions as required. 
  21039.  
  21040.  Related Information 
  21041.  
  21042.      Friends 
  21043.      Class Templates 
  21044.      Function Templates 
  21045.      C++ Classes 
  21046.      Functions 
  21047.  
  21048.  
  21049. ΓòÉΓòÉΓòÉ 15.8. Static Data Members and Templates ΓòÉΓòÉΓòÉ
  21050.  
  21051. A static declaration within a class template declares a static data member for 
  21052. each template class generated from the template. The static declaration can be 
  21053. of template argument type or of any defined type. 
  21054.  
  21055. Like member function templates, you can explicitly define a static data member 
  21056. of a template class at file scope for each type used to instantiate a template 
  21057. class. For example: 
  21058.  
  21059. template <class T> class key
  21060. {
  21061. public:
  21062.       static T x;
  21063. };
  21064. int key<int>::x;
  21065. char key<char>::x;
  21066. void main()
  21067. {
  21068.       key<int>::x = 0;
  21069. }
  21070.  
  21071. You can also define a static data member of a template class using a template 
  21072. definition at file scope. For example: 
  21073.  
  21074. template <class T> class key
  21075. {
  21076. public:
  21077.       static T x;
  21078. };
  21079. template <class T> T key<T> ::x; // template definition
  21080. void main()
  21081. {
  21082.       key<int>::x = 0;
  21083. }
  21084.  
  21085. When you instantiate a template class, you must have either an explicit 
  21086. definition or a template definition for each static data member, but not both. 
  21087.  
  21088. Example of Static Data Members in Templates 
  21089.  
  21090. Related Information 
  21091.  
  21092.      Static Members 
  21093.      Class Templates 
  21094.      Explicitly Defined Template Classes 
  21095.      Function Templates 
  21096.      Explicitly Defined Template Functions 
  21097.  
  21098.  
  21099. ΓòÉΓòÉΓòÉ <hidden> Example of Static Data Members in Templates ΓòÉΓòÉΓòÉ
  21100.  
  21101. In the following example: 
  21102.  
  21103. template<class L> class Key
  21104. {
  21105.       static L k;
  21106.       static L* kptr;
  21107.       static int length;
  21108.       // ...
  21109. }
  21110.  
  21111. The definitions of static variables and objects must be instantiated at file 
  21112. scope. If the classes Key<int> and Key<double> are instantiated from this 
  21113. template, and no template definitions exist, the following static data members 
  21114. must be explicitly defined at file scope, or an error occurs: 
  21115.  
  21116. int Key<int>::k, Key<int>::length, Key<double>::length;
  21117. int* Key<int>::kptr;
  21118. double Key<double>::k;
  21119. double* Key<double>::kptr = 0;
  21120.  
  21121.  
  21122. ΓòÉΓòÉΓòÉ 16. C++ Exception Handling ΓòÉΓòÉΓòÉ
  21123.  
  21124. This chapter describes the VisualAge C++ implementation of C++ exception 
  21125. handling. It discusses: 
  21126.  
  21127.      Formal and Informal Exception Handling 
  21128.      Using Exception Handling 
  21129.      Transferring Control 
  21130.      Constructors and Destructors in Exception Handling 
  21131.      Exception Specifications 
  21132.      unexpected() and terminate() Functions 
  21133.  
  21134.  Note:  C++ exception handling is not the same as OS/2 exception handling. A 
  21135.         C++ exception exists only within the C++ language. An OS/2 exception is 
  21136.         generated by the operating system, and can be used by the VisualAge C++ 
  21137.         library to generate a signal. In this section, the term exception 
  21138.         refers to a C++ exception. 
  21139.  
  21140.  OS/2 exception handling is described in detail in the IBM VisualAge C++ for 
  21141.  OS/2 User's Guide and Reference. 
  21142.  
  21143.  
  21144. ΓòÉΓòÉΓòÉ 16.1. C++ Exception Handling Overview ΓòÉΓòÉΓòÉ
  21145.  
  21146. Exception handling provides a way for a function that encounters an unusual 
  21147. situation to throw an exception and pass control to a direct or indirect caller 
  21148. of that function. The caller may or may not be able to handle the exception. 
  21149. Code that intercepts an exception is called a handler. Regardless of whether or 
  21150. not the caller can handle an exception, it may rethrow the exception so it can 
  21151. be intercepted by another handler. 
  21152.  
  21153. C++ provides three language constructs to implement exception handling: 
  21154.  
  21155.      Try blocks 
  21156.      Catch blocks 
  21157.      Throw expressions 
  21158.  
  21159.  Within a function, any unusual situation can be flagged with a throw 
  21160.  expression. The throw expression is of type void. Your program can throw an 
  21161.  object to pass information back to the caller. Any object can be thrown, 
  21162.  including the object that caused the exception or an object constructed when 
  21163.  the exception occurred. 
  21164.  
  21165.  A throw expression, or a call to a function that may throw an exception, 
  21166.  should be enclosed within a try block. If the called function throws an 
  21167.  exception and an exception handler is defined to catch the type of the object 
  21168.  thrown, the exception handler is executed. In C++, a catch block implements an 
  21169.  exception handler. A try block must be accompanied by one or more catch 
  21170.  clauses, otherwise the compiler will flag it as an error. 
  21171.  
  21172.  A catch block follows immediately after a try statement or immediately after 
  21173.  another catch block. A catch block includes a parenthesized exception 
  21174.  declaration containing optional qualifiers, a type, and an optional variable 
  21175.  name. The declaration specifies the type of object that the exception handler 
  21176.  may catch. Once an exception is caught, the body of the catch block is 
  21177.  executed. If no handler catches an exception, the program is terminated. 
  21178.  
  21179.  Exception handling is not strictly synonymous with error handling, because the 
  21180.  implementation allows the passing of an exception whether or not an error 
  21181.  actually occurred. You can use exception handlers for things other than 
  21182.  handling errors. For example, you can transfer control back to the original 
  21183.  caller of a function. You might use this if you wanted to process the Quit key 
  21184.  in a program and transfer control back to the driver program when the user 
  21185.  types Quit. To do this exception handlers could be used to throw an object 
  21186.  back to the driver. 
  21187.  
  21188.  Note:  C++ exception handling is not the same as OS/2 exception handling. A 
  21189.         C++ exception exists only within the C++ language. An OS/2 exception is 
  21190.         generated by the operating system, and can be used by the VisualAge C++ 
  21191.         library to generate a signal. In this section, the term exception 
  21192.         refers to a C++ exception. 
  21193.  
  21194.  OS/2 exception handling is described in detail in the IBM VisualAge C++ for 
  21195.  OS/2 User's Guide and Reference. 
  21196.  
  21197.  Related Information 
  21198.  
  21199.      Formal and Informal Exception Handling 
  21200.      Using Exception Handling 
  21201.      Transferring Control 
  21202.  
  21203.  
  21204. ΓòÉΓòÉΓòÉ 16.2. Formal and Informal Exception Handling ΓòÉΓòÉΓòÉ
  21205.  
  21206. While the exception handling features of C++ offer a formal mechanism for 
  21207. handling exceptions (language implemented), in many situations informal 
  21208. exception handling (logic implemented) is more appropriate. Generally speaking, 
  21209. formal exception handling should be implemented in libraries, classes, and 
  21210. functions likely to be accessed by several programs or programmers. It should 
  21211. also be used in classes and functions that are repeatedly accessed within a 
  21212. program but are not well-suited to handling their exceptions themselves. 
  21213. Because formal exception handling is designed for exceptional circumstances, it 
  21214. is not guaranteed to be efficient. Program performance is usually not affected 
  21215. when you do not invoke formal exception handling, although it can inhibit some 
  21216. optimizations. 
  21217.  
  21218. Informal exception handling, in which an appropriate action is defined if an 
  21219. error or exception occurs, is often more suitable for handling errors. For 
  21220. example, a simple error, such as entering incorrect input, can more easily and 
  21221. clearly be handled by testing the input for validity and by requesting the 
  21222. input again if the original input is incorrect. 
  21223.  
  21224. Related Information 
  21225.  
  21226.      C++ Exception Handling Overview 
  21227.      Using Exception Handling 
  21228.      Transferring Control 
  21229.  
  21230.  
  21231. ΓòÉΓòÉΓòÉ 16.3. Using Exception Handling ΓòÉΓòÉΓòÉ
  21232.  
  21233. The three keywords designed for exception handling in C++ are try, catch, and 
  21234. throw. 
  21235.  
  21236. Syntax of Exception Handling Keywords 
  21237.  
  21238. The steps required to implement an exception handler are: 
  21239.  
  21240.    1. Functions that are expected to be used by many programs are coded so 
  21241.       that, when an error is detected, an exception is thrown. The throw 
  21242.       expression generally throws an object. It may be created explicitly for 
  21243.       purposes of exception handling, or it may be the object that caused the 
  21244.       error to be detected. An example of throwing the problem object: 
  21245.  
  21246.                .
  21247.                .
  21248.                .
  21249.             int input=0;
  21250.             cout << "Enter a number between 1 and 10:";
  21251.             cin >> input;
  21252.  
  21253.             if (input < 1 || input >> 10);
  21254.              throw(input);  //throw the actual problem object
  21255.                .
  21256.                .
  21257.                .
  21258.  
  21259.       The following is an example of throwing an object for the purpose of 
  21260.       exception handling: 
  21261.  
  21262.                .
  21263.                .
  21264.                .
  21265.             int input=0;
  21266.             cout << "Enter a number between 1 and 10:;
  21267.             cin >> input;
  21268.  
  21269.             if (input < 1 || input >> 10)
  21270.                throw(out_of_range_object); //throw object to tell handler
  21271.                                            //what happened
  21272.  
  21273.    2. Exceptions are anticipated in a caller by means of a try statement. 
  21274.       Function calls that you anticipate might produce an exception must be 
  21275.       enclosed in braces and preceded by the keyword try. 
  21276.  
  21277.    3. Immediately following the try block, you must code one or more catch 
  21278.       blocks. Each catch block identifies what type or class of objects it can 
  21279.       catch: 
  21280.  
  21281.         a. If the object thrown matches the type of a catch expression, control 
  21282.            passes to that catch block. 
  21283.         b. If the object thrown does not match the first catch block, 
  21284.            subsequent catch blocks are searched for a matching type. 
  21285.         c. If no match is found, the search continues in all enclosing try 
  21286.            blocks and then in the code that called the current function. 
  21287.         d. If no match is found after all try blocks are searched, a call to 
  21288.            terminate() is made. For information on the default handlers of 
  21289.       uncaught exceptions, see unexpected() and terminate() Functions. 
  21290.  
  21291.  Notes: 
  21292.  
  21293.      Any object can be thrown if it can be copied and destroyed in the 
  21294.       function from which the throw occurs. 
  21295.      Exceptions should never be thrown from a C language signal handler. The 
  21296.       result is undefined, and can cause program termination. 
  21297.  
  21298.  A catch argument causes an error if it is a value argument, and a copy of it 
  21299.  cannot be generated. Similarly, a throw expression causes an error if a copy 
  21300.  of the value of the expression being thrown cannot be generated. 
  21301.  
  21302.  Example of an Incorrect catch Argument 
  21303.  
  21304.  Related Information 
  21305.  
  21306.      C++ Exception Handling Overview 
  21307.      Formal and Informal Exception Handling 
  21308.      Transferring Control 
  21309.      Exception Specifications 
  21310.      unexpected() and terminate() Functions 
  21311.  
  21312.  
  21313. ΓòÉΓòÉΓòÉ <hidden> Syntax of Exception Handling Keywords ΓòÉΓòÉΓòÉ
  21314.  
  21315. The syntax for the try and catch keywords is: 
  21316.  
  21317.       ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21318.             Γöé
  21319. >>ΓöÇΓöÇtryΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇcatchΓöÇΓöÇ(ΓöÇΓöÇ>
  21320.                              ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21321.                                    Γöé
  21322. >ΓöÇΓöÇΓö¼ΓöÇ. . .ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ)ΓöÇΓöÇ{ΓöÇΓöÇΓöÇΓöÇstatementΓöÇΓö┤ΓöÇΓöÇ}ΓöÇΓöÇ><
  21323.   Γöé ΓöîΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ              Γöé
  21324.   Γöé          Γöé              Γöé
  21325.   ΓööΓöÇΓöÇΓöÇtype_specifierΓöÇΓö┤ΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÿ
  21326.              Γö£ΓöÇdeclaratorΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöñ
  21327.              ΓööΓöÇabstract_declaratorΓöÇΓöÿ
  21328.  
  21329. The syntax for the throw keyword is: 
  21330.  
  21331. >>ΓöÇΓöÇthrowΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇ><
  21332.       ΓööΓöÇassignment_expressionΓöÇΓöÿ
  21333.  
  21334.  
  21335. ΓòÉΓòÉΓòÉ <hidden> Example of an Incorrect catch Argument ΓòÉΓòÉΓòÉ
  21336.  
  21337. A catch argument causes an error if it is a value argument, and a copy of it 
  21338. cannot be generated. For example: 
  21339.  
  21340. class B {
  21341. public:
  21342.       B();
  21343.       B(B&);
  21344. };
  21345.              // the following catch block will cause an error
  21346.              //
  21347. catch(const B x)
  21348. {
  21349. // ...
  21350. }
  21351.  
  21352. The catch block causes an error because the compiler does not know the type of 
  21353. the object thrown at compile time. It assumes that the type of the thrown 
  21354. object is the same as the type of the catch argument. In the above example, the 
  21355. thrown object is assumed to be of type const B. The compiler uses a copy 
  21356. constructor on the thrown argument to create the catch argument. Because there 
  21357. is no copy constructor for class B that accepts const B as an input argument, 
  21358. the compiler cannot perform the construction and an error occurs. 
  21359.  
  21360.  
  21361. ΓòÉΓòÉΓòÉ 16.4. Transferring Control ΓòÉΓòÉΓòÉ
  21362.  
  21363. C++ implements the termination model of exception handling. In the termination 
  21364. model, when an exception is thrown, control never returns to the throw point. 
  21365. The throw point is the point in program execution where the exception occurred. 
  21366.  
  21367. C++ exception handling does not implement the resumption model of exception 
  21368. handling, which allows an exception handler to correct the exception and then 
  21369. return to the throw point. 
  21370.  
  21371. When an exception is thrown, control is passed out of the throw expression and 
  21372. out of the try block that anticipated the exception. Control is passed to the 
  21373. catch block whose exception type matches the object thrown. The catch block 
  21374. handles the exception as appropriate. If the catch block ends normally, the 
  21375. flow of control passes over all subsequent catch blocks. 
  21376.  
  21377. When an exception is not thrown from within a try block, the flow of control 
  21378. continues normally through the block, and passes over all catch blocks 
  21379. following the try block. 
  21380.  
  21381. An exception handler cannot return control to the source of the error by using 
  21382. the return statement. A return issued in this context returns from the function 
  21383. containing the catch block. 
  21384.  
  21385. If an exception is thrown and no try block is active, or if a try block is 
  21386. active and no catch block exception declaration matches the object thrown, a 
  21387. call to terminate() is issued. A call to terminate() in turn calls abort() to 
  21388. terminate the program. The abort() C library function is defined in the 
  21389. standard header file <stdlib.h>. 
  21390.  
  21391. Example of Basic Exception Handling 
  21392.  
  21393. Related Information 
  21394.  
  21395.      Catching Exceptions 
  21396.      Nested Try Blocks 
  21397.      Rethrowing an Exception 
  21398.      Using a Conditional Expression in a Throw Expression 
  21399.      C++ Exception Handling Overview 
  21400.      Using Exception Handling 
  21401.      Exception Specifications 
  21402.      unexpected() and terminate() Functions 
  21403.      abort - Stop a Program 
  21404.      return 
  21405.  
  21406.  
  21407. ΓòÉΓòÉΓòÉ <hidden> Example of Basic Exception Handling ΓòÉΓòÉΓòÉ
  21408.  
  21409. /************************************************************************
  21410. *
  21411.  
  21412. The following example illustrates the basic use of try, catch, and throw. The 
  21413. program prompts for numerical input and determines the input's reciprocal. 
  21414. Before it attempts to print the reciprocal to standard output, it checks that 
  21415. the input value is nonzero, to avoid a division by zero. If the input is zero, 
  21416. an exception is thrown, and the catch block catches the exception. If the input 
  21417. is nonzero, the reciprocal is printed to standard output. 
  21418.  
  21419.                                                                         *
  21420. ************************************************************************/
  21421.  
  21422. // This example illustrates the basic use of
  21423. // try, catch, and throw.
  21424.  
  21425. #include <iostream.h>
  21426. #include <stdlib.h>
  21427. class IsZero { /* ... */ };
  21428. void ZeroCheck( int i )
  21429. {
  21430.          if (i==0)
  21431.                 throw IsZero();
  21432. }
  21433. void main()
  21434. {
  21435.          double a;
  21436.  
  21437.          cout << "Enter a number: ";
  21438.          cin >> a;
  21439.          try
  21440.          {
  21441.               ZeroCheck( a );
  21442.               cout << "Reciprocal is " << 1.0/a << endl;
  21443.          }
  21444.          catch ( IsZero )
  21445.          {
  21446.               cout << "Zero input is not valid" << endl;
  21447.               exit(1);
  21448.          }
  21449.          exit(0);
  21450. }
  21451.  
  21452. /************************************************************************
  21453. *
  21454.  
  21455. This example could have been coded more efficiently by using informal exception 
  21456. handling. However, it provides a simple illustration of formal exception 
  21457. handling. 
  21458.  
  21459.                                                                         *
  21460. ************************************************************************/
  21461.  
  21462.  
  21463. ΓòÉΓòÉΓòÉ 16.4.1. Catching Exceptions ΓòÉΓòÉΓòÉ
  21464.  
  21465. You can declare a handler to catch many types of exceptions. The allowable 
  21466. objects that a function can catch are declared in the parentheses following the 
  21467. catch keyword (the catch argument). You can catch objects of the fundamental 
  21468. types, base and derived class objects, references, and pointers to all of these 
  21469. types. You can also catch const and volatile types. 
  21470.  
  21471. You can also use the catch(...) form of the handler to catch all thrown 
  21472. exceptions that have not been caught by a previous catch block. The ellipsis in 
  21473. the catch argument indicates that any exception thrown can be handled by this 
  21474. handler. 
  21475.  
  21476. If an exception is caught by a catch(...) block, there is no direct way to 
  21477. access the object thrown. Information about an exception caught by catch(...) 
  21478. is very limited. You can declare an optional variable name if you want to 
  21479. access the thrown object in the catch block. 
  21480.  
  21481. A catch block can only catch accessible objects. The object caught must have an 
  21482. accessible copy constructor. For more information on access, see Member Access; 
  21483. on copy constructors, see Copy by Initialization. 
  21484.  
  21485. An argument in the catch argument of a handler matches an argument in the 
  21486. expression of the throw expression (throw argument) if any of the following 
  21487. conditions is met: 
  21488.  
  21489.      The catch argument type matches the type of the thrown object. 
  21490.      The catch argument is a public base class of the thrown class object. 
  21491.      The catch specifies a pointer type, and the thrown object is a pointer 
  21492.       type that can be converted to the pointer type of the catch argument by 
  21493.       standard pointer conversion. Pointer conversion is described on page 
  21494.       Pointer Conversions. 
  21495.  
  21496.  Note:  If the type of the thrown object is const or volatile, the catch 
  21497.  argument must also be a const or volatile for a match to occur. However, a 
  21498.  const, volatile, or reference type catch argument can match a nonconstant, 
  21499.  nonvolatile, or nonreference object type. A nonreference catch argument type 
  21500.  matches a reference to an object of the same type. 
  21501.  
  21502.  Always place a catch block that catches a derived class before a catch block 
  21503.  that catches the base class of that derived class (following a try block). If 
  21504.  a catch block for objects of a base class is followed by a catch block for 
  21505.  objects of a derived class of that base class, the latter block is flagged as 
  21506.  an error. 
  21507.  
  21508.  A catch block of the form catch(...) must be the last catch block following a 
  21509.  try block or an error occurs. This placement ensures that the catch(...) block 
  21510.  does not prevent more specific catch blocks from catching exceptions intended 
  21511.  for them. 
  21512.  
  21513.  Related Information 
  21514.  
  21515.      C++ Exception Handling Overview 
  21516.      Using Exception Handling 
  21517.      Transferring Control 
  21518.      Exception Specifications 
  21519.      volatile and const Qualifiers 
  21520.      Nested Try Blocks 
  21521.      Rethrowing an Exception 
  21522.  
  21523.  
  21524. ΓòÉΓòÉΓòÉ 16.4.2. Nested Try Blocks ΓòÉΓòÉΓòÉ
  21525.  
  21526. When try blocks are nested and a throw occurs in a function called by an inner 
  21527. try block, control is transferred outward through the nested try blocks until 
  21528. the first catch block is found whose argument matches the argument of the throw 
  21529. expression. 
  21530.  
  21531. For example: 
  21532.  
  21533. try
  21534. {
  21535.       func1();
  21536.       try
  21537.       {
  21538.              func2();
  21539.       }
  21540.       catch (spec_err) { /* ... */ }
  21541.       func3();
  21542. }
  21543. catch (type_err) { /* ... */ }
  21544. // if no throw is issued, control resumes here.
  21545.  
  21546. In the above example, if spec_err is thrown within the inner try block (in this 
  21547. case, from func2()), the exception is caught by the inner catch block, and, 
  21548. assuming this catch block does not transfer control, func3() is called. If 
  21549. spec_err is thrown after the inner try block (for instance, by func3()), it is 
  21550. not caught and the function terminate() is called. 
  21551.  
  21552. If the exception thrown from func2() in the inner try block is type_err, the 
  21553. program skips out of both try blocks to the second catch block without invoking 
  21554. func3(), because no appropriate catch block exists following the inner try 
  21555. block. If the entire try block in the example is in a function that has a throw 
  21556. list and does not include spec_err on its throw list, unexpected() is called. 
  21557.  
  21558. You can also nest a try block within a catch block. 
  21559.  
  21560. Related Information 
  21561.  
  21562.      Catching Exceptions 
  21563.      Transferring Control 
  21564.      Using Exception Handling 
  21565.      Rethrowing an Exception 
  21566.      Exception Specifications 
  21567.      unexpected() and terminate() Functions 
  21568.  
  21569.  
  21570. ΓòÉΓòÉΓòÉ 16.4.3. Rethrowing an Exception ΓòÉΓòÉΓòÉ
  21571.  
  21572. If a catch block cannot handle the particular exception it has caught, you can 
  21573. rethrow the exception. The rethrow expression (throw with no argument) causes 
  21574. the originally thrown object to be rethrown. 
  21575.  
  21576. Because the exception has already been caught at the scope in which the rethrow 
  21577. expression occurs, it is rethrown out to the next dynamically enclosing try 
  21578. block. Therefore, it cannot be handled by catch blocks at the scope in which 
  21579. the rethrow expression occurred. Any catch blocks following the dynamically 
  21580. enclosing try block have an opportunity to catch the exception. 
  21581.  
  21582. Example of Rethrowing an Exception 
  21583.  
  21584. The rethrow expression can be caught by any catch whose argument matches the 
  21585. argument of the exception originally thrown. 
  21586.  
  21587. Related Information 
  21588.  
  21589.      Catching Exceptions 
  21590.      Transferring Control 
  21591.      Using Exception Handling 
  21592.      Nested Try Blocks 
  21593.      Using a Conditional Expression in a Throw Expression 
  21594.      Exception Specifications 
  21595.  
  21596.  
  21597. ΓòÉΓòÉΓòÉ <hidden> Example of Rethrowing an Exception ΓòÉΓòÉΓòÉ
  21598.  
  21599. /************************************************************************
  21600. *
  21601.  
  21602. In the following example, catch(FileIO) catches any object of type FileIO and 
  21603. any objects that are public base classes of the FileIO class. It then checks 
  21604. for those exceptions it can handle. For any exception it cannot handle, it 
  21605. issues a rethrow expression to rethrow the exception and allow another handler 
  21606. in a dynamically enclosing try block to handle the exception. 
  21607.  
  21608.                                                                         *
  21609. ************************************************************************/
  21610.  
  21611. // This example illustrates rethrowing an exception.
  21612.  
  21613. #include <iostream.h>
  21614. class FileIO
  21615. {
  21616. public:
  21617.       int notfound;
  21618.       int endfile;
  21619.       FileIO(); // initialize data members
  21620.       // the following member functions throw an exception
  21621.       // if an input error occurs
  21622.       void advance(int x);
  21623.       void clear();
  21624.       void put(int x, int y);
  21625. };
  21626. //      .
  21627. //      .
  21628. //      .
  21629. void f()
  21630. {
  21631.       FileIO fio;
  21632.       try
  21633.       {
  21634.             // call member functions of FileIO class
  21635.             fio.advance (1);
  21636.             fio.clear();
  21637.             fio.put(1,-1);
  21638.       }
  21639.  
  21640.       catch(FileIO fexc)
  21641.       {
  21642.             if (fexc.notfound)
  21643.                   cout << "File not Found" << endl;
  21644.             else if (fexc.endfile)
  21645.                   cout << "End of File" << endl;
  21646.             else
  21647.                   throw;            // rethrow to outer handler
  21648.       }
  21649.       catch(...) { /* ... */ }      // catch other exceptions
  21650. }
  21651. main()
  21652. {
  21653.       try
  21654.       {
  21655.             f();
  21656.       }
  21657.       catch(FileIO) { cout << "Outer Handler" << endl; }
  21658. }
  21659.  
  21660. /************************************************************************
  21661. *
  21662.  
  21663. The rethrow expression can be caught by any catch whose argument matches the 
  21664. argument of the exception originally thrown. Note that, in this example, the 
  21665. catch(...) will not catch the rethrow expression because, when the rethrow 
  21666. expression is issued, control passes out of the scope of the function f() into 
  21667. the next dynamically enclosing block. 
  21668.  
  21669.                                                                         *
  21670. ************************************************************************/
  21671.  
  21672.  
  21673. ΓòÉΓòÉΓòÉ 16.4.4. Using a Conditional Expression in a Throw Expression ΓòÉΓòÉΓòÉ
  21674.  
  21675. You can use a conditional expression as a throw expression. as shown in the 
  21676. following example: 
  21677.  
  21678. // This example illustrates a conditional expresion
  21679. // used as a throw expression.
  21680.  
  21681. #include <iostream.h>
  21682. void main() {
  21683.       int doit = 1;
  21684.       int dont = 0;
  21685.       float f = 8.9;
  21686.       int i = 7;
  21687.       int j = 6;
  21688.       try { throw(doit ? i : f); }
  21689.       catch (int x)
  21690.       {
  21691.             cout << "Caught int " << x << endl;
  21692.       }
  21693.       catch (float x)
  21694.       {
  21695.             cout << "Caught float " << x << endl;
  21696.       }
  21697.       catch (double x)
  21698.       {
  21699.             cout << "Caught double " << x << endl;
  21700.       }
  21701.       catch (...)
  21702.       {
  21703.             cout << "Caught something " << endl;
  21704.       }
  21705. }
  21706.  
  21707. This example produces the following output because j is of type int: 
  21708.  
  21709. Caught float 7
  21710.  
  21711. At first glance, it looks as if the block that catches integer values should do 
  21712. the catch, but i is converted to a float value in the try block because it is 
  21713. in a conditional expression with the float value f. If the try block in the 
  21714. example is replaced with the following try block: 
  21715.  
  21716.       try { throw doit ? i : j; }
  21717.  
  21718. The following output is produced: 
  21719.  
  21720. Caught int 7
  21721.  
  21722. Related Information 
  21723.  
  21724.      Catching Exceptions 
  21725.      Transferring Control 
  21726.      Using Exception Handling 
  21727.      Nested Try Blocks 
  21728.      Rethrowing an Exception 
  21729.      Exception Specifications 
  21730.  
  21731.  
  21732. ΓòÉΓòÉΓòÉ 16.5. Constructors and Destructors in Exception Handling ΓòÉΓòÉΓòÉ
  21733.  
  21734. When an exception is thrown and control passes to a catch block following a try 
  21735. block, destructors are called for all automatic objects constructed since the 
  21736. beginning of the try block directly associated with that catch block. If an 
  21737. exception is thrown during construction of an object consisting of subobjects 
  21738. or array elements, destructors are only called for those subobjects or array 
  21739. elements successfully constructed before the exception was thrown. A destructor 
  21740. for a local static object will only be called if the object was successfully 
  21741. constructed. 
  21742.  
  21743. For more information on constructors and destructors, see Constructors and 
  21744. Destructors Overview. 
  21745.  
  21746. If a destructor detects an exception and issues a throw, the exception can be 
  21747. caught if the caller of the destructor was contained within a try block and an 
  21748. appropriate catch is coded. 
  21749.  
  21750. If an exception is thrown by a function called from an inner try block, but 
  21751. caught by an outer try block (because the inner try block did not have an 
  21752. appropriate handler), all objects constructed within both the outer and all 
  21753. inner try blocks are destroyed. If the thrown object has a destructor, the 
  21754. destructor is not called until the exception is caught and handled. 
  21755.  
  21756. Because a throw expression throws an object and a catch statement can catch an 
  21757. object, the object thrown enables error-related information to be transferred 
  21758. from the point at which an exception is detected to the exception's handler. If 
  21759. you throw an object with a constructor, you can construct an object that 
  21760. contains information relevant to the catch expression. The catch block can then 
  21761. access information provided by the thrown object. 
  21762.  
  21763. Example of Using Constructors in Exception Handling 
  21764.  
  21765. Exception handling can be used in conjunction with constructors and destructors 
  21766. to provide resource management that ensures that all locked resources are 
  21767. unlocked when an exception is thrown. 
  21768.  
  21769. Example of Managing Resources with Constructors and Destructors 
  21770.  
  21771. Related Information 
  21772.  
  21773.      Constructors and Destructors Overview 
  21774.      C++ Exception Handling Overview 
  21775.      Using Exception Handling 
  21776.      Transferring Control 
  21777.      Exception Specifications 
  21778.  
  21779.  
  21780. ΓòÉΓòÉΓòÉ <hidden> Managing Resources with Constructors and Destructors ΓòÉΓòÉΓòÉ
  21781.  
  21782. /************************************************************************
  21783. *
  21784.  
  21785. Exception handling can be used in conjunction with constructors and destructors 
  21786. to provide resource management that ensures that all locked resources are 
  21787. unlocked when an exception is thrown. For example: 
  21788.  
  21789.                                                                         *
  21790. ************************************************************************/
  21791.  
  21792. class data
  21793. {
  21794.       public:
  21795.             void lock();      // prevent other users from
  21796.                               // changing the object
  21797.             void unlock();    // allow other users to change
  21798.                               // the object
  21799. };
  21800. void q(data&), bar(data&);
  21801. // ...
  21802. main()
  21803. {
  21804.       data important;
  21805.       important.lock();
  21806.       q(important);
  21807.       bar(important);
  21808.       important.unlock();
  21809. }
  21810.  
  21811. /************************************************************************
  21812. *
  21813.  
  21814. If q() or bar() throw an exception, important.unlock() will not be called and 
  21815. the data will stay locked. This problem can be corrected by using a helper 
  21816. class to write an exception-aware program for resource management. 
  21817.  
  21818.                                                                         *
  21819. ************************************************************************/
  21820.  
  21821. class data
  21822. {
  21823.       public:
  21824.             void lock();      // prevent other users from
  21825.                               // changing the object
  21826.             void unlock();    // allow other users to change
  21827.                               // the object
  21828. };
  21829. class locked_data             // helper class
  21830. {
  21831.       data& real_data;
  21832.       public:
  21833.             locked_data(data& d) : real_data(d)
  21834.                               {real_data.lock();}
  21835.             ~locked_data() {real_data.unlock();}
  21836. };
  21837. void q(data&), bar(data&);
  21838. // ...
  21839. main()
  21840. {
  21841.       data important;
  21842.       locked_data my_lock(important);
  21843.       q(important);
  21844.       bar(important);
  21845. }
  21846.  
  21847. /************************************************************************
  21848. *
  21849.  
  21850. In this case, if q() or bar() throws an exception, the destructor for my_lock 
  21851. will be called, and the data will be unlocked. 
  21852.  
  21853.                                                                         *
  21854. ************************************************************************/
  21855.  
  21856.  
  21857. ΓòÉΓòÉΓòÉ <hidden> Example of Using Constructors in Exception Handling ΓòÉΓòÉΓòÉ
  21858.  
  21859. /************************************************************************
  21860. *
  21861.  
  21862. In the following example, an object of class DivideByZero is thrown by the 
  21863. function divide(). The constructor copies the string "Division by zero" into 
  21864. the char array errname. Because DivideByZero is a derived class of class 
  21865. Matherr, the catch block for Matherr catches the thrown exception. The catch 
  21866. block can then access information provided by the thrown object, in this case 
  21867. the text of an error message. 
  21868.  
  21869.                                                                         *
  21870. ************************************************************************/
  21871.  
  21872. // This example illustrates constructors and
  21873. // destructors in exception handling.
  21874.  
  21875. #include <string.h>            // needed for strcpy
  21876. #include <iostream.h>
  21877. class Matherr { public: char errname[30]; };
  21878. class DivideByZero : public Matherr
  21879. {
  21880. public:
  21881.       DivideByZero() {strcpy (errname, "Division by zero");}
  21882. };
  21883. double divide(double a, double b)
  21884. {
  21885.       if (b == 0) throw DivideByZero();
  21886.       return a/b;
  21887. }
  21888.  
  21889. void main()
  21890. {
  21891.       double a=7,b=0;
  21892.       try {divide (a,b);}
  21893.       catch (Matherr xx)
  21894.       {
  21895.             cout << xx.errname << endl;
  21896.       }
  21897. }
  21898.  
  21899.  
  21900. ΓòÉΓòÉΓòÉ 16.6. Exception Specifications ΓòÉΓòÉΓòÉ
  21901.  
  21902. C++ provides a mechanism to ensure that a given function is limited to throwing 
  21903. only a specified list of exceptions. An exception specification at the 
  21904. beginning of any function acts as a guarantee to the function's caller that the 
  21905. function will not directly or indirectly throw any exception not contained in 
  21906. the exception specification. For example, a function: 
  21907.  
  21908. void translate() throw(unknown_word,bad_grammar) { /* ... */ }
  21909.  
  21910. explicitly states that it will not throw any exception other than unknown_word 
  21911. or bad_grammar. The function translate() must handle any exceptions thrown by 
  21912. functions it might call, unless those exceptions are specified in the exception 
  21913. specification of translate(). If an exception is thrown by a function called by 
  21914. translate() and the exception is not handled by translate() or contained in the 
  21915. exception specification of translate(), unexpected() is called. 
  21916.  
  21917. Syntax of an Exception Specification 
  21918.  
  21919. If an exception is thrown from a function that has not specified the thrown 
  21920. exception in its exception specification, the result is a call to the function 
  21921. unexpected(), which is discussed in unexpected() and terminate() Functions. 
  21922.  
  21923. A function with an empty throw() specification guarantees that the function 
  21924. will not throw any exceptions. A function without an exception specification 
  21925. allows any object to be thrown from the function. 
  21926.  
  21927. The compiler does not prevent an exception specification from defining a more 
  21928. limited set of valid exceptions than the set of exceptions the function may 
  21929. actually throw. Such an error is detected only at run time, and only if the 
  21930. unspecified exception is thrown. 
  21931.  
  21932. Example of Throwing an Unspecified Exception 
  21933.  
  21934. If a function with an exception specification calls a subfunction with a less 
  21935. restrictive exception specification (one that contains more objects than the 
  21936. calling function's exception specification), any thrown objects from within the 
  21937. subfunction that are not handled by the subfunction, and that are not part of 
  21938. the outer function's specification list, must be handled within the outer 
  21939. function. If the outer function fails to handle an exception not in its 
  21940. exception specification, a call to unexpected() is made. 
  21941.  
  21942. Related Information 
  21943.  
  21944.      unexpected() and terminate() Functions 
  21945.      C++ Exception Handling Overview 
  21946.      Using Exception Handling 
  21947.      Transferring Control 
  21948.  
  21949.  
  21950. ΓòÉΓòÉΓòÉ <hidden> Syntax of an Exception Specification ΓòÉΓòÉΓòÉ
  21951.  
  21952. The syntax of the exception specification is: 
  21953.  
  21954.        ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21955.             Γöé
  21956. >>ΓöÇΓöÇthrowΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÇ><
  21957.         ΓööΓöÇtypeΓöÇΓöÿ
  21958.  
  21959. The syntax of a function definition that includes an exception specification 
  21960. is: 
  21961.  
  21962.                   ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ        ΓöîΓöÇ,ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÉ
  21963.                          Γöé             Γöé
  21964. >>ΓöÇΓöÇreturn_typeΓöÇΓöÇfunction_nameΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ)ΓöÇΓöÇthrowΓöÇΓöÇ(ΓöÇΓöÇΓöÇΓö¼ΓöÇΓöÇΓöÇΓöÇΓöÇΓöÇΓö¼Γö┤ΓöÇΓöÇ>
  21965.                   ΓööΓöÇargumentΓöÇΓöÿ         ΓööΓöÇtypeΓöÇΓöÿ
  21966. >ΓöÇΓöÇ)ΓöÇΓöÇ{ΓöÇΓöÇfunction_bodyΓöÇΓöÇ}ΓöÇΓöÇ><
  21967.  
  21968.  
  21969. ΓòÉΓòÉΓòÉ <hidden> Example of Throwing an Unspecified Exception ΓòÉΓòÉΓòÉ
  21970.  
  21971. In the following example, NameTooShort is thrown from within a function that 
  21972. explicitly states that it will only throw NameTooLong. This is a valid 
  21973. function, although at run time, if NameTooShort is thrown, a call to 
  21974. unexpected() will be made. 
  21975.  
  21976. #include <string.h>            // needed for strlen
  21977. class NameTooLong {};
  21978. class NameTooShort {};
  21979.  
  21980. void check(char* fname) throw (NameTooLong)
  21981. {
  21982.        if ( strlen(fname)<4 ) throw NameTooShort();
  21983. }
  21984.  
  21985.  
  21986. ΓòÉΓòÉΓòÉ 16.7. unexpected() and terminate() Functions ΓòÉΓòÉΓòÉ
  21987.  
  21988. Not all thrown errors can be caught and successfully dealt with by a catch 
  21989. block. In some situations, the best way to handle an exception is to terminate 
  21990. the program. Two special library functions are implemented in C++ to process 
  21991. exceptions not properly handled by catch blocks or exceptions thrown outside of 
  21992. a valid try block. These functions are unexpected() and terminate(). 
  21993.  
  21994. When a function with an exception specification throws an exception that is not 
  21995. listed in its exception specification, the function void unexpected() is 
  21996. called. Next, unexpected() calls a function specified by the set_unexpected() 
  21997. function. By default, unexpected() calls the function terminate(). 
  21998.  
  21999. In some cases, the exception handling mechanism fails and a call to void 
  22000. terminate() is made. This terminate() call occurs in any of the following 
  22001. situations: 
  22002.  
  22003.      When terminate() is explicitly called 
  22004.      When no catch can be matched to a thrown object 
  22005.      When the stack becomes corrupted during the exception-handling process 
  22006.      When a system defined unexpected() is called 
  22007.  
  22008.  The terminate() function calls a function specified by the set_terminate() 
  22009.  function. By default, terminate calls abort(), which exits from the program. 
  22010.  
  22011.  A terminate function cannot return to its caller, either by using return or by 
  22012.  throwing an exception. 
  22013.  
  22014.  Example of Using the Exception Handling Functions 
  22015.  
  22016.  Related Information 
  22017.  
  22018.      set_unexpected() and set_terminate() Functions 
  22019.      C++ Exception Handling Overview 
  22020.      Exception Specifications 
  22021.      Using Exception Handling 
  22022.      Transferring Control 
  22023.      abort - Stop a Program 
  22024.  
  22025.  
  22026. ΓòÉΓòÉΓòÉ 16.8. set_unexpected() and set_terminate() Functions ΓòÉΓòÉΓòÉ
  22027.  
  22028. The function unexpected(), when invoked, calls the function most recently 
  22029. supplied as an argument to set_unexpected(). If set_unexpected() has not yet 
  22030. been called, unexpected() calls terminate(). 
  22031.  
  22032. The function terminate(), when invoked, calls the function most recently 
  22033. supplied as an argument to set_terminate(). If set_terminate() has not yet been 
  22034. called, terminate() calls abort(), which ends the program. 
  22035.  
  22036. You can use set_unexpected() and set_terminate() to register functions you 
  22037. define to be called by unexpected() and terminate(). set_unexpected() and 
  22038. set_terminate() are included in the standard header files <unexpect.h>. and 
  22039. <terminat.h>. Each of these functions has as its return type and its argument 
  22040. type a pointer to function with a void return type and no arguments. The 
  22041. pointer to function you supply as the argument becomes the function called by 
  22042. the corresponding special function: the argument to set_unexpected() becomes 
  22043. the function called by unexpected(), and the argument to set_terminate() 
  22044. becomes the function called by terminate(). Both set_unexpected() and 
  22045. set_terminate() return a pointer to the function that was previously called by 
  22046. their respective special functions (unexpected() and terminate()). By saving 
  22047. the return values, you can restore the original special functions later so that 
  22048. unexpected() and terminate() will once again call terminate() and abort(). 
  22049.  
  22050. If you use set_terminate() to register your own function, the final action of 
  22051. that program should be to exit from the program. If you attempt to return from 
  22052. the function called by terminate(), abort() is called instead and the program 
  22053. ends. 
  22054.  
  22055. Note:  Providing a call to longjmp() inside a user-defined terminate function 
  22056. can transfer execution control to some other desired point. When you call 
  22057. longjmp, objects existing at the time of a setjmp call will still exist, but 
  22058. some objects constructed after the call to setjmp might not be destructed. 
  22059.  
  22060. Example of Using the Exception Handling Functions 
  22061.  
  22062. Related Information 
  22063.  
  22064.      unexpected() and terminate() Functions 
  22065.      C++ Exception Handling Overview 
  22066.      Using Exception Handling 
  22067.      Transferring Control 
  22068.      abort - Stop a Program 
  22069.      setjmp - Preserve Stack Environment 
  22070.      longjmp - Restore Stack Environment 
  22071.  
  22072.  
  22073. ΓòÉΓòÉΓòÉ 16.9. _set_mt_unexpected() and _set_mt_terminate() Functions ΓòÉΓòÉΓòÉ
  22074.  
  22075. The function _set_mt_terminate() registers a terminate handler exactly the same 
  22076. way set_terminate() does, except that it only affects the current thread. When 
  22077. a terminate function needs to be called, the code first checks to see if a 
  22078. thread terminate handler has been registered. If so, the thread terminate 
  22079. handler is called. If not, the global terminate handler (the one registered 
  22080. with set_terminate()) is called. 
  22081.  
  22082. The function _set_mt_unexpected() registers an unexpected handler exactly the 
  22083. same way set_unexpected() does, except that it only affects the current thread. 
  22084. When an unexpected handler needs to be called, the code first checks to see if 
  22085. a thread unexpected handler has been registered. If so, the thread unexpected 
  22086. handler is called. If not, the global unexpected handler (the one registered 
  22087. with set_unexpected()) is called. 
  22088.  
  22089. Related Information 
  22090.  
  22091.      unexpected() and terminate() Functions 
  22092.      set_unexpected() and set_terminate() Functions 
  22093.      C++ Exception Handling Overview 
  22094.      Using Exception Handling 
  22095.      Transferring Control 
  22096.      Exception Specifications 
  22097.  
  22098.  
  22099. ΓòÉΓòÉΓòÉ 16.10. Example of Using the Exception Handling Functions ΓòÉΓòÉΓòÉ
  22100.  
  22101. /************************************************************************
  22102. *
  22103.  
  22104. The following example shows the flow of control and special functions used in 
  22105. exception handling: 
  22106.  
  22107.                                                                         *
  22108. ************************************************************************/
  22109.  
  22110. #include <terminat.h>
  22111. #include <unexpect.h>
  22112. #include <iostream.h>
  22113. class X { /* ... */ };
  22114. class Y { /* ... */ };
  22115. class A { /* ... */ };
  22116. // pfv type is pointer to function returning void
  22117. typedef void (*pfv)();
  22118. void my_terminate()
  22119. {      cout << "Call to my terminate" << endl; }
  22120. void my_unexpected()
  22121. {      cout << "Call to my unexpected" << endl; }
  22122. void f() throw(X,Y)      // f() is permitted to throw objects of class
  22123.                          // types X and Y only
  22124. {
  22125.       A aobj;
  22126.       throw(aobj); // error, f() throws a class A object
  22127. }
  22128. main()
  22129. {
  22130.       pfv old_term = set_terminate(my_terminate);
  22131.       pfv old_unex = set_unexpected(my_unexpected);
  22132.       try{ f(); }
  22133.       catch(X)       { /* ... */ }
  22134.       catch(Y)       { /* ... */ }
  22135.       catch (...)    { /* ... */ }
  22136.  
  22137.       set_unexpected(old_unex);
  22138.       try { f();}
  22139.       catch(X)       { /* ... */ }
  22140.       catch(Y)       { /* ... */ }
  22141.       catch (...)    { /* ... */ }
  22142. }
  22143.  
  22144. /************************************************************************
  22145. *
  22146.  
  22147. At run time, this program behaves as follows: 
  22148.  
  22149.    1. The call to set_terminate() assigns to old_term the address of the 
  22150.       function last passed to set_terminate() when set_terminate() was 
  22151.       previously called. 
  22152.  
  22153.    2. The call to set_unexpected() assigns to old_unex the address of the 
  22154.       function last passed to set_unexpected() when set_unexpected() was 
  22155.       previously called. 
  22156.  
  22157.    3. Within a try block, function f() is called. Because f() throws an 
  22158.       unexpected exception, a call to unexpected() is made. unexpected() in 
  22159.       turn calls my_unexpected(), which prints a message to standard output and 
  22160.       returns. 
  22161.  
  22162.    4. The second call to set_unexpected() replaces the user-defined function 
  22163.       my_unexpected() with the saved pointer to the original function 
  22164.       (terminate()) called by unexpected(). 
  22165.  
  22166.    5. Within a second try block, function f() is called once more. Because f() 
  22167.       throws an unexpected exception, a call to unexpected() is again made. 
  22168.       unexpected() automatically calls terminate(), which calls the function 
  22169.       my_terminate(). 
  22170.  
  22171.    6. my_terminate() displays a message. It returns, and the system calls 
  22172.       abort(), which terminates the program. 
  22173.  
  22174.  At run time, the following information is displayed, and the program ends: 
  22175.  
  22176.   Call to my_unexpected
  22177.   Call to my_terminate
  22178.  
  22179.  Note:  The catch blocks following the try block are not entered, because the 
  22180.  exception was handled by my_unexpected() as an unexpected throw, not as a 
  22181.  valid exception. 
  22182.  
  22183.                                                                           *
  22184.   ************************************************************************/
  22185.  
  22186.  
  22187. ΓòÉΓòÉΓòÉ 17. C and C++ Compatibility ΓòÉΓòÉΓòÉ
  22188.  
  22189. The differences between ISO/ANSI C and C++ fall into two categories: 
  22190.  
  22191.      Constructs found in C++ but not in ISO/ANSI C 
  22192.      Constructs found in both C++ and ISO/ANSI C, but treated differently in 
  22193.       the two languages 
  22194.  
  22195.  C++ contains many constructs that are not found in ISO/ANSI C: 
  22196.  
  22197.      Single line comments beginning with // 
  22198.      Scope operator (::) 
  22199.      Free store management using the operators new and delete 
  22200.      Linkage specification for functions 
  22201.      Reference types 
  22202.      Default arguments for functions 
  22203.      Inline functions 
  22204.      Classes 
  22205.      Anonymous unions 
  22206.      Overloaded operators and functions 
  22207.      Class templates and function templates 
  22208.      Exception handling 
  22209.  
  22210.  Note:  The VisualAge C++ compiler also supports anonymous unions in C, but the 
  22211.  implementation is slightly different from C++.  For more information, see 
  22212.  Anonymous Unions in C. 
  22213.  
  22214.  
  22215. ΓòÉΓòÉΓòÉ 17.1. Constructs Treated Differently in C and C++ ΓòÉΓòÉΓòÉ
  22216.  
  22217. Because C++ is based on ISO/ANSI C, the two languages have many constructs in 
  22218. common. The use of some of these shared constructs differs, as shown here. 
  22219.  
  22220.      Character Array Initialization 
  22221.      Character Constants 
  22222.      Class and typedef Names 
  22223.      Class and Scope Declarations 
  22224.      const Object Initialization 
  22225.      Definitions 
  22226.      Definitions within Return or Argument Types 
  22227.      Enumerator Type 
  22228.      Enumeration Type 
  22229.      Function Declarations 
  22230.      Functions with an Empty Argument List 
  22231.      Global Constant Linkage 
  22232.      Jump Statements 
  22233.      Keywords 
  22234.      main() Recursion 
  22235.      Names of Nested Classes 
  22236.      Pointers to void 
  22237.      Prototype Declarations 
  22238.      Return without Declared Value 
  22239.      __STDC__ Macro 
  22240.      typedefs in Class Declarations 
  22241.  
  22242.  Related Information 
  22243.  
  22244.      C and C++ Compatibility 
  22245.  
  22246.  
  22247. ΓòÉΓòÉΓòÉ 17.1.1. Character Array Initialization ΓòÉΓòÉΓòÉ
  22248.  
  22249. In C++, when you initialize character arrays, a trailing '\0' (zero of type 
  22250. char) is appended to the string initializer. You cannot initialize a character 
  22251. array with more initializers than there are array elements. 
  22252.  
  22253. In ISO/ANSI C, space for the trailing '\0' can be omitted in this type of 
  22254. initialization. 
  22255.  
  22256. The following initialization, for instance, is not valid in C++: 
  22257.  
  22258. char v[3] = "asd"; // not valid in C++, valid in ISO/ANSI C
  22259.  
  22260. because four elements are required. This initialization produces an error 
  22261. because there is no space for the implied trailing '\0' (zero of type char). 
  22262.  
  22263. For more information, see Arrays. 
  22264.  
  22265.  
  22266. ΓòÉΓòÉΓòÉ 17.1.2. Character Constants ΓòÉΓòÉΓòÉ
  22267.  
  22268. A character constant has type char in C++ and int in ISO/ANSI C. 
  22269.  
  22270. For more information, see Character Constants. 
  22271.  
  22272.  
  22273. ΓòÉΓòÉΓòÉ 17.1.3. Class and typedef Names ΓòÉΓòÉΓòÉ
  22274.  
  22275. In C++, a class and a typedef cannot both use the same name to refer to a 
  22276. different type within the same scope (unless the typedef is a synonym for the 
  22277. class name). In C, a typedef name and a struct tag name declared in the same 
  22278. scope can have the same name because they have different name spaces. For 
  22279. example: 
  22280.  
  22281. void main ()
  22282. {
  22283.      typedef double db;
  22284.      struct db; // error in C++, valid in ISO/ANSI C
  22285.  
  22286.      typedef struct st st; // valid ISO/ANSI C and C++
  22287. }
  22288.  
  22289. For more information on typedef, see typedef. For information on class types, 
  22290. see C++ Classes. For information on structures, see Structures. 
  22291.  
  22292.  
  22293. ΓòÉΓòÉΓòÉ 17.1.4. Class and Scope Declarations ΓòÉΓòÉΓòÉ
  22294.  
  22295. In C++, a class declaration introduces the class name into the scope where it 
  22296. is declared and hides any object, function, or other declaration of that name 
  22297. in an enclosing scope. In ISO/ANSI C, an inner scope declaration of a struct 
  22298. name does not hide an object or function of that name in an outer scope. For 
  22299. example: 
  22300.  
  22301. double db;
  22302. void main ()
  22303. {
  22304.      struct db               // hides double object db in C++
  22305.      { char* str; };
  22306.      int x = sizeof(db);     // size of struct in C++
  22307.                              // size of double in ISO/ANSI C
  22308. }
  22309.  
  22310. For more information, see Scope of Class Names. For general information about 
  22311. scope, see Scope in C++. 
  22312.  
  22313.  
  22314. ΓòÉΓòÉΓòÉ 17.1.5. const Object Initialization ΓòÉΓòÉΓòÉ
  22315.  
  22316. In C++, const objects must be initialized. In ISO/ANSI C, they can be left 
  22317. uninitialized. 
  22318.  
  22319. For more information, see volatile and const Qualifiers. 
  22320.  
  22321.  
  22322. ΓòÉΓòÉΓòÉ 17.1.6. Definitions ΓòÉΓòÉΓòÉ
  22323.  
  22324. An object declaration, for example: 
  22325.  
  22326. int i;
  22327.  
  22328. is a definition in C++. In ISO/ANSI C, it is a tentative definition. 
  22329.  
  22330. In C++, a global data object must be defined only once. In ISO/ANSI C, a global 
  22331. data object can be declared several times without using the extern keyword. 
  22332.  
  22333. In C++, multiple definitions for a single variable cause an error. A C 
  22334. compilation unit can contain many identical tentative definitions for a 
  22335. variable. 
  22336.  
  22337. For more information, see Declarations. 
  22338.  
  22339.  
  22340. ΓòÉΓòÉΓòÉ 17.1.7. Definitions within Return or Argument Types ΓòÉΓòÉΓòÉ
  22341.  
  22342. In C++, types may not be defined in return or argument types. ISO/ANSI C allows 
  22343. such definitions. For example, the declarations: 
  22344.  
  22345. void print(struct X { int i;} x);      // error in C++
  22346. enum count{one, two, three} counter(); // error in C++
  22347.  
  22348. produce errors in C++, but are valid declarations in ISO/ANSI C. 
  22349.  
  22350. For more information, see Function Declarations and Calling Functions and 
  22351. Passing Arguments. 
  22352.  
  22353.  
  22354. ΓòÉΓòÉΓòÉ 17.1.8. Enumerator Type ΓòÉΓòÉΓòÉ
  22355.  
  22356. An enumerator has the same type as its enumeration in C++. In ISO/ANSI C, an 
  22357. enumeration has type int. 
  22358.  
  22359. For more information on enumerators, see Enumerations. 
  22360.  
  22361.  
  22362. ΓòÉΓòÉΓòÉ 17.1.9. Enumeration Type ΓòÉΓòÉΓòÉ
  22363.  
  22364. The assignment to an object of enumeration type with a value that is not of 
  22365. that enumeration type produces an error in C++. In ISO/ANSI C, an object of 
  22366. enumeration type can be assigned values of any integral type. 
  22367.  
  22368. For more information, see Enumerations. 
  22369.  
  22370.  
  22371. ΓòÉΓòÉΓòÉ 17.1.10. Function Declarations ΓòÉΓòÉΓòÉ
  22372.  
  22373. In C++, all declarations of a function must match the unique definition of a 
  22374. function. ISO/ANSI C has no such restriction. 
  22375.  
  22376. For more information, see Function Declarations. 
  22377.  
  22378.  
  22379. ΓòÉΓòÉΓòÉ 17.1.11. Functions with an Empty Argument List ΓòÉΓòÉΓòÉ
  22380.  
  22381. Consider the following function declaration: 
  22382.  
  22383.   int f();
  22384.  
  22385. In C++, this function declaration means that the function takes no arguments. 
  22386. In ISO/ANSI C, it could take any number of arguments, of any type. 
  22387.  
  22388. For more information, see Function Declarations. 
  22389.  
  22390.  
  22391. ΓòÉΓòÉΓòÉ 17.1.12. Global Constant Linkage ΓòÉΓòÉΓòÉ
  22392.  
  22393. In C++, an object declared const has internal linkage, unless it has previously 
  22394. been given external linkage. In ISO/ANSI C, it has external linkage. 
  22395.  
  22396. For more information, see Program Linkage. 
  22397.  
  22398.  
  22399. ΓòÉΓòÉΓòÉ 17.1.13. Jump Statements ΓòÉΓòÉΓòÉ
  22400.  
  22401. C++ does not allow you to jump over declarations containing initializations. 
  22402. ISO/ANSI C does allow you to use jump statements for this purpose. 
  22403.  
  22404. For more information, see Initializers. 
  22405.  
  22406.  
  22407. ΓòÉΓòÉΓòÉ 17.1.14. Keywords ΓòÉΓòÉΓòÉ
  22408.  
  22409. C++ contains some additional keywords not found in ISO/ANSI C. C programs that 
  22410. use these keywords as identifiers are not valid C++ programs: 
  22411.  
  22412.  catch                    protected 
  22413.  class                    public 
  22414.  delete                   template 
  22415.  friend                   this 
  22416.  inline                   throw 
  22417.  new                      try 
  22418.  operator                 virtual 
  22419.  private 
  22420.  
  22421.  For more information, see Keywords. 
  22422.  
  22423.  
  22424. ΓòÉΓòÉΓòÉ 17.1.15. main() Recursion ΓòÉΓòÉΓòÉ
  22425.  
  22426. In C++, main() cannot be called recursively and cannot have its address taken. 
  22427. ISO/ANSI C allows recursive calls and allows pointers to hold the address of 
  22428. main(). 
  22429.  
  22430. For more information, see The main() Function. 
  22431.  
  22432.  
  22433. ΓòÉΓòÉΓòÉ 17.1.16. Names of Nested Classes ΓòÉΓòÉΓòÉ
  22434.  
  22435. In C++, the name of a nested class is local to its enclosing class. In ISO/ANSI 
  22436. C, the name of the nested structure belongs to the same scope as the name of 
  22437. the outermost enclosing structure. 
  22438.  
  22439. For more information, see Nested Classes. 
  22440.  
  22441.  
  22442. ΓòÉΓòÉΓòÉ 17.1.17. Pointers to void ΓòÉΓòÉΓòÉ
  22443.  
  22444. C++ allows void pointers to be assigned only to other void pointers. In 
  22445. ISO/ANSI C, a pointer to void can be assigned to a pointer of any other type 
  22446. without an explicit cast. 
  22447.  
  22448. For more information, see void Type and Pointers. 
  22449.  
  22450.  
  22451. ΓòÉΓòÉΓòÉ 17.1.18. Prototype Declarations ΓòÉΓòÉΓòÉ
  22452.  
  22453. C++ requires full prototype declarations. ISO/ANSI C allows nonprototyped 
  22454. functions. 
  22455.  
  22456. For more information, see Function Declarator. 
  22457.  
  22458.  
  22459. ΓòÉΓòÉΓòÉ 17.1.19. Return without Declared Value ΓòÉΓòÉΓòÉ
  22460.  
  22461. In C++, a return (either explicit or implicit) from main() that is declared to 
  22462. return a value results in an error if no value is returned. A return (either 
  22463. explicit or implicit) from all other functions that is declared to return a 
  22464. value must return a value. In ISO/ANSI C, a function that is declared to return 
  22465. a value can return with no value, with unspecified results. 
  22466.  
  22467. For more information, see Function Return Values. 
  22468.  
  22469.  
  22470. ΓòÉΓòÉΓòÉ 17.1.20. __STDC__ Macro ΓòÉΓòÉΓòÉ
  22471.  
  22472. The predefined macro variable __STDC__ has the integer value 0 to indicate that 
  22473. C++ does not conform to ISO/ANSI C. In ISO/ANSI C, __STDC__ has the integer 
  22474. value 1. 
  22475.  
  22476. For an example of the use of __STDC__ macro, see Example of Predefined Macros 
  22477. For more information on macros, see Predefined Macro Names. 
  22478.  
  22479.  
  22480. ΓòÉΓòÉΓòÉ 17.1.21. typedefs in Class Declarations ΓòÉΓòÉΓòÉ
  22481.  
  22482. In C++, a typedef name may not be redefined in a class declaration after being 
  22483. used in the declaration. ISO/ANSI C allows such a declaration. For example: 
  22484.  
  22485. void main ()
  22486. {
  22487.      typedef double db;
  22488.      struct st
  22489.      {
  22490.           db x;
  22491.           double db; // error in C++, valid in ISO/ANSI C
  22492.      };
  22493. }
  22494.  
  22495. For more information, see typedef. 
  22496.  
  22497.  
  22498. ΓòÉΓòÉΓòÉ 18. Glossary ΓòÉΓòÉΓòÉ
  22499.  
  22500. This is a glossary of commonly used terms in the VisualAge C++ library. It 
  22501. includes definitions developed by the American National Standards Institute 
  22502. (ANSI) and entries from the IBM Dictionary of Computing (ZC20-1699). 
  22503.  
  22504. A      J      S
  22505. B      K      T
  22506. C      L      U
  22507. D      M      V
  22508. E      N      W
  22509. F      O      X
  22510. G      P      Y
  22511. H      Q      Z
  22512. I      R
  22513.  
  22514.  
  22515. ΓòÉΓòÉΓòÉ <hidden> A ΓòÉΓòÉΓòÉ
  22516.  
  22517. abstract class 
  22518.  
  22519. A class with at least one pure virtual function. It is a C++ class used as a 
  22520. base class for other classes. The abstract class represents a concept; classes 
  22521. derived from it represent implementations of the concept. You cannot have a 
  22522. direct object of an abstract class. (See also base class.) 
  22523.  
  22524. abstraction (data) 
  22525.  
  22526. A data type with a private representation and a public set of operations. The 
  22527. C++ language uses the concept of classes to implement data abstraction. 
  22528.  
  22529. access 
  22530.  
  22531. Determines whether or not a class member is accessible in an expression or 
  22532. declaration. 
  22533.  
  22534. access declaration 
  22535.  
  22536. Used to restore access to members of a base class. 
  22537.  
  22538. access resolution 
  22539.  
  22540. The process by which the accessibility of a particular class member is 
  22541. determined. 
  22542.  
  22543. access specifiers 
  22544.  
  22545. One of the C++ keywords: public, private, and protected. 
  22546.  
  22547. address 
  22548.  
  22549. A name, label, or number identifying a location in storage, a device in a 
  22550. system or network, or any other data source. 
  22551.  
  22552. aggregate 
  22553.  
  22554. An array or a class object with no private or protected members, no 
  22555. constructors, no base classes, and no virtual functions. 
  22556.  
  22557. alignment 
  22558.  
  22559. See boundary alignment. 
  22560.  
  22561. anonymous union 
  22562.  
  22563. A union without a class name. It must not be followed by a declarator. 
  22564.  
  22565. arithmetic object 
  22566.  
  22567. An integral object or objects having the type float, double, or long double. 
  22568.  
  22569. array 
  22570.  
  22571. A variable that contains an ordered group of data objects. All data items (or 
  22572. elements) in an array have the same data type. 
  22573.  
  22574. array element 
  22575.  
  22576. A single data item in an array. 
  22577.  
  22578. assignment conversion 
  22579.  
  22580. A change to the form of the right operand that makes the right operand have the 
  22581. same data type as the left operand. 
  22582.  
  22583. assignment expression 
  22584.  
  22585. An operation that stores the value of the right operand in the storage location 
  22586. specified by the left operand. 
  22587.  
  22588. associativity 
  22589.  
  22590. The order for grouping operands with an operator (either left-to-right or 
  22591. right-to-left). 
  22592.  
  22593.  
  22594. ΓòÉΓòÉΓòÉ <hidden> B ΓòÉΓòÉΓòÉ
  22595.  
  22596. base class 
  22597.  
  22598. A class from which other classes are derived.  A base class may itself be 
  22599. derived from another base class. (See also abstract class.) 
  22600.  
  22601. binary expression 
  22602.  
  22603. An operation containing two operands and one operator. 
  22604.  
  22605. bit field 
  22606.  
  22607. A member of a structure or union that contains 0 or more bits. 
  22608.  
  22609. block statement 
  22610.  
  22611. Any number of data definitions, declarations, and statements that appear 
  22612. between the symbols { (left brace) and } (right brace). 
  22613.  
  22614. boundary alignment 
  22615.  
  22616. The position in main storage of a fixed-length field (such as halfword or 
  22617. doubleword) on an integral boundary for that unit of information. For example, 
  22618. a word boundary is a storage address evenly divisible by four. 
  22619.  
  22620. break statement 
  22621.  
  22622. A language control statement that contains the word break and a semicolon.  It 
  22623. is used to end an iterative or a switch statement by exiting from it at any 
  22624. point other than the logical end.  Control is passed to the first statement 
  22625. after the iteration or switch statement. 
  22626.  
  22627. buffer flush 
  22628.  
  22629. A process that removes the contents of a buffer. After a buffer flush, the 
  22630. buffer is empty. 
  22631.  
  22632.  
  22633. ΓòÉΓòÉΓòÉ <hidden> C ΓòÉΓòÉΓòÉ
  22634.  
  22635. C library 
  22636.  
  22637. A system library that contains common C language subroutines for file access, 
  22638. string operators, character operations, memory allocation, and other functions. 
  22639.  
  22640. C++ class library 
  22641.  
  22642. See class library. 
  22643.  
  22644. C++ language statement 
  22645.  
  22646. A C++ language statement contains zero or more expressions. All C++ language 
  22647. statements, except block statements, end with a ; (semicolon) symbol. A block 
  22648. statement begins with a { (left brace) symbol, ends with a } (right brace) 
  22649. symbol, and contains any number of statements. 
  22650.  
  22651. C++ library 
  22652.  
  22653. A system library that contains common C++ language subroutines for file access, 
  22654. memory allocation, and other functions. 
  22655.  
  22656. case clause 
  22657.  
  22658. In a switch statement, a case label followed by any number of statements. 
  22659.  
  22660. case label 
  22661.  
  22662. The word case followed by a constant expression and a colon.  When the selector 
  22663. evaluates the value of the constant expression, the statements following the 
  22664. case label are processed. 
  22665.  
  22666. cast expression 
  22667.  
  22668. A cast expression explicitly converts its operand to a specified arithmetic, 
  22669. scalar, or class type. 
  22670.  
  22671. cast operator 
  22672.  
  22673. The cast operator is used for explicit type conversions. 
  22674.  
  22675. catch block 
  22676.  
  22677. A block associated with a try block that receives control when an exception 
  22678. matching its argument is thrown. 
  22679.  
  22680. char specifier 
  22681.  
  22682. A char is a built-in data type. In C++, char, signed char, and unsigned char 
  22683. are all distinct data types. 
  22684.  
  22685. character constant 
  22686.  
  22687. A character or an escape sequence enclosed in single quotation marks. 
  22688.  
  22689. character variable 
  22690.  
  22691. A data object whose value can be changed during program execution and whose 
  22692. data type is char, signed char, or unsigned char. 
  22693.  
  22694. class 
  22695.  
  22696. A class is a user-defined data type.  A class data type can contain both data 
  22697. representations (data members) and functions (member functions). 
  22698.  
  22699. class key 
  22700.  
  22701. One of the C++ keywords: class, struct and union. 
  22702.  
  22703. class library 
  22704.  
  22705. A collection of C++ classes. 
  22706.  
  22707. class member operators 
  22708.  
  22709. Used to access class members through class objects or pointers to class 
  22710. objects.  They are ., ->, .*, and ->*. 
  22711.  
  22712. class name 
  22713.  
  22714. A unique identifier of a class type that becomes a reserved word within its 
  22715. scope. 
  22716.  
  22717. class scope 
  22718.  
  22719. The names of class members have class scope. 
  22720.  
  22721. class tag 
  22722.  
  22723. See class name. 
  22724.  
  22725. class template 
  22726.  
  22727. A blueprint describing how a set of related classes can be constructed. 
  22728.  
  22729. client program 
  22730.  
  22731. A program that uses a class. The program is said to be a client of the class. 
  22732.  
  22733. comma expression 
  22734.  
  22735. An expression that contains two operands separated by a comma.  Although the 
  22736. compiler evaluates both operands, the value of the expression is the value of 
  22737. the right operand. If the left operand produces a value, the compiler discards 
  22738. this value.  Typically, the left operand of a comma expression is used to 
  22739. produce side effects. 
  22740.  
  22741. complete class name 
  22742.  
  22743. The complete qualification of a nested class name including all enclosing class 
  22744. names. 
  22745.  
  22746. Complex Mathematics Library 
  22747.  
  22748. A class library that provides the facilities to manipulate complex numbers and 
  22749. perform standard mathematical operations on them. 
  22750.  
  22751. complex number 
  22752.  
  22753. A complex number is made up of two parts: a real part and an imaginary part.  A 
  22754. complex number can be represented by an ordered pair (a, b ), where a is the 
  22755. value of the real part and b is the value of the imaginary part.  The same 
  22756. complex number could also be represented as a + bi, where i is the square root 
  22757. of -1. 
  22758.  
  22759. conditional compilation statement 
  22760.  
  22761. A preprocessor statement that causes the preprocessor to process specified 
  22762. source code in the file depending on the evaluation of a specific condition. 
  22763.  
  22764. conditional expression 
  22765.  
  22766. A compound expression that contains a condition (the first expression), an 
  22767. expression to be evaluated if the condition has a nonzero value (the second 
  22768. expression), and an expression to be evaluated if the condition has the value 
  22769. zero (the third expression). 
  22770.  
  22771. const 
  22772.  
  22773. A keyword that allows you to define a variable whose value does not change. 
  22774.  
  22775. constant expression 
  22776.  
  22777. An expression having a value that can be determined during compilation and that 
  22778. does not change during program execution. 
  22779.  
  22780. constructor 
  22781.  
  22782. A special class member function that has the same name as the class.  It is 
  22783. used to construct class objects and may initialize them. 
  22784.  
  22785. control statement 
  22786.  
  22787. A C or C++ language statement that changes the normal path of execution. 
  22788.  
  22789. conversion 
  22790.  
  22791. A change in the type of a value. For example, when you add values having 
  22792. different data types, the compiler converts both values to the same type before 
  22793. adding them. 
  22794.  
  22795. conversion function 
  22796.  
  22797. A member function that specifies a conversion from its class type to another 
  22798. type. 
  22799.  
  22800. copy constructor 
  22801.  
  22802. A constructor used to make a copy of a class object from another class object 
  22803. of the same class type. 
  22804.  
  22805.  
  22806. ΓòÉΓòÉΓòÉ <hidden> D ΓòÉΓòÉΓòÉ
  22807.  
  22808. data  abstraction 
  22809.  
  22810. See abstraction (data). 
  22811.  
  22812. data definition 
  22813.  
  22814. A program statement that describes the features of, specifies relationships of, 
  22815. or establishes the context of, data. A data definition can also provide an 
  22816. initial value.  Definitions appear outside a function (for example at file 
  22817. scope) or within a block statement. 
  22818.  
  22819. data member 
  22820.  
  22821. See member. 
  22822.  
  22823. data object 
  22824.  
  22825. Anything that exists in storage and on which operations can be performed, such 
  22826. as files, programs, classes, or arrays. 
  22827.  
  22828. data type 
  22829.  
  22830. A category that specifies the interpretation of a data object such as its 
  22831. mathematical qualities and internal representation. 
  22832.  
  22833. decimal constant 
  22834.  
  22835. A number containing any digits 0 through 9 that does not begin with 0 (zero). 
  22836.  
  22837. declaration 
  22838.  
  22839. Establishes the names and characteristics of data objects and functions used in 
  22840. a program. 
  22841.  
  22842. declarator 
  22843.  
  22844. Designates a data object or function declared.  Initializations can be 
  22845. performed in a declarator. 
  22846.  
  22847. default arguments 
  22848.  
  22849. Arguments that are declared with default values in a function prototype or 
  22850. declaration.  If a call to the function omits these arguments, default values 
  22851. are used.  Arguments with default values must be the trailing arguments in a 
  22852. function prototype argument list. 
  22853.  
  22854. default clause 
  22855.  
  22856. In a switch statement, the keyword default followed by a colon, and one or more 
  22857. statements.  When the conditions of the specified case labels in the switch 
  22858. statement do not hold, the default clause is chosen. 
  22859.  
  22860. default constructor 
  22861.  
  22862. A constructor that takes no arguments, or if it takes any arguments, all its 
  22863. arguments have default values. 
  22864.  
  22865. default initialization 
  22866.  
  22867. The initial value assigned to a data object by the compiler if no initial value 
  22868. is specified by the programmer. extern and static variables receive a default 
  22869. initialization of zero, while the default initial value for auto and register 
  22870. variables is undefined. 
  22871.  
  22872. define statement 
  22873.  
  22874. A preprocessor statement that causes the preprocessor to replace an identifier 
  22875. or macro call with specified code. 
  22876.  
  22877. definition 
  22878.  
  22879. A declaration that allocates storage, and may initialize a data object or 
  22880. specify the body of a function. 
  22881.  
  22882. delete 
  22883.  
  22884.    1. The keyword delete identifies a free store deallocation operator. 
  22885.  
  22886.    2. The delete operator is used to destroy objects created by new. (See also 
  22887.       new.) 
  22888.  
  22889.  demangling 
  22890.  
  22891.  The conversion of mangled names back to their original source code names. 
  22892.  During compilation, identifiers such as function and static class member names 
  22893.  are mangled (encoded) with type and scoping information to ensure type-safe 
  22894.  linkage. These mangled names appear in the object file and the final 
  22895.  executable file.  Demangling converts these names back to their original names 
  22896.  to make program debugging easier. 
  22897.  
  22898.  derivation 
  22899.  
  22900.  In C++, to derive a class, called a derived class, from an existing class, 
  22901.  called a base class. 
  22902.  
  22903.  derived class 
  22904.  
  22905.  A class that inherits the proper base class become members of a derived class 
  22906.  object. You can add additional data members and member functions to the 
  22907.  derived class. A derived class object can be manipulated as if it is a base 
  22908.  class object. The derived class can override virtual functions of the base 
  22909.  class. 
  22910.  
  22911.  destructor 
  22912.  
  22913.  A special member function of a class with the same name as the class with a 
  22914.  ~(tilde) preceding the name. You cannot specify arguments or a return type for 
  22915.  this function. A destructor "cleans up" after an object by doing such things 
  22916.  as freeing any storage that was dynamically allocated when the object was 
  22917.  created. (See also constructor.) 
  22918.  
  22919.  digraph sequence 
  22920.  
  22921.  A combination of two keystrokes used to represent unavailable characters in a 
  22922.  C++ source program. Digraphs are read as tokens during the preprocessor phase. 
  22923.  
  22924.  Distributed SOM (DSOM) 
  22925.  
  22926.  A model in which SOM objects can be shared remotely, so that a server on one 
  22927.  machine provides objects and services to a client program on another machine. 
  22928.  DSOM allows for transparent distribution of objects between a client machine 
  22929.  and one or more servers. 
  22930.  
  22931.  do statement 
  22932.  
  22933.  A looping statement that contains the word do followed by a statement (the 
  22934.  action), the word while, and an expression in parentheses (the condition). 
  22935.  
  22936.  double precision 
  22937.  
  22938.  The use of two computer words to represent a floating-point value in 
  22939.  accordance with the required precision. 
  22940.  
  22941.  DSOM 
  22942.  
  22943.  See Distributed SOM. 
  22944.  
  22945.  dynamic binding 
  22946.  
  22947.  Resolution of a call to a virtual member function at run time. 
  22948.  
  22949.  
  22950. ΓòÉΓòÉΓòÉ <hidden> E ΓòÉΓòÉΓòÉ
  22951.  
  22952. elaborated type specifier 
  22953.  
  22954. Typically used in an incomplete class declaration or to qualify types that are 
  22955. otherwise hidden. 
  22956.  
  22957. element 
  22958.  
  22959. The component of an array, subrange, enumeration, or set. 
  22960.  
  22961. else clause 
  22962.  
  22963. The part of an if statement that contains the word else followed by a 
  22964. statement. The else clause provides an action that is executed when the if 
  22965. condition evaluates to zero (false). 
  22966.  
  22967. encapsulation 
  22968.  
  22969. Hiding the internal representation of data objects and implementation details 
  22970. of functions from the client program. This enables the end user to focus on the 
  22971. use of data objects and functions without having to know about their 
  22972. representation or implementation. 
  22973.  
  22974. enumeration constant 
  22975.  
  22976. An identifier (that has an associated integer value) defined by an enumeration 
  22977. type.  You can use an enumeration constant anywhere an integer constant is 
  22978. allowed. 
  22979.  
  22980. enumeration tag 
  22981.  
  22982. The identifier that names an enumeration data type. 
  22983.  
  22984. enumeration type 
  22985.  
  22986. An enumeration type defines a set of enumeration constants. In C++, an 
  22987. enumeration type is a distinct data type that is not an integral type. 
  22988.  
  22989. enumerator 
  22990.  
  22991. An enumeration constant and its associated value. 
  22992.  
  22993. escape sequence 
  22994.  
  22995. A representation of a nonprintable character in a character or string literal. 
  22996. An escape sequence contains the \ symbol, followed by one of the characters: a, 
  22997. b, f, n, r, t, v, ', ?, or \, or followed by one to three octal digits or \ 
  22998. followed by an x followed by any number of hexadecimal digits. 
  22999.  
  23000. exception 
  23001.  
  23002. Any user, logic, or system error detected by a function that does not itself 
  23003. deal with the error but passes the error on to a handling routine. In C++, 
  23004. passing this error is called throwing an exception. 
  23005.  
  23006. exception handler 
  23007.  
  23008. Exception handlers are catch blocks in C++. catch blocks catch exceptions when 
  23009. they are thrown from a function enclosed in a try block. try blocks, catch 
  23010. blocks and throw expressions are the constructs used to implement formal 
  23011. exception handling in C++. 
  23012.  
  23013. exception handling 
  23014.  
  23015. A type of error handling that allows control and information to be passed to an 
  23016. exception handler when an exception occurs. try blocks, catch blocks and throw 
  23017. expressions are the constructs used to implement formal exception handling in 
  23018. C++. 
  23019.  
  23020. expression 
  23021.  
  23022. A representation of a value.  For example, variables and constants appearing 
  23023. alone or in combination with operators are expressions. 
  23024.  
  23025. external data definition 
  23026.  
  23027. A definition appearing outside a function.  The defined object is accessible to 
  23028. all functions that follow the definition and are located within the same source 
  23029. file as the definition. 
  23030.  
  23031.  
  23032. ΓòÉΓòÉΓòÉ <hidden> F ΓòÉΓòÉΓòÉ
  23033.  
  23034. file scope 
  23035.  
  23036. A name declared outside all blocks and classes has file scope and can be used 
  23037. after the point of declaration in a source file. 
  23038.  
  23039. float constant 
  23040.  
  23041. A number containing a decimal point, an exponent, or both a decimal point and 
  23042. an exponent.  The exponent contains an e or E, an optional sign (+ or -), and 
  23043. one or more digits (0 through 9). 
  23044.  
  23045. for statement 
  23046.  
  23047. A looping statement that contains the word for followed by a list of 
  23048. expressions enclosed in parentheses (the condition) and a statement (the 
  23049. action).  Each expression in the parenthesized list is separated by a 
  23050. semicolon. You can omit any of the expressions, but you cannot omit the 
  23051. semicolons. 
  23052.  
  23053. free store 
  23054.  
  23055. Dynamically allocates memory.  New and delete are used to allocate and 
  23056. deallocate free store. 
  23057.  
  23058. friend class 
  23059.  
  23060. A class in which all the member functions are granted access to the private and 
  23061. protected members of another class. It is named in the declaration of another 
  23062. class and uses the keyword friend as a prefix to the class. For example: 
  23063.  
  23064. class me {
  23065.    friend class you;
  23066.      // ...
  23067. };
  23068. makes all the functions in class you friends of class me. 
  23069.  
  23070. friend function 
  23071.  
  23072. A function that is granted access to the private and protected parts of a 
  23073. class.  It is named in the declaration of the class and uses the keyword friend 
  23074. as a prefix. 
  23075.  
  23076. function 
  23077.  
  23078. A named group of statements that can be invoked and evaluated and can return a 
  23079. value to the calling statement. 
  23080.  
  23081. function call 
  23082.  
  23083. An expression that moves the path of execution from the current function to a 
  23084. specified function and evaluates to the return value provided by the called 
  23085. function.  A function call contains the name of the function to which control 
  23086. moves and a parenthesized list of arguments. 
  23087.  
  23088. function declarator 
  23089.  
  23090. The part of a function definition that names the function, provides additional 
  23091. information about the return value of the function, and lists the function 
  23092. parameters. 
  23093.  
  23094. function definition 
  23095.  
  23096. The complete description of a function.  A function definition contains an 
  23097. optional storage class specifier, an optional type specifier, a function 
  23098. declarator, parameter declarations, and a block statement (the function body). 
  23099.  
  23100. function prototype 
  23101.  
  23102. A function declaration that provides type information for each parameter.  It 
  23103. is the first line of the function (header) followed by a ; (semicolon).  It is 
  23104. required by the compiler when the function will be declared later so type 
  23105. checking can occur. 
  23106.  
  23107. function scope 
  23108.  
  23109. Labels that are declared in a function have function scope and can be used 
  23110. anywhere in that function. 
  23111.  
  23112. function template 
  23113.  
  23114. Provides a blueprint describing how a set of related individual functions can 
  23115. be constructed. 
  23116.  
  23117.  
  23118. ΓòÉΓòÉΓòÉ <hidden> G ΓòÉΓòÉΓòÉ
  23119.  
  23120. generic class 
  23121.  
  23122. See class templates. 
  23123.  
  23124. global scope 
  23125.  
  23126. See file scope. 
  23127.  
  23128. global variable 
  23129.  
  23130. A symbol defined in one program module that is used in other independently 
  23131. compiled program modules. 
  23132.  
  23133.  
  23134. ΓòÉΓòÉΓòÉ <hidden> H ΓòÉΓòÉΓòÉ
  23135.  
  23136. header file 
  23137.  
  23138. A file that contains declarations used by a group of functions or users. 
  23139.  
  23140. hexadecimal 
  23141.  
  23142. A system of numbers to the base sixteen; hexadecimal digits range from 0 (zero) 
  23143. through 9 (nine) and A (ten) through F (fifteen). 
  23144.  
  23145. hexadecimal constant 
  23146.  
  23147. A constant, usually starting with special characters, that contains only 
  23148. hexadecimal digits.  The special characters are \x, 0x, or 0X. 
  23149.  
  23150.  
  23151. ΓòÉΓòÉΓòÉ <hidden> I ΓòÉΓòÉΓòÉ
  23152.  
  23153. I/O Stream Library 
  23154.  
  23155. A class library that provides the facilities to deal with many varieties of 
  23156. input and output. 
  23157.  
  23158. identifier 
  23159.  
  23160. A name that refers to a data object.  An identifier contains some combination 
  23161. of letters, digits, and underscores, but its first character cannot be a digit. 
  23162.  
  23163. if statement 
  23164.  
  23165. A conditional statement that contains the word if followed by an expression in 
  23166. parentheses (the condition), a statement (the action), and an optional else 
  23167. clause (the alternative action). 
  23168.  
  23169. include file 
  23170.  
  23171. A text file that contains declarations used by a group of functions, programs, 
  23172. or users. Also known as a header file. 
  23173.  
  23174. include statement 
  23175.  
  23176. A preprocessor statement that causes the preprocessor to replace the statement 
  23177. with the contents of a specified file. 
  23178.  
  23179. incomplete class declaration 
  23180.  
  23181. A class declaration that does not define any members of a class. Until a class 
  23182. is fully declared, or defined, you can only use the class name where the size 
  23183. of the class is not required. Typically, an incomplete class declaration is 
  23184. used as a forward declaration. 
  23185.  
  23186. inheritance 
  23187.  
  23188. An object-oriented programming technique that allows you to use existing 
  23189. classes as bases for creating other classes. 
  23190.  
  23191. initialize 
  23192.  
  23193. To set the starting value of a data object. 
  23194.  
  23195. initializer 
  23196.  
  23197. An expression used to initialize data objects. In C++, there are three types of 
  23198. initializers: 
  23199.  
  23200.      An expression followed by an assignment operator is used to initialize 
  23201.       fundamental data type objects or class objects that have copy 
  23202.       constructors. 
  23203.      An expression enclosed in braces ( {} ) is used to initialize aggregates. 
  23204.      A parenthesized expression list is used to initialize base classes and 
  23205.       members using constructors. 
  23206.  
  23207.  inline function 
  23208.  
  23209.  A function declared and defined simultaneously in a class definition. You can 
  23210.  also explicitly declare a function inline by using the keyword inline, which 
  23211.  is a hint to the compiler to perform inline expansion of the body of a 
  23212.  function member. Both member and nonmember functions can be inlined. 
  23213.  
  23214.  instance 
  23215.  
  23216.  An object-oriented programming term synonymous with 'object'. An instance is a 
  23217.  particular instantiation of a data type. It is simply a region of storage that 
  23218.  contains a value or group of values. For example, if a class box is previously 
  23219.  defined, two instances of a class box could be instantiated with the 
  23220.  declaration: 
  23221.  
  23222.   box box1, box2;
  23223.  
  23224.  instantiate 
  23225.  
  23226.  To create or generate a particular instance (or object) of a data type or 
  23227.  template. For example, an instance box1 of class box could be instantiated 
  23228.  with the declaration: 
  23229.  
  23230.   box box1;
  23231.  
  23232.  instruction 
  23233.  
  23234.  A program statement that specifies an operation to be performed by the 
  23235.  computer, along with the values or locations of operands.  This statement 
  23236.  represents the programmer's request to the processor to perform a specific 
  23237.  operation. 
  23238.  
  23239.  integer constant 
  23240.  
  23241.  A decimal, octal, or hexadecimal constant. 
  23242.  
  23243.  integral object 
  23244.  
  23245.  A character object, an object having variations of the type int, or an object 
  23246.  that is a bit field. 
  23247.  
  23248.  internal data definition 
  23249.  
  23250.  A description of a variable appearing in a block that directs the system to 
  23251.  allocate storage for that variable and makes that variable accessible to the 
  23252.  current block after its point of declaration. 
  23253.  
  23254.  
  23255. ΓòÉΓòÉΓòÉ <hidden> K ΓòÉΓòÉΓòÉ
  23256.  
  23257. keyword 
  23258.  
  23259. A reserved C or C++ language identifier. 
  23260.  
  23261.  
  23262. ΓòÉΓòÉΓòÉ <hidden> L ΓòÉΓòÉΓòÉ
  23263.  
  23264. label 
  23265.  
  23266. An identifier followed by a colon, used to identify a statement in a program. 
  23267. Usually the target of a goto or switch statement. 
  23268.  
  23269. labeled statement 
  23270.  
  23271. A possibly empty statement immediately preceded by a label. 
  23272.  
  23273. late binding 
  23274.  
  23275. See dynamic binding. 
  23276.  
  23277. link 
  23278.  
  23279. To interconnect items of data or portions of one or more computer programs, 
  23280. such as linking object programs by a linkage editor or linking data items by 
  23281. pointers. 
  23282.  
  23283. linkage editor 
  23284.  
  23285. A program that resolves cross-references between separately compiled object 
  23286. modules and then assigns final addresses to create a single relocatable load 
  23287. module.  If a single object module is linked, the linkage editor simply makes 
  23288. it relocatable. 
  23289.  
  23290. literal 
  23291.  
  23292. See constant. 
  23293.  
  23294. load module 
  23295.  
  23296. A computer program in a form suitable for loading into main storage for 
  23297. execution. 
  23298.  
  23299. local 
  23300.  
  23301. Pertaining to information that is defined and used only in one subdivision of a 
  23302. computer program. 
  23303.  
  23304. local scope 
  23305.  
  23306. A name declared in a block has local scope and can only be used in that block. 
  23307.  
  23308. long constant 
  23309.  
  23310. An integer constant followed by the letter l (el) or L. 
  23311.  
  23312. lvalue 
  23313.  
  23314. An expression that represents an object.  A modifiable Ivalue can be both 
  23315. examined and changed. 
  23316.  
  23317.  
  23318. ΓòÉΓòÉΓòÉ <hidden> M ΓòÉΓòÉΓòÉ
  23319.  
  23320. macro call 
  23321.  
  23322. An identifier followed by a parenthetical list of arguments that the 
  23323. preprocessor replaces with the replacement code located in a preprocessor 
  23324. define statement. 
  23325.  
  23326. main function 
  23327.  
  23328. An external function that has the identifier main. Each program must have 
  23329. exactly one external function named main( ). Program execution begins with this 
  23330. function. 
  23331.  
  23332. mangling 
  23333.  
  23334. The encoding, during compilation, of identifiers such as function and variable 
  23335. names to include type and scoping information.  The linker uses these mangled 
  23336. names to ensure type-safe linkage. 
  23337.  
  23338. manipulator 
  23339.  
  23340. A value that can be inserted into streams or extracted from streams to affect 
  23341. or query the behavior of the stream. 
  23342.  
  23343. member 
  23344.  
  23345. A data object or function in a structure, class, or union. Members can also be 
  23346. classes, enumerations, bit fields and type names. 
  23347.  
  23348. member function 
  23349.  
  23350. Operators and functions that are declared as members of a class. A member 
  23351. function has access to the private and protected data members and member 
  23352. functions of an object of its class. Member functions are also called methods. 
  23353.  
  23354. method 
  23355.  
  23356. Method is an object-oriented programming term synonymous with member function. 
  23357.  
  23358. multiple inheritance 
  23359.  
  23360. An object-oriented programming technique implemented in C++ through derivation, 
  23361. in which the derived class inherits members from more than one base class. (See 
  23362. also inheritance.) 
  23363.  
  23364.  
  23365. ΓòÉΓòÉΓòÉ <hidden> N ΓòÉΓòÉΓòÉ
  23366.  
  23367. name 
  23368.  
  23369. In C++, a name is commonly referred to as an identifier. However, 
  23370. syntactically, a name can be an identifier, operator function name, conversion 
  23371. function name, destructor name or qualified name. 
  23372.  
  23373. nested class 
  23374.  
  23375. A class defined within the scope of another class. 
  23376.  
  23377. new 
  23378.  
  23379. A keyword identifying a free store allocation operator. The new operator may be 
  23380. used to create class objects. (See also delete.) 
  23381.  
  23382. new-line character 
  23383.  
  23384. A control character that causes the print or display position to move to the 
  23385. first position on the next line. This character is represented by '\n' in C and 
  23386. C++. 
  23387.  
  23388. NULL 
  23389.  
  23390. A pointer that has a value 0 is guaranteed not to point to any data object. The 
  23391. pointer can be converted to any pointer type. 
  23392.  
  23393. null character (NUL) 
  23394.  
  23395. The character hex 00, used to represent the absence of a printed or displayed 
  23396. character. 
  23397.  
  23398. null statement 
  23399.  
  23400. A C or C++ statement that consists solely of a semicolon. 
  23401.  
  23402.  
  23403. ΓòÉΓòÉΓòÉ <hidden> O ΓòÉΓòÉΓòÉ
  23404.  
  23405. object 
  23406.  
  23407. A region of storage.  An object is created when a variable is defined or new is 
  23408. invoked.  An object is destroyed when it goes out of scope. (See also 
  23409. instance.) 
  23410.  
  23411. object code 
  23412.  
  23413. Machine-executable instructions, usually generated by a compiler from source 
  23414. code written in a higher level language. For programs that must be linked, 
  23415. object code consists of relocatable machine code. 
  23416.  
  23417. object-oriented programming 
  23418.  
  23419. A programming approach based on the concepts of data abstraction and 
  23420. inheritance. Unlike procedural programming techniques, object-oriented 
  23421. programming concentrates not on how something is accomplished but instead on 
  23422. what data objects comprise the problem and how they are manipulated. 
  23423.  
  23424. octal 
  23425.  
  23426. A base eight numbering system. 
  23427.  
  23428. octal constant 
  23429.  
  23430. The digit 0 (zero) followed by any digits 0 through 7. 
  23431.  
  23432. operand 
  23433.  
  23434. An entity on which an operation is performed. 
  23435.  
  23436. operator 
  23437.  
  23438. A symbol (such as +, -, *) that represents an operation (in this case, 
  23439. addition, subtraction, multiplication). 
  23440.  
  23441. operator function 
  23442.  
  23443. An overloaded operator that is either a member of a class, or takes at least 
  23444. one argument that is a class type or a pointer or a reference to a class type. 
  23445.  
  23446. overflow 
  23447.  
  23448. That portion of an operation's result that exceeds the capacity of the intended 
  23449. unit of storage. 
  23450.  
  23451. overflow condition 
  23452.  
  23453. A condition that occurs when a portion of the result of an operation exceeds 
  23454. the capacity of the intended unit of storage. 
  23455.  
  23456. overloading 
  23457.  
  23458. Allows you to redefine functions and most standard C++ operators when the 
  23459. functions and operators are used with class types. 
  23460.  
  23461.  
  23462. ΓòÉΓòÉΓòÉ <hidden> P ΓòÉΓòÉΓòÉ
  23463.  
  23464. pad 
  23465.  
  23466. To fill unused positions in a field with dummy data, usually zeros, ones, or 
  23467. blanks. 
  23468.  
  23469. parameter declaration 
  23470.  
  23471. A description of a value that a function receives. A parameter declaration 
  23472. determines the storage class and the data type of the value. 
  23473.  
  23474. pointer 
  23475.  
  23476. A variable that holds the address of a data object or function. 
  23477.  
  23478. pointer to member 
  23479.  
  23480. Used to access the address of nonstatic members of a class. 
  23481.  
  23482. polymorphic functions 
  23483.  
  23484. Functions that can be applied to objects of more than one data type. C++ 
  23485. implements polymorphic functions in two ways: 
  23486.  
  23487.    1. Overloaded functions (calls are resolved at compile time) 
  23488.    2. Virtual functions (calls are resolved at run time). 
  23489.  
  23490.  precedence 
  23491.  
  23492.  The priority system for grouping different types of operators with their 
  23493.  operands. 
  23494.  
  23495.  precision 
  23496.  
  23497.  A measure of the ability to distinguish between nearly equal values. (See also 
  23498.  single precision and double precision.) 
  23499.  
  23500.  preprocessor 
  23501.  
  23502.  A program that examines the source program for preprocessor statements that 
  23503.  are then interpreted, resulting in the alteration of the source program. 
  23504.  
  23505.  preprocessor statement 
  23506.  
  23507.  A statement that begins with the pound sign (#) and contains instructions that 
  23508.  the preprocessor interprets. 
  23509.  
  23510.  primary expression 
  23511.  
  23512.  Literals, names, and names qualified by the :: (scope resolution) operator. 
  23513.  
  23514.  private 
  23515.  
  23516.  A private member of a class is only accessible to member functions and friends 
  23517.  of that class. 
  23518.  
  23519.  protected 
  23520.  
  23521.  A protected member of a class is accessible to member functions and friends of 
  23522.  that class, or member functions and friends of classes derived from that 
  23523.  class. 
  23524.  
  23525.  prototype 
  23526.  
  23527.  See function prototype. 
  23528.  
  23529.  public 
  23530.  
  23531.  A public member of a class is accessible to all functions. 
  23532.  
  23533.  pure virtual function 
  23534.  
  23535.  A virtual function defined with '=0;'. (See also abstract classes.) 
  23536.  
  23537.  
  23538. ΓòÉΓòÉΓòÉ <hidden> Q ΓòÉΓòÉΓòÉ
  23539.  
  23540. qualified class name 
  23541.  
  23542. Any class name qualified with one or more :: (scope resolution) operators. 
  23543.  
  23544. qualified name 
  23545.  
  23546. Used to qualify a nonclass type name such as a member by its class name. 
  23547.  
  23548. qualified type name 
  23549.  
  23550. Used to reduce complex class name syntax by using typedefs to represent 
  23551. qualified class names. 
  23552.  
  23553.  
  23554. ΓòÉΓòÉΓòÉ <hidden> R ΓòÉΓòÉΓòÉ
  23555.  
  23556. register 
  23557.  
  23558. A storage area commonly associated with fast-access storage, capable of storing 
  23559. a specified amount of data such as a bit or an address. 
  23560.  
  23561. register variable 
  23562.  
  23563. A variable defined with the register storage class specifier. Register 
  23564. variables have automatic storage. 
  23565.  
  23566.  
  23567. ΓòÉΓòÉΓòÉ <hidden> S ΓòÉΓòÉΓòÉ
  23568.  
  23569. scalar 
  23570.  
  23571. An arithmetic object, or a pointer, or a reference to an object of any type. 
  23572.  
  23573. scope 
  23574.  
  23575. That part of a source program in which a variable is visible. 
  23576.  
  23577. scope resolution operator (::) 
  23578.  
  23579. Defines the scope for the right argument. If the left argument is blank, the 
  23580. scope is global. If the left argument is a class name, then the scope is within 
  23581. that class. Also called the scope resolution operator. 
  23582.  
  23583. single-byte character set 
  23584.  
  23585. A set of characters in which each character is represented by 1 byte of 
  23586. storage. 
  23587.  
  23588. single precision 
  23589.  
  23590. Pertaining to the use of one computer word to represent a number, in accordance 
  23591. with the required precision. 
  23592.  
  23593. SOM 
  23594.  
  23595. See System Object Model 
  23596.  
  23597. source program 
  23598.  
  23599. A set of instructions written in a programming language that must be translated 
  23600. to machine language before the program can be run. 
  23601.  
  23602. specifiers 
  23603.  
  23604. Used in declarations to indicate storage class, fundamental data type and other 
  23605. properties of the object or function being declared. 
  23606.  
  23607. statement 
  23608.  
  23609. An instruction that ends with a semicolon (;) or one or more instructions 
  23610. enclosed in braces ({}). 
  23611.  
  23612. static 
  23613.  
  23614. A keyword used for defining the scope and linkage of variables and functions. 
  23615. For internal variables, the variable has block scope and retains its value 
  23616. between function calls. For external values, the variable has file scope and 
  23617. retains its value within the source file. For class variables, the variable is 
  23618. shared by all objects of the class and retains its value within the entire 
  23619. program. 
  23620.  
  23621. static binding 
  23622.  
  23623. Binding that occurs at compilation time based on the resolution of overloaded 
  23624. functions. 
  23625.  
  23626. storage class specifier 
  23627.  
  23628. One of: auto, register, static, or extern. 
  23629.  
  23630. stream buffer 
  23631.  
  23632. A stream buffer is a buffer between the ultimate consumer and the I/O Stream 
  23633. Library functions that format data. It is implemented in the I/O Stream Library 
  23634. by the streambuf class and the classes derived from streambuf. 
  23635.  
  23636. string literal 
  23637.  
  23638. Zero or more characters enclosed in double quotation marks. 
  23639.  
  23640. structure 
  23641.  
  23642. A class data type that contains an ordered group of data objects and member 
  23643. functions. Unlike an array, the data objects within a structure can have varied 
  23644. data types. A structure can be used in all places a class is used. The initial 
  23645. projection is public. 
  23646.  
  23647. structure tag 
  23648.  
  23649. The identifier that names a structure data type. 
  23650.  
  23651. subscript 
  23652.  
  23653. One or more expressions, each enclosed in brackets, that follow an array name. 
  23654. A subscript refers to an element in an array. 
  23655.  
  23656. switch expression 
  23657.  
  23658. The controlling expression of a switch statement. 
  23659.  
  23660. switch statement 
  23661.  
  23662. A C or C++ language statement that causes control to be transferred to one of 
  23663. several statements depending on the value of an expression. 
  23664.  
  23665. System Object Model (SOM) 
  23666.  
  23667. An object-oriented software model that provides a common programming interface 
  23668. for building and using objects.  SOM-compliant class definitions can be created 
  23669. in one language, and objects of those classes can be used by client programs 
  23670. written in another language.  SOM also enables upward binary compatibility of 
  23671. object libraries without requiring client programs to be recompiled. 
  23672.  
  23673.  
  23674. ΓòÉΓòÉΓòÉ <hidden> T ΓòÉΓòÉΓòÉ
  23675.  
  23676. template 
  23677.  
  23678. A family of classes or functions with variable types. 
  23679.  
  23680. template class 
  23681.  
  23682. A class instance generated by a class template. 
  23683.  
  23684. template function 
  23685.  
  23686. A function generated by a function template. 
  23687.  
  23688. this 
  23689.  
  23690. A keyword that identifies a special type of pointer that references in a member 
  23691. function the class object with which the member function was invoked. 
  23692.  
  23693. throw expression 
  23694.  
  23695. An argument to the exception being thrown. 
  23696.  
  23697. token 
  23698.  
  23699. The smallest independent unit of meaning of a program as defined either by a 
  23700. parser or a lexical analyzer. A token can contain data, a language keyword, an 
  23701. identifier, or other parts of language syntax. 
  23702.  
  23703. trigraph sequence 
  23704.  
  23705. A combination of three keystrokes used to represent unavailable characters in a 
  23706. C or C++ source program. Before preprocessing, each trigraph sequence in a 
  23707. string or a literal is replaced by the single character that it represents. 
  23708.  
  23709. try block 
  23710.  
  23711. A block in which a known exception is passed to a handler. 
  23712.  
  23713. type 
  23714.  
  23715. The description of the data and the operations that can be performed on or by 
  23716. the data. 
  23717.  
  23718. type balancing 
  23719.  
  23720. A conversion that makes both operands have the same data type. If the operands 
  23721. do not have the same size data type, the compiler converts the value of the 
  23722. operand with the smaller type to a value having the larger type. 
  23723.  
  23724. type conversion 
  23725.  
  23726. See boundary alignment. 
  23727.  
  23728. type definition 
  23729.  
  23730. A definition of a data type. 
  23731.  
  23732. type specifier 
  23733.  
  23734. Used to indicate the data type of an object or function being declared. 
  23735.  
  23736.  
  23737. ΓòÉΓòÉΓòÉ <hidden> U ΓòÉΓòÉΓòÉ
  23738.  
  23739. unary expression 
  23740.  
  23741. An expression that contains one operand. 
  23742.  
  23743. union 
  23744.  
  23745. A variable that can hold any one of several data types, but only one data type 
  23746. at a time. 
  23747.  
  23748. union tag 
  23749.  
  23750. The identifier that names a union data type. 
  23751.  
  23752.  
  23753. ΓòÉΓòÉΓòÉ <hidden> V ΓòÉΓòÉΓòÉ
  23754.  
  23755. variable 
  23756.  
  23757. An object that can take different values at different times. 
  23758.  
  23759. virtual function 
  23760.  
  23761. A function of a class, declared with the keyword virtual. The implementation 
  23762. that is executed when you make a call to a virtual function depends on the type 
  23763. of the pointer or reference through which the member function is applied. This 
  23764. is determined at run time. 
  23765.  
  23766. visible 
  23767.  
  23768. Visibility of identifiers is based on scoping rules and is independent of 
  23769. access. 
  23770.  
  23771.  
  23772. ΓòÉΓòÉΓòÉ <hidden> W ΓòÉΓòÉΓòÉ
  23773.  
  23774. while statement 
  23775.  
  23776. A looping statement that contains the word while followed by an expression in 
  23777. parentheses (the condition) and a statement (the action). 
  23778.  
  23779. white space 
  23780.  
  23781. Space characters, tab characters, form feed characters, new-line characters, 
  23782. and (when referring to source code) comments. 
  23783.  
  23784.  
  23785. ΓòÉΓòÉΓòÉ <hidden> Z ΓòÉΓòÉΓòÉ
  23786.  
  23787. zero suppression 
  23788.  
  23789. The removal of, or substitution of blanks for, leading zeros in a number. For 
  23790. example, 00057 becomes 57 when using zero suppression.