Ada Programming
Ada Programming
Wikibooks.org
On the 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. An URI to this license is given in the list of gures on page 397. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatible license, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 393. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 399, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the gures are given in the list of A A gures on page 397. This PDF was generated by the L TEX typesetting software. The L TEX source code is included as an attachment (source.7z.txt) in this PDF le. To extract the source from the PDF le, we recommend the use of http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility or clicking the paper clip attachment symbol on the lower left of your PDF Viewer, selecting Save Attachment. After extracting it from the PDF le you have to rename it to source.7z. To A uncompress the resulting archive we recommend the use of http://www.7-zip.org/. The L TEX source itself was generated by a program written by Dirk Hnniger, which is freely available under an open source license from http://de.wikibooks.org/wiki/Benutzer:Dirk_Huenniger/wb2pdf. This distribution also contains a congured version of the pdflatex compiler with all necessary A packages and fonts needed to compile the L TEX source included in this PDF le.
Contents
1 Basic Ada 1.1 "Hello, world!"programs . . . . . . . . 1.2 Compiling the "Hello, world!"program 1.3 Things to look out for . . . . . . . . . 1.4 Where to ask for help . . . . . . . . . 1.5 Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 5 6 8 8 9 9 9 10 10 25 25 25 26 26 27 27 27 28 29 29 33 36 37 37 39 41 44 45 45 47 50 50
Installing 2.1 AdaMagic from SofCheck . . . . . . . . . . . . . 2.2 AdaMULTI from Green Hills Software . . . . . . 2.3 DEC Ada from HP . . . . . . . . . . . . . . . . . 2.4 GNAT, the GNU Ada Compiler from AdaCore Foundation . . . . . . . . . . . . . . . . . . . . . 2.5 ICC from Irvine Compiler Corporation . . . . . . 2.6 Janus/Ada 83 and 95 from RR Software . . . . . 2.7 MAXAda from Concurrent . . . . . . . . . . . . . 2.8 ObjectAda from Atego (formerly Aonix) . . . . . 2.9 PowerAda from OC Systems . . . . . . . . . . . . 26section.2.10 2.11 SCORE from DDC-I . . . . . . . . . . . . . . . . 2.12 XD Ada from SWEP-EDS . . . . . . . . . . . . . 2.13 XGC Ada from XGC Software . . . . . . . . . . . 2.14 References . . . . . . . . . . . . . . . . . . . . . . 3
. . . . . . . . . and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Building 3.1 Building with various compilers . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Compiling our Demo Source . . . . . . . . . . . . . . . . . . . . . . . . . . 3.3 External links . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Control Statements 4.1 Conditionals . . 4.2 Unconditionals 4.3 Loops . . . . . 4.4 See also . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
Type System 5.1 Predened types . . 5.2 The Type Hierarchy 5.3 Concurrency Types . 5.4 Limited Types . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
III
Contents 5.5 5.6 5.7 5.8 5.9 5.10 5.11 6 Dening new types and subtypes . . . . . Subtype categories . . . . . . . . . . . . . Qualied expressions . . . . . . . . . . . . Type conversions . . . . . . . . . . . . . . Elaborated Discussion of Types for Signed Relations between types . . . . . . . . . . See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Integer Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 54 57 58 65 67 67 69 69 70 71 71 72 73 73 74 75 76 77 77 77 79 79 79 80 80 82 83 83 87 88 91 91 91 91 93 93 95 95 96 96 97
Integer types 6.1 Working demo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unsigned integer types 7.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Enumerations 8.1 Operators and attributes 8.2 Enumeration literals . . 8.3 Enumeration subtypes . 8.4 See also . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
10 Fixed point types 10.1 Description . . . . . . . . . . . . 10.2 Ordinary Fixed Point . . . . . . . 10.3 Decimal Fixed Point . . . . . . . 10.4 Dierences between Ordinary and 10.5 See also . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . Decimal . . . . .
. . . . . . . . . . . . . . . . . . . . . Fixed Point . . . . . . .
. . . . . . . . . . . . Types . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
11 Arrays 11.1 Declaring arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Using arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Records 12.1 Basic record . . . . . . 12.2 Null record . . . . . . 12.3 Record Values . . . . . 12.4 Discriminated record . 12.5 Variant record . . . . . 12.6 Union . . . . . . . . . 12.7 Tagged record . . . . . 12.8 Abstract tagged record 12.9 With aliased elements 12.10 Limited Records . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
IV
Contents 12.11 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Access types 13.1 What s an Access Type? . . 13.2 Pool access . . . . . . . . . 13.3 General access . . . . . . . . 13.4 Anonymous access . . . . . 13.5 Implicit Dereference . . . . 13.6 Null exclusions . . . . . . . 13.7 Access to Subprogram . . . 13.8 Access FAQ . . . . . . . . . 13.9 Thin and Fat Access Types 13.10 See also . . . . . . . . . . . 14 Limited types 14.1 Limited Types . . . . . . . 14.2 Initialising Limited Types 14.3 See also . . . . . . . . . . 14.4 References . . . . . . . . . 97 99 99 99 102 103 104 105 106 106 109 110 113 113 115 116 117 119 119 120 122 123 125 126 127 129 129 130 131 133 133 134 137 141 145 145 147 147 148 148 149 149 150
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
15 Strings 15.1 Fixed-length string handling . . . . 15.2 Bounded-length string handling . . 15.3 Unbounded-length string handling 15.4 See also . . . . . . . . . . . . . . . 16 Subprograms 16.1 Procedures . . . . 16.2 Functions . . . . . 16.3 Named parameters 16.4 Default parameters 16.5 Renaming . . . . . 16.6 See also . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
17 Packages 17.1 Separate compilation 17.2 Parts of a package . 17.3 Using packages . . . 17.4 Package organisation 17.5 Notes . . . . . . . . . 17.6 See also . . . . . . . 18 Input Output 18.1 Overview . . . 18.2 Text I/O . . . . 18.3 Direct I/O . . . 18.4 Sequential I/O 18.5 Stream I/O . . 18.6 See also . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
Contents 19 Exceptions 19.1 Robustness . . . . . . . . . . . . . . . . . . 19.2 Modules, preconditions and postconditions . 19.3 Predened exceptions . . . . . . . . . . . . . 19.4 Input-output exceptions . . . . . . . . . . . 19.5 Exception declarations . . . . . . . . . . . . 19.6 Raising exceptions . . . . . . . . . . . . . . 19.7 Exception handling and propagation . . . . 19.8 Information about an exception occurrence 19.9 See also . . . . . . . . . . . . . . . . . . . . 20 Generics 20.1 Parametric polymorphism (generic units) 20.2 Generic parameters . . . . . . . . . . . . . 20.3 Instantiating generics . . . . . . . . . . . . 20.4 Advanced generics . . . . . . . . . . . . . 20.5 See also . . . . . . . . . . . . . . . . . . . 21 Tasking 21.1 Tasks . . . . . . . . . . . . . . 21.2 Protected types . . . . . . . . 21.3 Entry families . . . . . . . . . 21.4 Termination . . . . . . . . . . 21.5 Timeout . . . . . . . . . . . . 21.6 Conditional entry calls . . . . 21.7 Requeue statements . . . . . 21.8 Scheduling . . . . . . . . . . . 21.9 Interfaces . . . . . . . . . . . 21.10 See also . . . . . . . . . . . . 21.11 Ada Quality and Style Guide 153 153 153 154 156 156 157 157 158 159 161 161 162 168 168 172 173 173 177 180 180 181 183 183 184 184 184 185 187 187 206 207 217 219 219 222 223 224 227 228
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
22 Object Orientation 22.1 Object orientation in Ada . . . . . . . . . . 22.2 Class names . . . . . . . . . . . . . . . . . . 22.3 Object-Oriented Ada for C++ programmers 22.4 See also . . . . . . . . . . . . . . . . . . . . 23 New 23.1 23.2 23.3 23.4 23.5 23.6 in Ada 2005 Language features . . . . . . . . . . . . Language library . . . . . . . . . . . . Real-Time and High Integrity Systems Summary of what s new . . . . . . . . See also . . . . . . . . . . . . . . . . . External links . . . . . . . . . . . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
VI
Contents 25 Interfacing 25.1 Interfacing . . . . . . . . . . . 25.2 Other programming languages 25.3 Hardware devices . . . . . . . 25.4 See also . . . . . . . . . . . . 26 Coding Standards 26.1 Introduction . . . 26.2 Tools . . . . . . . 26.3 Coding guidelines 26.4 See also . . . . . 26.5 External links . . 27 Tips 27.1 27.2 27.3 27.4 27.5 27.6 27.7 27.8 243 243 243 243 244 245 245 245 246 246 247 249 249 250 250 251 253 253 254 254 255 255 256 256 257 257 258 258
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Full declaration of a type can be deferred to Lambda calculus through generics . . . . . . Compiler Messages . . . . . . . . . . . . . . Universal integers . . . . . . . . . . . . . . . I/O . . . . . . . . . . . . . . . . . . . . . . . Quirks . . . . . . . . . . . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . See also . . . . . . . . . . . . . . . . . . . .
the . . . . . . . . . . . . . .
unit s body . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
. . . . . . . .
28 Common Errors 28.1 pragma Atomic & Volatile 28.2 References . . . . . . . . . 28.3 pragma Pack . . . . . . . 28.4 Bit_Order attribute . . . 28.5 Size attribute . . . . . . . 28.6 See also . . . . . . . . . . 28.7 References . . . . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
. . . . . . .
29 Algorithms 259 29.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 29.2 Chapter 1: Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 29.3 Chapter 6: Dynamic Programming . . . . . . . . . . . . . . . . . . . . . . 261 30 Function overloading 267 30.1 Function overloading in Ada . . . . . . . . . . . . . . . . . . . . . . . . . . 267 30.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 31 Mathematical calculations 31.1 Simple calculations . . . 31.2 Exponential calculations 31.3 Higher math . . . . . . . 31.4 See also . . . . . . . . . 32 Statements 269 269 272 275 280 283
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
VII
Contents 33 Variables 285 33.1 Assignment statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 33.2 Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 33.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 34 Lexical elements 287 34.1 Character set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 34.2 Lexical elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 34.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 35 Keywords 293 35.1 Language summary keywords . . . . . . . . . . . . . . . . . . . . . . . . . 293 35.2 List of keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 35.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 36 Delimiters 36.1 Single character delimiters . . . 36.2 Compound character delimiters 36.3 Others . . . . . . . . . . . . . . 36.4 See also . . . . . . . . . . . . . 37 Operators 37.1 Standard operators . . . . 37.2 Short-circuit control forms 37.3 Membership tests . . . . . 37.4 See also . . . . . . . . . . 297 297 298 299 299 301 301 303 303 304 305 305 305 310 314 315 317 317 317 320 328 329
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
38 Attributes 38.1 Language summary attributes . . . . . . . 38.2 List of language dened attributes . . . . 38.3 List of implementation dened attributes . 38.4 See also . . . . . . . . . . . . . . . . . . . 38.5 References . . . . . . . . . . . . . . . . . . 39 Pragmas 39.1 Description . . . . . . . . . . . . . . . . 39.2 List of language dened pragmas . . . . 39.3 List of implementation dened pragmas 39.4 See also . . . . . . . . . . . . . . . . . . 39.5 References . . . . . . . . . . . . . . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
40 Libraries 331 40.1 Predened Language Libraries . . . . . . . . . . . . . . . . . . . . . . . . . 331 40.2 Other Language Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . 331 40.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 41 Libraries: Standard 333 41.1 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 41.2 Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
VIII
42 Libraries: Ada 42.1 List of language dened child units . . . . . . . . . . . . . . . . . . . . . . 42.2 List of implementation dened child units . . . . . . . . . . . . . . . . . . 42.3 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43 Libraries: Interfaces 349 43.1 Child Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 43.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 44 Libraries: System 351
45 Libraries: GNAT 353 45.1 Child packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 45.2 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 46 Libraries: Multi-Purpose 357 46.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 47 Libraries: Container 359 47.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359 48 Libraries: GUI 361 48.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 49 Libraries: Distributed Systems 363 49.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 50 Libraries: Databases 365
51 Libraries: Web 371 51.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 52 Libraries: Input Output 373 52.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 53 Platform Support 375 53.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 54 Platform: Linux 377 54.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 55 Platform: Windows 379 55.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 56 Platform: Virtual Machines 381 56.1 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 57 Portals 383 57.1 Forges of open-source projects . . . . . . . . . . . . . . . . . . . . . . . . . 383
IX
Contents 57.2 57.3 57.4 Directories of freely available tools and libraries . . . . . . . . . . . . . . . 383 Collections of Ada source code . . . . . . . . . . . . . . . . . . . . . . . . 384 See also . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 387 389 393 397
61 Licenses 399 61.1 GNU GENERAL PUBLIC LICENSE . . . . . . . . . . . . . . . . . . . . 399 61.2 GNU Free Documentation License . . . . . . . . . . . . . . . . . . . . . . 400 61.3 GNU Lesser General Public License . . . . . . . . . . . . . . . . . . . . . . 401
1 Basic Ada
1.1 "Hello, world!" programs
1.1.1 "Hello, world!"
A common example of a language s syntax1 is the Hello world program2 . Here is a straightforward Ada Implementation:
File:
hello_world_1.adb
The with statement adds the package Ada.Text_IO to the program. This package comes with every Ada compiler and contains all functionality needed for textual Input/Output. The with statement makes the declarations of Ada.Text_IO available to procedure Hello. This includes the types declared in Ada.Text_IO, the subprograms of Ada.Text_IO and everything else that is declared in Ada.Text_IO for public use. In Ada, packages can be used as toolboxes. Text_IO provides a collection of tools for textual input and output in one easy-to-access module. Here is a partial glimpse at package Ada.Text_IO
package Ada.Text_IO is type F ileT ype is limited private; morestuf f procedure Open(F ile : in out F ileT ype; M ode : F ileM ode; N ame : String ; F orm : String := ); morestuf f procedure P utL ine (Item : String ); morestuf f
1 2
http://en.wikipedia.org/wiki/Syntax_%28programming_languages%29 http://en.wikipedia.org/wiki/Hello_world_program
Basic Ada
Next in the program we declare a main procedure. An Ada main procedure does not need to be called "main". Any simple name is ne so here it is Hello. Compilers might allow procedures or functions to be used as main subprograms. 3 The call on Ada.Text_IO.Put_Line writes the text "Hello World" to the current output le. A with clause makes the content of a package visible by selection: we need to prex the procedure name Put_Line from the Text_IO package with its full package name Ada.Text_IO. If you need procedures from a package more often some form of shortcut is needed. There are two options open:
File:
hello_world_2.adb
with Ada.Text_IO procedure Hello is package IO renames Ada.Text_IO; begin IO.Put_Line("Hello, world!"); IO.New_Line; IO.Put_Line("I am an Ada program with package rename."); end Hello;
Main subprograms may even have parameters; it is implementation-dened what kinds of subprograms can be used as main subprograms. The reference manual explains the details in 10.2 LRM 10.2(29) {http://www.adaic.org/resources/add_content/standards/05rm/html/RM-10-2.html} : . . . , an implementation is required to support all main subprograms that are public parameterless library procedures. Library means not nested in another subprogram, for example, and other things that needn t concern us now. renames can also be used for procedures, functions, variables, array elements. It can not be used for types - a type rename can be accomplished with subtype.
File:
hello_world_3.adb
with Ada.Text_IOuse Ada.Text_IO; procedure Hello is begin Put_Line("Hello, world!"); New_Line; Put_Line("I am an Ada program with package use."); end Hello;
use can be used for packages and in the form of use type for types. use type makes only the operators5 of the given type directly visible but not any other operations on the type.
5 6 7
Basic Ada For comparison the sizes for a plain gnat make compile:
497K 500K 1.5M 589K hello_world_1 (Linux i686) hello_world_1 (Linux x86_64) hello_world_1.exe (Windows_NT i686) hello_world_1.exe (VMS AXP)
Worth mentioning is that hello_world (Ada,C,C++) compiled with GNAT/MSVC 7.1/GCC(C) all produces executables with approximately the same size given comparable optimisation and linker methods.
declare declarations begin statements exception handlers end; procedure P (parameters : in out type) is declarations begin statements
exception handlers end P; function F (parameters : in type) return type is declarations begin statements exception handlers end F; package P is declarations private declarations end P;
Note that semicolons consistently terminate statements and declarations; the empty line (or a semicolon alone) is not a valid statement: the null statement is
null;
Basic Ada Loosely speaking, objects must be of a constrained type, but formal parameters may be of an unconstrained type (they adopt the constraint of any corresponding actual parameter). This solves the problem of array parameters in Pascal (among other things).
1.5 Notes
9 10 11 12 13 14
2 Installing
Ada compilers1 are available from several vendors, on a variety of host and target platforms. The Ada Resource Association2 maintains a list of available compilers3 . Below is an alphabetical list of available compilers with additional comments.
Available from
1 2 3 4 5 6
Installing
Commercial IDE, debugger, TimeMachine, integration with various version control systems, source browsers, other utilities
GHS claims to make great eorts to ensure that their compilers produce the most ecient code and often cites the EEMBC7 benchmark results as evidence, since many of the results published by chip manufacturers use GHS compilers to show their silicon in the best light, although these benchmarks are not Ada specic. GHS has no publicly announced plans to support the new Ada standard published in 2007 but they do continue to actively market and develop their existing Ada products.
2.4 GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation
GNAT12 is the free GNU Ada compiler, which is part of the GNU Compiler Collection13 . It is the only Ada compiler that supports all of the optional annexes of the language standard. The original authors formed the company AdaCore14 to oer professional support, consulting, training and custom development services. It is thus possible to obtain GNAT from many dierent sources, detailed below. GNAT is always licensed under the terms of the GNU General Public License15 . However, the run-time library uses either the GPL16 , or the GNAT Modied GPL17 , depending on where you obtain it.
7 8 9 10 11 12 13 14 15 16 17
http://www.eembc.com http://en.wikipedia.org/wiki/OpenVMS http://h71000.www7.hp.com/commercial/ada/ada_index.html http://h71000.www7.hp.com/commercial/ada/ada_avms_ig.pdf http://h71000.www7.hp.com/commercial/ada/ada_vvms_ig.pdf http://en.wikipedia.org/wiki/GNAT http://en.wikipedia.org/wiki/GNU_Compiler_Collection http://www.adacore.com http://en.wikipedia.org/wiki/GNU%20General%20Public%20License http://en.wikipedia.org/wiki/GNU%20General%20Public%20License http://en.wikipedia.org/wiki/GNAT%20Modified%20General%20Public%20License
10
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation Several optional add-ons are available from various places: ASIS, the Ada Semantic Interface Specication18 , is a library that allows Ada programs to examine and manipulate other Ada programs. FLORIST19 is a library that provides a POSIX programming interface to the operating system. GDB, the GNU Debugger, with Ada extensions. GLADE implements Annex E, the Distributed Systems Annex. With it, one can write distributed programs in Ada, where partitions of the program running on dierent computers communicate over the network with one another and with shared objects. GPS, the GNAT Programming Studio, is a full-featured integrated development environment, written in Ada. It allows you to code in Ada, C and C++. Many Free Software libraries are also available.
11
Installing GNAT 3.15p This is the last public release of GNAT from AdaCore that uses the GNAT Modied General Public License20 . GNAT 3.15p has passed the Ada Conformity Assessment Test Suite21 (ACATS22 ). It was released in October 2002. The binary distribution from AdaCore also contains an Ada-aware version of the GNU Debugger (GDB23 ), and a graphical front-end to GDB called the GNU Visual Debugger (GVD). Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Available from Support Add-ons included Ada 83, Ada 95, C GNAT-modied GPL GNU/Linux on i386 (with glibc 2.1 or later), Microsoft Windows on i386, OS/2 2.0 or later on i386, Solaris 2.5 or later on SPARC none GCC 2.8.1 ftp://ftp.cs.kuleuven.ac.be/pub/AdaBelgium/mirrors/gnu-ada/3.15p/ None ASIS, Florist, GLADE, GDB, Gnatwin (on Windows only), GtkAda 1.2, GVD
GNAT Pro GNAT Pro is the professional version of GNAT, oered as a subscription package by AdaCore. The package also includes professional consulting, training and maintenance services. AdaCore can provide custom versions of the compiler for native or cross development. For more information, see http://www.adacore.com/. Languages supported License for the run-time library Native platforms Cross platforms Ada 83, Ada 95, Ada 2005, Ada 2012, C, and optionally C++ GNAT-modied GPL many, see http://www.adacore.com/home/ products/gnatpro/supported_platforms/ many, see http://www.adacore.com/home/ products/gnatpro/supported_platforms/; even more on request
20 21 22 23
12
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation
GCC 4.3 http://www.adacore.com/ by subscription (commercial) Commercial; customer-only bug database ASIS, Florist, GDB, GLADE, GPS, GtkAda, XML/Ada, and many more in source and, on request, binary form.
GCC GNAT has been part of the Free Software Foundation24 s GCC25 since October 2001. The Free Software Foundation does not distribute binaries, only sources. Its licensing of the run-time library for Ada (and other languages) allows the development of proprietary software without necessarily imposing the terms of the GPL26 . Most GNU/Linux distributions and several distributions for other platforms include prebuilt binaries; see below. For technical reasons, we recommend against using the Ada compilers included in GCC 3.1, 3.2, 3.3 and 4.0. Instead, we recommend using GCC 3.4, 4.1 or later, or one of the releases from AdaCore27 (3.15p, GPL Edition or Pro). Since October 2003, AdaCore merge most of their changes from GNAT Pro into GCC during Stage 128 ; this happens once for each major release. Since GCC 3.4, AdaCore has gradually added support for revised language standards, rst Ada 2005 and now Ada 2012. GCC version 4.4 switched to version 3 of the GNU General Public License29 and grants a Runtime Library Exception30 similar in spirit to the GNAT Modied General Public License31 used in all previous versions. This Runtime Library Exception applies to run-time libraries for all languages, not just Ada. As of GCC 4.7, released on 2012-03-22: Languages supported License for the run-time library Native platforms
24 25 26 27 28 29 30 31 32 33
Ada 83, Ada 95, Ada 2005, parts of Ada 2012, C, C++, Fortran 95, Java, Objective-C, ObjectiveC++ (and others) GPL version 332 with Runtime Library Exception33 none (source only)
http://www.fsf.org/ http://gcc.gnu.org/ http://en.wikipedia.org/wiki/GNU%20General%20Public%20License http://www.adacore.com http://gcc.gnu.org/develop.html#stage1 http://www.gnu.org/licenses/gpl.html http://www.gnu.org/licenses/gcc-exception.html http://en.wikipedia.org/wiki/GNAT%20Modified%20General%20Public%20License http://www.gnu.org/licenses/gpl.html http://www.gnu.org/licenses/gcc-exception.html
13
Installing
none (source only) GCC 4.7 http://gcc.gnu.org/ in source only form. Volunteer; public bug database none
Sourceforge40 Volunteer; public bug database AdaBrowse, ASIS, Booch Components, Charles, GPS, GtkAda (more?)
http://gnuada.sourceforge.net http://ada.krischik.com/index.php/Articles/CompileGNAT http://forward-in-code.blogspot.com/2011/11/building-gcc-again.html http://en.wikipedia.org/wiki/GNU%20General%20Public%20License http://en.wikipedia.org/wiki/GNAT%20Modified%20General%20Public%20License http://www.gnu.org/licenses/gcc-exception.html http://sourceforge.net/projects/gnuada/files/ Chapter 2.4.1 on page 11 Chapter 2.4.2 on page 12
14
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation A# is a port of Ada to the .NET Platform43 . A# was originally developed at the Department of Computer Science at the United States Air Force Academy which distribute A# as a service to the Ada community under the terms of the GNU general public license. A# integrates well with Microsoft Visual Studio 2005, AdaGIDE and the RAPID open-source GUI Design tool. As of 2006-06-06: Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Available from Support Add-ons included Ada 83, Ada 95, C pure GPL Microsoft .NET none GCC 3.4 (GNAT GPL 2006 Edition?) http://sourceforge.net/projects/asharp/ None (but see GNAT Pro) none.
43 44 45 46
15
Installing
Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Available from Support Add-ons included
Ada 83, Ada 95, Ada 2005, C pure GPL none GNU/Linux on i686 to LEON2 bare boards GCC 4.1 (GNAT GPL 2007 Edition) http://www.dit.upm.es/ork/ ? OpenRavenscar real-time kernel; minimal runtime library
16
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation
Native platforms Cross platforms Compiler back-end Available from Support Add-ons included
Microsoft Windows on i386 none GCC 2.8.1 http://www.ada-france.org/ AIDE/ftp://ftp.cs.kuleuven.ac.be/pub/AdaBelgium/mirrors/aide/ ? ASIS, GDB, GPS, GtkAda (more?)
Blastwave (for Solaris on SPARC and x86) Blastwave54 has binary packages of GCC 3.4.5 and 4.0.2 with Ada support. The package names are gcc3ada and gcc4ada respectively. Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Support Available from Add-ons included Ada 83, Ada 95, parts of Ada 2005, C, C++, Fortran 95, Java, Objective-C, Objective-C++ GNAT-modied GPL Solaris and OpenSolaris on SPARC none GCC 3.4.5 and 4.0.2 (both available) ? http://www.blastwave.org/ none (?)
OpenCSW (for Solaris on SPARC and x86) OpenCSW55 has binary packages of GCC 3.4.6 and 4.6.2 with Ada support. The package names are gcc3ada and gcc4ada respectively. Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Support Available from Add-ons included
54 55
Ada 83, Ada 95, parts of Ada 2005, C, C++, Fortran 95, Java, Objective-C, Objective-C++ GNAT-modied GPL Oracle Solaris and OpenSolaris on SPARC and x86 none GCC 3.4.6 and 4.6.2 (both available) ? http://www.opencsw.org/ none (?)
http://www.blastwave.org http://www.opencsw.org
17
Installing Cygwin (for Microsoft Windows) Cygwin56 , the Linux-like environment for Windows, also contains a version of the GNAT57 compiler. The Cygwin58 version of GNAT59 is older than the MinGW60 version and does not support DLLs and Multi-Threading (as of 11.2004). Debian (GNU/Linux and GNU/kFreeBSD) There is a Debian Policy for Ada61 which tries to make Debian the best Ada development and deployment platform. The development platform includes the compiler and many libraries, pre-packaged and integrated so as to be easy to use in any program. The deployment platform is the renowned stable62 distribution, which is suitable for mission-critical workloads and enjoys long life cycles, typically 3 to 4 years. Because Debian is a binary distribution, it is possible to deploy non-free, binary-only programs on it while enjoying all the benets of a stable platform. Compiler choices are conservative for this reason, and the Policy mandates that all Ada programs and libraries be compiled with the same version of GNAT. This makes it possible to use all libraries in the same program. Debian separates run-time libraries from development packages, so that end users do not have to install the development system just to run a program. The GNU Ada compiler can be installed on a Debian system with this command:
aptitude install gnat
This will also give you a list of related packages, which are likely to be useful for an Ada programmer. Debian is unique in that it also allows programmers to use some of GNAT s internal components by means of two libraries: libgnatvsn (licensed under GNAT-Modied GPL) and libgnatprj (the project manager, licensed under pure GPL). Debian packages make use of these libraries. In the table below, the information about the future Debian 7.0 Wheezy is accurate as of July 2012 but may change.
56 57 58 59 60 61 62
18
3.1 Sarge 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy June 2005 April 2007 February 2009 February 2011 2013? Ada 83, Ada 95, Ada 83, Ada 95, Ada 2005, parts of Ada 2012, C, C++, Fortran 95, Java, C Objective-C, Objective-C++ GNAT-modied GPL (both ZCX and SJLJ versions GPL version 3 with Run-time starting from 5.0 Lenny) library exception 3.1 Sarge yes yes yes preliminary yes yes yes 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy
yes
yes yes yes yes yes yes yes yes yes yes
preliminary yes yes yes yes yes yes yes yes yes yes
Release date Languages supported License for the run-time library Native platforms: alpha amd64 armel armhf hppa hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc ppc64 s390 sparc Cross platforms Compiler back-end Available from GCC 4.3 GCC 4.4 GCC 4.6 http://www.debian.org/
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation
19
20 3.1 Sarge 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy Volunteer; public bug database; paid support available from third parties; public mailing list63 3.1 Sarge 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy 1995 0.7.2 4.0.2 1.6 4.0.2 1.6 1.6r8 4.0.2 1.6 1.9r4 1995 1995 2005 2012 4.0.3 1.6 1.12r3 3.0 1.8.8 1.7 0.3 4.0.3 1.6 1.12r3 3.2 1.8.10 2.1 0.4.1 0.1 2010 1.03 2.10.2 2011 1.8.4.7 1.8.4.7 1.8.4.7 1.2 0.1 3.15p 1.01 2.0 2005-02-17 3.15p 2005 2007 2008 1.03 1.03 1.03 2.2 2.5 prerelease 2.7 (superseded by Ada.Containers in gnat) 2006 2006 2009
Installing
Release date Languages supported License for the run-time library Native platforms: Support Add-ons included ada-referencemanual AdaBindX AdaBrowse AdaCGI AdaControl APQ (with PostgreSQL) AdaSockets Ahven Alog anet ASIS AUnit AWS Charles Florist
3.1 Sarge 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy June 2005 April 2007 February 2009 February 2011 2013? Ada 83, Ada 95, Ada 83, Ada 95, Ada 2005, parts of Ada 2012, C, C++, Fortran 95, Java, C Objective-C, Objective-C++ GNAT-modied GPL (both ZCX and SJLJ versions GPL version 3 with Run-time starting from 5.0 Lenny) library exception
63
http://lists.debian.org/debian-ada
3.1 Sarge 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy June 2005 April 2007 February 2009 February 2011 2013? Ada 83, Ada 95, Ada 83, Ada 95, Ada 2005, parts of Ada 2012, C, C++, Fortran 95, Java, C Objective-C, Objective-C++ GNAT-modied GPL (both ZCX and SJLJ versions GPL version 3 with Run-time starting from 5.0 Lenny) library exception 3.1 Sarge 5.3 3.15p 1.5.1 1999-05-19 2.1 2.4 4.0.1 2.8.1 4.0.1 2.8.1 1.6.1 1.6.1 (superseded by AdaControl) 6.4 2006 6.8 7.0.1 (see PolyORB) 0.0.20091124 1.6.2 7.4.1 0.0.20120331 1.6.2 2011 5.0 2.24.0 1.2 4.0 Etch 5.0 Lenny 6.0 Squeeze 7.0 Wheezy
3.0b
3.0b
3.0b
Release date Languages supported License for the run-time library Native platforms: GDB GLADE GMPAda GNADE GNAT Checker GPRBuild GPS GtkAda Log4Ada Narval OpenToken PC/SC Ada PolyORB PLPlot Templates Parser TextTools XML/Ada XML-EZ-out 1.3.0w 4.3 2.14.2 1.0 1.10.2 4.0b 0.6 2.6 prerelease 5.9.5 11.5 2.0.6 3.2 1.06 4.0b 0.7.1 2.8 prerelease 5.9.5 11.6 4.1 1.06.1
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation
21
Installing The ADT plugin for Eclipse (see section ObjectAda from Aonix64 ) can be used with GNAT as packaged for Debian Etch. Specify "/usr" as the toolchain path. DJGPP (for MS-DOS) DJGPP has GNAT65 as part of their GCC66 distribution. DJGPP67 is a port of a comprehensive collection of GNU utilities to MS-DOS with 32-bit extensions, and is actively supported (as of 1.2005). It includes the whole GCC68 compiler collection, that now includes Ada. See the DJGPP69 website for installation instructions. DJGPP programs run also in a DOS command box in Windows, as well as in native MS-DOS systems. FreeBSD FreeBSD70 s ports collection71 contains GNAT GPL 2006 Edition (package gnat-2006), GNAT 3.15p, GCC 4.1, 4.2 and 4.3 with support for Ada. The usual way to install a package on FreeBSD is to compile it from source; not all add-ons are compatible with all versions of GNAT provided. You can also use the Debian packages described above in a jail, thanks to Debian GNU/kFreeBSD. As of 2008-11-10: Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Available from Support Add-ons included Ada 83, Ada 95, parts of Ada 2005, C both pure and modied GPL available FreeBSD on i386 (more?) none GCC 2.8.1, 3.4, 4.1, 4.2, 4.3 http://www.freebsd.org Volunteer; public bug database AdaBindX, AdaCurses, AdaSDL, AdaSockets, AFlex+AYACC, ASIS, AUnit, Booch Components, CBind, Florist, GLADE, GtkAda, SGL, XML/Ada (more?)
64 65 66 67 68 69 70 71
Chapter 2.4.8 on page 24 http://en.wikipedia.org/wiki/GNAT http://en.wikipedia.org/wiki/GCC http://www.delorie.com/djgpp/ http://en.wikipedia.org/wiki/GCC http://www.delorie.com/djgpp/ http://www.freebsd.org http://www.freebsd.org/ports
22
GNAT, the GNU Ada Compiler from AdaCore and the Free Software Foundation Gentoo GNU/Linux The GNU Ada compiler can be installed on a Gentoo system using emerge:
emerge dev-lang/gnat
In contrast to Debian, Gentoo is primarily a source distribution, so many packages are available only in source form, and require the user to recompile them (using emerge). Also in contrast to Debian, Gentoo supports several versions of GNAT in parallel on the same system. Be careful, because not all add-ons and libraries are available with all versions of GNAT. Languages supported License for the run-time library Native platforms Cross platforms Compiler back-end Available from Support Add-ons included Ada 83, Ada 95, Ada 2005, C (more?) pure or GNAT-modied GPL (both available) Gentoo GNU/Linux on amd64, powerpc and i386 none GCC 3.4, 4.1 (various binary packages) http://www.gentoo.org/ (see other Gentoo dev-ada72 packages) Volunteer; public bug database AdaBindX, AdaBroker, AdaDoc, AdaOpenGL, AdaSockets, ASIS, AUnit, Booch Components, CBind, Charles, Florist, GLADE, GPS, GtkAda, XML/Ada
Mandriva Linux The GNU Ada compiler can be installed on a Mandriva system with this command:
urpmi gnat
MinGW (for Microsoft Windows) MinGW Minimalist GNU for Windows73 contains a version of the GNAT compiler. The current version of MinGW (5.1.6) contains gcc-4.5.0. This includes a fully functional GNAT compiler. If the automatic downloader does not work correctly you can download the compiler directly: pick gcc-4.5.0-1 from MinGW/BaseSystem/GCC/Version4/
72 73
http://es.znurt.org/dev-ada http://mingw.sourceforge.net
23
Installing old instructions The following list should help you with the installation. (I may have forgotten something but this is wiki, just add to the list) 1. Install MinGW-3.1.0-1.exe a) extract binutils-2.15.91-20040904-1.tar.gz b) extract mingw-runtime-3.5.tar.gz c) extract gcc-core-3.4.2-20040916-1.tar.gz d) extract gcc-ada-3.4.2-20040916-1.tar.gz e) extract gcc-g++-3.4.2-20040916-1.tar.gz (Optional) f) extract gcc-g77-3.4.2-20040916-1.tar.gz (Optional) g) extract gcc-java-3.4.2-20040916-1.tar.gz (Optional) h) extract gcc-objc-3.4.2-20040916-1.tar.gz (Optional) i) extract w32api-3.1.tar.gz 2. Install mingw32-make-3.80.0-3.exe (Optional) 3. Install gdb-5.2.1-1.exe (Optional) 4. Install MSYS-1.0.10.exe (Optional) 5. Install msysDTK-1.0.1.exe (Optional) a) extract msys-automake-1.8.2.tar.bz2 (Optional) b) extract msys-autoconf-2.59.tar.bz2 (Optional) c) extract msys-libtool-1.5.tar.bz2 (Optional) I have made good experience in using D:\MinGW as target directory for all installations and extractions. Also noteworthy is that the Windows version for GNAT from Libre is also based on MinGW. In gcc-3.4.2-release_notes.txt from MinGW site reads: please check that the les in the /lib/gcc/mingw32/3.4.2/adainclude and adalib directories are agged as read-only. This attribute is necessary to prevent them from being deleted when using gnatclean to clean a project. So be sure to do this. SuSE Linux All versions of SuSE Linux have a GNAT compiler included. SuSE versions 9.2 and higher also contains ASIS, Florist and GLADE libraries. The following two packages are needed:
gnat gnat-runtime
For 64 bit system you will need the 32 bit compatibility packages as well:
24
gnat-32bit gnat-runtime-32bit
Ubuntu Ubuntu (and derivatives like Kubuntu, Xubuntu...) is a Debian-based Linux distribution, thus the installation process described above74 can be used. Graphical package managers like Synaptic or Adept can also be employed to select the Ada packages.
74 75 76 77 78
25
Installing
79 80 81 82 83 84 85 86 87 88 89 90 91
http://www.atego.com/ http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FPOSIX http://www.atego.com/pressreleases/pressitem/aonix-shatters-ada-price-barrier-for-linux http://www.atego.com/support/eval-aonix-objectada/ http://www.aonix.com/adt.html http://www.eclipse.org http://www.eclipse.org/proposals/adt/ http://www.eclipse.org/hibachi/ http://www.ocsystems.com/ http://www.ocsystems.com/prod_powerada.html http://www.ocsystems.com/prod_legacyada.html Atego acquires IBM Rational Apex Ada Developer product family http://www-306.ibm.com/software/awdtools/developer/ada/
26
Commercial, proprietary.
92 93
http://www.ddci.com/ http://www.swep-eds.com/XD%20Ada/Xd%20ada.htm
27
Installing
Cross platforms
Hosts: sun-sparc-solaris, pc-linux2.*; targets are bare boards with ERC3294 , MIL-STD-1750A95 , Motorola 6800096 family or Intel 32-bit97 processors. PowerPC98 and Intel 8018699 targets on request. GCC 2.8.1 http://www.xgc.com/ Commercial Ravenscar-compliant run-time kernels, certied for avionics and space applications; gdb crossdebugger; target simulator.
2.14 References
References
94 95 96 97 98 99
28
3 Building
Ada programs are usually easier to build than programs written in other languages like C or C++, which frequently require a makele. This is because an Ada source le already species the dependencies of its source unit. See the with keyword1 for further details. Building an Ada program is not dened by the Reference Manual, so this process is absolutely dependent on the compiler. Usually the compiler kit includes a make tool which compiles a main program and all its dependencies, and links an executable le.
3.1.1 GNAT
With GNAT3 , you can run this command:
gnat make <your_unit_file>
If the le contains a procedure, gnatmake will generate an executable le with the procedure as main program. Otherwise, e.g. a package, gnatmake will compile the unit and all its dependencies. GNAT command line gnatmake can be written as one word gnatmake or two words gnat make. For a full list of gnat commands just type gnat without any command options. The output will look something like this:
1 2 3
29
Building
GNAT 3.4.3 Copyright 1996-2004 Free Software Foundation, Inc. List of available commands GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT GNAT BIND CHOP CLEAN COMPILE ELIM FIND KRUNCH LINK LIST MAKE NAME PREPROCESS PRETTY STUB XREF gnatbind gnatchop gnatclean gnatmake -c -f -u gnatelim gnatfind gnatkr gnatlink gnatls gnatmake gnatname gnatprep gnatpp gnatstub gnatxref
Commands FIND, LIST, PRETTY, STUB and XREF accept project file switches -vPx, -Pprj and -Xnam=val
For further help on the option just type the command (one word or two words as you like) without any command options. GNAT IDE The GNAT toolchain comes with an IDE4 called GPS5 . You need to download and install it separately. The GPS features a graphical user interface6 . There are also GNAT plugins for Emacs7 ( Ada Mode8 ), KDevelop9 and Vim10 ( Ada Mode11 ) available. Both Emacs and Vim Ada-Mode are maintained by The GNU Ada project12 . GNAT with Xcode Apple s free (gratis) IDE, Xcode, is included with every Macintosh but requires an explicit installation step from DVD-ROM or CD-ROM. It is also downloadable from http:// developer.apple.com/. Xcode uses the GNU Compiler Collection13 and thus supports Ada, GDB14 , etc... and also includes myriad tools for optimizing code which are unique to
4 5 6 7 8 9 10 11 12 13 14
http://en.wikipedia.org/wiki/Integrated%20development%20environment http://en.wikipedia.org/wiki/GNAT%20Programming%20Studio http://en.wikipedia.org/wiki/Graphical%20user%20interface http://en.wikipedia.org/wiki/Emacs http://stephe-leake.org/emacs/ada-mode/emacs-ada-mode.html http://en.wikipedia.org/wiki/KDevelop http://en.wikipedia.org/wiki/Vim%20%28text%20editor%29 http://www.vim.org/scripts/script.php?script_id=1609 http://gnuada.sourceforge.net http://en.wikipedia.org/wiki/GNU%20Compiler%20Collection http://en.wikipedia.org/wiki/GNU%20Debugger
30
the Macintosh platform. However, GNAT must be installed separately as it is (as of 2008) not distributed as part of Xcode. Get the binary and/or sources at http://www.macada.org/, along with numerous tools and bindings including bindings to Apple s Carbon frameworks which allow the development of complete, "real" Mac programs, all in Ada.
31
Building
3.1.3 ObjectAda
ObjectAda is a set of tools for editing, compiling, navigating and debugging programs written in Ada. There are various editions of ObjectAda. With some editions you compile programs for the same platform and operating systems on which you run the tools. These are called native. With others, you can produce programs for dierent operating systems and platforms. One possible platform is the Java virtual machine. These remarks apply to the native Microsoft Windows edition. You can run the translation tools either from the IDE or from the command line. Whether you prefer to work from the IDE, or from the command line, a little bookkeeping is required. This is done by creating a project. Each project consists of a number of source les, and a number of settings like search paths for additional Ada libraries and other dependences. Each project also has at least one target. Typically, there is a debug target, and a release target. The names of the targets indicate their purpose. At one time you compile for debugging, typically during development, at other times you compile with dierent settings, for example when the program is ready for release. Some (all commercial?) editions of ObjectAda permit a Java (VM) target.
When creating a library you already set some constraints like support for Long_Float or the available memory size. So carefully read
HELP ACS Library Create *
Then next step is to load your Ada sources into the library:
ACS Load [Source]*.ada
The sources don t need to be perfect at this stage but syntactically correct enough for the compiler to determine the packages declared and analyze the with statements. Dec Ada allows you to have more than one package in one source le and you have any lename
15 16 http://en.wikipedia.org/wiki/OpenVMS http://h71000.www7.hp.com/commercial/ada/ada_index.html
32
convention you like. The purpose of ACS Load is the creation of the dependency tree between the source les. Next you compile them:
ACS Compile *
Note that compile take the package name and not the lename. The wildcard * means all packages loaded. The compiler automatically determines the right order for the compilation so a make17 tool is not strictly needed. Last but not least you link your le into an
ACS Link /Executable=[Executables]Main.exe Main
On large systems you might want to break sources down into several libraries in which case you also need
ACS Merge /Keep *
to merge the content of the current library with the library higher up the hierarchy. The larger libraries should then be created with:
ACS Library Create /Large
This uses a dierent directory layout more suitable for large libraries. DEC Ada IDE Dec Ada comes without an IDE, however the DEC LSE18 as well as the Ada Mode19 of the Vim text editor20 support DEC Ada.
17 18 19 20 21
33
Building First you need to extract the sources. Use your favorite zip tool22 to achieve that. On extraction a directory with the same name as the lename is created. Beware: WinZip might also create a directory equaling the lename so Windows users need to be careful using the right option otherwise they end up with wikibook-ada-1_2_0.src\wikibook-ada-1_2_0. Once you extracted the les you will nd all sources in wikibook-ada-1_2_0/Source. You could compile them right there. For your convenience we also provide ready made project les for the following IDEs (If you nd a directory for an IDEs not named it might be in the making and not actually work).
3.2.1 GNAT
You will nd multi-target GNAT Project les and a multi-make Makele le in wikibookada-2_0_0/GNAT. For i686 Linux and Windows you can compile any demo using:
gnat make -P project_file
For other target platform it is a bit more dicult since you need to tell the project les which target you want to create. The following options can be used: style ("Debug", "Release") you can dene if you like a debug or release version so you can compare how the options aect size and speed. os ("Linux", "OS2", "Windows_NT", "VMS") choose your operating system. Since there is no Ada 2005 available for OS/2 don t expect all examples to compile. target ("i686", "x86_64", "AXP") choose your CPU "i68623 " is any form of 32bit Intel or AMD CPU, "x86_6424 " is an 64 bit Intel or AMD CPU and if you have an "AXP25 " then you know it. Remember to type all options as they are shown. To compile a debug version on x86-64 Linux you type:
gnat make -P project_file -Xstyle=Debug -Xos=Linux -Xtarget=x86_64
22 23 24 25
34
As said in the beginning there is also a makele available that will automatically determine the target used. So if you have a GNU make you can save yourself a lot of typing by using:
make project
or even use
make all
to make all examples in debug and release in one go. Each compile is stored inside its own directory which is created in the form of wikibook-ada2_0_0/GNAT/OS-Target-Style. Empty directories are provided inside the archive.
3.2.3 ObjectAda
ObjectAda command-line The following describes using the ObjectAda tools for Windows in a console window. Before you can use the ObjectAda tools from the command line, make sure the PATH environment variable lists the directory containing the ObjectAda tools. Something like
set path=%path%;P:\Programs\Aonix\ObjectAda\bin
A le.
minimal
project Hello
can World
File: hello_world_1.adb To build an executable from this source le, follow these steps (assuming the current directory is a fresh one and contains the above mentioned source le):
35
This makes your sources known to the ObjectAda tools. Have a look at the le UNIT.MAP created by adareg in the current directory if you like seeing what is happening under the hood. Compile the source le:
X:\some\directory> adacomp hello_world_1.adb Front end of hello_world_1.adb succeeded with no errors.
Notice that you specify the name of the main unit as argument to adabuild, not the name of the source le. In this case, it is Hello_World_1 as in
procedure Hello_World_1 is
More information about the tools can be found in the user guide Using the command line interface, installed with the ObjectAda tools.
26 27 28 29
36
4 Control Statements
4.1 Conditionals
Conditionals Conditional clauses are blocks of code that will only execute if a particular expression (the condition) is true1 .
4.1.1 if-else
The if-else statement is the simplest of the conditional statements. They are also called branches, as when the program arrives at an if statement during its execution, control will "branch" o into one of two or more "directions". An if-else statement is generally in the following form:
if condition then statement; else other statement; end if;
If the original condition is met, then all the code within the rst statement is executed. The optional else section species an alternative statement that will be executed if the condition is false. Exact syntax will vary between programming languages, but the majority of programming languages (especially procedural2 and structured3 languages) will have some form of if-else conditional statement built-in. The if-else statement can usually be extended to the following form:
if condition then statement; elsif condition then other statement; elsif condition then other statement; ... else another statement; end if;
1 2 3
37
Control Statements Only one statement in the entire block will be executed. This statement will be the rst one with a condition which evaluates to be true. The concept of an if-else-if structure is easier to understand with the aid of an example:
with Ada ; use Ada ; ... type Degrees is new Float range -273.15 .. Float Last; ... Temperature : Degrees; ... if Temperature >= 40.0 then Put_Line ("Wow!"); Put_Line ("It s extremely hot"); elsif Temperature >= 30.0 then Put_Line ("It s hot"); elsif Temperature >= 20.0 then Put_Line ("It s warm"); elsif Temperature >= 10.0 then Put_Line ("It s cool"); elsif Temperature >= 0.0 then Put_Line ("It s cold"); else Put_Line ("It s freezing"); end if;
4 5 6 7 8 9 10
38
4.1.3 case
Often it is necessary to compare one specic variable against several constant expressions. For this kind of conditional expression the case statement exists. For example:
case X is when 1 => Walk_The_Dog; when 5 => Launch_Nuke; when 8 | 10 => Sell_All_Stock; when others => Self_Destruct; end case;
The subtype of X must be a discrete type, i.e. an enumeration or integer type. In Ada, one advantage of the case statement is that the compiler will check the coverage of the choices, that is, all the values of the subtype of variable X must be present or a default branch when others must specify what to do in the remaining cases.
4.2 Unconditionals
Unconditionals Unconditionals let you change the ow of your program without a condition. You should be careful when using unconditionals. Often they make programs dicult to understand. Read Isn t goto evil?11 for more information.
4.2.1 return
End a function and return to the calling procedure or function. For procedures:
return;
For functions:
11
39
Control Statements
return Value;
4.2.2 goto
Goto transfers control to the statement after the label.
goto Label; Dont_Do_Something; << Label>> ...
Isn t goto evil? One often hears that goto is evil and one should avoid using goto. But it is often overlooked that any return which is not the last statement inside a procedure or function is also an unconditional statement a goto in disguise. There is an important dierence though: a return is a forward only use of goto. Exceptions are also a type of goto statement; worse, they need not specify where they are going to! Therefore if you have functions and procedures with more than one return statement you can just as well use goto. When it comes down to readability the following two samples are almost the same:
procedure Use_Return is begin Do_Something; if Test then return; end if; Do_Something_Else; return; end Use_Return; procedure Use_Goto is begin Do_Something; if Test then goto Exit_Use_Goto; end if; Do_Something_Else; << Exit_Use_Goto>> return; end Use_Goto;
Because the use of a goto needs the declaration of a label, the goto is in fact twice as readable than the use of return. So if readability is your concern and not a strict "don t use goto"
40
programming rule then you should rather use goto than multiple returns. Best, of course, is the structured approach where neither goto nor multiple returns are needed:
procedure Use_If is begin Do_Something; if not Test then Do_Something_Else; end if; return; end Use_If;
4.3 Loops
Loops Loops allow you to have a set of statements repeated over and over again.
The loop name (in this case, "Endless_Loop") is an optional feature of Ada. Naming loops is nice for readability but not strictly needed. Loop names are useful though if the program should jump out of an inner loop, see below.
41
Control Statements
In Ada the exit condition can be combined with any other loop statement as well. You can also have more than one exit statement. You can also exit a named outer loop if you have several loops inside each other.
You don t have to declare both type and range as seen in the example. If you leave out the type then the compiler will determine the type by context and leave out the range then the loop will iterate over every valid value for the type given.
12
42
As always with Ada: when "determine by context" gives two or more possible options then an error will be displayed and then you have to name the type to be used. Ada will only do "guess-works" when it is safe to do so. for loop on arrays Another very common situation is the need for a loop which iterates over every element of an array. The following sample code shows you how to achieve this:
Array_Loop : for I in X Range loop X (I) := Get_Next_Element; end loop Array_Loop;
With X being an array. Note: This syntax is mostly used on arrays hence the name but will also work with other types when a full iteration is needed. Unlike other loop counters, the loop counter i, in the for loop statement the value cannot be changed. The following is illegal.
for i in 1 .. 10 loop i := i + 1; end loop;
Also the declaration of the loop counter ceases after the body of the loop. Working Demo The following Demo shows how to iterate over every element of an integer type.
File:
range_1.adb
with Ada ; procedure Range_1 is type Range_Type is range -5 .. 10; package T_IO renames Ada ; package I_IO is new Ada (Range_Type); begin for A in Range_Type loop I_IO.Put (Item => A, Width => 3, Base => 10); if A < Range_Type Last then T_IO.Put (","); else T_IO.New_Line; end if;
43
Control Statements
4.4.1 Wikibook
Ada Programming13
13
http://en.wikibooks.org/wiki/Ada%20Programming
44
5 Type System
Ada s type system allows the programmer to construct powerful abstractions that represent the real world, and to provide valuable information to the compiler, so that the compiler can nd many logic or design errors before they become bugs. It is at the heart of the language, and good Ada programmers learn to use it to great advantage. Four principles govern the type system: Strong typing: types are incompatible with one another, so it is not possible to mix apples and oranges. There are, however, ways to convert between types. Static typing: type checked while compiling, this allows type errors to be found earlier. Abstraction: types represent the real world or the problem at hand; not how the computer represents the data internally. There are ways to specify exactly how a type must be represented at the bit level, but we will defer that discussion to another chapter. Name equivalence, as opposed to structural equivalence used in most other languages. Two types are compatible if and only if they have the same name; not if they just happen to have the same size or bit representation. You can thus declare two integer types with the same ranges that are totally incompatible, or two record types with exactly the same components, but which are incompatible. Types are incompatible with one another. However, each type can have any number of subtypes, which are compatible with one another, and with their base type.
45
Type System most of the time you would dene your own oating-point types, and specify your precision and range requirements. Duration A xed point type1 used for timing. It represents a period of time in seconds (RM A.1 (43) {http://www.adaic.org/resources/add_content/standards/ 05rm/html/RM-A-1.html} ). Character A special form of Enumerations2 . There are three predened kinds of character types: 8-bit characters (called Character), 16-bit characters (called Wide_Character), and 32-bit characters (Wide_Wide_Character). Character has been present since the rst version of the language (Ada 833 ), Wide_Character was added in Ada 954 , while the type Wide_Wide_Character is available with Ada 20055 . String6 Three indenite array types7 , of Character, Wide_Character, and Wide_Wide_Character respectively. The standard library contains packages for handling strings in three variants: xed length (Ada ), with varying length below a certain upper bound (Ada ), and unbounded length (Ada ). Each of these packages has a Wide_and a Wide_Wide_variant. Boolean A Boolean in Ada is an Enumeration8 of False and True with special semantics. Packages System and System predene some types which are primarily useful for low-level programming and interfacing to hardware. System.Address An address in memory. System.Storage_Elements.Storage_Oset An oset, which can be added to an address to obtain a new address. You can also subtract one address from another to get the oset between them. Together, Address, Storage_Oset and their associated subprograms provide for address arithmetic. System.Storage_Elements.Storage_Count A subtype of Storage_Oset which cannot be negative, and represents the memory size of a data structure (similar to C s size_t). System.Storage_Elements.Storage_Element
1 2 3 4 5 6 7 8
Chapter 10 on page 79 Chapter 8 on page 73 http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%2083 http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%2095 Chapter 23 on page 219 Chapter 15 on page 119 Chapter 11 on page 83 Chapter 8 on page 73
46
In most computers, this is a byte. Formally, it is the smallest unit of memory that has an address. System.Storage_Elements.Storage_Array An array of Storage_Elements without any meaning, useful when doing raw memory access.
Figure 1
47
Type System Here is a broad overview of each category of types; please follow the links for detailed explanations. Inside parenthesis there are equivalences in C and Pascal for readers familiar with those languages. Signed Integers10 (int, INTEGER) Signed Integers are dened via the range11 of values needed. Unsigned Integers12 (unsigned, CARDINAL) Unsigned Integers are called Modular Types13 . Apart from being unsigned they also have wrap-around functionality. Enumerations14 (enum, char, bool, BOOLEAN) Ada Enumeration15 types are a separate type family. Floating point16 (oat, double, REAL) Floating point types are dened by the digits17 needed, the relative error bound. Ordinary and Decimal Fixed Point18 (DECIMAL) Fixed point types are dened by their delta19 , the absolute error bound. Arrays20 ( [ ], ARRAY [ ] OF, STRING ) Arrays with both compile-time and run-time determined size are supported. Record21 (struct, class, RECORD OF) A record is a composite type22 that groups one or more elds. Access23 (*, , POINTER TO) Ada s Access24 types may be more than just a simple memory address. Task & Protected25 (no equivalence in C or Pascal) Task and Protected types allow the control of concurrency Interfaces26 (no equivalence in C or Pascal)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Chapter 6 on page 69 Chapter 6 on page 69 Chapter 7 on page 71 Chapter 7 on page 71 Chapter 8 on page 73 Chapter 8 on page 73 Chapter 9 on page 77 Chapter 9 on page 77 Chapter 10 on page 79 Chapter 10 on page 79 Chapter 11 on page 83 Chapter 12 on page 91 http://en.wikibooks.org/wiki/Ada%20Programming%2FTypes%23List%20of%20types Chapter 13 on page 99 Chapter 13 on page 99 Chapter 21 on page 173 http://en.wikibooks.org/wiki/Ada%20Programming%2FKeywords%2Finterface
48
New in Ada 2005, these types are similar to the Java interfaces.
Operations of specic types are non-dispatching, those on class-wide types are dispatching. New types can be declared by deriving from specic types; primitive operations are inherited by derivation. You cannot derive from class-wide types. Constrained vs. Unconstrained
type I is range 1 .. 10; type AC is array (1 .. 10) of ... -- constrained -- constrained
type AU is array (I range <>) of ... -- unconstrained type R (X: Discriminant [:= Default]) is ... -- unconstrained
Declaring an unconstrained object is only possible if a default value is given in the type declaration above. The language does not specify how such objects are allocated. GNAT allocates the maximum size, so that size changes that might occur with discriminant changes present no problem. Another possibility is implicit dynamic allocation on the heap and deallocation followed be a re-allocation when the size changes. Denite vs. Indenite
type I is range 1 .. 10; type RD (X: Discriminant := Default) is ... type T (<>) is ... type AU is array (I range <>) of ... type RI (X: Discriminant) is ... -- definite -- definite
Denite subtypes allow the declaration of objects without initial value, since objects of denite subtypes have constraints that are known at creation-time. Object declarations of indenite subtypes need an initial value to supply a constraint; they are then constrained by
49
Unconstrained vs. Indenite Note that unconstrained subtypes are not necessarily indenite as can be seen above with RD: it is a denite unconstrained subtype.
(The ellipsis stands for private, or for a record denition, see the corresponding subsection on this page.) A limited type also doesn t have an equality operator unless the programmer denes one. You can learn more in the limited types28 chapter.
27 28
50
Dening new types and subtypes You can dene a new type with the following syntax:
type T is...
followed by the description of the type, as explained in detail in each category of type. Formally, the above declaration creates a type and its rst subtype named T. The type itself, correctly called the "type of T", is anonymous; the RM refers to it as T (in italics), but often speaks sloppily about the type T. But this is an academic consideration; for most purposes, it is sucient to think of T as a type. For scalar types, there is also a base type called T Base, which encompasses all values of T. For signed integer types, the type of T comprises the (complete) set of mathematical integers. The base type is a certain hardware type, symmetric around zero (except for possibly one extra negative value), encompassing all values of T. As explained above, all types are incompatible; thus:
type Integer_1 is range 1 .. 10; type Integer_2 is range 1 .. 10; A : Integer_1 := 8; B : Integer_2 := A; --illegal!
is illegal, because Integer_1 and Integer_2 are dierent and incompatible types. It is this feature which allows the compiler to detect logic errors at compile time, such as adding a le descriptor to a number of bytes, or a length to a weight. The fact that the two types have the same range does not make them compatible: this is name equivalence in action, as opposed to structural equivalence. (Below, we will see how you can convert between incompatible types; there are strict rules for this.)
--bad --OK
The declaration of Integer_2 is bad because the constraint 7 .. 11 is not compatible with Integer_1; it raises Contraint_Error at subtype elaboration time. Integer_1 and Integer_3 are compatible because they are both subtypes of the same type, namely Integer_1 Base.
51
Type System It is not necessary that the subtype ranges overlap, or be included in one another. The compiler inserts a run-time range check when you assign A to B; if the value of A, at that point, happens to be outside the range of Integer_3, the program raises Constraint_Error. There are a few predened subtypes which are very useful:
subtype Natural is Integer range 0 .. Integer Last; subtype Positive is Integer range 1 .. Integer Last;
Here both types are discrete; it is mandatory that the range of the derived type be included in the range of its parent. Contrast this with subtypes. The reason is that the derived type inherits the primitive operations dened for its parent, and these operations assume the range of the parent type. Here is an illustration of this feature:
procedure Derived_Types is package Pak is type Integer_1 is range 1 .. 10; procedure P (I: in Integer_1); --primitive operation, assumes 1 .. 10 type Integer_2 is new Integer_1 range 8 .. 10; --must not break P s assumption --procedure P (I: in Integer_2); inherited P implicitly defined here end Pak; package body Pak is --omitted end Pak; use Pak; A: Integer_1 := 4; B: Integer_2 := 9; begin P (B); --OK, call the inherited operation end Derived_Types;
When we call P (B), the parameter B is converted to Integer_1; this conversion of course passes since the set of acceptable values for the derived type (here, 8 .. 10) must be included in that of the parent type (1 .. 10). Then P is called with the converted parameter.
52
When P (B, Y) is called, both parameters are converted to Integer_1. Thus the range check on J (7) in the body of P will pass. However on return parameter Y is converted back to Integer_2 and the range check on Y will of course fail. With the above in mind, you will see why in the following program Constraint_Error will be called at run time.
procedure Derived_Types is package Pak is type Integer_1 is range 1 .. 10; procedure P (I: in Integer_1; J: out Integer_1); type Integer_2 is new Integer_1 Base range 8 .. 12; end Pak; package body Pak is procedure P (I: in Integer_1; J: out Integer_1) is begin J := I - 1; end P; end Pak; use Pak; B: Integer_2 := 11; begin P (B, Y); end Derived_Types; Y: Integer_2;
53
Type System
The base type Int Base is a hardware type selected by the compiler that comprises the values of Int. Thus it may have the range -27 .. 27 -1 or -215 .. 215 -1 or any other such type.
type Enum is (A, B, C, D); type Short is new Enum range A .. C;
Enum Base is the same as Enum, but Short Base also holds the literal D.
29 30
54
Constraints for all indices must be given, the result is necessarily a denite subtype32 .
X is an object of the indenite (sub)type String. Its constraint is derived implicitly from its initial value. X may change its value, but not its bounds. It should be noted that it is not necessary to initialize the object from a literal. You can also use a function. For example:
31 32 33 34 35
55
Type System
Count_to_Ten is the rst subtype of a suitable integer base type. However, if you would like to use this as an index constraint on String, the following declaration is illegal:
subtype Ten_Characters is String (Count_to_Ten);
This is because String has Positive as index, which is a subtype of Integer (these declarations are taken from package Standard):
subtype Positive is Integer range 1 .. Integer Last; type String is (Positive range <>) of Character;
Now Ten_Characters is the name of that subtype of String which is constrained to Count_To_Ten. You see that posing constraints on types versus subtypes has very dierent eects.
56
Here the compiler knows that A is a value of the type Enum. But consider:
procedure Bad is type Enum_1 is (A, B, C); procedure P (E : in Enum_1) is... --omitted type Enum_2 is (A, X, Y, Z); procedure P (E : in Enum_2) is... --omitted begin P (A); --illegal: ambiguous end Bad;
The compiler cannot choose between the two versions of P; both would be equally valid. To remove the ambiguity, you use a qualied expression:
P (Enum_1 (A)); --OK
As seen in the following example, this syntax is often used when creating new objects. If you try to compile the example, it will fail with a compilation error since the compiler will determine that 256 is not in range of Byte.
convert_evaluate_as.adb
procedure Convert_Evaluate_As is type Byte is mod 2**8; type Byte_Ptr is access Byte; package T_IO renames Ada ; package M_IO is new Ada (Byte); A : constant Byte_Ptr := new Byte (256); begin T_IO.Put ("A = "); M_IO.Put (Item => A.all, Width => 5, Base => 10); end Convert_Evaluate_As;
57
Type System Type conversions Data do not always come in the format you need them. You must, then, face the task of converting them. As a true multi-purpose language with a special emphasis on "mission critical", "system programming" and "safety", Ada has several conversion techniques. The most dicult part is choosing the right one, so the following list is sorted in order of utility. You should try the rst one rst; the last technique is a last resort, to be used if all others fail. There are also a few related techniques that you might choose instead of actually converting the data. Since the most important aspect is not the result of a successful conversion, but how the system will react to an invalid conversion, all examples also demonstrate faulty conversions.
The compiler rst checks that the conversion is legal, and if it is, it inserts a run-time check at the point of the conversion; hence the name checked conversion. If the conversion fails, the program raises Constraint_Error. Most compilers are very smart and optimise away the constraint checks; so, you need not worry about any performance penalty. Some compilers can also warn that a constraint check will always fail (and optimise the check with an unconditional raise). Explicit type conversions are legal: between any two numeric types between any two subtypes of the same type between any two types derived from the same type (note special rules for tagged types) between array types under certain conditions (see RM 4.6(24.2/2..24.7/2)) and nowhere else
(The rules become more complex with class-wide and anonymous access types.)
I: Integer := Integer (10); J: Integer := 10; K: Integer := Integer (10); --Unnecessary explicit type conversion --Implicit conversion from universal integer --Use the value 10 of type Integer: qualified expression --(qualification not necessary here).
File:
convert_checked.adb
58
with Ada ; procedure Convert_Checked is type Short is range -128 .. +127; type Byte is mod 256; package T_IO renames Ada ; package I_IO is new Ada (Short); package M_IO is new Ada (Byte); A : Short := -1; B : Byte; begin B := Byte (A); -- range check will lead to Constraint_Error T_IO.Put ("A = "); I_IO.Put (Item => A, Width => 5, Base => 10); T_IO.Put (", B = "); M_IO.Put (Item => B, Width => 5, Base => 10); end Convert_Checked;
Explicit conversions are possible between any two numeric types: integers, xed-point and oating-point types. If one of the types involved is a xed-point or oating-point type, the compiler not only checks for the range constraints (thus the code above will raise Constraint_Error), but also performs any loss of precision necessary. Example 1: the loss of precision causes the procedure to only ever print "0" or "1", since P / 100 is an integer and is always zero or one.
with Ada.Text_IO; procedure Naive_Explicit_Conversion is type Proportion is digits 4 range 0.0 .. 1.0; type Percentage is range 0 .. 100; function To_Proportion (P : in Percentage) return Proportion is begin return Proportion (P / 100); end To_Proportion; begin Ada.Text_IO.Put_Line (Proportion Image (To_Proportion (27))); end Naive_Explicit_Conversion;
59
Type System You might ask why you should convert between two subtypes of the same type. An example will illustrate this.
subtype String_10 is String (1 .. 10); X: String := "A line long enough to make the example valid"; Slice: constant String := String_10 (X (11 .. 20));
60
package Device_Driver is type Size_Type is range 0 .. 64; type Register is record A, B : Boolean; Size : Size_Type; end record; procedure Read (R : out Register); procedure Write (R : in Register); end Device_Driver;
The compiler chooses a default, ecient representation for Register. For example, on a 32-bit machine, it would probably use three 32-bit words, one for A, one for B and one for Size. This ecient representation is good for applications, but at one point we want to convert the entire record to just 8 bits, because that s what our hardware requires.
package body Device_Driver is type Hardware_Register is new Register; --Derived type. for Hardware_Register use record A at 0 range 0 .. 0; B at 0 range 1 .. 1; Size at 0 range 2 .. 7; end record; function Get return Hardware_Register; --Body omitted procedure Put (H : in Hardware_Register); --Body omitted procedure Read (R : out Register) is H : Hardware_Register := Get; begin R := Register (H); --Explicit conversion. end Read; procedure Write (R : in Register) is begin Put (Hardware_Register (R)); --Explicit conversion. end Write; end Device_Driver;
In the above example, the package body declares a derived type with the inecient, but compact representation, and converts to and from it. This illustrates that type conversions can result in a change of representation.
61
Type System There are no conversions to derived types (where would you get the further components from?); extension aggregates have to be used instead.
type Parent_Type is tagged null record; type Child_Type is new Parent_Type with null record; Child_Instance : Child_Type;
--View conversion from the child type to the parent type: Parent_View : Parent_Type := Parent_Type (Child_Instance);
Since, in object-oriented programming, an object of child type is an object of the parent type, no run-time check is necessary. With class-wide types, conversions to ancestor and child types are possible and are checked as well. These conversions are also view conversions, no data is created or lost.
procedure P (Parent_View : Parent_Type Class) is --View conversion to the child type: One : Child_Type := Child_Type (Parent_View); --View conversion to the class-wide child type: Two : Child_Type Class := Child_Type Class (Parent_View);
This view conversion involves a run-time check to see if Parent_View is indeed a view of an object of type Child_Type. In the second case, the run-time check accepts objects of type Child_Type but also any type derived from Child_Type. View renaming A renaming declaration does not create any new object and performs no conversion; it only gives a new name to something that already exists. Performance is optimal since the renaming is completely done at compile time. We mention it here because it is a common idiom in object oriented programming37 to rename the result of a view conversion.
type Parent_Type is tagged record <components>; end record; type Child_Type is new Parent_Type with record <further components>; end record; Child_Instance : Child_Type; Parent_View : Parent_Type Class renames Parent_Type Class (Child_Instance);
Now, Parent_View is not a new object, but another name for Child_Instance viewed as the parent, i.e. only the parent components are visible, the further child components are hidden.
37
62
Unchecked_Conversion will bit-copy the source data and reinterprete them under the target type without any checks. It is your chore to make sure that the requirements on unchecked conversion as stated in RM 13.9 {http://www.adaic.org/resources/add_content/ standards/05rm/html/RM-13-9.html} are fullled; if not, the result is implementation dependent and may even lead to abnormal data. Use the Valid attribute after the conversion to check the validity of the data in problematic cases. A function call to (an instance of) Unchecked_Conversion will copy the source to the destination. The compiler may also do a conversion in place (every instance has the convention Intrinsic). To use Unchecked_Conversion you need to instantiate the generic.
38 39 40 41
13 13 13 13
on on on on
99 99 99 99
63
Type System In the example below, you can see how this is done. When run, the example will output "A = -1, B = 255". No error will be reported, but is this the result you expect?
convert_unchecked.adb
procedure Convert_Unchecked is type Short is range -128 .. +127; type Byte is mod 256; package T_IO renames Ada ; package I_IO is new Ada (Short); package M_IO is new Ada (Byte); function Convert is new Ada Byte); A : constant Short := -1; B : Byte; begin B := Convert (A); T_IO.Put ("A = "); I_IO.Put (Item => A, Width => 5, Base => 10); T_IO.Put (", B = "); M_IO.Put (Item => B, Width => 5, Base => 10); end Convert_Unchecked; (Source => Short, Target =>
There is of course a range check in the assignment B := Convert (A);. Thus if B were dened as B: Byte range 0 .. 10;, Constraint_Error would be raised.
5.8.7 Overlays
If the copying of the result of Unchecked_Conversion is too much waste in terms of performance, then you can try overlays, i.e. address mappings. By using overlays, both objects share the same memory location. If you assign a value to one, the other changes as well. The syntax is:
for Target Address use expression; pragma (Ada, Target);
where expression denes the address of the source object. While overlays might look more elegant than Unchecked_Conversion, you should be aware that they are even more dangerous and have even greater potential for doing something very
64
wrong. For example if Source Size < Target Size and you assign a value to Target, you might inadvertently write into memory allocated to a dierent object. You have to take care also of implicit initializations of objects of the target type, since they would overwrite the actual value of the source object. The Import pragma with convention Ada can be used to prevent this, since it avoids the implicit initialization, RM B.1 {http: //www.adaic.org/resources/add_content/standards/05rm/html/RM-B-1.html} . The example below does the same as the example from "Unchecked Conversion".
File:
convert_address_mapping.adb
with Ada ; procedure Convert_Address_Mapping is type Short is range -128 .. +127; type Byte is mod 256; package T_IO renames Ada ; package I_IO is new Ada (Short); package M_IO is new Ada (Byte); A : aliased Short; B : aliased Byte; for B Address use A Address; pragma (Ada, B); begin A := -1; T_IO.Put ("A = "); I_IO.Put (Item => A, Width => 5, Base => 10); T_IO.Put (", B = "); M_IO.Put (Item => B, Width => 5, Base => 10); end Convert_Address_Mapping;
65
Type System
declares an anonymous type T and its rst subtype T (please note the italicization). T encompasses the complete set of mathematical integers. Static expressions and named numbers make use of this fact. All numeric integer literals are of type Universal_Integer. They are converted to the appropriate specic type where needed. Universal_Integer itself has no operators. Some examples with static named numbers:
S1: S2: S3: S4: constant constant constant constant := := := := Integer Last + Integer Last; Long_Integer Last + 1; S1 + S2; Integer Last + Long_Integer Last; --"+" of Integer --"+" of Long_Integer --"+" of root_integer --illegal
Static expressions are evaluated at compile-time on the appropriate types with no overow checks, i.e. mathematically exact (only limited by computer store). The result is then implicitly converted to Universal_Integer. The literal 1 in S2 is of type Universal_Integer and implicitly converted to Long_Integer. S3 implicitly converts the summands to root_integer, performs the calculation and converts back to Universal_Integer. S4 is illegal because it mixes two dierent types. You can however write this as
S5: constant := Integer Pos (Integer Last) + Long_Integer Pos (Long_Integer Last); --"+" of root_integer
where the Pos attributes convert the values to Universal_Integer, which are then further implicitly converted to root_integer, added and the result converted back to Universal_Integer. root_integer is the anonymous greatest integer type representable by the hardware. It has the range System.Min_Integer .. System.Max_Integer. All integer types are rooted at root_integer, i.e. derived from it. Universal_Integer can be viewed as root_integer Class. During run-time, computations of course are performed with range checks and overow checks on the appropriate subtype. Intermediate results may however exceed the range limits. Thus with I, J, K of the subtype T above, the following code will return the correct result:
I := 10; J := 8; K := (I + J) - 12; --I := I + J; -- range check would fail, leading to Constraint_Error
66
Real literals are of type Universal_Real, and similar rules as the ones above apply accordingly.
The type Color is the index type and the type Intensity is the component type of the array type Colored_Point. See array42 .
5.11.1 Wikibook
Ada Programming43
42 43
67
Type System 13.3 Operational and Representation Attributes {http://www.adaic.org/resources/ add_content/standards/05rm/html/RM-13-3.html} Annex K (informative) Language-Dened Attributes {http://www.adaic.org/ resources/add_content/standards/05rm/html/RM-K.html}
68
6 Integer types
A range is a signed integer value which ranges from a First to a last Last. It is dened as
range First .. Last
When a value is assigned to an object with such a range constraint, the value is checked for validity and Constraint_Error exception1 is raised when the value is not within First to Last. When declaring a range type, the corresponding mathematical operators are implicitly declared by the language at the same place. The compiler is free to choose a suitable underlaying hardware type for this user dened type.
File:
range_1.adb
with Ada ; procedure Range_1 is type Range_Type is range -5 .. 10; package T_IO renames Ada.Text_IO; package I_IO is new Ada.Text_IO.Integer_IO (Range_Type); begin for A in Range_Type loop I_IO.Put ( Item => A, Width => 3, Base => 10); if A < Range_Type Last then T_IO.Put (","); else T_IO.New_Line;
69
Integer types
6.2.1 Wikibook
Ada Programming2 Ada Programming/Types3 Ada Programming/Keywords/range4
2 3 4 5
70
where First is 0 and Last is Modulus - 1. Wrap-around arithmetic means that Last + 1 = 0 = First, and First - 1 = Last. Additionally to the normal arithmetic operators, bitwise and, or and xor are dened for the type. The predened package Interfaces (RM B.2 {http://www.adaic.org/resources/add_ content/standards/05rm/html/RM-B-2.html} ) presents unsigned integers based on powers of 2
type Unsigned_n is mod 2**n;
for which also shift and rotate operations are dened. The values of n depend on compiler and target architecture. You can use range to sub-range a modular type:
type Byte is mod 256; subtype Half_Byte is Byte range 0 .. 127;
But beware: the Modulus of Half_Byte is still 256! Arithmetic with such a type is interesting to say the least.
71
7.2.1 Wikibook
Ada Programming1 Ada Programming/Types2 Ada Programming/Keywords/mod3
1 2 3
72
8 Enumerations
An enumeration type is dened as a list of possible values:
type Primary_Color is (Red, Green, Blue);
Like for numeric types, where e.g. 1 is an integer literal, Red, Green and Blue are called the literals of this type. There are no other values assignable to objects of this type.
There are two other important attributes: Image and Value (don t confuse Val with Value). Image returns the string representation of the value (in capital letters), Value is the inverse:
Primary_Color Image ( Red ) = "RED" Primary_Color Value ("Red") = Red
These attributes are important for simple IO3 (there are more elaborate IO facilities in Ada for enumeration types). Note that, since Ada is case-insensitive, the string given to Value can be in any case.
1 2 3
73
Enumerations Enumeration literals Literals are overloadable, i.e. you can have another type with the same literals.
type Traffic_Light is (Red, Yellow, Green);
Overload resolution within the context of use of a literal normally resolves which Red is meant. Only if you have an unresolvable overloading conict, you can qualify with special syntax which Red is meant:
Primary_Color (Red)
Like many other declarative items, enumeration literals can be renamed. In fact, such a literal is a actually function4 , so it has to be renamed as such:
function Red return P.Primary_Color renames P.Red;
Here, Primary_Color is assumed to be dened in package P, which is visible at the place of the renaming declaration. Renaming makes Red directly visible without necessity to resort the use-clause. Note that redeclaration as a function does not aect the staticness of the literal.
This literal A has nothing in common with the literal A of the predened type Character (or Wide_Character). Every type that has at least one character literal is a character type. For every character type, string literals and the concatenation operator "&"5 are also implicitly dened.
type My_Character is (No_Character, a , Literal, z ); type My_String is array (Positive range <>) of My_Character; S: My_String := "aa" & Literal & "za" & z ; T: My_String := ( a , a , Literal, z , a , z );
4 5
74
There is special semantics implied with this declaration in that objects and expressions of this type can be used as conditions. Note that the literals False and True are not Ada keywords. Thus it is not sucient to declare a type with these literals and then hope objects of this type can be used like so:
type My_Boolean is (False, True); Condition: My_Boolean; if Condition then -- wrong, won t compile
If you need your own Booleans (perhaps with special size requirements), you have to derive from the predened Boolean:
type My_Boolean is new Boolean; Condition: My_Boolean; if Condition then -- OK
type Day_Of_Week is (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday); subtype Working_Day is Day_Of_Week range Monday .. Friday;
75
8.4.1 Wikibook
Ada Programming7 Ada Programming/Types8 Ada Programming/Libraries/Standard9
7 8 9 10
76
If you like, you can declare the minimum range needed as well:
digits Num_Digits range3 Low .. High
This facility is a great benet of Ada over (most) other programming languages. In other languages, you just choose between "oat" and "long oat", and what most people do is: choose oat if they don t care about accuracy otherwise, choose long oat, because it is the best you can get In either case, you don t know what accuracy you get. In Ada, you specify the accuracy you need, and the compiler will choose an appropriate oating point type with at least the accuracy you asked for. This way, your requirement is guaranteed. Moreover, if the computer has more than two oating point types available, the compiler can make use of all of them.
9.2.1 Wikibook
Ada Programming4
1 2 4
77
Floating point types Ada Ada Ada Ada Ada Programming/Types5 Programming/Types/range6 Programming/Types/delta7 Programming/Types/mod8 Programming/Keywords/digits9
5 6 7 8 9 10
78
The delta can be any real value for example you may dene a circle with one arcsecond resolution with:
http://en.wikipedia.org/wiki/Fixed-point%20arithmetic
79
[There is one rather strange rule about xed point types: Because of the way they are internally represented, the range might only go up to Last - Delta. This is a bit like a circle the 0 and 360 mark is also the same.]
1 1 It should be noted that in the example above the smallest possible value used is not 60 2 = 3600 . The compiler will choose a smaller value which, by default, is an integer power of 2 not 1 greater than the delta. In our example this could be 212 = 4096 . In most cases this should render better performance but sacrices precision for it.
If this is not what you wish and precision is indeed more important, you can choose your own small value via the attribute clause Small.
type Angle is delta Pi/2.0**31 range -Pi .. Pi; for Angle Small use Pi/2.0**31;
Delta must be a positive or negative integer power of 10 otherwise the declaration is illegal.
delta 10.0**(+2) digits 12 delta 10.0**(-2) digits 12
80
You might wonder what the dierence then is between these two declarations. The answer is: None with respect to precision, addition, subtraction, multiplication with integer values. The following is an incomplete list of dierences between ordinary and decimal xed point types. Decimal xed point types are intended to reect typical COBOL declarations with a given number of digits. Truncation is required for decimal, not for ordinary, xed point in multiplication and division (RM 4.5.5 (21) {http://www.adaic.org/resources/add_content/standards/ 95lrm/ARM_HTML/RM-4-5-5.html} ) and type conversions. Operations on decimal xed point are fully specied, which is not true for ordinary xed point. The following attributes are only dened for decimal xed point: T Digits (RM 3.5.10 (10) {http://www.adaic.org/resources/add_content/standards/95lrm/ ARM_HTML/RM-3-5-10.html} ) corresponds to the number of decimal digits that are representable; T Scale (RM 3.5.10 (11) {http://www.adaic.org/resources/ add_content/standards/95lrm/ARM_HTML/RM-3-5-10.html} , taken from COBOL) indicates the position of the point relative to the rightmost signicant digits; T Round (RM 3.5.10 (12) {http://www.adaic.org/resources/add_content/ standards/95lrm/ARM_HTML/RM-3-5-10.html} ) can be used to specify rounding on conversion. Package Decimal (RM F.2 {http://www.adaic.org/resources/add_content/ standards/95lrm/ARM_HTML/RM-F-2.html} ), which of course applies only to decimal xed point, denes the decimal Divide generic procedure. If annex F is supported (GNAT does), at least 18 digits must be supported (there is no such rule for xed point). Decimal_IO (RM A.10.1 (73) {http://www.adaic.org/resources/add_content/ standards/95lrm/ARM_HTML/RM-A-10-1.html} ) has semantics dierent from Fixed_IO (RM A.10.1 (68) {http://www.adaic.org/resources/add_content/standards/ 95lrm/ARM_HTML/RM-A-10-1.html} ). Static expressions must be a multiple of the Small for decimal xed point. Conclusion: For normal numeric use, an ordinary xed point (probably with Small dened) should be dened. Only if you are interested in COBOL like use, i.e. well dened deterministic decimal semantics (especially for nancial computations, but that might apply to cases other than money) should you take decimal xed point.
81
10.5.1 Wikibook
Ada Ada Ada Ada Ada Ada Ada Programming2 Programming/Types3 Programming/Types/range4 Programming/Types/digits5 Programming/Types/mod6 Programming/Keywords/delta7 Programming/Attributes/ Small8
2 3 4 5 6 7 8 9
http://en.wikibooks.org/wiki/Ada%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FTypes Chapter 6 on page 69 Chapter 9 on page 77 Chapter 7 on page 71 http://en.wikibooks.org/wiki/Ada%20Programming%2FKeywords%2Fdelta http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Small http://es.wikibooks.org/wiki/Programaci%F3n%20en%20Ada%2FTipos%2FComa%20fija
82
11 Arrays
An array1 is a collection of elements which can be accessed by one or more index values. In Ada any denite type is allowed as element and any discrete type, i.e. Range2 , Modular3 or Enumeration4 , can be used as an index.
where Index_Range is a range of values within a discrete index type, and Element_Type is a denite subtype. The array consists of one element of "Element_Type" for each possible value in the given range. If you for example want to count how often a specic letter appears inside a text, you could use:
type Character_Counter is array (Character) of Natural;
As a general advice, do not use Integer as the index range, since most of the time negative indices do not make sense. It is also a good style when using numeric indices, to dene them starting in 1 instead of 0, since it is more intuitive for humans and avoids o-by-one error5 s.
1 2 3 4 5
83
Arrays
Since this may involve a lot of typing and you may also run out of useful names for new subtypes6 , the array declaration allows for a shortcut:
array (Index_Type range First .. Last) of Element_Type
Since First and Last are expressions of Index_Type, a simpler form of the above is:
array (First .. Last) of Element_Type
Note that if First and Last are numeric literals, this implies the index type Integer. If in the example above the character counter should only count upper case characters and discard all other characters, you can use the following array type:
type Character_Counter is array (Character range A .. Z ) of Natural;
When you declare objects of such a type, the bounds must of course be given and the object is constrained to them. The predened type String7 is such a type. It is dened as
type String is array (Positive range <>) of Character;
6 7
84
You dene objects of such an unconstrained type in several ways (the extrapolation to other arrays than String should be obvious):
Text : String (10 .. 20); Input: String := Read_from_some_file;
(These declarations additionally dene anonymous subtypes of String.) In the rst example, the range of indices is explicitly given. In the second example, the range is implicitly dened from the initial expression, which here could be via a function reading data from some le. Both objects are constrained to their ranges, i.e. they cannot grow nor shrink.
Since we have packed the array, the compiler will use as little storage as possible. And in most cases this will mean that 8 boolean values will t into one byte. So Ada knows about arrays where more than one element shares one address. So what if you need to address each single element. Just not using pragma12 Pack13 is not enough. If the CPU14 has very fast bit access, the compiler might pack the array without being told. You need to tell the compiler that you need to address each element via an access.
type Day_Of_Month is range 1 .. 31; type Day_Has_Appointment is array (Day_Of_Month) of aliased Boolean;
8 9 10 11 12 13 14
85
Arrays
of Character;
The index values of the second dimension, those indexing the characters in each row, are in 1 .. 5 here. By choosing a dierent second range, we could change these to be in 11 .. 15:
Magic_Square: ( 1 => ( ... constant Character_Display( 1 .. S , A , T , O , R 5, ) , 11 .. 15) :=
By adding more dimensions to an array type, we could have squares, cubes (or bricks ), etc., of homogenous data items. Finally, an array of characters is a string (see Ada Programming/Strings15 ). Therefore, Magic_Square may simply be declared like this:
Magic_Square: ( "SATOR", "AREPO", "TENET", "OPERA", "ROTAS") ; constant Character_Display :=
15
86
Using arrays
11.2.1 Assignment
When accessing elements, the index is specied in parentheses. It is also possible to access slices in this way:
Vector_A (1 .. 3) := Vector_B (3 .. 5);
Note that the index range slides in this example: After the assignment, Vector_A (1) = Vector_B (3) and similarly for the other indices. Also note that the ranges overlap, nevertheless Vector_A (3) /= Vector_B (3); a compiler delivering such a result would be severely broken.
11.2.2 Concatenate
The operator "&" can be used to concatenate arrays:
Name := First_Name & & Last_Name;
In both cases, if the resulting array does not t in the destination array, Constraint_Error is raised. If you try to access an existing element by indexing outside the array bounds, Constraint_Error is raised (unless checks are suppressed).
Then the four attributes will have the following values: Array Hello_World World Empty_String First 1 7 1 Last 12 11 0 Length 12 5 0 Range 1 .. 12 7 .. 11 1 .. 0
The example was chosen to show a few common beginner s mistakes: 1. The assumption that strings begin with the index value 1 is wrong.
87
Arrays 2. The assumption (which follows from the rst one) that X Length = X Last is wrong. 3. And last the assumption that X Last >= X First; this is not true for empty strings. The attribute Range is a little special as it does not return a discrete value but an abstract description of the array. One might wonder what it is good for. The most common use is in the for loop on arrays16 but Range can also be used in declaring a name for the index subtype:
subtype Hello_World_Index is Integer range Hello_World Range;
Note: If you give an initial expression to an empty array (which is a must for a constant), the expression in the aggregate will of course not be evaluated since there are no elements actually stored.
11.3.1 Wikibook
Ada Programming17 Ada Programming/Types18 Data Structures19 Data Structures/Arrays20
16 17 18 19 20
88
21
http://es.wikibooks.org/wiki/Programaci%F3n%20en%20Ada%2FTipos%2FArrays
89
12 Records
A record is a composite type1 that groups one or more elds. A eld can be of any type, even a record.
For the compiler they are the same. However, programmers often use the rst variant if the type is not nished yet to show that they are planning to expand the type later, or they usually use the second if the (tagged) record is a base class in object oriented programming.
http://en.wikibooks.org/wiki/ada%20Programming%2FTypes%23List%20of%20types
91
Records
Basic_Record
:=
Basic_Record
( A =>
a value may be specied using positional notation, that is, specifying a value for each record component in declaration order
BMW : Car := ( 2007_752_83992434, 5, Blue, 190. 0, 10. 1) ;
However, naming the components of a Car aggregate oers a number of advantages. 1. Easy identication of which value is used for which component. (After all, named components are the raison d tre of records.) 2. Reordering the components is allowedyou only have to remember the component names, not their position. 3. Improved compiler diagnostic messages. Reordering components is possible because component names will inform the compiler (and the human reader!) of the intended value associations. Improved compiler messages are also in consequence of this additional information passed to the compiler. While an omitted component will always be reported due to Ada s coverage rules2 , messages can be much more specic when there are named associations. Considering the Car type from above, suppose a programmer by mistake species only one of the two oating point values for BMW in positional notation. The compiler, in search of another component value, will then not be able to decide whether the specied value is intended for Horse_Power_kW or for Consumption. If the programmer instead uses named association, say Horse_Power_kW => 190. 0, it will be clear which other component is missing.
BMW : Car := ( Identity Number_Wheels Horse_Power_kW Consumption Paint
In order to access a component of a record instance, use the dot delimiter (. ), as in BMW. Number_Wheels.
2 http://www.adacore.com/2007/05/14/gem-1/
92
93
Records
... Mutable_Traffic_Light : Mutable_Variant_Record; --not declaring a discriminant makes this record mutable --it has the default discriminant/variant --structure and values Immutable_Traffic_Light : Mutable_Variant_Record (Option => Yellow); --this record is immutable, the discriminant cannot be changed --even though the type declaration allows for mutable objects --with different discriminant values ... Mutable_Traffic_Light := (Option => Yellow, --mutation requires assignment of all components Location => 54, --for the given variant structure Timeout => 2.3); ... --restrictions on objects, causing them to be immutable type Traffic_Light_Access is access Mutable_Variant_Record; Any_Traffic_Light : Traffic_Light_Access := new Mutable_Variant_Record; Aliased_Traffic_Light : aliased Mutable_Variant_Record;
case Option is when Red => --components for red Flashing : Boolean := True; when Yellow => --components for yellow Timeout : Duration := 0.0; when Green => --components for green Whatever : Positive := 1; end case; end record;
Conversely, you can declare record types so that the discriminant along with the structure of the variant record may not be changed. To make a record type declaration immutable, the discriminant must not have a default value.
type Traffic_Light is (Red, Yellow, Green); type Immutable_Variant_Record (Option : Traffic_Light) is --no default value makes the record type immutable record --common components Location : Natural := 0; case Option is when Red => --components for red Flashing : Boolean := True; when Yellow => --components for yellow Timeout : Duration; when Green => --components for green Whatever : Positive := 1; end case; end record;
94
... Default_Traffic_Light : Immutable_Variant_Record; --ILLEGAL! Immutable_Traffic_Light : Immutable_Variant_Record (Option => Yellow); --this record is immutable, since the type declaration is immutable
12.6 Union
Union This language feature is only available in Ada 2005
type Traffic_Light is (Red, Yellow, Green); type Union (Option : Traffic_Light := Traffic_Light First) is record --common components case Option is when Red => --components for red when Yellow => --components for yellow when Green => --components for green end case; end record; pragma pragma (Union); (C, Union); --optional
The dierence to a variant record is such that Option is not actually stored inside the record and never checked for correctness - it s just a dummy. This kind of record is usually used for interfacing with C but can be used for other purposes as well (then without pragma (C, Union);).
3 4 5
Chapter 22 on page 187 Chapter 22.4.2 on page 217 Chapter 22.1.2 on page 188
95
Records
type Person is tagged record Name : String (1 .. 10); Gender : Gender_Type; end record; type Programmer is new Person with record Skilled_In : Language_List; end record;
6 7
http://en.wikibooks.org/wiki/C%20Programming http://en.wikibooks.org/wiki/C%2B%2B%20Programming
96
12.11.1 Wikibook
Ada Ada Ada Ada Ada Ada Ada Ada Programming9 Programming/Types10 Programming/Keywords/record11 Programming/Keywords/null12 Programming/Keywords/abstract13 Programming/Keywords/case14 Programming/Keywords/when15 Programming/Pragmas/Unchecked_Union16
97
Records Ada Issues AI95-00216-01 Unchecked unions variant records with no run-time discriminant {http: //www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00216.TXT}
98
13 Access types
13.1 What s an Access Type?
What s an Access Type? Access types in Ada are what other languages call pointers. They point to objects located at certain addresses. So normally one can think of access types as simple addresses (there are exceptions from this simplied view). Ada instead of saying points to talks of granting access to or designating an object. Objects of access types are implicitly initialized with null, i.e. they point to nothing when not explicitly initialized. Access types should be used rarely in Ada. In a lot of circumstances where pointers are used in other languages, there are other ways without pointers. If you need dynamic data structures, rst check whether you can use the Ada Container library. Especially for indenite record or array components, the Ada 2012 package Indenite_Holders (RM A.18.18) can be used instead of pointers. There are four kinds of access types in Ada: Pool access types - General access types Anonymous access types - Access to subprogram types.
99
Access types A size clause may be used to limit the corresponding (implementation dened anonymous) storage pool. A size clause of 0 disables calls of an allocator.
for Person_Access Size use 0;
The storage pool is implementation dened if not specied. Ada supports user dened storage pools, so you can dene the storage pool with
for Person_Access Storage_Pool use Pool_Name;
You access the object in the storage pool by appending .all. Mother.all is the complete record; components are denoted as usual with the dot notation: Mother.all.First_Name. When accessing components, implicit dereferencing (i.e. omitting all) can serve as a convenient shorthand:
Mother.all := (Last_Name => Father.Last_Name, First_Name => Mother.First_Name); -- marriage
Be careful to discriminate between deep and shallow copies when copying with access objects:
Obj1.all := Obj2.all; content Obj1 := Obj2; object as Obj2 -- Deep copy: Obj1 still refers to an object -- different from Obj2, but it has the same -- Shallow copy: Obj1 now refers to the same
100
VA.all := (others => 0.0); -... Do whatever you need to do with the vector
Free_Vector (VA); -- The memory is deallocated and VA is now null V := VB.all; erroneous -- VB is not null, access to a dangling pointer is
end Deallocation_Sample;
It is exactly because of this problem with dangling pointers that the deallocation operation is called unchecked. It is the chore of the programmer to take care that this does not happen. Since Ada allows for user dened storage pools, you could also try a garbage collector library1 .
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FAdaCL% 23Garbage_Collector
101
Access types
2 3 4
102
Before using an anonymous access, you should consider a named access type or, even better, consider if the "out" or "in out" modier is not more appropriate. This language feature is only available in Ada 2005 In Ada 2005, anonymous accesses are allowed in more circumstances:
103
Access types
type Object is record M : Integer; Next: access Object; end record; X: access Integer; function F return access constant Float;
Now how do you access elements stored in the container. Of course you can retrieve them by
function Get (From: Container) return Element;
This will however copy the element, which is unfortunate if the element is big. You get direct access with
function Get (From: Container) return Element_Ptr;
Now pointers are dangerous since you might easily create dangling pointers like so:
P: Element_Ptr := Get (Cont); P.all := E; Free (P); ... Get (Cont) -- this is now a dangling pointer
Use of an accessor object instead of an access type can prevent inadvertant deallocation (this is still Ada 2005):
type Accessor (Data: not null access Element) is limited private; function Get (From: Container) return Accessor; -- read/write access
(For the null exclusion not null in the declaration of the discriminant, see below). Access via such an accessor is safe: The discriminant can only be used for dereferencing, it cannot be copied to an object of type Element_Ptr because its accessibility level is deeper. In the
104
form above, the accessor provides read and write access. If the keyword constant is added, only read access is possible.
type Accessor (Data: not null access constant Element) is limited private; -- only read access
Here the new Ada 2012 feature of aspects comes along handy; for the case at hand, the aspect Implicit_Dereference is the one we need:
type Accessor (Data: not null access Element) is limited private with Implicit_Dereference => Data;
Now rather than writing the long and ugly function call of above, we can just omit the discriminant and its dereference like so:
Get (Cont).Data.all := E; Get (Cont) := E; -- Ada 2005 via accessor: safe, but ugly -- Ada 2012 implicit dereference
Note that the call Get (Cont) is overloaded it can denote the accessor object or the element, the compiler will select the correct interpretation depending on context.
The language also allows to declare the rst subtype directly with a null exclusion:
type Day_Of_Month_Access is not null access Day_Of_Month;
However, in nearly all cases this is not a good idea because it renders objects of this type nearly unusable (for example, you are unable to free the allocated memory). Not null accesses are intended for access subtypes, object declarations, and subprogram parameters.http: //groups.google.com/group/comp.lang.ada/msg/13a41ced7af75192
105
Access types
For getting an access to a subprogram, the attribute Access is applied to a subprogram name with the proper parameter and result prole.
procedure Process_Event (Id : Integer; Text: String); My_Callback: Callback_Procedure := Process_Event Access;
This is a function that returns the access to a function that in turn returns an access to a function returning an access to some type.
5 6
106
With a simple access you know at least that you won t try to deallocate a stack object.
107
Access types
type Day_Of_Month_Access is access Day_Of_Month; pragma (Convention => C, Entity => Day_Of_Month_Access);
pragma should be used on any type you want to use in C. The compiler will warn you if the type cannot be made C compatible. You may also consider the following - shorter - alternative when declaring Day_Of_Month:
type Day_Of_Month is new Interfaces.C.int range 1 .. 31;
Before you use access types in C, you should consider using the normal "in", "out" and "in out" modiers. pragma and pragma know how parameters are usually passed in C and will use a pointer to pass a parameter automatically where C would have used them as well. Of course the RM contains precise rules on when to use a pointer for "in", "out", and "in out" - see "B.3 Interfacing with C {http://www.adaic.org/resources/add_content/ standards/05rm/html/RM-B-3.html} ".
108
Closer to the true nature of void - pointing to an element of zero size is a pointer to a null record. This also has the advantage of having a representation for void and void*:
type Void is null record; pragma (C, Void); type Void_Ptr is access all Void; pragma (C, Void_Ptr);
Objects of subtypes like these have a static size, so a simple address suces to access them. In the case of arrays, this is generally the address of the rst element. For pointers of this kind, use of System.Address_to_Access_Conversion is safe.
109
Access types Objects of subtype Unc need a constraint, i.e. a start and a stop index, thus pointers to them need also to include those. So a simple address like the one of the rst component is not sucient. Note that A Address is the same as A(A First) Address for any array object. For pointers of this kind, System.Address_to_Access_Conversion will probably not work satisfactorily.
13.9.3 Example
CO: aliased Unc (-1 .. +1) := (-1 .. +1 => UO: aliased Unc := (-1 .. +1 => ); );
Here, CO is a nominally constrained object, a pointer to it need not store the constraint, i.e. a thin pointer suces. In contrast, UO is an object of a nominally unconstrained subtype, its actual subtype is constrained by the initial value.
A: Acc_Unc := CO Access; B: Acc_Unc := UO Access; C: Acc_Unc (CO Range) := CO Access; -- illegal -- OK -- also illegal
The relevant paragraphs in the RM are dicult to understand. In short words: An access type s target type is called the designated subtype, in our example Unc. RM 3.10.2(27.1/2) requires that Unc_Acc s designated subtype statically match the nominal subtype of the object. Now the nominal subtype of CO is the constrained anonymous subtype Unc (-1 .. +1), the nominal subtype of UO is the unconstrained subtype Unc. In the illegal cases, the designated and nominal subtypes do not statically match.
13.10.1 Wikibook
Ada Programming7 Ada Programming/Types8
7 8
http://en.wikibooks.org/wiki/Ada%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FTypes
110
111
14 Limited types
14.1 Limited Types
Limited Types When a type is declared limited this means that objects of the type cannot be assigned values of the same type. An Object b of limited type LT cannot be copied into an object a of same type LT. Additionally, there is no predened equality operation for objects of a limited type. The desired eects of declaring a type limited include prevention of shallow copying. Also, the (unique) identity of an object is retained: once declared, a name of a variable of type LT will continue to refer to the same object. The following example will use a rather simplifying type Boat.
type Boat is limited private; function Choose ( Load : Sailors_Units; Speed : Sailors_Units) return Boat; procedure Set_Sail ( The_Boat : in out Boat) ;
When we declare a variable to be of type Boat, its name will denote one boat from then on. Boats will not be copied into one another. The full view of a boat might be implemented as a record such as
type Boat is limited Max_Sail_Area : Max_Freight : Sail_Area : Freight : end record; record Sailors_Units; Sailors_Units; Sailors_Units; Sailors_Units;
The Choose function returns a Boat object depending on the parameters Load and Speed. If we now declare a variable of type Boat we will be better o Choosing an initial Boat (or else we might be dropping into uninitialized waters!). But when we do so, the initialization looks suspiciously like assignment which is not available with limited types:
113
Limited types
Positive;
Average_Speed :
Sailors_Units)
is
Henrietta : Boat := --assignment? Choose ( Load => People * Average_Weight * Speed => Average_Speed * 1. 5) ; begin Set_Sail ( Henrietta) ; end Travel;
1.
5,
Fortunately, current Ada distinguishes initialization from copying. Objects of a limited type may be initialized by an initialization expression on the right of the delimiter := . (Just to prevent confusion: The Ada Reference Manual discriminates between assignment and assignment statement, where assignment is part of the assignment statement. An initialisation is of course an assignment which, for limited types, is done in place. An assignment statement involves copying, which is forbidden for limited types.) Related to this feature are aggregates of limited types1 and constructor functions for limited types. Internally, the implementation of the Choose function will return a limited record. However, since the return type Boat is limited, there must be no copying anywhere. Will this work? A rst attempt might be to declare a result variable local to Choose, manipulate result, and return it. The result object needs to be transported into the calling environment. But result is a variable local to Choose. When Choose returns, result will no longer be in scope. Therefore it looks like result must be copied but this is not permitted for limited types. There are two solutions provided by the language: extended return statements (see 6.5 Return Statements {http: //www.adaic.org/resources/add_content/standards/05rm/html/RM-6-5.html} ) and aggregates of limited types. The following body of Choose returns an aggregate of limited type Boat, after nding the initial values for its components.
function Choose ( Load : Sailors_Units; Speed : Sailors_Units) return Boat is Capacity : constant Sailors_Units := Capacity_Needed ( Load) ; begin return Boat ( Max_Freight => Capacity, Max_Sail_Area => Sail_Needed ( Capacity) , Freight => Load, Sail_Area => 0. 0) ; end Choose;
The object that is returned is at the same time the object that is to have the returned value. The function therefore initializes Henrietta in place. In parallel to the predened type Ada .Controlled, Ada provides the type Limited_Controlled in the same package. It is a limited version of the former.
http://www.adacore.com/2007/05/14/gem-1/
114
115
Limited types
with Limited_Private_Samples; use Limited_Private_Samples; procedure Try is U: P: D1: D2: D3: Uninitialised; Preinitialised; --very bad --has initial value (good)
Dynamic_Initialisation; --has initial value (good) Dynamic_Initialisation := Constructor ( 0) ; --Ada 2005 initialisation Dynamic_Initialisation renames Constructor ( 0) ; --already Ada 95
--I: Needs_Constructor; -- Illegal without initialisation N: Needs_Constructor := Constructor ( 0) ; --Ada 2005 initialisation begin null; end Try;
Note that D3 is a constant, whereas all others are variables. Also note that the initial value that is dened for the component of Preinitialised is evaluated at the time of object creation, i.e. if an expression is used instead of the literal, the value can be run-time dependent.
X, Y: Preinitialised;
In this declaration of two objects, the initial expression will be evaluated twice and can deliver dierent values, because it is equivalent to the sequence2 :
X: Preinitialised; Y: Preinitialised;
So X is initialised before Y.
ISO/IEC 8652:2007. 3.3.1 Object Declarations (7). Ada 2005 Reference Manual. Any declaration [...] with more than one defining_identifier is equivalent to a series of declarations each containing one defining_identifier from the list, [...] in the same order as the list. {http://www.adaic.org/ resources/add_content/standards/05rm/html/RM-3-3-1.html}
116
14.4 References
References
117
15 Strings
Ada supports three dierent types of strings. Each string type is designed to solve a dierent problem. In addition, every string type is implemented for each available Characters type (Character, Wide_Character, Wide_Wide_Character) giving a complement of nine combinations.
However once the length has been calculated and the strings have been created the length stays constant. Try the following program which shows a typical mistake:
show_commandline_1.adb
procedure Show_Commandline_1 is package T_IO renames Ada ; package CL renames Ada ; X : String := CL.Argument (1); begin T_IO.Put ("Argument 1 = "); T_IO.Put_Line (X); X := CL.Argument (2); T_IO.Put ("Argument 2 = ");
1 2
119
Strings
The program will only work when the 1st and 2nd parameter have the same length. This is even true when the 2nd parameter is shorter. There is neither an automatic padding of shorter strings nor an automatic truncation of longer strings. Having said that, the package Ada contains a set of procedures and functions for FixedLength String Handling which allows padding of shorter strings and truncation of longer strings. Try the following example to see how it works:
File:
show_commandline_2.adb
with Ada ; with Ada ; with Ada ; procedure Show_Commandline_2 is package package package package T_IO CL S SF renames renames renames renames Ada Ada Ada Ada ; ; ; ;
X : String := CL.Argument (1); begin T_IO.Put ("Argument 1 = "); T_IO.Put_Line (X); SF.Move ( Source Target Drop Justify Pad => => => => => CL.Argument (2), X, S.Right, S.Left, S.Space);
120
Like Fixed-Length Strings the maximum length does not need to be known at compile time it can also be calculated at runtime as the example below shows:
show_commandline_3.adb
procedure Show_Commandline_3 is package T_IO renames Ada.Text_IO; package CL renames Ada.Command_Line; function Max_Length ( Value_1 : Integer; Value_2 : Integer) return Integer is Retval : Integer; begin if Value_1 > Value_2 then Retval := Value_1; else Retval := Value_2; end if; return Retval; end Max_Length; pragma Inline (Max_Length); package SB is new Ada.Strings.Bounded.Generic_Bounded_Length ( Max => Max_Length ( Value_1 => CL.Argument (1) Length, Value_2 => CL.Argument (2) Length)); X : SB.Bounded_String := SB.To_Bounded_String (CL.Argument (1)); begin T_IO.Put ("Argument 1 = "); T_IO.Put_Line (SB.To_String (X)); X := SB.To_Bounded_String (CL.Argument (2)); T_IO.Put ("Argument 2 = "); T_IO.Put_Line (SB.To_String (X)); end Show_Commandline_3;
You should know that Bounded-Length Strings have some distinct disadvantages. Most noticeable is that each Bounded-Length String is a dierent type which makes converting them rather cumbersome. Also a Bounded-Length String type always allocates memory for the maximum permitted string length for the type. The memory allocation for a BoundedLength String is equal to the maximum number of string "characters" plus an implementation dependent number containing the string length (each character can require allocation of more than one byte per character, depending on the underlying character type of the string,
121
Strings and the length number is 4 bytes long for the Windows GNAT Ada compiler v3.15p, for example).
File:
show_commandline_4.adb
with Ada ; with Ada ; with Ada ; procedure Show_Commandline_4 is package T_IO renames Ada.Text_IO; package CL renames Ada.Command_Line; package SU renames Ada.Strings.Unbounded; X : SU.Unbounded_String := SU.To_Unbounded_String (CL.Argument (1)); begin T_IO.Put ("Argument 1 = "); T_IO.Put_Line (SU.To_String (X)); X := SU.To_Unbounded_String (CL.Argument (2)); T_IO.Put ("Argument 2 = "); T_IO.Put_Line (SU.To_String (X)); end Show_Commandline_4;
As you can see the Unbounded-Length String example is also the shortest (discarding the rst example, which is buggy) this makes using Unbounded-Length Strings very appealing.
122
See also
15.4.1 Wikibook
Ada Programming3
http://en.wikibooks.org/wiki/Ada%20Programming
123
16 Subprograms
In Ada the subprograms are classied into two categories: procedures1 and functions2 . A procedures call is a statement and does not return any value, whereas a function returns a value and must therefore be a part of an expression. Subprogram parameters may have three modes. in The actual parameter value goes into the call and is not changed there. The formal parameter is a constant and allows only reading. This is the default when no mode is given. The actual parameter is an expression. in out The actual parameter goes into the call and may be redened. The formal parameter is a variable and can be read and written. out The actual parameter s value before the call is irrelevant, it will get a value in the call. The formal parameter can be read and written. (In Ada 83 out parameters were write-only.) A parameter of any mode may also be explicitly aliased. access The formal parameter is an access (a pointer) to some variable. (This is not a parameter mode from the reference manual point of view.) Note that parameter modes do not specify the parameter passing method. Their purpose is to document the data ow. The parameter passing method depends on the type of the parameter. A rule of thumb is that parameters tting into a register are passed by copy, others are passed by reference. For certain types, there are special rules, for others the parameter passing mode is left to the compiler (which you can assume to do what is most sensible). Tagged types are always passed by reference. Explicitly aliased parameters and access parameters specify pass by reference. Unlike in the C class of programming languages, Ada subprogram calls cannot have empty parameters parentheses ( ) when there are no parameters.
1 2
125
Subprograms
16.1 Procedures
Procedures A procedure call in Ada constitutes a statement by itself. For example:
procedure A_Test ( A, B: in Integer; C: out Integer) begin C := A + B; end A_Test; is
the expressions 5 + P and 48 are evaluated (expressions are only allowed for in parameters), and then assigned to the formal parameters A and B, which behave like constants. Then, the value A + B is assigned to formal variable C, whose value will be assigned to the actual parameter Q when the procedure nishes. C, being an out parameter, is an uninitialized variable before the rst assignment. (Therefore in Ada 83, there existed the restriction that out parameters are write-only. If you wanted to read the value written, you had to declare a local variable, do all calculations with it, and nally assign it to C before return. This was awkward and error prone so the restriction was removed in Ada 95.) Within a procedure, the return statement can be used without arguments to exit the procedure and return the control to the caller. For example, to solve an equation of the kind ax2 + bx + c = 0:
with Ada ; use Ada ; procedure Quadratic_Equation ( A, B, C : Float; --By default it is "in". R1, R2 : out Float; Valid : out Boolean) is Z : Float; begin Z := B**2 - 4.0 * A * C; if Z < 0.0 or A = 0.0 then Valid := False; --Being out parameter, it should be modified at least once. R1 := 0.0; R2 := 0.0; else Valid := True; R1 := (-B + Sqrt (Z)) / (2.0 * A); R2 := (-B - Sqrt (Z)) / (2.0 * A); end if; end Quadratic_Equation;
126
The function SQRT calculates the square root of non-negative values. If the roots are real, they are given back in R1 and R2, but if they are complex or the equation degenerates (A = 0), the execution of the procedure nishes after assigning to the Valid variable the False value, so that it is controlled after the call to the procedure. Notice that the out parameters should be modied at least once, and that if a mode is not specied, it is implied in.
16.2 Functions
Functions A function is a subprogram that can be invoked as part of an expression. Until Ada 2005, functions can only take in (the default) or access parameters; the latter can be used as a work-around for the restriction that functions may not have out parameters. Ada 2012 has removed this restriction. Here is an example of a function body:
function Minimum (A, B: Integer) return Integer is begin if A <= B then return A; else return B; end if; end Minimum;
Or in Ada2012:
function Minimum (A, B: Integer) return Integer is begin return (if A <= B then A else B); end Minimum;
The formal parameters with mode in behave as local constants whose values are provided by the corresponding actual parameters. The statement return is used to indicate the value returned by the function call and to give back the control to the expression that called the function. The expression of the return statement may be of arbitrary complexity and must be of the same type declared in the specication. If an incompatible type is used, the compiler gives an error. If the restrictions of a subtype are not fullled, e.g. a range, it raises a Constraint_Error exception. The body of the function can contain several return statements and the execution of any of them will nish the function, returning control to the caller. If the ow of control within the function branches in several ways, it is necessary to make sure that each one of them is nished with a return statement. If at run time the end of a function is reached without
127
Subprograms encountering a return statement, the exception Program_Error is raised. Therefore, the body of a function must have at least one such return statement. Every call to a function produces a new copy of any object declared within it. When the function nalizes, its objects disappear. Therefore, it is possible to call the function recursively. For example, consider this implementation of the factorial function:
function Factorial (N : Positive) return Positive is begin if N = 1 then return 1; else return (N * Factorial (N - 1)); end if; end Factorial;
When evaluating the expression Factorial (4); the function will be called with parameter 4 and within the function it will try to evaluate the expression Factorial (3), calling itself as a function, but in this case parameter N would be 3 (each call copies the parameters) and so on until N = 1 is evaluated which will nalize the recursion and then the expression will begin to be completed in the reverse order. A formal parameter of a function can be of any type, including vectors or records. Nevertheless, it cannot be an anonymous type, that is, its type must be declared before, for example:
type Float_Vector is array (Positive range <>) of Float; function Add_Components (V: Float_Vector) return Float is Result : Float := 0.0; begin for I in V Range loop Result := Result + V(I); end loop; return Result; end Add_Components;
In this example, the function can be used on a vector of arbitrary dimension. Therefore, there are no static bounds in the parameters passed to the functions. For example, it is possible to be used in the following way:
V4 : Float_Vector (1 .. 4) := (1.2, 3.4, 5.6, 7.8); Sum : Float; Sum := Add_Components (V4);
In the same way, a function can also return a type whose bounds are not known a priori. For example:
function Invert_Components (V : Float_Vector) return Float_Vector is Result : Float_Vector(V Range); --Fix the bounds of the vector to be returned. begin for I in V Range loop
128
Result(I) := V (V First + V Last - I); end loop; return Result; end Invert_Components;
The variable Result has the same bounds as V, so the returned vector will always have the same dimension as the one passed as parameter. A value returned by a function can be used without assigning it to a variable, it can be referenced as an expression. For example, Invert_Components (V4) (1), where the rst element of the vector returned by the function would be obtained (in this case, the last element of V4, i.e. 7.8).
The rst call (from Ada.Numerics.Elementary_Functions) is not very clear. One might easily confuse the parameters. The second call makes the meaning clear without any ambiguity. Another use is for calls with numeric literals:
Ada.Float_Text_IO.Put_Line (X, 3, 2, 0); -- ? Ada.Float_Text_IO.Put_Line (X, Fore => 3, Aft => 2, Exp => 0); OK
--
129
Subprograms
In the rst statement, a "regular call" is used (with positional association); the second also uses positional association but omits the second parameter to use the default; in the third statement, all parameters are by default; the fourth statement uses named association to omit the rst parameter; nally, the fth statement uses mixed association, here the positional parameters have to precede the named ones. Note that the default expression is evaluated once for each formal parameter that has no actual parameter. Thus, if in the above example a function would be used as defaults for A and B, the function would be evaluated once in case 2 and 4; twice in case 3, so A and B could have dierent values; in the others cases, it would not be evaluated.
16.5 Renaming
Renaming Subprograms may be renamed. The parameter and result prole for a renaming-asdeclaration must be mode conformant.
procedure Solve (A, B, C: in Float; R1, R2 : out Float; Valid : out Boolean) renames Quadratic_Equation;
130
--GNAT GPL 2012 allows illegal call via an access to the renamed --This has been corrected in the current version (as of Nov 22,
But note that Message.Print Access; is illegal, you have to use a renaming declaration as above. Since only mode conformance is required (and not full conformance as between specication and body), parameter names and default values may be changed with renamings:
procedureP (X: inInteger := 0); procedureR (A: inInteger := -1) renamesP;
16.6.1 Wikibook
Ada Programming3 Ada Programming/Operators4
3 4
131
Subprograms
http://es.wikibooks.org/wiki/Programaci%F3n%20en%20Ada%2FSubprogramas
132
17 Packages
Ada encourages the division of code into separate modules called packages. Each package can contain any combination of items. Some of the benets of using packages are: package contents are placed in a separate namespace, preventing naming collisions, implementation details of the package can be hidden from the programmer (information hiding), object orientation requires dening a type and its primitive subprograms within a package, and packages can be separately compiled. Some of the more common package usages are: a group of related subprograms along with their shared data, with the data not visible outside the package, one or more data types along with subprograms for manipulating those data types, and a generic package that can be instantiated under varying conditions. The following is a quote from the current Ada Reference Manual 7. Packages. RM 7(1) {http://www.adaic.org/resources/add_content/standards/05rm/html/RM-7-. html} Packages are program units that allow the specication of groups of logically related entities. Typically, a package contains the declaration of a type (often a private type or private extension) along with the declaration of primitive subprograms of the type, which can be called from outside the package, while their inner workings remain hidden from outside users.
133
Packages One of the biggest advantages of Ada over most other programming languages is its well dened system of modularization and separate compilation. Even though Ada allows separate compilation, it maintains the strong type checking among the various compilations by enforcing rules of compilation order and compatibility checking. Ada uses separate compilation (like Modula-21 , Java2 and C#3 ), and not independent compilation (as C4 /C++5 does), in which the various parts are compiled with no knowledge of the other compilation units with which they will be combined. A note to C/C++ users: Yes, you can use the preprocessor to emulate separate compilation but it is only an emulation and the smallest mistake leads to very hard to nd bugs. It is telling that all C/C++ successor languages including D6 have turned away from the independent compilation and the use of the preprocessor. So it s good to know that Ada has had separate compilation ever since Ada-83 and is probably the most sophisticated implementation around.
134
record type in the private part, and provide the code to implement the subprograms in the package body.
135
Packages
end Package_With_Body; package body Package_With_Body is procedure Set_A (This : in out Basic_Record; An_A : in Integer) is begin This.A := An_A; end Set_A; function Get_A (This : Basic_Record) return Integer is begin return This.A; end Get_A; end Package_With_Body;
7 8
http://en.wikipedia.org/wiki/GNAT http://en.wikipedia.org/wiki/Abstract_data_type
136
pragma Pure_Function ( Get_A) ; end Package_With_Body; package body Package_With_Body is The_A: Integer; in Integer) is
begin The_A := 0;
end Package_With_Body;
(A note on construction: The package initialization part after begin corresponds to a construction subprogram of an ADT package. However, as a state machine is an object already, construction is happening during package initialization. (Here it sets the state variable The_A to its initial value.) An ASM package can be viewed as a singleton9 .)
http://en.wikipedia.org/wiki/Singleton_pattern
137
Packages
end Private_With; package body Private_With is --The private withed package is visible in the body too procedure Set_A (This : in out Basic_Record; An_A : in String) is begin This.A := Unbounded.To_Unbounded_String (An_A); end Set_A; function Get_A (This : Basic_Record) return String is begin return Unbounded.To_String (This.A); end Get_A; end Private_With;
138
type Employee is tagged private; procedure Assign_Employee (E : in out Employee; D : access Departments.Department Class); type Dept_Ptr is access all Departments.Department Class; function Current_Department(E : in Employee) return Dept_Ptr; ... end Employees; limited with Employees; package Departments is type Department is tagged private; procedure Choose_Manager (Dept : in out Department; Manager : access Employees.Employee Class); ... end Departments;
10.
0;
--illegal
This program fragment is illegal since the operators implicitly dened in Universe are not directly visible. You have four choices to make the program legal. Use a use_package_clause. This makes all declarations in Universe directly visible (provided they are not hidden because of other homographs).
with Universe; use Universe; procedure P is V: Universe. T := begin V := V * 42. 0; end P;
10.
0;
Use renaming. This is error prone since if you rename many operators, cut and paste errors are probable.
139
Packages
with Universe; procedure P is function "*" ( Left, Right: function "/" ( Left, Right: --oops V: Universe. T := 10. 0; begin V := V * 42. 0; end P;
Universe. Universe.
T) T)
"*"; "*";
0) ;
Use the use_type_clause. This makes only the operators in Universe directly visible.
with Universe; procedure P is V: Universe. T := 10. use type Universe. T; begin V := V * 42. 0; end P;
0;
There is a special beauty in the use_type_clause. Suppose you have a set of packages like so:
with Universe; package Pack is subtype T is Universe. end Pack;
T;
Now you ve got into trouble. Since Universe is not made visible, you cannot use a use_package_clause for Universe to make the operator directly visible, nor can you use qualication for the same reason. Also a use_package_clause for Pack does not help, since the operator is not dened in Pack. The eect of the above construct means that the operator is not nameable, i.e. it cannot be renamed in a renaming statement. Of course you can add Universe to the context clause, but this may be impossible due to some other reasons (e.g. coding standards); also adding the operators to Pack may be forbidden or not feasible. So what to do?
140
The solution is simple. Use the use_type_clause for Pack.T and all is well!
with Pack; procedure P is V: Pack. T := 10. use type Pack. T; begin V := V * 42. 0; end P;
0;
Inside a package, declarations become visible as they are introduced, in textual order. That is, a nested package N that is declared after some other declaration D can refer to this declaration D. A declaration E following N can refer to items of N10 . But neither can look ahead and refer to any declaration that goes after them. For example, spec N above cannot refer to M in any way. In the following example, a type is derived in both of the two nested packages Disks and Books. Notice that the full declaration of parent type Item appears before the two nested
10
141
Packages packages.
with Ada ; use Ada ;
package Shelf is pragma Elaborate_Body; --things to put on the shelf type ID is range 1_000 .. 9_999; type Item ( Identifier : ID) is abstract tagged limited null record; type Item_Ref is access constant Item class; function Next_ID return ID; --a fresh ID for an Item to Put on the shelf package Disks is type Music is ( Jazz, Rock, Raga, Classic, Pop, Soul) ; type Disk ( Style : Music; Identifier : with record Artist : Unbounded_String; Title : Unbounded_String; end record; end Disks; package Books is type Literature is ( Play, Novel, Poem, Story, Text, Art) ; type Book ( Kind : Literature; Identifier : ( Identifier) with record Authors : Unbounded_String; Title : Unbounded_String; Year : Integer; end record; end Books; --shelf manipulation procedure Put ( it: Item_Ref) ; function Get ( identifier : ID) return Item_Ref; function Search ( title : String) return ID; private ID) is new Item ID) is new Item ( Identifier)
142
--keeping private things private package Boxes is type Treasure( Identifier: private type Treasure( Identifier: end Boxes; end Shelf; ID) ID) is limited private; is new Item( Identifier) with null record;
A package may also be nested inside a subprogram. In fact, packages can be declared in any declarative part, including those of a block.
The name of a child package consists of the parent unit s name followed by the child package s identier, separated by a period (dot) . .
with Ada ; use Ada ; Books is
package Shelf.
143
Packages
Novel, Poem, Story, Text, Art) ; type Book ( Kind : Literature; Identifier : with record Authors : Unbounded_String; Title : Unbounded_String; Year : Integer; end record; function match( it: end Shelf. Books; Book; text: String) ID) is new Item ( Identifier)
return Boolean;
Book has two components of type Unbounded_String, so Ada appears in a with clause of the child package. This is unlike the nested packages case which requires that all units needed by any one of the nested packages be listed in the context clause of the enclosing package (see 10.1.2 Context Clauses - With Clauses {http://www.adaic.org/resources/ add_content/standards/05rm/html/RM-10-1-2.html} ). Child packages thus give better control over package dependences. With clauses are more local. The new child package Shelf.Disks looks similar. The Boxes package which was a nested package in the private part of the original Shelf package is moved to a private child package:
private package Shelf. Boxes is type Treasure( Identifier: ID) is limited private; private type Treasure( Identifier: ID) is new Item( Identifier) with null record; function match( it: Treasure; text: String) return Boolean; end Shelf. Boxes;
The privacy of the package means that it can only be used by equally private client units. These clients include private siblings and also the bodies of siblings (as bodies are never public). Child packages may be listed in context clauses just like normal packages. A with of a child also withs the parent.
17.4.3 Subunits
A subunit is just a feature to move a body into a place of its own when otherwise the enclosing body will become too large. It can also be used for limiting the scope of context clauses. The subunits allow to physically divide a package into dierent compilation units without breaking the logical unity of the package. Usually each separated subunit goes to a dierent le allowing separate compilation of each subunit and independent version control history for each one.
144
package body Pack is procedure Proc is separate; end Pack; with Some_Unit; separate ( Pack) procedure Proc is begin ... end Proc;
17.5 Notes
Notes
17.6.1 Wikibook
Ada Programming11
17.6.2 Wikipedia
Module12
11 12 13 14
145
18 Input Output
18.1 Overview
Overview The standard Ada libraries provide several Input/Output facilities, each one adapted to specic needs. Namely, the language denes the following dedicated packages: Text_IO Sequential_IO Direct_IO Stream_IO
The programmer must choose the adequate package depending on the application needs. For example, the following properties of the data handled by the application should be considered: Data contents: plain text, or binary data? Accessing the data: random access, or sequential access? Medium: data le, console, network/data-bus? Data structure: homogeneous le (sequence of the same data eld), heterogeneous le (dierent data elds)? Data format: adherence to an existing data format, or the application can freely choose a new one? For example, Stream_IO is very powerful and can handle complex data structures but can be heavier than other packages; Sequential_IO is lean and easy to use but cannot be used by applications requiring random data access; Text_IO can handle just textual data, but it is enough for handling the command-line console. The following table gives some advices for choosing the more adequate one: Simple heuristics for choosing an I/O package Binary data Data access Plain text Homogeneous Sequential Text_IO Sequential_IO Random Text_IO Direct_IO
So the most important lesson to learn is choosing the right one. This chapter will describe more in detail these standard packages, explaining how to use them eectively. Besides these Ada-dened packages for general I/O operations each Ada compiler usually has other
147
Input Output implementation-dened Input-Output facilities, and there are also other external libraries for specialized I/O needs1 like XML processing or interfacing with databases.
procedure Main is Str : String ( 1.. 5) ; Last : Natural; begin Ada. Text_IO. Get_Line ( Str, Last) ; Ada. Text_IO. Put_Line ( Str ( 1.. Last) ) ; end;
It also contains several generic packages for converting numeric and enumeration types to character strings, or for handling Bounded and Unbounded strings, allowing the programmer to read and write dierent data types in the same le easily (there are ready-to-use instantiations of these generic packages for the Integer, Float, and Complex types). Finally, the same family of Ada.Text_IO packages (including the several children and instantiation packages) for the type Wide_Character and Wide_Wide_Character. It is worth noting that the family of Text_IO packages provide some automatic text processing. For example, the Get_Line ignores white spaces at the beginning of a line (Get_Immediate does not present this behavior), or adding a newline character when closing the le. This is thus adequate for applications handling simple textual data, but users requiring direct management of text (e.g. raw access to the character encoding) must consider other packages like Sequential_IO.
148
http://en.wikibooks.org/wiki/ada%20Programming%2FSubtypes%23definite_subtype http://en.wikibooks.org/wiki/ada%20Programming%2FSubtypes%23Ada%20Programming% 2FSubtypes%23indefinite_subtype http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Read http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Write http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Input http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Output http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Read http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Write http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Input http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Output http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27First http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Last http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Class http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Input http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Class http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Output
149
18.6.1 Wikibook
Ada Programming20 Ada Programming/Libraries/Ada.Direct_IO21 Ada Programming/Libraries/Ada.Sequential_IO22 Ada Programming/Libraries/Ada.Streams23 Ada Programming/Libraries/Ada.Streams.Stream_IO24 Ada Programming/Libraries/Ada.Text_IO.Text_Streams25 Ada Programming/Libraries/Ada.Text_IO26 Ada Programming/Libraries/Ada.Text_IO.Enumeration_IO27 (nested package) Ada Programming/Libraries/Ada.Text_IO.Integer_IO28 (nested package) Ada Programming/Libraries/Ada.Text_IO.Modular_IO29 (nested package) Ada Programming/Libraries/Ada.Text_IO.Float_IO30 (nested package) Ada Programming/Libraries/Ada.Text_IO.Fixed_IO31 (nested package) Ada Programming/Libraries/Ada.Text_IO.Decimal_IO32 (nested package) Ada Programming/Libraries/Ada.Text_IO.Bounded_IO33 Ada Programming/Libraries/Ada.Text_IO.Unbounded_IO34 Ada Programming/Libraries/Ada.Text_IO.Complex_IO35 (specialized needs annex) Ada Programming/Libraries/Ada.Text_IO.Editing36 (specialized needs annex) Ada Programming/Libraries/Ada.Integer_Text_IO37 Ada Programming/Libraries/Ada.Float_Text_IO38 Ada Programming/Libraries/Ada.Complex_Text_IO39 (specialized needs annex) Ada Programming/Libraries/Ada.Storage_IO40 (not a general-purpose I/O package) Ada Programming/Libraries/Ada.IO_Exceptions41 Ada Programming/Libraries/Ada.Command_Line42
http://en.wikibooks.org/wiki/Ada%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Direct_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Sequential_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Streams.Stream_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Text_Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Enumeration_ IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Integer_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Modular_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Float_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Fixed_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Decimal_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Bounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Unbounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Complex_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Editing http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Integer_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Float_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Complex_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Storage_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.IO_Exceptions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Command_Line
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
150
Ada Programming/Libraries/Ada.Directories43 Ada Programming/Libraries/Ada.Environment_Variables44 Ada Programming/Libraries/GNAT.IO45 (implementation dened) Ada Programming/Libraries/GNAT.IO_Aux46 (implementation dened) Ada Programming/Libraries/GNAT.Calendar.Time_IO47 (implementation dened) Ada Programming/Libraries/System.IO48 (implementation dened) Ada Programming/Libraries49 Ada Programming/Libraries/GUI50 Ada Programming/Libraries/Web51 Ada Programming/Libraries/Database52 Ada Programming/Platform53 Ada Programming/Platform/Linux54 Ada Programming/Platform/Windows55
43 44 45 46 47 48 49 50 51 52 53 54 55
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Directories http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Environment_ Variables http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.IO_Aux http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Calendar.Time_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FSystem.IO Chapter 40 on page 331 Chapter 48 on page 361 Chapter 51 on page 371 Chapter 50 on page 365 Chapter 53 on page 375 Chapter 54 on page 377 Chapter 55 on page 379
151
Input Output
152
19 Exceptions
19.1 Robustness
Robustness Robustness is the ability of a system or system component to behave reasonably when it detects an anomaly, e.g.: It receives invalid inputs. Another system component (hardware or software) malfunctions. Take as example a telephone exchange control program. What should the control program do when a line fails? It is unacceptable simply to halt all calls will then fail. Better would be to abandon the current call (only), record that the line is out of service, and continue. Better still would be to try to reuse the line the fault might be transient. Robustness is desirable in all systems, but it is essential in systems on which human safety or welfare depends, e.g., hospital patient monitoring, aircraft y-by-wire, nuclear power station control, etc.
153
Exceptions A unit (e.g., block or subprogram body) may raise an exception, to signal that an anomaly has been detected. The computation that raised the exception is abandoned (and can never be resumed, although it can be restarted). A unit may propagate an exception that has been raised by itself (or propagated out of another unit it has called). A unit may alternatively handle such an exception, allowing programmer-dened recovery from an anomalous situation. Exception handlers are segregated from normal-case code.
Ex.1
Name : String (1 .. 10); ... Name := "Hamlet"; --Raises Constraint_Error, --because the "Hamlet" has bounds (1 ..
6).
Ex.2
loop P := new Int_Node (0, P); end loop; --Soon raises Storage_Error, --because of the extreme memory leak.
154
... procedure Triangle (A, B, C : in Float; Area, Perimeter : out Float; Exists : out Boolean) is S : Float := 0.5 * (A + B + C); OK : Boolean; begin Compute_Sqrt (S * (S-A) * (S-B) * (S-C), Area, OK); Perimeter := 2.0 * S; Exists := OK; end Triangle;
A negative argument to Compute_Sqrt causes OK to be set to False. Triangle uses it to determine its own status parameter value, and so on up the calling tree, ad nauseam. versus
function Sqrt (X : Float) return Float is begin if X < 0.0 then raise Constraint_Error; end if; --compute X ... end Sqrt; ... procedure Triangle (A, B, Area, is S : Float := 0.5 * (A OK : Boolean; begin Area := Sqrt (S * Perimeter := 2.0 * S; end Triangle; C : in Float; Perimeter : out Float) + B + C); (S-A) * (S-B) * (S-C));
A negative argument to Sqrt causes Constraint_Error to be explicitly raised inside Sqrt, and propagated out. Triangle simply propagates the exception (by not handling it). Alternatively, we can catch the error by using the type system:
subtype Pos_Float is Float range 0.0 .. Float Last; function Sqrt (X : Pos_Float) return Pos_Float is begin --compute X ... end Sqrt;
A negative argument to Sqrt now raises Constraint_Error at the point of call. Sqrt is never even entered.
155
Exceptions Input-output exceptions Some examples of exceptions raised by subprograms of the predened package Ada.Text_IO are: End_Error, raised by Get, Skip_Line, etc., if end-of-le already reached. Data_Error, raised by Get in Integer_IO, etc., if the input is not a literal of the expected type. Mode_Error, raised by trying to read from an output le, or write to an input le, etc. Layout_Error, raised by specifying an invalid data format in a text I/O operation Ex. 1
declare A : Matrix (1 .. M, 1 .. N); begin for I in 1 .. M loop for J in 1 .. N loop begin Get (A(I,J)); exception when Data_Error => Put ("Ill-formed matrix element"); A(I,J) := 0.0; end; end loop; end loop; exception when End_Error => Put ("Matrix element(s) missing"); end;
Ex.2
package Directory_Enquiries is procedure Insert (New_Name : in Name; New_Number : in Number); procedure Lookup (Given_Name : in Name;
156
Corr_Number : out Number); Name_Duplicated : exception; Name_Absent : exception; Directory_Full : exception; end Directory_Enquiries;
157
Exceptions by by by by completing; executing a return statement; raising a dierent exception (raise e;); re-raising the same exception (raise;).
Suppose that an exception e is raised in a sequence of statements U (a block, subprogram body, etc.). If U contains a handler for e: that handler is executed, then control leaves U. If U contains no handler for e: e is propagated out of U; in eect, e is raised at the "point of call of U. So the raising of an exception causes the sequence of statements responsible to be abandoned at the point of occurrence of the exception. It is not, and cannot be, resumed. Ex. 1
... exception when Line_Failed => begin --attempt recovery Log_Error; Retransmit (Current_Packet); exception when Line_Failed => Notify_Engineer; --recovery failed! Abandon_Call; end; ...
158
end;
Put_Line (Exception_Information(Error));
The exception message content is implementation dened when it is not set by the user who raises the exception. It usually contains a reason for the exception and the raising location. The user can specify a message using the procedure Raise_Exception.
declare Valve_Failure : exception; begin ... Raise_Exception (Valve_Failure Identity, "Failure while opening"); ... Raise_Exception (Valve_Failure Identity, "Failure while closing"); ... exception when Fail: Valve_Failure => Put (Exception_Message (Fail)); end;
Starting with Ada 2005, a simpler syntax can be used to associate a string message with exception occurrence.
-- This language feature is only available in Ada 2005 declare Valve_Failure : exception; begin ... raise Valve_Failure with "Failure while opening"; ... raise Valve_Failure with "Failure while closing"; ... exception when Fail: Valve_Failure => Put (Exception_Message (Fail)); end;
The Ada.Exceptions package also provides subprograms for saving exception occurrences and re-raising them.
19.9.1 Wikibook
Ada Programming1
http://en.wikibooks.org/wiki/Ada%20Programming
159
Exceptions
160
20 Generics
20.1 Parametric polymorphism (generic units)
Parametric polymorphism (generic units) The idea of code reuse arises from the necessity for constructing large software systems combining well-established building blocks. The reusability of code improves the productivity and the quality of software. The generic units are one of the ways in which the Ada language supports this characteristic. A generic unit is a subprogram or package that denes algorithms in terms of types and operations that are not dened until the user instantiates them. Note to C++ programmers: generic units are similar to C++ templates. For example, to dene a procedure for swapping variables of any (non-limited) type:
generic type Element_T is private; --Generic formal type parameter procedure Swap (X, Y : in out Element_T); procedure Swap (X, Y : in out Element_T) is Temporary : constant Element_T := X; begin X := Y; Y := Temporary; end Swap;
The Swap subprogram is said to be generic. The subprogram specication is preceded by the generic formal part consisting of the reserved word generic followed by a list of generic formal parameters which may be empty. The entities declared as generic are not directly usable, it is necessary to instantiate them. To be able to use Swap, it is necessary to create an instance for the wanted type. For example:
procedure Swap_Integers is new Swap (Integer);
Now the Swap_Integers procedure can be used for variables of type Integer. The generic procedure can be instantiated for all the needed types. It can be instantiated with dierent names or, if the same identier is used in the instantiation, each declaration overloads the procedure:
161
Generics
procedure Instance_Swap is new Swap (Float); procedure Instance_Swap is new Swap (Day_T); procedure Instance_Swap is new Swap (Element_T => Stack_T);
Similarly, generic packages can be used, for example, to implement a stack of any kind of elements:
generic Max: Positive; type Element_T is private; package Generic_Stack is procedure Push (E: Element_T); function Pop return Element_T; end Generic_Stack; package body Generic_Stack is Stack: array (1 .. Max) of Element_T; Top : Integer range 0 .. Max := 0; --initialise to empty --... end Generic_Stack;
When instantiating the generic, the programmer passes one actual parameter for each formal. Formal values and subprograms can have defaults, so passing an actual for them is optional.
162
For mode in out, the actual must be a variable. One limitation with generic formal objects is that they are never considered static, even if the actual happens to be static. If the object is a number, it cannot be used to create a new type. It can however be used to create a new derived type, or a subtype:
generic Size : in Natural := 0; package P is type T1 is mod Size; --illegal! type T2 is range 1 .. Size; --illegal! type T3 is new Integer range 1 .. Size; --OK subtype T4 is Integer range 1 .. Size; --OK end P;
The reason why formal objects are nonstatic is to allow the compiler to emit the object code for the generic only once, and to have all instances share it, passing it the address of their actual object as a parameter. This bit of compiler technology is called shared generics. If formal objects were static, the compiler would have to emit one copy of the object code, with the object embedded in it, for each instance, potentially leading to an explosion in object code size (code bloat). (Note to C++ programmers: in C++, since formal objects can be static, the compiler cannot implement shared generics in the general case; it would have to examine the entire body of the generic before deciding whether or not to share its object code. In contrast, Ada generics are designed so that the compiler can instantiate a generic without looking at its body.)
163
Generics
This is quite complex, so some examples are given below. A type declared with the syntax type T (<>) denotes a type with unknown discriminants. This is the Ada vernacular for indenite types, i.e. types for which objects cannot be declared without giving an initial expression. An example of such a type is one with a discriminant without default, another example is an unconstrained array type. Generic formal type type T (<>) is limited private; Acceptable actual types Any type at all. The actual type can be limited1 or not, indenite or denite, but the generic treats it as limited and indenite, i.e. does not assume that assignment is available for the type. Any nonlimited type: the generic knows that it is possible to assign to variables of this type, but it is not possible to declare objects of this type without initial value. Any nonlimited denite type: the generic knows that it is possible to assign to variables of this type and to declare objects without initial value. Any tagged type2 , abstract or concrete, limited or not. Any concrete tagged type, limited or not. Any nonlimited tagged type, abstract or concrete. Any nonlimited, concrete tagged type. Any type derived from Parent. The generic knows about Parent s operations, so can call them. Neither T nor Parent can be abstract. Any type, abstract or concrete, derived from Parent, where Parent is a tagged type, so calls to T s operations can dispatch dynamically. Any concrete type, derived from the tagged type Parent.
type T is private;
type T (<>) is abstract tagged limited private; type T (<>) is tagged limited private; type T (<>) is abstract tagged private; type T (<>) is tagged private; type T (<>) is new Parent;
type T (<>) is abstract new Parent with private; type T (<>) is new Parent with private;
1 2
164
Generic formal type type T is (<>); type type type type type type T T T T T T is range <>; is mod <>; is delta <>; is delta <> digits <>; is digits <>; is array (I) of E;
type T is access O;
Acceptable actual types Any discrete type: integer3 , modular4 , or enumeration5 . Any signed integer type Any modular type Any (non-decimal) xed point type6 Any decimal xed point type Any oating point type7 Any array type8 with index of type I and elements of type E (I and E could be formal parameters as well) Any access type9 pointing to objects of type O (O could be a formal parameter as well)
In the body we can only use the operations predened for the type category of the formal parameter. That is, the generic specication is a contract between the generic implementor and the client instantiating the generic unit. This is dierent to the parametric features of other languages, such as C++. It is possible to further restrict the set of acceptable actual types like so: Generic formal type type T (<>) is... type T (D : DT) is... type T is... Acceptable actual types Denite or indenite types (loosely speaking: types with or without discriminants, but other forms of indefiniteness exist) Types with a discriminant of type DT (it is possible to specify several discriminants, too) Denite types (loosely speaking types without a discriminant or with a discriminant with default value)
3 4 5 6 7 8 9
165
Generics Here is the specication of a generic subprogram that takes another subprogram as its parameter:
generic type Element_T is private; with function "*" (X, Y: Element_T) return Element_T; function Square (X : Element_T) return Element_T;
And here is the body of the generic subprogram; it calls parameter as it would any other subprogram.
function Square (X: Element_T) return Element_T is begin return X * X; --The formal operator "*". end Square;
This generic function could be used, for example, with matrices, having dened the matrix product.
with Square; with Matrices; procedure Matrix_Example is function Square_Matrix is new Square (Element_T => Matrices.Matrix_T, "*" => Matrices.Product); A : Matrices.Matrix_T := Matrices.Identity; begin A := Square_Matrix (A); end Matrix_Example;
It is possible to specify a default with "the box" (is <> ), like this:
generic type Element_T is private; with function "*" (X, Y: Element_T) return Element_T is <>;
This means that if, at the point of instantiation, a function "*" exists for the actual type, and if it is directly visible, then it will be used by default as the actual subprogram. One of the main uses is passing needed operators. The following example shows this (follow download links for full example):
File:
Algorithms/binary_search.adb
generic type Element_Type is private; ... with function "<" (Left : in Element_Type; Right : in Element_Type) return Boolean
166
is <> ; procedure Search (Elements : in Array_Type; Search : in Element_Type; Found : out Boolean; Index : out Index_Type Base) ...
This means that the actual must be an instance of the generic package Q. The box after Q means that we do not care which actual generic parameters were used to create the actual for P. It is possible to specify the exact parameters, or to specify that the defaults must be used, like this:
generic --P1 must be an instance of Q with the specified actual parameters: with package P1 is new Q (Param1 => X, Param2 => Y); --P2 must be an instance of Q where the actuals are the defaults: with package P2 is new Q;
It is all or nothing: if you specify the generic parameters, you must specify all of them. Similarly, if you specify no parameters and no box, then all the generic formal parameters of Q must have defaults. The actual package must, of course, match these constraints. The generic sees both the public part and the generic parameters of the actual package (Param1 and Param2 in the above example). This feature allows the programmer to pass arbitrarily complex types as parameters to a generic unit, while retaining complete type safety and encapsulation. (example needed) It is not possible for a package to list itself as a generic formal, so no generic recursion is possible. The following is illegal:
with A; generic with package P is new A (<> ); package A; --illegal: A references itself
167
Generics
Notes of special interest to C++ programmers: The generic formal types dene completely which types are acceptable as actuals; therefore, the compiler can instantiate generics without looking at the body of the generic. Each instance has a name and is dierent from all other instances. In particular, if a generic package declares a type, and you create two instances of the package, then you will get two dierent, incompatible types, even if the actual parameters are the same. Ada requires that all instantiations be explicit. It is not possible to create special-case instances of a generic (known as "template specialisation" in C++). As a consequence of the above, Ada does not permit template metaprogramming. However, this design has signicant advantages: the object code can be shared by all instances of a generic, unless of course the programmer has requested that subprograms be inlined; there is no danger of code bloat. when reading programs written by other people, there are no hidden instantiations, and no special cases to worry about. Ada follows the Law of Least Astonishment.
168
package Bag_Of_Strings is type Bag is private; generic with procedure Operator (S : in out String); procedure Apply_To_All (B : in out Bag); private --omitted end Bag_Of_Strings;
To use Apply_To_All, you rst dene the procedure to be applied to each String in the Bag. Then, you instantiate Apply_To_All, and nally you call the instance.
with Bag_Of_Strings; procedure Example_1 is procedure Capitalize (S : in out String) is separate; --omitted procedure Capitalize_All is new Bag_Of_Strings.Apply_To_All (Operator => Capitalize); B : Bag_Of_Strings.Bag; begin Capitalize_All (B); end Example_1;
Example 2. A generic subprogram nested in a generic package This is the same as above, except that now the Bag itself is generic:
generic type Element_Type (<>) is private; package Generic_Bag is type Bag is private; generic with procedure Operator (S : in out Element_Type); procedure Apply_To_All (B : in out Bag); private --omitted end Generic_Bag;
As you can see, the generic formal subprogram Operator takes a parameter of the generic formal type Element_Type. This is okay: the nested generic sees everything that is in its enclosing unit. You cannot instantiate Generic_Bag.Apply_To_All directly, so you must rst create an instance of Generic_Bag, say Bag_Of_Strings, and then instantiate Bag_Of_Strings.Apply_To_All.
with Generic_Bag; procedure Example_2 is procedure Capitalize (S : in out String) is separate; --omitted package Bag_Of_Strings is new Generic_Bag (Element_Type => String); procedure Capitalize_All is new Bag_Of_Strings.Apply_To_All (Operator => Capitalize); B : Bag_Of_Strings.Bag; begin
169
Generics
The dierences between this and Example 1 are: Bag_Of_Strings.Apply_To_All is compiled separately. In particular, Bag_Of_Strings.Apply_To_All might have been written by a dierent person who did not have access to the source text of Bag_Of_Strings. Before you can use Bag_Of_Strings.Apply_To_All, you must with it explicitly; withing the parent, Bag_Of_Strings, is not sucient. If you do not use Bag_Of_Strings.Apply_To_All, your program does not contain its object code. Because Bag_Of_Strings.Apply_To_All is at the library level, it can declare controlled types; the nested package could not do that in Ada 95. In Ada 2005, one can declare controlled types at any level.
with Bag_Of_Strings.Apply_To_All; --implicitly withs Bag_Of_Strings, too procedure Example_3 is procedure Capitalize (S : in out String) is separate; --omitted procedure Capitalize_All is new Bag_Of_Strings.Apply_To_All (Operator => Capitalize); B : Bag_Of_Strings.Bag; begin Capitalize_All (B); end Example_3;
Example 4. A generic unit that is a child of a generic unit This is the same as Example 3, except that now the Bag is generic, too.
generic type Element_Type (<>) is private; package Generic_Bag is type Bag is private; private
170
--omitted end Generic_Bag; generic with procedure Operator (S : in out Element_Type); procedure Generic_Bag.Apply_To_All (B : in out Bag); with Generic_Bag.Apply_To_All; procedure Example_4 is procedure Capitalize (S : in out String) is separate; --omitted package Bag_Of_Strings is new Generic_Bag (Element_Type => String); procedure Capitalize_All is new Bag_Of_Strings.Apply_To_All (Operator => Capitalize); B : Bag_Of_Strings.Bag; begin Capitalize_All (B); end Example_4;
Example 5. A parameterless generic child unit Children of a generic unit must be generic, no matter what. If you think about it, it is quite logical: a child unit sees the public and private parts of its parent, including the variables declared in the parent. If the parent is generic, which instance should the child see? The answer is that the child must be the child of only one instance of the parent, therefore the child must also be generic.
generic type Element_Type (<>) is private; type Hash_Type is (<>); with function Hash_Function (E : Element_Type) return Hash_Type; package Generic_Hash_Map is type Map is private; private --omitted end Generic_Hash_Map;
Suppose we want a child of a Generic_Hash_Map that can serialise the map to disk; for this it needs to sort the map by hash value. This is easy to do, because we know that Hash_Type is a discrete type, and so has a less-than operator. The child unit that does the serialisation does not need any additional generic parameters, but it must be generic nevertheless, so it can see its parent s generic parameters, public and private part.
generic package Generic_Hash_Map.Serializer is procedure Dump (Item : in Map; To_File : in String); procedure Restore (Item : out Map; From_File : in String); end Generic_Hash_Map.Serializer;
To read and write a map to disk, you rst create an instance of Generic_Hash_Map, for example Map_Of_Unbounded_Strings, and then an instance of Map_Of_Unbounded_Strings.Serializer:
171
Generics
with Ada.Strings.Unbounded; with Generic_Hash_Map.Serializer; procedure Example_5 is use Ada.Strings.Unbounded; function Hash (S : in Unbounded_String) return Integer is separate; --omitted package Map_Of_Unbounded_Strings is new Generic_Hash_Map (Element_Type => Unbounded_String, Hash_Type => Integer, Hash_Function => Hash); package Serializer is new Map_Of_Unbounded_Strings.Serializer; M : Map_Of_Unbounded_Strings.Map; begin Serializer.Restore (Item => M, From_File => "map.dat"); end Example_5;
20.5.1 Wikibook
Ada Programming10 Ada Programming/Object Orientation11 : tagged types provides other mean of polymorphism in Ada.
20.5.2 Wikipedia
Generic programming12
10 11 12 13
172
21 Tasking
21.1 Tasks
Tasks A task unit is a program unit that is obeyed concurrently with the rest of an Ada program. The corresponding activity, a new locus of control, is called a task in Ada terminology, and is similar to a thread, for example in Java Threads1 . The execution of the main program is also a task, the anonymous environment task. A task unit has both a declaration and a body, which is mandatory. A task body may be compiled separately as a subunit, but a task may not be a library unit, nor may it be generic. Every task depends on a master, which is the immediately surrounding declarative region - a block, a subprogram, another task, or a package. The execution of a master does not complete until all its dependent tasks have terminated. The environment task is the master of all other tasks; it terminates only when all other tasks have terminated. Task units are similar to packages in that a task declaration denes entities exported from the task, whereas its body contains local declarations and statements of the task. A single task is declared as follows:
task Single is declarations of exported identifiers end Single; ... task body Single is local declarations and statements end Single;
Ex. 1
procedure Housekeeping is task Check_CPU; task Backup_Disk;
http://en.wikibooks.org/wiki/Java%3AThreads
173
Tasking
task body Check_CPU is ... end Check_CPU; task body Backup_Disk is ... end Backup_Disk; --the two tasks are automatically created and begin execution begin --Housekeeping null; --Housekeeping waits here for them to terminate end Housekeeping;
It is possible to declare task types, thus allowing task units to be created dynamically, and incorporated in data structures:
task type T is ... end T; ... Task_1, Task_2 : T; ... task body T is ... end T;
Task types are limited, i.e. they are restricted in the same way as limited private types, so assignment and comparison are not allowed.
21.1.1 Rendezvous
The only entities that a task may export are entries. An entry looks much like a procedure. It has an identier and may have in, out or in out parameters. Ada supports communication from task to task by means of the entry call. Information passes between tasks through the actual parameters of the entry call. We can encapsulate data structures within tasks and operate on them by means of entry calls, in a way analogous to the use of packages for encapsulating variables. The main dierence is that an entry is executed by the called task, not the calling task, which is suspended until the call completes. If the called task is not ready to service a call on an entry, the calling task waits in a (FIFO) queue associated with the entry. This interaction between calling task and called task is known as a rendezvous. The calling task requests rendezvous with a specic named task by calling one of its entries. A task accepts rendezvous with any caller of a specic entry by executing an accept statement for the entry. If no caller is waiting, it is held up. Thus entry call and accept statement behave symmetrically. (To be honest, optimized object code may reduce the number of context switches below the number implied by this naive description.) Ex. 2 The following task type implements a single-slot buer, i.e. an encapsulated variable that can have values inserted and removed in strict alternation. Note that the buer task has no need of state variables to implement the buer protocol: the alternation of insertion and removal operations is directly enforced by the control structure in the body of Encapsulated_Buer_Task_Type which is, as is typical, a loop.
174
task type Encapsulated_Buffer_Task_Type is entry Insert (An_Item : in Item); entry Remove (An_Item : out Item); end Encapsulated_Buffer_Task_Type; ... Buffer_Pool : array (0 .. 15) of Encapsulated_Buffer_Task_Type; This_Item : Item; ... task body Encapsulated_Buffer_Task_Type is Datum : Item; begin loop accept Insert (An_Item : in Item) do Datum := An_Item; end Insert; accept Remove (An_Item : out Item) do An_Item := Datum; end Remove; end loop; end Encapsulated_Buffer_Task_Type; ... Buffer_Pool(1).Remove (This_Item); Buffer_Pool(2).Insert (This_Item);
175
Tasking
accept Fetch (An_Item : out Item) do An_Item := Datum; end Fetch; end select; end loop; end Encapsulated_Variable_Task_Type; x, y : Encapsulated_Variable_Task_Type;
Again, note that the control structure of the body ensures that an Encapsulated_Variable_Task_Type must be given an initial value by a rst Store operation before any Fetch operation can be accepted.
21.1.3 Guards
Depending on circumstances, a server task may not be able to accept calls for some of the entries that have accept alternatives in a selective wait statement. The acceptance of any alternative can be made conditional by using a guard, which is Boolean2 precondition for acceptance. This makes it easy to write monitor-like server tasks, with no need for an explicit signaling mechanism, nor for mutual exclusion. An alternative with a True guard is said to be open. It is an error if no alternative is open when the selective wait statement is executed, and this raises the Program_Error exception. Ex. 4
task Cyclic_Buffer_Task_Type is entry Insert (An_Item : in Item); entry Remove (An_Item : out Item); end Cyclic_Buffer_Task_Type; ... task body Cyclic_Buffer_Task_Type is Q_Size : constant := 100; subtype Q_Range is Positive range 1 .. Q_Size; Length : Natural range 0 .. Q_Size := 0; Head, Tail : Q_Range := 1; Data : array (Q_Range) of Item; begin loop select when Length < Q_Size => accept Insert (An_Item : in Item) do
http://en.wikibooks.org/wiki/Ada%20Programming%2FTypes%23Boolean
176
Data(Tail) := An_Item; end Insert; Tail := Tail mod Q_Size + 1; Length := Length + 1; or when Length > 0 => accept Remove (An_Item : out Item) do An_Item := Data(Head); end Remove; Head := Head mod Q_Size + 1; Length := Length - 1; end select; end loop; end Cyclic_Buffer_Task_Type;
177
Tasking
protected type Protected_Buffer_Type is entry Insert (An_Item : in Item); entry Remove (An_Item : out Item); private Buffer : Item; Empty : Boolean := True; end Protected_Buffer_Type; ... protected body Protected_Buffer_Type is entry Insert (An_Item : in Item) when Empty is begin Buffer := An_Item; Empty := False; end Insert; entry Remove (An_Item : out Item) when not Empty is begin An_Item := Buffer; Empty := True; end Remove; end Protected_Buffer_Type;
Note how the guards, using the state variable Empty, ensure that messages are alternately inserted and removed, and that no attempt can be made to take data from an empty buer. All this is achieved without explicit signaling or mutual exclusion constructs, whether in the calling task or in the protected type itself. The notation for calling a protected entry or procedure is exactly the same as that for calling a task entry. This makes it easy to replace one implementation of the abstract type by the other, the calling code being unaected. Ex. 6 The following task type implements Dijkstra s semaphore ADT, with FIFO scheduling of resumed processes. The algorithm will accept calls to both Wait and Signal, so long as the semaphore invariant would not be violated. When that circumstance approaches, calls to Wait are ignored for the time being.
task type Semaphore_Task_Type is entry Initialize (N : in Natural); entry Wait; entry Signal; end Semaphore_Task_Type; ... task body Semaphore_Task_Type is Count : Natural; begin accept Initialize (N : in Natural) do Count := N; end Initialize; loop select when Count > 0 => accept Wait do Count := Count - 1; end Wait; or accept Signal; Count := Count + 1; end select;
178
Alternatively, semaphore functionality can be provided by a protected object, with major eciency gains. Ex. 7 The Initialize and Signal operations of this protected type are unconditional, so they are implemented as protected procedures, but the Wait operation must be guarded and is therefore implemented as an entry.
protected type Semaphore_Protected_Type is procedure Initialize (N : in Natural); entry Wait; procedure Signal; private Count : Natural := 0; end Semaphore_Protected_Type; ... protected body Semaphore_Protected_Type is procedure Initialize (N : in Natural) is begin Count := N; end Initialize; entry Wait when Count > 0 is begin Count := Count - 1; end Wait; procedure Signal is begin Count := Count + 1; end Signal; end Semaphore_Protected_Type;
Unlike the task type above, this does not ensure that Initialize is called before Wait or Signal, and Count is given a default initial value instead. Restoring this defensive feature of the task version is left as an exercise for the reader.
179
Tasking Entry families Sometimes we need a group of related entries. Entry families, indexed by a discrete type3 , meet this need. Ex. 8 This task provides a pool of several buers.
type Buffer_Id is Integer range 1 .. nr_Bufs; ... task Buffer_Pool_Task is entry Insert (Buffer_Id) (An_Item : in Item); entry Remove (Buffer_Id) (An_Item : out Item); end Buffer_Pool_Task; ... task body Buffer_Pool_Task is Data : array (Buffer_Id) of Item; Filled : array (Buffer_Id) of Boolean := (others => False); begin loop for I in Data Range loop select when not Filled(I) => accept Insert (I) (An_Item : in Item) do Data(I) := An_Item; end Insert; Filled(I) := True; or when Filled(I) => accept Remove (I) (An_Item : out Item) do An_Item := Data(I); end Remove; Filled(I) := False; else null; --N.B. "polling" or "busy waiting" end select; end loop; end loop; end Buffer_Pool_Task; ... Buffer_Pool_Task.Remove(K)(This_Item);
Note that the busy wait else null is necessary here to prevent the task from being suspended on some buer when there was no call pending for it, because such suspension would delay serving requests for all the other buers (perhaps indenitely).
21.4 Termination
Termination Server tasks often contain innite loops to allow them to service an arbitrary number of calls in succession. But control cannot leave a task s master until the task terminates, so we need a way for a server to know when it should terminate. This is done by a terminate alternative in a selective wait.
http://en.wikibooks.org/wiki/ada%20Programming%2FTypes%23List%20of%20Types
180
Ex. 9
task type Terminating_Buffer_Task_Type is entry Insert (An_Item : in Item); entry Remove (An_Item : out Item); end Terminating_Buffer_Task_Type; ... task body Terminating_Buffer_Task_Type is Datum : Item; begin loop select accept Insert (An_Item : in Item) do Datum := An_Item; end Insert; or terminate; end select; select accept Remove (An_Item : out Item) do An_Item := Datum; end Remove; or terminate; end select; end loop; end Terminating_Buffer_Task_Type;
The task terminates when: 1. 2. 3. 4. at least one terminate alternative is open, and there are no pending calls to its entries, and all other tasks of the same master are in the same state (or already terminated), and the task s master has completed (i.e. has run out of statements to execute).
Conditions (1) and (2) ensure that the task is in a t state to stop. Conditions (3) and (4) ensure that stopping cannot have an adverse eect on the rest of the program, because no further calls that might change its state are possible.
21.5 Timeout
Timeout A task may need to avoid being held up by calling to a slow server. A timed entry call lets a client specify a maximum delay before achieving rendezvous, failing which the attempted entry call is withdrawn and an alternative sequence of statements is executed. Ex. 10
task Password_Server is entry Check (User, Pass : in String; Valid : out Boolean); entry Set (User, Pass : in String); end Password_Server; ... User_Name, Password : String (1 .. 8); ...
181
Tasking
Put ("Please give your new password:"); Get_Line (Password); select Password_Server.Set (User_Name, Password); Put_Line ("Done"); or delay 10.0; Put_Line ("The system is busy now, please try again later."); end select;
To time out the functionality provided by a task, two distinct entries are needed: one to pass in arguments, and one to collect the result. Timing out on rendezvous with the latter achieves the desired eect. Ex. 11
task Process_Data is entry Input (D : in Datum); entry Output (D : out Datum); end Process_Data; Input_Data, Output_Data : Datum; loop collect Input_Data from sensors; Process_Data.Input (Input_Data); select Process_Data.Output (Output_Data); pass Output_Data to display task; or delay 0.1; Log_Error ("Processing did not complete quickly enough."); end select; end loop;
Symmetrically, a delay alternative in a selective wait statement allows a server task to withdraw an oer to accept calls after a maximum delay in achieving rendezvous with any client. Ex. 12
task Resource_Lender is entry Get_Loan (Period : in Duration); entry Give_Back; end Resource_Lender; ... task body Resource_Lender is Period_Of_Loan : Duration; begin loop select accept Get_Loan (Period : in Duration) do Period_Of_Loan := Period; end Get_Loan; select accept Give_Back; or delay Period_Of_Loan; Log_Error ("Borrower did not give up loan soon
182
enough."); or
end select;
and
select Callee.Rendezvous; or delay 0.0; Do_something_else; end select;
seem to be conceptually equivalent. However, the attempt to start the rendezvous may take some time, especially if the callee is on another processor, so the delay 0.0; may expire although the callee would be able to accept the rendezvous, whereas the else construct is safe.
21.8 Scheduling
183
21.9 Interfaces
Interfaces This language feature is only available in Ada 2005 Task and Protected types can also implement interfaces4 .
type Printable is task interface; procedure Input (D : in Printable);
task Process_Data is new Printable with entry Input (D : in Datum); entry Output (D : out Datum); end Process_Data;
21.10.1 Wikibook
Ada Programming5 Ada Programming/Libraries/Ada.Storage_IO6
184
7 8
http://www.adaic.org/docs/95style/html/sec_6/toc.html http://es.wikibooks.org/wiki/Programaci%F3n%20en%20Ada%2FTareas
185
22 Object Orientation
22.1 Object orientation in Ada
Object orientation in Ada Object oriented programming consists in building the software in terms of "objects". An "object" contains data and has a behavior. The data, normally, consists in constants and variables as seen in the rest of this book but could also, conceivably, reside outside the program entirely, i.e. on disk or on the network. The behavior consists in subprograms that operate on the data. What makes Object Orientation unique, compared to procedural programming, is not a single feature but the combination of several features: encapsulation, i.e. the ability to separate the implementation of an object from its interface; this in turn separates "clients" of the object, who can only use the object in certain predened ways, from the internals of the object, which have no knowledge of the outside clients. inheritance, the ability for one type of objects to inherit the data and behavior (subprograms) of another, without necessarily needing to break encapsulation; type extension, the ability for an object to add new data components and new subprograms on top of the inherited ones and to replace some inherited subprograms with its own versions; this is called overriding. polymorphism, the ability for a "client" to use the services of an object without knowing the exact type of the object, i.e. in an abstract way. The actual type of the object can indeed change at run time from one invocation to the next. It is possible to do object-oriented programming in any language, even assembly. However, type extension and polymorphism are very dicult to get right without language support. In Ada, each of these concepts has a matching construct; this is why Ada supports objectoriented programming directly. Packages provide encapsulation; Derived types provide inheritance; Record extensions, described below, provide for type extension; Class-wide types, also described below, provide for polymorphism.
Ada has had encapsulation and derived types since the rst version (MIL-STD-1815 in 1980), which led some to qualify the language as "object-oriented" in a very narrow sense. Record extensions and class-wide types were added in Ada 95. Ada 2005 further adds interfaces. The rest of this chapter covers these aspects.
187
Object Orientation
The Directory is an object consisting of data (the telephone numbers and addresses, presumably held in an external le or database) and behavior (it can look an entry up and traverse all the entries matching a Name_Pattern, calling Visit on each). A simple package provides for encapsulation (the inner workings of the directory are hidden) and a pair of subprograms provide the behavior. This pattern is appropriate when only one object of a certain type must exist; there is, therefore, no need for type extension or polymorphism.
188
type Acc_T is access T; procedure Proc (Pointer: Acc_T); private type T is record Data: Boolean; end record; end P;
--not primitive
The above example creates a type T that contains data (here just a Boolean but it could be anything) and behavior consisting of some subprograms. It also demonstrates encapsulation by placing the details of the type T in the private part of the package. The primitive operations of T are the function Create, the overloaded procedures Work, and the predened "=" operator; Proc is not primitive, since it has an access type on T as parameter don t confuse this with an access parameter, as used in the second procedure Work. When deriving from T, the primitive operations are inherited.
with P; package Q is type Derived is new P.T; end Q;
The type Q.Derived has the same data and the same behavior as P.T; it inherits both the data and the subprograms. Thus it is possible to write:
with Q; procedure Main is Object: Q.Derived := Q.Create (Data => False); begin Q.Work (Object); end Main;
Admittedly, the reasons for writing this may seem obscure. The purpose of this kind of code is to have objects of types P.T and Q.Derived, which are not compatible:
Ob1: P.T; Ob2: Q.Derived; Ob1 := Ob2; Ob1 := P.T (Ob2); -- illegal -- but convertible
This feature is not used very often (it s used e.g. for declaring types reecting physical dimensions) but I present it here to introduce the next step: type extension.
189
Object Orientation record is like any other record, so it can contain arbitrary data.
package Person is type Object is tagged record Name : String (1 .. 10); Gender : Gender_Type; end record; procedure Put (O : Object); end Person;
As you can see, a Person.Object is an object in the sense that it has data and behavior (the procedure Put). However, this object does not hide its data; any program unit that has a with Person clause can read and write the data in a Person.Object directly. This breaks encapsulation and also illustrates that Ada completely separates the concepts of encapsulation and type. Here is a version of Person.Object that encapsulates its data:
package Person is type Object is tagged private; procedure Put (O : Object); private type Object is tagged record Name : String (1 .. 10); Gender : Gender_Type; end record; end Person;
Because the type Person.Object is tagged, it is possible to create a record extension, which is a derived type with additional data.
with Person; package Programmer is type Object is new Person.Object with private; private type Object is new Person.Object with record Skilled_In : Language_List; end record; end Programmer;
The type Programmer.Object inherits the data and behavior, i.e. the type s primitive operations, from Person.Object; it is thus possible to write:
with Programmer; procedure Main is Me : Programmer.Object; begin Programmer.Put (Me); Me.Put; --equivalent to the above, Ada 2005 only end Main;
So the declaration of the type Programmer.Object, as a record extension of Person.Object, implicitly declares a procedure Put that applies to a Programmer.Object.
190
Like in the case of untagged types, objects of type Person and Programmer are convertible. However, where untagged objects are convertible in either direction, conversion of tagged types only works in the direction to the root. (Conversion away from the root would have to add components out of the blue.) Such a conversion is called a view conversion, because components are not lost, they only become invisible. Extension aggregates have to be used if you go away from the root.
22.1.5 Overriding
Now that we have introduced tagged types, record extensions and primitive operations, it becomes possible to understand overriding. In the examples above, we introduced a type Person.Object with a primitive operation called Put. Here is the body of the package:
with Ada.Text_IO; package body Person is procedure Put (O : Object) is begin Ada.Text_IO.Put (O.Name); Ada.Text_IO.Put (" is a "); Ada.Text_IO.Put_Line (Gender_Type Image (O.Gender)); end Put; end Person;
As you can see, this simple operation prints both data components of the record type to standard output. Now, remember that the record extension Programmer.Object has an additional data member. If we write:
with Programmer; procedure Main is Me : Programmer.Object; begin Programmer.Put (Me); Me.Put; --equivalent to the above, Ada 2005 only end Main;
then the program will call the inherited primitive operation Put, which will print the name and gender but not the additional data. In order to provide this extra behavior, we must override the inherited procedure Put like this:
with Person; package Programmer is type Object is new Person.Object with private; overriding --Optional keyword, new in Ada 2005 procedure Put (O : Object); private type Object is new Person.Object with record Skilled_In : Language_List; end record; end Programmer; package body Programmer is
191
Object Orientation
procedure Put (O : Object) is begin Person.Put (Person.Object (O)); --view conversion to the ancestor type Put (O.Skilled_In); --presumably declared in the same package as Language_List end Put; end Programmer;
Programmer.Put overrides Person.Put; in other words it replaces it completely. Since the intent is to extend the behavior rather than replace it, Programmer.Put calls Person.Put as part of its behavior. It does this by converting its parameter from the type Programmer.Object to its ancestor type Person.Object. This construct is a view conversion; contrary to a normal type conversion, it does not create a new object and does not incur any run-time cost. Of course, it is optional that an overriding operation call its ancestor; there are cases where the intent is indeed to replace, not extend, the inherited behavior. (Note that also for untagged types, overriding of inherited operations is possible. The reason why it s discussed here is that derivation of untagged types is done rather seldom.)
192
The declaration of Someone denotes an object that may be of either type, Person.Object or Programmer.Object. Consequently, the call to the primitive operation Put dispatches dynamically to either Person.Put or Programmer.Put. The only problem is that, since we don t know whether Someone is a programmer or not, we don t know how many data components Someone has, either, and therefore we don t know how many bytes Someone takes in memory. For this reason, the class-wide type Person.Object Class is indenite1 . It is impossible to declare an object of this type without giving some constraint. It is, however, possible to: declare an object of a class-wide with an initial value (as above). The object is then constrained by its initial value. declare an access value to such an object (because the access value has a known size); pass objects of a class-wide type as parameters to subprograms assign an object of a specic type (in particular, the result of a function call) to a variable of a class-wide type. With this knowledge, we can now build a polymorphic collection of persons; in this example we will quite simply create an array of access values to persons:
with Person; procedure Main is type Person_Access is access Person.Object Class; type Array_Of_Persons is array (Positive range <>) of Person_Access; function Read_From_Disk return Array_Of_Persons is separate; Everyone : constant Array_Of_Persons := Read_From_Disk; begin --Main for K in Everyone Range loop Everyone (K).all.Put; --dereference followed by dynamic dispatching end loop; end Main;
The above procedure achieves our desired goal: it traverses the array of Persons and calls the procedure Put that is appropriate for each person. Advanced topic: How dynamic dispatching works You don t need to know how dynamic dispatching works in order to use it eectively but, in case you are curious, here is an explanation. The rst component of each object in memory is the tag; this is why objects are of a tagged type rather than plain records. The tag really is an access value to a table; there is one table for each specic type. The table contains access values to each primitive operation of the type. In our example, since there are two types Person.Object and Programmer.Object, there are two tables, each containing a single access value. The table for Person.Object contains an access value to Person.Put and the table for Programmer.Object contains an access value to Programmer.Put. When you compile your program, the compiler constructs both tables and places them in the program executable code.
1 http://en.wikibooks.org/wiki/ada%20Programming%2FSubtypes%23Indefinite_subtype
193
Object Orientation Each time the program creates a new object of a specic type, it automatically sets its tag to point to the appropriate table. Each time the program calls a primitive operation, the compiler inserts object code that: dereferences the tag to nd the table of primitive operations for the specic type of the object at hand dereferences the access value to the primitive operation calls the primitive operation. When you perform a view conversion to an ancestor type, the compiler performs these two dereferences at compile time rather than run time: this is static dispatching; the compiler emits code that directly calls the primitive operation of the ancestor type specied in the view conversion. Redispatching Dispatching works on the (hidden) tag of the object. So what happens when a primitive operation Op1 calls another primitive operation Op2? Which operation will be called when Op1 is called by dispatching?
type Root is tagged private; procedure Op1 (R: Root); procedure Op2 (R: Root); type Derived is new Root with private; -- Derived inherits Op1 overriding procedure Op2 (D: Derived); procedure Op1 (R: Root) is begin ... Op2 (R); -- not redispatching Op2 (Root Class (R)); -- redispatching ... end Op1; D: Derived; C: Root Class := D; Op1 (D); Op1 (C); -- static call -- dispatching call
In this fragment, Op1 is not overridden, whereas Op2 is overridden. The body of Op1 calls Op2, thus which Op2 will be called for a call of Op1 with a parameter of type Derived? The answer is: Ada gives complete control over dispatching and redispatching. If you want redispatching, it has to be required explicitly by converting the parameter to the class-wide type again. (Remember: View conversions never lose components, they just hide them. A conversion to the class-wide type makes them visible again.) Thus the rst call of Op1 (statically linked, i.e. not dispatching) calls the inherited Op1 and within Op1, the rst call to Op2 is therefore also a static call to the inherited Op2 (there is no redispatching). However the second call, since the parameter R is converted to the class-wide type, dispatches to the overriding Op2.
194
The second call of Op1 is a dispatching call to the inherited Op1 and behaves exactly as the rst. To understand what happens here, the implicitly dened inherited Op1 is just the parent operation called with a view conversion of the parameter:
procedure Op1 (D: Derived) is begin Op1 (Root (R)); -- view conversion end Op1;
Run-time type identication Run-time type identication allows the program to (indirectly or directly) query the tag of an object at run time to determine which type the object belongs to. This feature, obviously, makes sense only in the context of polymorphism and dynamic dispatching, so works only on tagged types. You can determine whether an object belongs to a certain class of types, or to a specic type, by means of the membership test in, like this:
type Base is tagged private; type Derived is new Base with private; type Leaf is new Derived with private; ... procedure Explicit_Dispatch (This : in Base Class) is begin if This in Leaf then ... end if; if This in Derived Class then ... end if; end Explicit_Dispatch;
Thanks to the strong typing rules of Ada, run-time type identication is in fact rarely needed; the distinction between class-wide and specic types usually allows the programmer to ensure objects are of the appropriate type without resorting to this feature. Additionally, the reference manual denes package Ada.Tags (RM 3.9(6/2)), attribute Tag (RM 3.9(16,18)), and function Ada.Tags.Generic_Dispatching_Constructor (RM 3.9(18.2/2)), which enable direct manipulation with tags.
Objects are created at run time and contain a value of a given type. An object be created and initialized as part of elaborating a declaration, evaluating an alloc aggregate, or function_call.
195
Object Orientation For example, assume a typical hierarchy of object oriented types: a top-level type Person, a Programmer type derived from Person, and possibly more kinds of persons. Each person has a name; assume Person objects to have a Name component. Likewise, each Person has a Gender component. The Programmer type inherits the components and the operations of the Person type, so Programmer objects have a Name and a Gender component, too. Programmer objects may have additional components specic to programmers. Objects of a tagged type are created the same way as objects of any type. The second LRM sentence says, for example, that an object will be created when you declare a variable or a constant of a type. For the tagged type Person,
declare P: Person; begin Text_IO. Put_Line( "The name is " & end;
P. Name) ;
Nothing special so far. Just like any ordinary variable declaration this O-O one is elaborated. The result of elaboration is an object named P of type Person. However, P has only default name and gender value components. These are likely not useful ones. One way of giving initial values to the object s components is to assign an aggregate.
declare P: Person := ( Name => "Scorsese", Gender => begin Text_IO. Put_Line( "The name is " & P. Name) ; end;
Male) ;
The parenthesized expression after := is called an aggregate (4.3 Aggregates {http://www. adaic.org/resources/add_content/standards/05rm/html/RM-4-3.html} ). Another way to create an object that is mentioned in the LRM paragraph is to call a function. An object will be created as the return value of a function call. Therefore, instead of using an aggregate of initial values, we might call a function returning an object. Introducing proper O-O information hiding, we change the package containing the Person type so that Person becomes a private type. To enable clients of the package to construct Person objects we declare a function that returns them. (The function may do some interesting construction work on the objects. For instance, the aggregate above will most probably raise the exception Constraint_Error depending on the name string supplied; the function can mangle the name so that it matches the declaration of the component.) We also declare a function that returns the name of Person objects.
package Persons is type Person is tagged private; function Make ( Name: function Name ( P: private String; Sex: Gender_Type) return Person;
Person)
return String;
196
type Person is tagged record Name : String ( 1 .. Gender : Gender_Type; end record; end Persons;
10) ;
Calling the Make function results in an object which can be used for initialization. Since the Person type is private we can no longer refer to the Name component of P. But there is a corresponding function Name declared with type Person making it a socalled primitive operation. (The component and the function in this example are both named Name However, we can choose a dierent name for either if we want.)
declare P: Person := Make ( Name => "Orwell", Sex => Male) ; begin Text_IO. Put_Line( "The name is " & Name( P) ) ; end;
Objects can be copied into another. The target object is rst destroyed. Then the component values of the source object are assigned to the corresponding components of the target object. In the following example, the default initialized P gets a copy of one of the objects created by the Make calls.
declare P: Person; begin if 2001 > 1984 then P := Make ( Name => else P := Make ( Name => end if;
"Kubrick", "Orwell",
Male) ; Male) ;
Name( P) ) ;
So far there is no mention of the Programmer type derived from Person. There is no polymorphism yet, and likewise initialization does not yet mention inheritance. Before dealing with Programmer objects and their initialization a few words about class-wide types are in order.
197
Object Orientation In Ada 2005 only, functions returning an anonymous access type to the tagged type; Additionally, primitive operations must be declared before the type is frozen (the concept of freezing will be explained later): Examples:
package X is type Object is tagged null record; procedure procedure procedure procedure function function end X; Primitive_1 Primitive_2 Primitive_3 Primitive_4 Primitive_5 Primitive_6 (This : in Object); (That : out Object); (Me : in out Object); (Them : access Object); return Object; (Everyone : Boolean) return access Object;
All of these subprograms are primitive operations. A primitive operation can also take parameters of the same or other types; also, the controlling operand does not have to be the rst parameter:
package X is type Object is tagged null record; procedure Primitive_1 (This : in Object; Number : in Integer); procedure Primitive_2 (You : in Boolean; That : out Object); procedure Primitive_3 (Me, Her : in out Object); end X;
The denition of primitive operations specically excludes named access types and class-wide types as well as operations not dened immediately in the same declarative region. Counter-examples:
package type type type X is Object is tagged null record; Object_Access is access Object; Object_Class_Access is access Object Class; Not_Primitive_1 Not_Primitive_2 Not_Primitive_3 Not_Primitive_4 (This : in Object Class); (This : in out Object_Access); (This : out Object_Class_Access); return Object Class;
198
Advanced topic: Freezing rules Freezing rules (http://www.adaic.com/standards/05rm/html/RM-13-14.html ARM 13.143 ) are perhaps the most complex part of the Ada language denition; this is because the standard tries to describe freezing as unambiguously as possible. Also, that part of the language denition deals with freezing of all entities, including complicated situations like generics and objects reached by dereferencing access values. You can, however, get an intuitive understanding of freezing of tagged types if you understand how dynamic dispatching works4 . In that section, we saw that the compiler emits a table of primitive operations for each tagged type. The point in the program text where this happens is the point where the tagged type is frozen, i.e. the point where the table becomes complete. After the type is frozen, no more primitive operations can be added to it. This point is the earliest of: the end of the package spec where the tagged type is declared the appearance of the rst type derived from the tagged type Example:
package X is type Object is tagged nullrecord; procedure Primitive_1 (This: in Object); -- this declaration freezes Object type Derived is new Object with null record; -- illegal: declared after Object is frozen procedure Primitive_2 (This: in Object); end X;
Intuitively: at the point where Derived is declared, the compiler starts a new table of primitive operations for the derived type. This new table, initially, is equal to the table of the primitive operations of the parent type, Object. Hence, Object must freeze. the declaration of a variable of the tagged type Example:
package X is type Object is tagged null record; procedure Primitive_1 (This: in Object); V: Object; -- this declaration freezes Object -- illegal: declared after Object is frozen procedure Primitive_2 (This: in Object); end X;
3 4
199
Object Orientation Intuitively: after the declaration of V, it is possible to call any of the primitive operations of the type on V. Therefore, the list of primitive operations must be known and complete, i.e. frozen. The completion (not the declaration, if any) of a constant of the tagged type:
package X is type Object is tagged null record; procedure Primitive_1 (This: in Object); -- this declaration does NOT freeze Object Deferred_Constant: constant Object; procedure Primitive_2 (This : in Object); -- OK private -- only the completion freezes Object Deferred_Constant: constant Object := (null record); -- illegal: declared after Object is frozen procedure Primitive_3 (This: in Object); end X;
type Derived_Object is new Object with null record; not overriding --new optional keywords in Ada 2005 procedure Primitive (This : in Derived_Object); --new primitive operation overriding function Primitive return access Derived_Object; end X;
200
This is a good programming practice because it avoids some nasty bugs like not overriding an inherited subprogram because the programmer spelt the identier incorrectly, or because a new parameter is added later in the parent type. It can also be used with abstract operations, with renamings, or when instantiating a generic subprogram:
not overriding procedure Primitive_X (This : in Object) is abstract; overriding function Primitive_Y return Object renames Some_Other_Subprogram; not overriding procedure Primitive_Z (This : out Object) is new Generic_Procedure (Element => Integer);
This notation is only available for primitive operations where the controlling parameter is the rst parameter.
201
Object Orientation An abstract operation cannot have any body, so derived types are forced to override it (unless those derived types are also abstract). See next section about interfaces for more information about this. The dierence with a non-abstract tagged type is that you cannot declare any variable of this type. However, you can declare an access to it, and use it as a parameter of a class-wide operation.
not overriding procedure New_Class_Member (This : Object; That : String); end Programmer;
As usual, all inherited abstract operations must be overridden although null subprograms ones need not.
202
Such a type may implement a list of interfaces (called the progenitors), but can have only one parent. The parent may be a concrete type or also an interface.
type Derived is new Parent and Progenitor_1 and Progenitor_2 ... with ...;
and you want to make Derived controlled, i.e. add the behavior that Derived controls its initialization, assignment and nalization. Alas you cannot write:
type Derived is new Base and Ada.Finalization.Controlled with private; --illegal
since Ada.Finalization for historical reasons does not dene interfaces Controlled and Limited_Controlled, but abstract types. If your base type is not limited, there is no good solution for this; you have to go back to the root of the class and make it controlled. (The reason will become obvious presently.) For limited types however, another solutions is the use of a mix-in:
type Base is tagged limited private; type Derived; type Controlled_Mix_In (Enclosing: access Derived) is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize (This: in out Controlled_Mix_In); overriding procedure Finalize (This: in out Controlled_Mix_In); type Derived is new Base with record Mix_In: Controlled_Mix_In (Enclosing => Derived Access); --special syntax here --other components here... end record;
This special kind of mix-in is an object with an access discriminant that references its enclosing object (also known as Rosen trick). In the declaration of the Derived type, we initialize this discriminant with a special syntax: Derived Access really refers to an a access value to the current instance of type Derived. Thus the access discriminant allows the mix-in to see its enclosing object and all its components; therefore it can initialize and
203
and similarly for Finalize. The reason why this does not work for non-limited types is the self-referentiality via the discriminant. Imagine you have two variables of such a non-limited type and assign one to the other:
X := Y;
In an assignment statement, Adjust is called only after Finalize of the target X and so cannot provide the new value of the discriminant. Thus X.Mixin_In.Enclosing will inevitably reference Y. Now let s further extend our hierarchy:
type Further is new Derived with null record; overriding procedure Initialize (This: in out Further); overriding procedure Finalize (This: in out Further);
Oops, this does not work because there are no corresponding procedures for Derived, yet so let s quickly add them.
type Base is tagged limited private; type Derived; type Controlled_Mix_In (Enclosing: access Derived) is new Ada.Finalization.Limited_Controlled with null record; overriding procedure Initialize (This: in out Controlled_Mix_In); overriding procedure Finalize (This: in out Controlled_Mix_In); type Derived is new Base with record Mix_In: Controlled_Mix_In (Enclosing => Derived Access); --other components here... end record; not overriding procedure Initialize (This: in out Derived); not overriding procedure Finalize (This: in out Derived); type Further is new Derived with null record; overriding procedure Initialize (This: in out Further); overriding procedure Finalize (This: in out Further); --special syntax here
204
We have of course to write not overriding for the procedures on Derived because there is indeed nothing they could override. The bodies are
not overriding procedure Initialize (This: in out Derived) is begin --initialize Derived... end Initialize; overriding procedure Initialize (This: in out Controlled_Mix_In) is Enclosing: Derived renames This.Enclosing.all; begin Initialize (Enclosing); end Initialize;
To our dismay, we have to learn that Initialize/Finalize for objects of type Further will not be called, instead those for the parent Derived. Why?
declare X: Further; -- Initialize (Derived (X)) is called here begin null; end; -- Finalize (Derived (X)) is called here
The reason is that the mix-in denes the local object Enclosing to be of type Derived in the renames-statement above. To cure this, we have necessarily to use the dreaded redispatch (shown in dierent but equivalent notations):
overriding procedure Initialize (This: in out Controlled_Mix_In) is Enclosing: Derived renames This.Enclosing.all; begin Initialize (Derived Class (Enclosing)); end Initialize; overriding procedure Finalize (This: in out Controlled_Mix_In) is Enclosing: Derived Class renames Derived Class (This.Enclosing.all); begin Enclosing.Finalize; end Finalize; declare X: Further; -- Initialize (X) is called here begin null; end; -- Finalize (X) is called here
Then we automatically get redispatch and can omit the type conversions on Enclosing.
205
Object Orientation Class names Both the class package and the class record need a name. In theory they may have the same name, but in practice this leads to nasty (because of unintutive error messages) name clashes when you use the use clause. So over time three de facto naming standards have been commonly used.
22.2.1 Classes/Class
The package is named by a plural noun and the record is named by the corresponding singular form.
package Persons is type Person is tagged record Name : String (1 .. 10); Gender : Gender_Type; end record; end Persons;
This convention is the usually used in Ada s built-in libraries. Disadvantage: Some "multiples" are tricky to spell, especially for those of us who aren t native English speakers.
22.2.2 Class/Object
The package is named after the class, the record is just named Object.
package Person is type Object is tagged record Name : String (1 .. 10); Gender : Gender_Type; end record; end Person;
Most UML5 and IDL6 code generators use this technique. Disadvantage: You can t use the use clause on more than one such class packages at any one time. However you can always use the "type" instead of the package.
5 6
http://en.wikipedia.org/wiki/Unified%20Modeling%20Language http://en.wikipedia.org/wiki/Interface%20description%20language
206
22.2.3 Class/Class_Type
The package is named after the class, the record is postxed with _Type.
package Person is type Person_Type is tagged record Name : String (1 .. 10); Gender : Gender_Type; end record; end Person;
--primitive operation, will be inherited upon derivation --not primitive, will not be inherited upon derivation
In C++, member functions implicitly take a parameter this which is of type C*. In Ada, all parameters are explicit. As a consequence, the fact that u() does not take a parameter is implicit in C++ but explicit in Ada. In C++, this is a pointer. In Ada, the explicit This parameter does not have to be a pointer; all parameters of a tagged type are implicitly passed by reference anyway.
207
both dispatch statically. In particular, the static dispatch for v() may be confusing; this is because object is neither a pointer nor a reference. Ada behaves exactly the same in this respect, except that Ada calls this static binding rather than dispatching:
declare Object : P.C; begin Object.V; --statically bound Object.W; --statically bound end;
In Ada, a primitive subprogram call dispatches (dynamically) if and only if: the target object is of a class-wide type; Note: In Ada vernacular, the term dispatching always means dynamic. For example:
declare Object : P.C Class := ...; begin P.V (Object); --dispatching P.W (Object); --statically bound: P.U; --statically bound end;
As can be seen there is no need for access types or pointers to do dispatching in Ada. In Ada, tagged types are always passed by-reference to subprograms without the need for explicit access values.
208
Also note that in C++, the class serves as: the unit of encapsulation (Ada uses packages and visibility for this) the type, like in Ada. As a consequence, you call C::u() in C++ because u() is encapsulated in C, but P.U in Ada since U is encapsulated in the package P, not the type C.
which, in Ada, are two dierent, incompatible types, possibly allocating their memory from dierent storage pools! In Ada, you do not need access values for dynamic dispatching. In Ada, you use access values for dynamic memory management (only) and class-wide types for dynamic dispatching (only). In C++, you use pointers and references both for dynamic memory management and for dynamic dispatching. In Ada, class-wide types are explicit (with Class). In C++, class-wide types are implicit (with * or &).
22.3.4 Constructors
in C++, a special syntax declares a constructor:
class C { C(/* optional parameters */); // constructor };
A constructor cannot be virtual. A class can have as many constructors, dierentiated by their parameters, as necessary. Ada does not have such constructors. Perhaps they were not deemed necessary since in Ada, any function that returns an object of the tagged type can serve as a kind of constructor. This is however not the same as a real constructor like the C++ one; this dierence is most striking in cases of derivation trees (see Finalization below). The Ada constructor
209
Object Orientation subprograms do not have to have a special name and there can be as many constructors as necessary; each function can take parameters as appropriate.
package P is type T is tagged private; function Make return T; function To_T (From: Integer) return T; -- procedure Make (This: out T); private ... end P;
If an Ada constructor function is also a primitive operation (as in the example above), it becomes abstract upon derivation and has to be overridden if the derived type is not itself abstract. If you do not want this, declare such functions in a nested scope. In C++, one idiom is the copy constructor and its cousin the assignment operator:
class C { C(const C& that); // copies "that" into "this" C& operator= (const C& right); // assigns "right" to "this", which is "left" };
Ada provides a similar functionality by means of controlled types. A controlled type is one that extends the predened type Ada.Finalization.Controlled:
with Ada.Finalization; package P is type T is new Ada.Finalization.Controlled with private; function Make return T; -- constructor private type T is ... end record; overriding procedure Initialize (This: in out T); overriding procedure Adjust (This: in out T); -- copy contructor end P;
Note that Initialize is not a constructor; it resembles the C++ constructor in some way, but is also very dierent. Suppose you have a type T1 derived from T with an appropriate overriding of Initialize. A real constructor (like the C++ one) would automatically rst construct the parent components (T), then the child components. In Ada, this is not automatic. In order to mimic this in Ada, we have to write:
procedure Initialize (This: in out T1) is begin
210
Initialize (T (This)); -- Don t forget this part! ... -- handle the new components here end Initialize;
The compiler inserts a call to Initialize after each object of type T is allocated when no initial value is given. It also inserts a call to Adjust after each assignment to the object. Thus, the declarations:
A: T; B: T := X;
will: allocate memory for A call Initialize (A) allocate memory for B copy the contents of X to B call Adjust (B)
Initialize (B) will not be called because of the explicit initialization. So, the equivalent of a copy constructor is an overriding of Adjust. If you would like to provide this functionality to a type that extends another, non-controlled type, see "Multiple Inheritance"7 .
22.3.5 Destructors
In C++, a destructor is a member function with only the implicit this parameter:
class C { virtual C(); // destructor }
While a constructor cannot be virtual, a destructor must be virtual. Unfortunately, the rules of the C++ language do not enforce this, so it is quite easy for a programmer to wreak havoc in their programs by simply forgetting the keyword virtual. In Ada, the equivalent functionality is again provided by controlled types, by overriding the procedure Finalize:
with Ada.Finalization; package P is type T is new Ada.Finalization.Controlled with private; function Make return T; -- constructor private type T is ... end record;
211
Object Orientation
-- destructor
Because Finalize is a primitive operation, it is automatically "virtual"; you cannot, in Ada, forget to make a destructor virtual.
A way to mimic this C++ class in Ada is to dene a hierarchy of types, where the base type is the public part, which must be abstract so that no stand-alone objects of this base type can be dened. It looks like so:
private with Ada.Finalization; package CPP is type Public_Part is abstract tagged record A: Integer; end record; -- no objects of this type
procedure Public_Proc (This: in out Public_Part); type Complete_Type is new Public_Part with private; -- procedure Public_Proc (This: in out Complete_Type); inherited, implicitly defined private -- visible for children --
type Private_Part; -- declaration stub type Private_Part_Pointer is access Private_Part; type Private_Component is new Ada.Finalization.Controlled with record P: Private_Part_Pointer; end record; overriding procedure Initialize (X: in out Private_Component); overriding procedure Adjust (X: in out Private_Component); overriding procedure Finalize (X: in out Private_Component);
212
type Complete_Type is new Public_Part with record B: Integer; P: Private_Component; -- must be controlled to avoid storage leaks end record; not overriding procedure Protected_Proc (This: Complete_Type); end CPP;
The private part is dened as a stub only, its completion is hidden in the body. In order to make it a component of the complete type, we have to use a pointer since the size of the component is still unknown (the size of a pointer is known to the compiler). With pointers, unfortunately, we incur the danger of memory leaks, so we have to make the private component controlled. For a little test, this is the body, where the subprogram bodies are provided with identifying prints:
with Ada.Unchecked_Deallocation; with Ada.Text_IO; package body CPP is procedure Public_Proc (This: in out Public_Part) is -- primitive begin Ada.Text_IO.Put_Line ("Public_Proc" & Integer Image (This.A)); end Public_Proc; type Private_Part is record C: Boolean; end record; -- complete declaration
overriding procedure Initialize (X: in out Private_Component) is begin X.P := new Private_Part (C => True); Ada.Text_IO.Put_Line ("Initialize " & Boolean Image (X.P.C)); end Initialize; overriding procedure Adjust (X: in out Private_Component) is begin Ada.Text_IO.Put_Line ("Adjust " & Boolean Image (X.P.C)); X.P := new Private_Part (C => X.P.C); -- deep copy end Adjust; overriding procedure Finalize (X: in out Private_Component) is procedure Free is new Ada.Unchecked_Deallocation (Private_Part, Private_Part_Pointer); begin Ada.Text_IO.Put_Line ("Finalize " & Boolean Image (X.P.C)); Free (X.P); end Finalize; procedure Private_Proc (This: in out Complete_Type) is -- not primitive begin Ada.Text_IO.Put_Line ("Private_Proc" & Integer Image (This.A) & Integer Image (This.B) & & Boolean Image (This.P.P.C)); end Private_Proc; not overriding procedure Protected_Proc (This: Complete_Type) is X: Complete_Type := This; -- primitive
213
Object Orientation
begin Ada.Text_IO.Put_Line ("Protected_Proc" & Integer Image (This.A) & Integer Image (This.B)); Private_Proc (X); end Protected_Proc; end CPP;
We see that, due to the construction, the private procedure is not a primitive operation. Let s dene a child class so that the protected operation can be reached:
package CPP.Child is procedure Do_It (X: Complete_Type); end CPP.Child; -- not primitive
A child can look inside the private part of the parent and thus can see the protected procedure:
with Ada.Text_IO; package body CPP.Child is procedure Do_It (X: Complete_Type) is begin Ada.Text_IO.Put_Line ("Do_It" & Integer Image (X.A) & Integer Image (X.B)); Protected_Proc (X); end Do_It; end CPP.Child;
214
Protected_Proc (X):
You see that a direct translation of the C++ behaviour into Ada is dicult, if feasible at all. Methinks, the primitive Ada subprograms corresponds more to virtual C++ methods (in the example, they are not). Each language has its own idiosyncrasies which have to be taken into account, so that attempts to directly translate code from one into the other may not be the best approach.
215
Object Orientation
Ada does not need this construct because it denes stream input and output operations by default:
package P is pragma Elaborate_Body; -- explained below type C is tagged private; private type C is tagged record A, B : Integer; C : Boolean; end record; end P; with Ada.Text_IO.Text_Streams; with P; procedure Main is Object : P.C; begin P.C Output (Stream => Ada.Text_IO.Text_Streams.Stream (Ada.Text_IO.Default_Output), Item => Object); end Main;
By default, the Output attribute sends the tag of the object to the stream then calls the more basic Write attribute, which sends the components to the stream in the same order as the declaration, i.e. A, B then C. It is possible to override the default implementation of the Input, Output, Read and Write attributes like this:
with Ada.Streams; package body P is procedure My_Write (Stream : not null access Ada.Streams.Root_Stream_Type Class; Item : in C) is begin -- The default is to write A then B then C; here we change the ordering. Boolean Write (Stream, Item.C); Integer Write (Stream, Item.B); Integer Write (Stream, Item.A); end My_Write; for C Write use My_Write; -- override the default attribute end P;
In the above example, P.C output calls P.C Write which is overridden in the body of the package. Since the specication of package P does not dene any subprograms, it does not normally need a body, so a package body is forbidden. The pragma Elaborate_Body tells the compiler that this package does have a body that is needed for other reasons.
216
Note that the stream IO attributes are not primitive operations of the tagged type; this is also the case in C++ where the friend operators are not, in fact, member functions of the type.
22.3.8 Terminology
Ada Package Tagged type Primitive operation Tag Class (of types) Class-wide type Class-wide operation Access value to a specic tagged type Access value to a class-wide type C++ class (as a unit of encapsulation) class (of objects) (as a type) (not pointer or reference, which are class-wide) virtual member function pointer to the virtual table static member function Pointer or reference to a class
22.4.1 Wikibook
Ada Programming8 Ada Programming/Types/record9 record10 interface11 tagged12
22.4.2 Wikipedia
Object-oriented programming13
8 9 10 11 12 13
217
Object Orientation
14
http://es.wikibooks.org/wiki/Programaci%F3n%20en%20Ada%2FTipos%20etiquetados
218
1 2 3 4 5 6 7 8
219
: constant := Pi;
This is not a new idea GNAT9 always had the -gnatic compiler option to specify the character set http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Character-Set-Control. html. But now this idea has become standard, so all Ada compilers will need to support Unicode 4.010 for identiers as the new standard requires. See also: AI95-00285-01 Support for 16-bit and 32-bit characters {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00285.TXT} AI95-00388-01 Add Greek pi to Ada.Numerics {http://www.ada-auth.org/cgi-bin/ cvsweb.cgi/AIs/AI-00388.TXT}
23.1.2 Interfaces
Interfaces allow for a limited form of multiple inheritance similar to Java and C#. You nd a full description here: Ada Programming/OO11 . See also: AI95-00251-01 Abstract Interfaces to provide multiple inheritance {http://www. ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00251.TXT} AI95-00345-01 Protected and task interfaces {http://www.ada-auth.org/cgi-bin/ cvsweb.cgi/AIs/AI-00345.TXT}
23.1.3 Union
In addition to Ada s safe variant record an unchecked C style union is now available. You can nd a full description here: Ada Programming/Types/record#Union12 . See also: AI95-00216-01 Unchecked unions -- variant records with no run-time discriminant {http: //www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00216.TXT} Annex B.3.3 Pragma Unchecked_Union {http://www.adaic.org/resources/add_ content/standards/05rm/html/RM-B-3-3.html}
9 10 11 12
220
23.1.4 With
The with statement got a massive upgrade. First there is the new limited with13 which allows two packages to with each other. Then there is private with14 to make a package only visible inside the private part of the specication. See also: AI95-00217-01 Limited With Clauses {http://www.ada-auth.org/cgi-bin/cvsweb. cgi/AIs/AI-00217.TXT} AI95-00262-01 Access to private units in the private part {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00262.TXT}
See Ada Programming/Types/access#Anonymous access16 . See also: AI95-00230-01 Generalized use of anonymous access types {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00230.TXT} AI95-00385-01 Stand-alone objects of anonymous access types {http://www.ada-auth. org/cgi-bin/cvsweb.cgi/AIs/AI-00385.TXT}
13 14 15 16 Chapter Chapter Chapter Chapter 17.3.3 on page 138 17.3.2 on page 138 13.10.1 on page 110 13.4 on page 103
221
New in Ada 2005 AI95-00318-01 Limited and anonymous access return types {http://www.ada-auth. org/cgi-bin/cvsweb.cgi/AIs/AI-00318.TXT}
23.2.1 Containers
A major addition to the language library is the generic packages for containers. If you are familiar with the C++ STL, you will likely feel very much at home using Ada . One thing, though: Ada is a block structured language. Many ideas of how to use the STL employ this feature of the language. For example, local subprograms can be supplied to iteration schemes. The original Ada Issue text AI95-00302-01 Container library {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00302.TXT} has now been transformed into A.18 Containers {http://www.adaic.org/resources/add_content/standards/05rm/html/RM-A-18. html} . If you know how to write Ada programs, and have a need for vectors, lists, sets, or maps (tables), please have a look at the AI95-00302-01 AI Text {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00302.TXT} mentioned above. There is an !example section in the text explaining the use of the containers in some detail. Matthew Heaney provides a number of demonstration programs with his reference implementation of AI-302 (Ada ) which you can nd at tigris17 . In Ada Programming/Containers18 you will nd a demo using containers. Historical side note: The C++ STL draws upon the work of David R. Musser and Alexander A. Stepanov. For some of their studies of generic programming, they had been using Ada 83. The Stepanov Papers Collection19 has a few publications available.
17 18 19
222
23.2.3 Numerics
Besides the new constant of package Ada.Numerics (see Character Set20 above), the most important addition are the packages to operate with vectors and matrices. See also: AI95-00388-01 Add Greek pi () to Ada.Numerics {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00388.TXT} AI95-00296-01 Vector and matrix operations {http://www.ada-auth.org/cgi-bin/ cvsweb.cgi/AIs/AI-00296.TXT} (Related note on Ada programming tools: AI-388 contains an interesting assessment of how compiler writers are bound to perpetuate the lack of handling of international characters in programming support tools for now. As an author of Ada programs, be aware that your tools provider or Ada consultant could recommend that the program text be 7bit ASCII only.)
20
223
New in Ada 2005 AI95-00265-01 Partition Elaboration Policy for High-Integrity Systems {http://www. ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00265.TXT}
224
225
New in Ada 2005 Ada.Strings.Unbounded.Hash (generic function) Ada.Strings.Wide_Hash (generic function) Ada.Strings.Wide_Fixed.Wide_Hash (generic function) Ada.Strings.Wide_Bounded.Wide_Hash (generic function) Ada.Strings.Wide_Unbounded.Wide_Hash (generic function) Ada.Strings.Wide_Wide_Hash (generic function) Ada.Strings.Wide_Wide_Fixed.Wide_Wide_Hash (generic function) Ada.Strings.Wide_Wide_Bounded.Wide_Wide_Hash (generic function) Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Hash (generic function)
Time operations: Ada.Calendar.Time_Zones Ada.Calendar.Arithmetic Ada.Calendar.Formatting Tagged types: Ada.Tags.Generic_Dispatching_Constructor (generic function) Text packages: Ada.Complex_Text_IO Ada.Text_IO.Bounded_IO Ada.Text_IO.Unbounded_IO Ada.Wide_Text_IO.Bounded_IO Ada.Wide_Text_IO.Unbounded_IO Ada.Wide_Characters Ada.Wide_Wide_Characters Wide_Wide_Character packages: Ada.Strings.Wide_Wide_Bounded Ada.Strings.Wide_Wide_Fixed Ada.Strings.Wide_Wide_Maps Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants Ada.Strings.Wide_Wide_Unbounded Ada.Wide_Wide_Text_IO Ada.Wide_Wide_Text_IO.Complex_IO Ada.Wide_Wide_Text_IO.Editing Ada.Wide_Wide_Text_IO.Text_Streams Ada.Wide_Wide_Text_IO.Unbounded_IO Execution-time clocks: Ada.Execution_Time Ada.Execution_Time.Timers Ada.Execution_Time.Group_Budgets Dispatching: Ada.Dispatching Ada.Dispatching.EDF Ada.Dispatching.Round_Robin Timing events: Ada.Real_Time.Timing_Events
226
23.5.1 Wikibook
Ada Ada Ada Ada Ada Ada Ada Ada Ada Ada Ada Ada Ada Programming/Ada 8321 Programming/Ada 9522 Programming/Ada 201223 Programming/Object Orientation24 Programming/Types/access25 Programming/Keywords26 Programming/Keywords/and27 Programming/Keywords/interface28 Programming/Attributes29 Programming/Pragmas30 Programming/Pragmas/Restrictions31 Programming/Libraries/Ada.Containers32 Programming/Libraries/Ada.Directories33
21 22 23 24 25 26 27 28 29 30 31 32 33 34
http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%2083 http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%2095 http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%202012 Chapter 22 on page 187 Chapter 13 on page 99 Chapter 35 on page 293 http://en.wikibooks.org/wiki/Ada%20Programming%2FKeywords%2Fand http://en.wikibooks.org/wiki/Ada%20Programming%2FKeywords%2Finterface Chapter 38 on page 305 Chapter 39 on page 317 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FRestrictions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Directories http://en.wikibooks.org/wiki/%3ACategory%3AAda%20Programming%2FAda%202005%20feature
227
23.6.2 Rationale
Rationale for Ada 200539 by John Barnes40 : 1. Introduction 2. Object Oriented Model 3. Access Types 4. Structure and Visibility 5. Tasking and Real-Time 6. Exceptions, Generics, Etc. 7. Predened Library 8. Containers 9. Epilogue References Index Available as a single document for printing41 .
35 36 37 38 39 40 41 42 43 44
http://www.sigada.org/conf/sigada2004/SIGAda2004-CDROM/SIGAda2004-Proceedings/ Ada2005Panel.pdf http://www.adacore.com/wp-content/files/attachments/Ada_2005_and_GNAT.pdf http://sigada.org/ada_letters/sept2003/Invitation_to_Ada_2005.pdf http://www.cs.kuleuven.ac.be/~dirk/ada-belgium/events/04/040616-aec-ada2005.pdf http://www.adaic.com/standards/05rat/html/Rat-TTL.html http://en.wikipedia.org/wiki/John%20Barnes%20%28computer%20scientist%29 http://www.adaic.com/standards/05rat/Rationale05.pdf http://www.open-std.org/jtc1/sc22/WG9/n412.pdf http://std.dkuug.dk/JTC1/sc22/wg9/n423.pdf http://www.adaic.com/standards/05rm/html/RM-TTL.html
228
Annotated Ada Reference Manual, ISO/IEC 8652:1995(E) with COR.1:2001 and AMD.1:200745 (colored dis) List of Ada Amendment drafts46
229
New in Ada 2005 AI95-00364-01 Fixed-point multiply/divide {http://www.ada-auth.org/cgi-bin/ cvsweb.cgi/AIs/AI-00364.TXT} AI95-00267-01 Fast oat-to-integer conversions {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00267.TXT} AI95-00321-01 Denition of dispatching policies {http://www.ada-auth.org/ cgi-bin/cvsweb.cgi/AIs/AI-00321.TXT} AI95-00329-01 pragma No_Return -- procedures that never return {http://www. ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00329.TXT} AI95-00362-01 Some predened packages should be recategorized {http://www. ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00362.TXT} AI95-00351-01 Time operations {http://www.ada-auth.org/cgi-bin/cvsweb. cgi/AIs/AI-00351.TXT} AI95-00427-01 Default parameters and Calendar operations {http://www.ada-auth. org/cgi-bin/cvsweb.cgi/AIs/AI-00427.TXT} AI95-00270-01 Stream item size control {http://www.ada-auth.org/cgi-bin/ cvsweb.cgi/AIs/AI-00270.TXT}
230
24 Containers
What follows is a simple demo of some of the container types. It does not cover everything, but should get you started. This language feature is only available in Ada 2005 First Example: Maps The program below prints greetings to the world in a number of human languages. The greetings are stored in a table, or hashed map. The map associates every greeting (a value) with a language code (a key). That is, you can use language codes as keys to nd greeting values in the table. The elements in the map are constant strings of international characters, or really, pointers to such constant strings. A package Regional is used to set up both the language IDs and an instance of Ada .
File:
regional.ads
use Ada.Containers;
type Language_ID is (DE, EL, EN, ES, FR, NL); --a selection from the two-letter codes for human languages type Hello_Text is access constant Wide_String; --objects will contain a hello-string in some language function ID_Hashed (id: Language_ID) return Hash_Type; --you need to provide this to every hashed container package Phrases is new Ada.Containers.Hashed_Maps (Key_Type => Language_ID, Element_Type => Hello_Text, Hash => ID_Hashed, Equivalent_Keys => "="); end Regional;
231
Containers
File:
hello_world_extended.ads
with Regional; use Regional; with Ada.Wide_Text_IO; use Ada; procedure Hello_World_Extended is --print greetings in different spoken languages greetings: Phrases.Map; --the dictionary of greetings begin -- Hello_World_Extended
Phrases.Insert(greetings, Key => EN, New_Item => new Wide_String ("Hello, World!")); --or, shorter, greetings.Insert(DE, greetings.Insert(NL, greetings.Insert(ES, greetings.Insert(FR, greetings.Insert(EL, Wide_String Wide_String Wide_String Wide_String Wide_String ("Hallo, Welt!")); ("Hallo, Wereld!")); ("Hola mundo!")); ("Bonjour, Monde!")); (" ")); -- ?
declare use Phrases; speaker: Cursor := First(greetings); begin while Has_Element(speaker) loop Wide_Text_IO.Put_Line( Element(speaker).all ); Next(speaker); end loop; end; end Hello_World_Extended;
The next insertions use so called distinguished receiver notation which you can use in Ada 2005. (It s O-O parlance. While the Insert call involves all of: a Container object (greetings), a Key object (EN), and a New_Item object (new Wide_String ("Hello, World!")), the Container object is distinguished from the others in that the Insert call provides it (and only it) with the other objects. In this case the Container object will be modied by the call, using arguments named Key and New_Item for the modication.)
232
After the table is set up, the program goes on to print all the greetings contained in the table. It does so employing a cursor that runs along the elements in the table in some order. The typical scheme is to obtain a cursor, here using First, and then to iterate the following calls: 1. Has_Element, for checking whether the cursor is at an element 2. Element, to get the element and 3. Next, to move the cursor to another element When there is no more element left, the cursor will have the special value No_Element. Actually, this is an iteration scheme that can be used with all containers in child packages of Ada . A slight variation: picking an element The next program shows how to pick a value from the map, given a key. Actually, you will provide the key. The program is like the previous one, except that it doesn t just print all the elements in the map, but picks one based on a Language_ID value that it reads from standard input.
File:
hello_world_pick.adb
with Regional; use Regional; with Ada.Wide_Text_IO; use Ada; procedure Hello_World_Pick is ... as before ... declare use Phrases; package Lang_IO is new Wide_Text_IO.Enumeration_IO(Language_ID); lang: Language_ID; begin Lang_IO.Get(lang); Wide_Text_IO.Put_Line( greetings.Element(lang).all ); end; end Hello_World_Pick;
This time the Element function consumes a Key (lang) not a Cursor. Actually, it consumes two values, the other value being greetings, in distinguished receiver notation.
233
Containers Second Example: Vectors and Maps Let s take bean counting literally. Red beans, green beans, and white beans. (Yes, white beans really do exist.) Your job will be to collect a number of beans, weigh them, and then determine the average weight of red, green, and white beans, respectively. Here is one approach. Again, we need a package, this time for storing vegetable related information. Introducing the Beans package (the Grams type doesn t belong in a vegetable package, but it s there to keep things simple):
File:
1/beans.ads
with Ada ; package Beans is type Bean_Color is ( R, G, W) ; --red, green, and white beans type Grams is delta 0. 01 digits 7; --enough to weigh things as light as beans but also as heavy as --many of them type Bean is --info about a single bean record kind: Bean_Color; weight: Grams; end record; subtype Bean_Count is Positive range 1 .. 1_000; --numbers of beans to count (how many has Cinderella have to count?) package Bean_Vecs is new Ada. Containers. ( Element_Type => Bean, Index_Type => Bean_Count) ; end Beans; Vectors
The Vectors instance oers a data structure similar to an array that can change its size at run time. It is called Vector. Each bean that is read will be appended to a Bean_Vecs.Vector object. The following program rst calls read_input to ll a buer with beans. Next, it calls a function that computes the average weight of beans having the same color. This function:
with Beans; use Beans;
function average_weight ( buffer: Bean_Vecs. Vector; desired_color: Bean_Color) return Grams; --scan buffer for all beans that have desired_color. Compute the --mean of their .weight components
234
Then the average value is printed for beans of each color and the program stops.
File:
1/bean_counting.adb
with Beans; with average_weight; with Ada ; procedure bean_counting is use Beans, Ada; buffer: Bean_Vecs. Vector;
procedure read_input( buf: in out Bean_Vecs. Vector) is separate; --collect information from a series of bean measurements into buf begin --bean_counting read_input( buffer) ; --now everything is set up for computing some statistical data. --For every bean color in Bean_Color, the function average_weight --will scan buffer once, and accumulate statistical data from --each element encountered. for kind in Bean_Color loop Wide_Text_IO. Put_Line ( Bean_Color Wide_Image( kind) & " =" & Grams Wide_Image( average_weight( buffer, end loop; end bean_counting;
kind)
) ) ;
All container operations take place in function average_weight. To nd the mean weight of beans of the same color, the function is looking at all beans in order. If a bean has the right color, average_weight adds its weight to the total weight, and increases the number of beans counted by 1. The computation visits all beans. The iteration that is necessary for going from one bean to the next and then performing the above steps is best left to the Iterate procedure which is part of all container packages. To do so, wrap the above steps inside some procedure and pass this procedure to Iterate. The eect is that Iterate calls your procedure for each element in the vector, passing a cursor value to your procedure, one for each element. Having the container machinery do the iteration can also be faster than moving and checking the cursor yourself, as was done in the Hello_World_Extended example.
File:
average_weight.adb
with Beans;
use Beans.
Bean_Vecs;
function average_weight
235
Containers
( buffer: is
Bean_Vecs.
Vector;
desired_color:
Bean_Color)
return Grams
total: Grams := 0. 0; --weight of all beans in buffer having desired_color number: Natural := 0; --number of beans in buffer having desired_color procedure accumulate( c: Cursor) is --if the element at c has the desired_color, measure it begin if Element( c) . kind = desired_color then number := number + 1; total := total + Element( c) . weight; end if; end accumulate; begin --average_weight Iterate( buffer, accumulate Access) ;
if number > 0 then return total / number; else return 0. 0; end if; end average_weight;
This approach is straightforward. However, imagine larger vectors. average_weight will visit all elements repeatedly for each color. If there are M colors and N beans, average_weight will be called M * N times, and with each new color, N more calls are necessary. A possible alternative is to collect all information about a bean once it is visited. However, this will likely need more variables, and you will have to nd a way to return more than one result (one average for each color), etc. Try it! A dierent approach might be better. One is to copy beans of dierent colors to separate vector objects. (Remembering Cinderella.) Then average_weight must visit each element only one time. The following procedure does this, using a new type from Beans, called Bean_Pots.
... type Bean_Pots is array( Bean_Color) ... of Bean_Vecs. Vector;
Note how this plain array associates colors with Vectors. The procedure for getting the beans into the right bowls uses the bean color as array index for nding the right bowl (vector).
File:
2/gather_into_pots.adb
Bean_Vecs.
Vector;
pots:
in out Bean_Pots)
is
procedure put_into_right_pot( c: Cursor) is --select the proper bowl for the bean at c and append
236
--the bean to the selected bowl begin Append( pots( Element( c) . kind) , end put_into_right_pot; begin --gather_into_pots Iterate( buffer, put_into_right_pot end gather_into_pots;
Element( c) ) ;
Access) ;
File:
2/bean_counting.adb
procedure bean_counting is use Beans, Ada; buffer: bowls: Bean_Vecs. Bean_Pots; Vector;
procedure read_input( buf: in out Bean_Vecs. Vector) is separate; --collect information from a series of bean measurements into buf begin --bean_counting read_input( buffer) ; --now everything is set up for computing some statistical data. --Gather the beans into the right pot by color. --Then find the average weight of beans in each pot. gather_into_pots( buffer, bowls) ;
for color in Bean_Color loop Wide_Text_IO. Put_Line ( Bean_Color Wide_Image( color) & " =" & Grams Wide_Image( average_weight( bowls( color) , end loop; end bean_counting;
color) ) ) ;
As a side eect of having chosen one vector per color, we can determine the number of beans in each vector by calling the Length function. But average_weight, too, computes the number of elements in the vector. Hence, a summing function might replace average_weight here. All In Just One Map! The following program rst calls read_input to ll a buer with beans. Then, information about these beans is stored in a table, mapping bean properties to numbers of occurrence.
237
Containers The processing that starts at Iterate uses chained procedure calls typical of the Ada iteration mechanism. The Beans package in this example instantiates another generic library unit, Ada . Where the Ada require a hashing function, Ada require a comparison function. We provide one, "<", which sorts beans rst by color, then by weight. It will automatically be associated with the corresponding generic formal function, as its name, "<", matches that of the generic formal function, "<".
... function "<"( a, b: Bean) return Boolean; --order beans, first by color, then by weight package Bean_Statistics --instances will map beans of a particular color and weight to the --number of times they have been inserted. is new Ada. Containers. Ordered_Maps ( Element_Type => Natural, Key_Type => Bean) ; ...
Where the previous examples have withed subprograms, this variation on bean_counting packs them all as local subprograms.
File:
3/bean_counting.adb
with Beans; with Ada. Wide_Text_IO; procedure bean_counting is use Beans, Ada; buffer: Bean_Vecs. Vector; stats_cw: Bean_Statistics. Map; --maps beans to numbers of occurrences, grouped by color, ordered by --weight procedure read_input( buf: in out Bean_Vecs. Vector) is separate; --collect information from a series of bean measurements into buf procedure add_bean_info( specimen: in Bean) ; --insert bean specimen as a key into the stats_cw table unless --present. In any case, increase the count associated with this key --by 1. That is, count the number of equal beans. procedure add_bean_info( specimen: in Bean) is is
procedure one_more( b: in Bean; n: in out Natural) --increase the count associated with this kind of bean begin n := n + 1; end one_more; c : Bean_Statistics. Cursor; inserted: Boolean; begin stats_cw. Insert( specimen, 0, c, Bean_Statistics. Update_Element( c,
238
end add_bean_info; begin --bean_counting read_input( buffer) ; --next, for all beans in the vector buffer just filled, store --information about each bean in the stats_cw table. declare use Bean_Vecs; procedure count_bean( c: Cursor) is begin add_bean_info( Element( c) ) ; end count_bean; begin Iterate( buffer, count_bean Access) ; end; --now everything is set up for computing some statistical data. The --keys of the map, i.e. beans, are ordered by color and then weight. --The First, and Ceiling functions will find cursors --denoting the ends of a group.
declare use Bean_Statistics; --statistics is computed groupwise: q_sum: Grams; q_count: Natural; procedure q_stats( lo, hi: Cursor) ; --q_stats will update the q_sum and q_count globals with --the sum of the key weights and their number, respectively. lo --(included) and hi (excluded) mark the interval of keys --to use from the map. procedure q_stats( lo, hi: Cursor) is k: Cursor := lo; begin q_count := 0; q_sum := 0. 0; loop exit when k = hi; q_count := q_count + Element( k) ; q_sum := q_sum + Key( k) . weight * Next( k) ; end loop; end q_stats; --precondition pragma assert( not Is_Empty( stats_cw) ,
Element( k) ;
"container is empty") ;
lower, upper: Cursor := First( stats_cw) ; --denoting the first key of a group, and the first key of a --following group, respectively begin --start reporting and trigger the computations Wide_Text_IO. Put_Line( "Summary:") ;
239
Containers
0.
for color in Bean_Color loop lower := upper; if color = Bean_Color Last then upper := No_Element; else upper := Ceiling( stats_cw, Bean 0) ) ; end if; q_stats( lower, upper) ;
( Bean_Color
Succ( color) ,
if q_count > 0 then Wide_Text_IO. Put_Line ( Bean_Color Wide_Image( color) & " group:" & " =" & Grams Wide_Image( q_sum / q_count) ", # =" & Natural Wide_Image( q_count) & ", =" & Grams Wide_Image( q_sum) ) ; end if; end loop; end; end bean_counting;
&
Like in the greetings example, you can pick values from the table. This time the values tell the number of occurrences of beans with certain properties. The stats_cw table is ordered by key, that is by bean properties. Given particular properties, you can use the Floor and Ceiling functions to approximate the bean in the table that most closely matches the desired properties. It is now easy to print a histogram showing the frequency with which each kind of bean has occurred. If N is the number of beans of a kind, then print N characters on a line, or draw a graphical bar of length N, etc. A histogram showing the number of beans per color can be drawn after computing the sum of beans of this color, using groups like in the previous example. You can delete beans of a color from the table using the same technique. Finally, think of marshalling the beans in order starting at the least frequently occurring kind. That is, construct a vector appending rst beans that have occurred just once, followed by beans that have occurred twice, if any, and so on. Starting from the table is possible, but be sure to have a look at the sorting functions of Ada .
24.1.1 Wikibook
Ada Programming1 Ada Programming/Libraries/Ada.Containers2
1 2
http://en.wikibooks.org/wiki/Ada%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers
240
241
25 Interfacing
25.1 Interfacing
Interfacing Ada is one of the few languages where interfacing is part of the language standard. The programmer can interface with other programming languages, or with the hardware.
1 2 3 4 5 6 7 8 9 10
http://en.wikibooks.org/wiki/C%20Programming http://en.wikibooks.org/wiki/COBOL http://en.wikibooks.org/wiki/Programming%3AFortran http://en.wikibooks.org/wiki/Ada%20Programming%2FGNAT http://en.wikibooks.org/wiki/C%2B%2B%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FConvention http://en.wikibooks.org/wiki/Ada%20Programming%2FRepresentation%20clauses http://en.wikipedia.org/wiki/Interrupt%20service%20routine
243
Interfacing
25.4.1 Wikibook
Ada Programming11 Ada Programming/Libraries/Interfaces12
11 12
244
26 Coding Standards
26.1 Introduction
Introduction Each project should follow a specic coding standard1 to ease readability and maintenance of the source code, and reduce the insertion of errors. Depending on the requirements of the project, a set of guidelines can help to achieve the desired level of performance, portability, code complexity... There are many ASIS2 tools that can be used to check automatically the adherence of Ada source code to the guidelines.
26.2 Tools
Tools AdaControl3 ( Rules4 ) gnatcheck5 ( Rules6 ) GNAT Pretty-Printer7 The GNAT Metric Tool gnatmetric8 RainCode Engine9 RainCode Checker10 AdaSTAT11
1 2 3 4 5 6 7 8 9 10 11
http://en.wikipedia.org/wiki/coding%20standard http://en.wikipedia.org/wiki/Ada%20Semantic%20Interface%20Specification http://www.adalog.fr/adacontrol2.htm http://www.adalog.fr/compo/adacontrol_ug.html#Rules-reference http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Verifying-Properties-Using-gnatcheck.html http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/Predefined-Rules.html http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/The-GNAT-Pretty_002dPrinter-gnatpp.html http://gcc.gnu.org/onlinedocs/gnat_ugn_unw/The-GNAT-Metric-Tool-gnatmetric.html http://www.raincode.com/adaengine.html http://www.raincode.com/adachecker.html http://www.adastat.com/
245
Coding Standards Coding guidelines Ada Quality & Style Guide12 : Guidelines for Professional Programmers ISO/IEC TR 15942:2000, Guide for the use of the Ada programming language in high integrity systems13 , First edition (2000-03-01). ISO Freely Available Standards14 Stephen Leake, NASA Flight Software Branch Ada Coding Standard15 (2004-01-30) ESA16 BSSC
| title = Ada Coding Standard
. ,,
| edition | year | month | url | accessdate = = = = = BSSC(98)3 Issue 1 1998 October ftp://ftp.estec.esa.nl/pub/wm/wme/bssc/bssc983.pdf 2009-01-19
. Retrieved
. Retrieved ( PDF19 )
12 13 14 15 16 17 18 19 20
http://gcc.gnu.org/onlinedocs/gnat-style.pdf http://en.wikibooks.org/wiki/Ada%20Style%20Guide
246
26.4.2 Wikibook
Ada Programming21
21 22
247
27 Tips
27.1 Full declaration of a type can be deferred to the unit s body
Full declaration of a type can be deferred to the unit s body Often, you ll want to make changes to the internals of a private type. This, in turn, will require the algorithms that act on it to be modied. If the type is completed in the unit specication, it is a pain to edit and recompile both les, even with an IDE1 , but it s something some programmers learn to live with. It turns out you don t have to. Nonchalantly mentioned in the ARM2 , and generally skipped over in tutorials, is the fact that private types can be completed in the unit s body itself, making them much closer to the relevant code, and saving a recompile of the specication, as well as every unit depending on it. This may seem like a small thing, and, for small projects, it is. However, if you have one of those uncooperative types that requires dozens of tweaks, or if your dependence graph has much depth, the time and annoyance saved add up quickly. Also, this construction is very useful when coding a shared library, because it permits to change the implementation of the type while still providing a compatible ABI3 . Code sample:
package Private_And_Body is type Private_Type is limited private; --Operations... private type Body_Type; --Defined in the body type Private_Type is access Body_Type; end Private_And_Body;
The type in the public part is an access4 to the hidden type. This has the drawback that memory management has to be provided by the package implementation. That is the reason why Private_Type is a limited type, the client will not be allowed to copy the access values, in order to prevent dangling references.
1 2 3 4
249
Tips These types are sometimes called "Taft types" named after Tucker Taft, the main designer of Ada 95 because were introduced in the so-called Taft Amendment to Ada 83. In other programming languages, this technique is called "opaque pointer5 s".
250
to Bar. But they are both right. The reason is that selected_component is an item from Ada s grammar (4.1.3 Selected Components {http://www.adaic.org/resources/add_ content/standards/05rm/html/RM-4-1-3.html} ). It denotes all of: a prex, a dot, and a selector_name. In the Foo.Bar example these correspond to Foo, . , and Bar. Look for more grammar words in the compiler messages, e.g. prex, and associate them with identiers quoted in the messages. For example, if you submit the following code to the compiler,
with Pak; package Foo is type T is new Pak. end Foo; Bar; --Oops, Pak is generic!
the compiler may print a diagnostic message about a prexed component: Foo s author thought that Pak denotes a package, but actually it is the name of a generic package. (Which needs to be instantiated rst; and then the instance name is a suitable prex.)
Since universal_integer has no operators, its values are converted in this example to root_integer, another anonymous type, the calcuation is performed and the result again converted back in universal_integer. Generally values of universal_integer are implicitly converted to the appropriate type when used in some expression. So the expression not A Length is ne; the value of A Length is interpreted as a modular integer since not can only be applied to modular integers (of course a context is needed to decide which modular integer type is meant). This feature can lead to pitfalls. Consider
type Ran_6 is range 1 .. type Mod_6 is mod 6; 6;
and then
if A Length in Ran_6 then ... if not A --OK --not OK
251
Tips
... --this is the same as if (not A Length) in Ran_6 then ... if A Length in 1 .. ... if not A ... 6 then
--not OK
--OK --not OK
Length in 1 ..
6 then --OK?
--OK?
The second conditional cannot be compiled because the expressions to the left of in is incompatible to the type at the right. Note that not has precedence over in. It does not negate the entire membership test but only A Length. The fourth conditional fails in various ways. The sixth conditional might be ne because not turns A Length into a modular value which is OK if the value is covered by modular type Mod_6. GNAT GPL 2009 gives these diagnoses respectively:
error: incompatible types error: operand of not must be enclosed in parentheses warning: not expression should be parenthesized here
A way to avoid these problems is to use not in for the membership test,
if A Length not in Ran_6 then ... --OK
See 2.4 Numeric Literals {http://www.adaic.org/resources/add_content/standards/ 05rm/html/RM-2-4.html} , 3.6.2 Operations of Array Types {http://www.adaic.org/resources/add_content/ standards/05rm/html/RM-3-6-2.html} ), and 4.5 Operators and Expression Evaluation {http://www.adaic.org/resources/add_ content/standards/05rm/html/RM-4-5.html} , 4.5.2 Relational Operators and Membership Tests {http://www.adaic.org/ resources/add_content/standards/05rm/html/RM-4-5-2.html} , Membership Tests9
27.5 I/O
252
I/O
27.6 Quirks
Quirks Using GNAT on Windows, calls to subprograms from Ada might need special attention. (For example, the Real_Time.Clock function might seem to return values indicating that no time has passed between two invocations when certainly some time has passed.) The cause is reported to be a missing initialization of the run-time support when no other real-time features are present in the program.11 As a provisional x, it is suggested to insert
delay 0. 0;
http://groups.google.com/group/comp.lang.ada/browse_thread/thread/5afe598156615c8b# Vincent Celier . Timing code blocks Timing code blocks {groups.google.es/group/comp.lang.ada/ browse_thread/thread/c8acfc87fbb1813d} . , Usenet article forwards this information from AdaCore.
253
27.7 References
References
27.8.1 Wikibook
Ada Programming12 Ada Programming/Errors13
12 13
254
28 Common Errors
Some language features are often misunderstood, resulting in common programming errors, performance degradation and portability problems. The following incorrect usages of the Ada language are often seen in code written by Ada beginners.
The compiler will not (and is not allowed by the Standard to) generate an atomic increment instruction to directly increment and update from memory the variable A.6 This is the code generated by the compiler:
A := A + 1; 804969f: a1 04 95 05 08 80496a4: 40 80496a5: a3 04 95 05 08
As can be seen, no atomic increment instruction or test-and-set opcode will be generated. Like in other programming languages, if these specic instructions are required in the program they must be written explicitly using machine code insertions.8
1 2 3 4 6 8 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAtomic http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FVolatile Chapter 21 on page 173 Volatile: Almost Useless for Multi-Threaded Programming 5 . Intel Software Network . Retrieved 2008-05-30 Volatile 7 . . Retrieved 2008-05-28 Laurent Guerby Ada 95 Rationale . Intermetrics , , 1995
255
Common Errors The above code snippet is equivalent to the following code (both code sequences generates exactly the same object code), where T is a (non-atomic) temporary variable:
T := A; T := T + 1; A := T; --A is copied atomically to local variable T --local variable T is incremented --A is stored atomically
Thus it is incorrect to modify an atomic variable at the same time from multiple tasks. For example, two tasks incrementing a counter in parallel. Even in an uniprocessor, other Ada tasking features like a protected object should be used instead. In multiprocessors, depending on the memory consistency model9 , using various atomic or volatile variables for task communication can have surprising consequences.1012 Therefore, extreme care should be taken when using atomic objects for task data sharing or synchronization, specially in a multiprocessor.
28.2 References
References
9 10 12
http://en.wikipedia.org/wiki/Memory%20model%20%28programming%29 Volatile 11 . . Retrieved 2008-05-28 Sarita V. Adve, Kourosh Gharachorloo . Shared Memory Consistency Models: A Tutorial Shared Memory Consistency Models: A Tutorial {www.hpl.hp.com/techreports/Compaq-{}DEC/WRL-{}95-{}7. pdf} . IEEE Computer , 29 : 6676 December 1996 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPack Adam Beneschan . Pragma Pack vs. Convention C, portability issue? Pragma Pack vs. Convention C, portability issue? {groups.google.es/group/comp.lang.ada/msg/6698960624779ec7} . , http://en.wikibooks.org/wiki/Ada%20Programming%2FRepresentation%20clauses http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Component_Size
13 14 15 16 17
256
18 19 20 21 22 23
24 26
Software Productivity Consortium (October 1995). Ada 95 Quality and Style Guide, "10.5.7 Packed Boolean Array Shifts {http://www.adaic.org/resources/add_content/docs/95style/html/sec_10/ 10-5-7.html} " Chapter 7 on page 71 Software Productivity Consortium (October 1995). Ada 95 Quality and Style Guide, "10.6.3 Bit Operations on Modular Types {http://www.adaic.org/resources/add_content/docs/95style/html/ sec_10/10-6-3.html} " http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Bit%20Order . . , ISO/IEC 8652:2007. 13.5.3 Bit Ordering (9/2). Ada 2005 Reference Manual. Bit_Order clauses make it possible to write record_representation_clauses that can be ported between machines having dierent bit ordering. They do not guarantee transparent exchange of data between such machines. {http://www.adaic.org/resources/add_content/standards/05rm/html/RM-13-5-3.html} 25 . . Retrieved http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Size
257
28.6.1 Wikibook
Ada Programming27 Ada Programming/Tips28
28.7 References
References
27 28
258
29 Algorithms
29.1 Introduction
Introduction Welcome to the Ada implementations of the Algorithms1 Wikibook. For those who are new to Ada Programming2 a few notes: All examples are fully functional with all the needed input and output operations. However, only the code needed to outline the algorithms at hand is copied into the text the full samples are available via the download links. (Note: It can take up to 48 hours until the cvs is updated). We seldom use predened types in the sample code but dene special types suitable for the algorithms at hand. Ada allows for default function parameters; however, we always ll in and name all parameters, so the reader can see which options are available. We seldom use shortcuts - like using the attributes Image or Value for String <=> Integer conversions. All these rules make the code more elaborate than perhaps needed. However, we also hope it makes the code easier to understand Category:Ada Programming3
29.2.1 To Lower
The Ada example code does not append to the array as the algorithms. Instead we create an empty array of the desired length and then replace the characters inside.
1 2 3 4
259
Algorithms
File:
to_lower_1.adb
function To_Lower (C : Character) return Character renames Ada.Characters.Handling.To_Lower; -- tolower - translates all alphabetic, uppercase characters -- in str to lowercase function To_Lower (Str : String) return String is Result : String (Str Range); begin for C in Str Range loop Result (C) := To_Lower (Str (C)); end loop; return Result; end To_Lower;
Would the append approach be impossible with Ada? No, but it would be signicantly more complex and slower.
-- equal-ignore-case -- returns true if s or t are equal, -- ignoring case function Equal_Ignore_Case (S : String; T : String) return Boolean is O : constant Integer := S First - T First; begin if T Length /= S Length then return False; -- if they aren t the same length, they -- aren t equal else for I in S Range loop if To_Lower (S (I)) /= To_Lower (T (I + O)) then return False; end if; end loop; end if; return True; end Equal_Ignore_Case;
260
...
To calculate Fibonacci numbers negative values are not needed so we dene an integer type which starts at 0. With the integer type dened you can calculate up until Fib (87). Fib (88) will result in an Constraint_Error.
type Integer_Type is range 0 .. 999_999_999_999_999_999;
You might notice that there is not equivalence for the assert (n >= 0) from the original example. Ada will test the correctness of the parameter before the function is called.
function Fib (n : Integer_Type) return Integer_Type is begin if n = 0 then return 0; elsif n = 1 then return 1; else return Fib (n - 1) + Fib (n - 2); end if; end Fib; ...
For this implementation we need a special cache type can also store a -1 as "not calculated" marker
http://en.wikibooks.org/wiki/Algorithms%2FDynamic%20Programming%23Fibonacci_Numbers
261
Algorithms
The actual type for calculating the bonacci numbers continues to start at 0. As it is a subtype of the cache type Ada will automatically convert between the two. (the conversion
is - of course - checked for validity)
subtype Integer_Type is Cache_Type range 0 .. Cache_Type Last;
In order to know how large the cache need to be we rst read the actual value from the command line.
Value : constant Integer_Type := Integer_Type Value (Ada.Command_Line.Argument (1));
The Cache array starts with element 2 since Fib (0) and Fib (1) are constants and ends with the value we want to calculate.
type Cache_Array is array (Integer_Type range 2 .. Value) of Cache_Type;
The Cache is initialized to the rst valid value of the cache type this is -1.
F : Cache_Array := (others => Cache_Type First);
This implementation is faithful to the original from the Algorithms6 book. However, in Ada you would normally do it a little dierent: File: bonacci_3.adb
http://en.wikibooks.org/wiki/Algorithms
262
when you use a slightly larger array which also stores the elements 0 and 1 and initializes them to the correct values
type Cache_Array is array (Integer_Type range 0 .. Value) of Cache_Type; F : Cache_Array := (0 => 0, 1 => 1, others => Cache_Type First);
263
Algorithms
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
264
This will save about 45% of the execution-time (measured on Linux i686) while needing only two more elements in the cache array. Memory Optimized Implementation This version looks just like the original in WikiCode. File: bonacci_4.adb
type Integer_Type is range 0 .. 999_999_999_999_999_999; function Fib (N : Integer_Type) return Integer_Type is U : Integer_Type := 0; V : Integer_Type := 1; begin for I in 2 .. N loop Calculate_Next : declare T : constant Integer_Type := U + V; begin U := V; V := T; end Calculate_Next; end loop; return V; end Fib;
No 64 bit integers Your Ada compiler does not support 64 bit integer numbers? Then you could try to use decimal numbers7 instead. Using decimal numbers results in a slower program (takes about three times as long) but the result will be the same. The following example shows you how to dene a suitable decimal type. Do experiment with the digits and range parameters until you get the optimum out of your Ada compiler.
File:
fibonacci_5.adb
You should know that oating point numbers are unsuitable for the calculation of bonacci numbers. They will not report an error condition when the number calculated becomes too large instead they will lose in precision which makes the result meaningless.
Chapter 10 on page 79
265
30 Function overloading
File: function_overloading.adb
function Generate_Number (MaxValue : Integer) return Integer is subtype Random_Type is Integer range 0 .. MaxValue; package Random_Pack is new Ada.Numerics.Discrete_Random (Random_Type); G : Random_Pack.Generator; begin Random_Pack.Reset (G); return Random_Pack.Random (G); end Generate_Number; function Generate_Number (MinValue : Integer; MaxValue : Integer) return Integer is subtype Random_Type is Integer range MinValue .. MaxValue; package Random_Pack is new Ada.Numerics.Discrete_Random (Random_Type); G : Random_Pack.Generator; begin Random_Pack.Reset (G); return Random_Pack.Random (G); end Generate_Number; Number_1 : Integer := Generate_Number (10); Number_2 : Integer := Generate_Number (6, 10);
Ada supports all six signature options but if you use the arguments name as option you will always have to name the parameter when calling the function. i.e.:
Number_2 : Integer := Generate_Number (MinValue => 6, MaxValue => 10);
Note that you cannot overload a generic procedure or generic function within the same package. The following example will fail to compile:
267
Function overloading
package myPackage generic type Value_Type is (<>); --The first declaration of a generic subprogram --with the name "Generic_Subprogram" procedure Generic_Subprogram (Value : in out Value_Type); ... generic type Value_Type is (<>); --This subprogram has the same name, but no --input or output parameters. A non-generic --procedure would be overloaded here. --Since this procedure is generic, overloading --is not allowed and this package will not compile. procedure Generic_Subprogram; ... generic type Value_Type is (<>); --The same situation. --Even though this is a function and not --a procedure, generic overloading of --the name "Generic_Subprogram" is not allowed. function Generic_Subprogram (Value : Value_Type) return Value_Type; end myPackage;
30.2.1 Wikibook
Ada Programming1 Ada Programming/Subprograms2
1 2
268
31 Mathematical calculations
Ada is very well suited for all kind of calculations. You can dene you own xed point and oating point types and with the aid of generic packages call all the mathematical functions you need. In that respect Ada is on par with Fortran1 . This module will show you how to use them and while we progress we create a simple RPN2 calculator.
31.1.1 Addition
Additions can be done using the predened operator + . The operator is predened for all numeric types and the following, working code, demonstrates its use:
File:
numeric_1.adb
-- The Package Text_IO3 with Ada ; procedure Numeric_1 is type Value_Type is digits 12 range -999_999_999_999.0e999 .. 999_999_999_999.0e999; package T_IO renames Ada.Text_IO; package F_IO is new Ada.Text_IO.Float_IO (Value_Type); Value_1 : Value_Type; Value_2 : Value_Type; begin T_IO.Put F_IO.Get T_IO.Put F_IO.Get ("First Value : "); (Value_1); ("Second Value : "); (Value_2);
F_IO.Put (Value_1); T_IO.Put (" + "); F_IO.Put (Value_2); T_IO.Put (" = "); F_IO.Put (Value_1 + end Numeric_1;
Value_2);
1 2
http://en.wikibooks.org/wiki/Programming%3AFortran http://en.wikipedia.org/wiki/Reverse%20Polish%20notation
269
Mathematical calculations
31.1.2 Subtraction
Subtractions can be done using the predened operator - . The following extended demo shows the use of + and - operator together:
File:
numeric_2.adb
-- The Package Text_IO4 with Ada ; procedure Numeric_2 is type Value_Type is digits 12 range -999_999_999_999.0e999 .. 999_999_999_999.0e999; package T_IO renames Ada ; package F_IO is new Ada.Text_IO.Float_IO (Value_Type); Value_1 Value_2 Result Operation begin T_IO.Put F_IO.Get T_IO.Put F_IO.Get T_IO.Put T_IO.Get : : : : Value_Type; Value_Type; Value_Type; Character;
("First Value : "); (Value_1); ("Second Value : "); (Value_2); ("Operation : "); (Operation);
case Operation is when + => Result := Value_1 + Value_2; when - => Result := Value_1 - Value_2; when others => T_IO.Put_Line ("Illegal Operation."); goto Exit_Numeric_2; end case; F_IO.Put T_IO.Put T_IO.Put T_IO.Put F_IO.Put T_IO.Put F_IO.Put (Value_1); (" "); (Operation); (" "); (Value_2); (" = "); (Result);
270
Purists might be surprised about the use of goto but some people prefer the use of goto over the use of multiple return statements if inside functions given that, the opinions on this topic vary strongly. See the isn t goto evil5 article.
31.1.3 Multiplication
Multiplication can be done using the predened operator * . For a demo see the next chapter about Division.
31.1.4 Division
Divisions can be done using the predened operators / , mod , rem . The operator / performs a normal division, mod returns a modulus division and rem returns the remainder of the modulus division. The following extended demo shows the use of the + , - , * and / operators together as well as the use of a four number wide stack to store intermediate results: The operators mod and rem are not part of the demonstration as they are only dened for integer types.
numeric_3.adb
procedure Numeric_3 is procedure Pop_Value; procedure Push_Value; type Value_Type is digits 12 range -999_999_999_999.0e999 .. 999_999_999_999.0e999; type Value_Array is array (Natural range 1 .. 4) of Value_Type; package T_IO renames Ada.Text_IO; package F_IO is new Ada.Text_IO.Float_IO (Value_Type); Values : Value_Array := (others => 0.0); Operation : String (1 .. 40); Last : Natural; procedure Pop_Value is begin Values (Values First + 1 .. Values Last) := Values (Values First + 2 .. Values Last) & 0.0; end Pop_Value; procedure Push_Value is begin Values (Values First + 1 .. Values Last) := Values (Values First .. Values Last - 1); end Push_Value;
Chapter 4 on page 37
271
Mathematical calculations
begin Main_Loop: loop T_IO.Put (">"); T_IO.Get_Line (Operation, Last); if Last = 1 and then Operation (1) = + then Values (1) := Values (1) + Values (2); Pop_Value; elsif Last = 1 and then Operation (1) = - then Values (1) := Values (1) + Values (2); Pop_Value; elsif Last = 1 and then Operation (1) = * then Values (1) := Values (1) * Values (2); Pop_Value; elsif Last = 1 and then Operation (1) = / then Values (1) := Values (1) / Values (2); Pop_Value; elsif Last = 4 and then Operation (1 .. 4) = "exit" then exit Main_Loop; else Push_Value; F_IO.Get (From => Operation, Item => Values (1), Last => Last); end if; Display_Loop: for I in reverse Value_Array Range loop F_IO.Put (Item => Values (I), Fore => F_IO.Default_Fore, Aft => F_IO.Default_Aft, Exp => 4); T_IO.New_Line; end loop Display_Loop; end loop Main_Loop; return; end Numeric_3;
All exponential functions are dened inside the generic package Ada .
31.2.1 Power of
Calculation of the form xy are performed by the operator ** . Beware: There are two versions of this operator. The predened operator ** allows only for Standard.Integer to be used as exponent. If you need to use a oating point type as exponent you need to use the ** dened in Ada .
272
31.2.2 Root
The square root x is calculated with the function Sqrt(). There is no function dened to calculate an arbitrary root n x. However you can use logarithms to calculate an arbitrary root using the mathematical identity: b a = eloge (a)/b which will become root := Exp (Log 1 (a) / b) in Ada. Alternatively, use b a = a b which, in Ada, is root := a**(1.0/b).
31.2.3 Logarithm
Ada denes a function for both the arbitrary logarithm logn (x) and the natural logarithm loge (x), both of which have the same name Log() distinguished by the number of parameters.
31.2.4 Demonstration
The following extended demo shows the how to use the exponential functions in Ada. The new demo also uses Unbounded_String6 instead of Strings which make the comparisons easier. Please note that from now on we won t copy the full sources any more. Do follow the download links to see the full program.
numeric_4.adb
procedure Numeric_4 is package Str renames Ada.Strings.Unbounded; package T_IO renames Ada.Text_IO; procedure Pop_Value; procedure Push_Value; function Get_Line return Str.Unbounded_String; type Value_Type is digits 12 range -999_999_999_999.0e999 .. 999_999_999_999.0e999; type Value_Array is array (Natural range 1 .. 4) of Value_Type; package F_IO is new Ada.Text_IO.Float_IO (Value_Type); package Value_Functions is new Ada.Numerics.Generic_Elementary_Functions ( Value_Type); use Value_Functions; use type Str.Unbounded_String; Values : Value_Array := (others => 0.0); Operation : Str.Unbounded_String; Dummy : Natural;
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Unbounded
273
Mathematical calculations
function Get_Line return Str.Unbounded_String is BufferSize : constant := 2000; Retval : Str.Unbounded_String := Str.Null_Unbounded_String; Item : String (1 .. BufferSize); Last : Natural; begin Get_Whole_Line : loop T_IO.Get_Line (Item => Item, Last => Last); Last)); Str.Append (Source => Retval, New_Item => Item (1 .. exit Get_Whole_Line when Last < Item Last; end loop Get_Whole_Line; return Retval; end Get_Line; ... begin Main_Loop : loop T_IO.Put (">"); Operation := Get_Line; ... elsif Operation = "e" then -- insert e Push_Value; Values (1) := Ada.Numerics.e; elsif Operation = "**" or else Operation = "" then -- power of xy Values (1) := Values (1) ** Values (2); Pop_Value; elsif Operation = "sqr" then -- square root Values (1) := Sqrt (Values (1)); elsif Operation = "root" then -- arbritary root Values (1) := Exp (Log (Values (2)) / Values (1)); Pop_Value; elsif Operation = "ln" then -- natural logarithm Values (1) := Log (Values (1)); elsif Operation = "log" then -- based logarithm Values (1) := Log (Base => Values (1), X => Values (2)); Pop_Value; elsif Operation = "exit" then exit Main_Loop; else Push_Value; F_IO.Get (From => Str.To_String (Operation), Item => Values (1), Last => Dummy); end if; end loop Main_Loop;
...
274
with Ada ; with Ada ; with Ada ; procedure Numeric_5 is ... procedure Put_Line (Value : in Value_Type); use Value_Functions; use type Str.Unbounded_String; Values Cycle Operation Dummy ... procedure Put_Line (Value : in Value_Type) is begin if abs Value_Type Exponent (Value) >= abs Value_Type Exponent (10.0 ** F_IO.Default_Aft) then F_IO.Put (Item => Value, Fore => F_IO.Default_Aft, Aft => F_IO.Default_Aft, Exp => 4); else F_IO.Put (Item => Value, Fore => F_IO.Default_Aft, Aft => F_IO.Default_Aft, Exp => 0); end if; : : : : Value_Array := (others => 0.0); Value_Type := Ada.Numerics.Pi; Str.Unbounded_String; Natural;
http://en.wikibooks.org/wiki/%2FTrigonometry
275
Mathematical calculations
T_IO.New_Line; return; end Put_Line; ... begin Main_Loop : loop Display_Loop : for I in reverse Value_Array Range loop Put_Line (Values (I)); end loop Display_Loop; T_IO.Put (">"); Operation := Get_Line; ... elsif Operation = "deg" then -- switch to degrees Cycle := 360.0; elsif Operation = "rad" then -- switch to degrees Cycle := Ada.Numerics.Pi; elsif Operation = "grad" then -- switch to degrees Cycle := 400.0; elsif Operation = "pi" or else Operation = "" then -- switch to degrees Push_Value; Values (1) := Ada.Numerics.Pi; elsif Operation = "sin" then -- sinus Values (1) := Sin (X => Values (1), Cycle => Cycle); elsif Operation = "cos" then -- cosinus Values (1) := Cos (X => Values (1), Cycle => Cycle); elsif Operation = "tan" then -- tangents Values (1) := Tan (X => Values (1), Cycle => Cycle); elsif Operation = "cot" then -- cotanents Values (1) := Cot (X => Values (1), Cycle => Cycle); elsif Operation = "asin" then -- arc-sinus Values (1) := Arcsin (X => Values (1), Cycle => Cycle); elsif Operation = "acos" then -- arc-cosinus Values (1) := Arccos (X => Values (1), Cycle => Cycle); elsif Operation = "atan" then -- arc-tangents Values (1) := Arctan (Y => Values (1), Cycle => Cycle); elsif Operation = "acot" then -- arc-cotanents Values (1) := Arccot (X => Values (1), Cycle => Cycle); end loop Main_Loop;
...
The Demo also contains an improved numeric output which behaves more like a normal calculator.
276
You guessed it: The full set of hyperbolic functions is dened inside the generic package Ada .
File:
numeric_6.adb
; ; ; ; Numeric_6 is Str renames Ada.Strings.Unbounded; T_IO renames Ada.Text_IO; Exept renames Ada.Exceptions;
begin Main_Loop : loop Try : begin Display_Loop : ... elsif Operation = "sinh" then -- sinus hyperbolic Values (1) := Sinh (Values (1)); elsif Operation = "cosh" then -- cosinus hyperbolic Values (1) := Coth (Values (1)); elsif Operation = "tanh" then -- tangents hyperbolic Values (1) := Tanh (Values (1)); elsif Operation = "coth" then -- cotanents hyperbolic Values (1) := Coth (Values (1)); elsif Operation = "asinh" then -- arc-sinus hyperbolic Values (1) := Arcsinh (Values (1)); elsif Operation = "acosh" then -- arc-cosinus hyperbolic Values (1) := Arccosh (Values (1)); elsif Operation = "atanh" then -- arc-tangents hyperbolic Values (1) := Arctanh (Values (1)); elsif Operation = "acoth" then -- arc-cotanents hyperbolic Values (1) := Arccoth (Values (1)); ... exception when An_Exception : others => T_IO.Put_Line (Exept.Exception_Information (An_Exception)); end Try; end loop Main_Loop; return; end Numeric_6;
277
Mathematical calculations As added bonus this version supports error handling and therefore won t just crash when an illegal calculation is performed.
procedure Numeric_7 is ... package Complex_Types is new Ada.Numerics.Generic_Complex_Types ( Value_Type); package Complex_Functions is new Ada.Numerics.Generic_Complex_Elementary_Functions ( Complex_Types); package C_IO is new Ada.Text_IO.Complex_IO (Complex_Types); type Value_Array is array (Natural range 1 .. 4) of Complex_Types.Complex; procedure Put_Line (Value : in Complex_Types.Complex); use type Complex_Types.Complex; use type Str.Unbounded_String;
http://en.wikibooks.org/wiki/Algebra%2FComplex%20Numbers
278
use Complex_Functions; Values : Value_Array := (others => Complex_Types.Complex (Re => 0.0, Im => 0.0)); ... procedure Put_Line (Value : in Complex_Types.Complex) is begin if (abs Value_Type Exponent (Value.Re) >= abs Value_Type Exponent (10.0 ** C_IO.Default_Aft)) or else (abs Value_Type Exponent (Value.Im) >= abs Value_Type Exponent (10.0 ** C_IO.Default_Aft)) then C_IO.Put (Item => Value, Fore => C_IO.Default_Aft, Aft => C_IO.Default_Aft, Exp => 4); else C_IO.Put (Item => Value, Fore => C_IO.Default_Aft, Aft => C_IO.Default_Aft, Exp => 0); end if; T_IO.New_Line; return; end Put_Line; begin ... elsif Operation = "e" then -- insert e Push_Value; Values (1) := Complex_Types.Complex (Re => Ada.Numerics.e, Im
=> 0.0);
elsif Operation = "pi" or else Operation = "" then -- insert pi Push_Value; Values (1) := Complex_Types.Complex (Re => Ada.Numerics.Pi, Im elsif Operation = "sin" then -- sinus Values (1) := Sin (Values (1)); elsif Operation = "cos" then -- cosinus Values (1) := Cot (Values (1)); elsif Operation = "tan" then -- tangents Values (1) := Tan (Values (1)); elsif Operation = "cot" then -- cotanents Values (1) := Cot (Values (1)); elsif Operation = "asin" then -- arc-sinus Values (1) := Arcsin (Values (1)); elsif Operation = "acos" then -- arc-cosinus
279
Mathematical calculations
Values (1) := Arccos (Values (1)); elsif Operation = "atan" then -- arc-tangents Values (1) := Arctan (Values (1)); elsif Operation = "acot" then -- arc-cotanents Values (1) := Arccot (Values (1)); ... return; end Numeric_7;
31.4.1 Wikibook
Ada Programming11
9 10 11 http://en.wikibooks.org/wiki/Linear%20Algebra%2FVectors%20in%20Space http://en.wikibooks.org/wiki/Linear_Algebra%2FDescribing_the_Solution_Set%23matrix http://en.wikibooks.org/wiki/Ada%20Programming
280
12 13 14
281
32 Statements
Note: there are some simplications in the explanations below. Don t take anything too literally. Most programming languages have the concept of a statement. A statement is a command that the programmer gives to the computer. For example:
Ada.Text_IO.Put_Line ("Hi there!");
This command has a verb ("") and other details (what to print). In this case, the command "" means "show on the screen," not "print on the printer." The programmer either gives the statement directly to the computer (by typing it while running a special program), or creates a text le with the command in it. You could create a le called "hi.txt", put the above command in it, and give the le to the computer. If you have more than one command in the le, each will be performed in order, top to bottom. So the le could contain:
Ada.Text_IO.Put_Line ("Hi there!"); Ada.Text_IO.Put_Line ("Strange things are afoot...");
This does seem like a lot of typing but don t worry: Ada allows you to declare shorter aliasnames if you need a long statement very often.
283
33 Variables
Variables are references that stand in for a value that is contained at a certain memory address. Variables are said to have a value and may have a data type1 . If a variable has a type, then only values of this type may be assigned to it. Variables do not always have a type. A value can have many values of many dierent types: integers (7), ratios (1/2), (approximations of) reals (10.234), complex numbers (4+2i), characters ( a ), strings ("hello"), and much more. Dierent languages use dierent names for their types and may not include any of the above.
33.2 Uses
Uses Variables store everything in your program. The purpose of any useful program is to modify variables.
285
286
34 Lexical elements
34.1 Character set
Character set The character set used in Ada programs is composed of: Upper-case letters: A, ..., Z and lower-case letters: a, ..., z. Digits: 0, ..., 9. Special characters. Take into account that in Ada 95 the letter range includes accented characters and other letters used in Western Europe languages, those belonging to the ISO Latin-11 character set, as , , , etc. In Ada 20052 the character set has been extended to the full Unicode3 set, so the identiers and comments can be written in almost any language in the world. Ada is a case-insensitive language, i. e. the upper-case set is equivalent to the lower-case set except in character string literals and character literals.
This line contains 5 lexical elements: The identier Temperature_In_Room. The compound delimiter :=. The number 25. The single delimiter ;.
1 2 3 4 5 http://en.wikipedia.org/wiki/ISO%208859-1 Chapter 23 on page 219 http://en.wikipedia.org/wiki/Unicode Chapter 36 on page 297 Chapter 35 on page 293
287
34.2.1 Identiers
Denition in BNF6 :
identifier ::= letter { [ underscore ] letter | digit } letter ::= A | ... | Z | a | ... | z digit ::= 0 | ... | 9 underscore ::= _
From this denition we must exclude the keywords that are reserved words in the language and cannot be used as identiers. Examples: The following words are legal Ada identiers:
Time_Of_Day TimeOfDay El_Nio_Forecast Faade counter ALARM
Exercise: could you give the reason for not being legal for each one of them?
34.2.2 Numbers
The numeric literals are composed of the following characters: digits 0 .. 9 the decimal separator ., the exponentiation sign e or E, the negative sign - (in exponents only) and the underscore _. The underscore is used as separator for improving legibility for humans, but it is ignored by the compiler. You can separate numbers following any rationale, e.g. decimal integers in groups of three digits, or binary integers in groups of eight digits. For example, the real number such as 98.4 can be represented as: 9.84E1, 98.4e0, 984.0e-1 or 0.984E+2, but not as 984e-1. For integer numbers, for example 1900, it could be written as 1900, 19E2, 190e+1 or 1_900E+0. A numeric literal could also be expressed in a base dierent to 10, by enclosing the number between # characters, and preceding it by the base, which can be a number between 2 and 16. For example, 2#101# is 1012 , that is 510 ; a hexadecimal number with exponent is 16#B#E2, that is 11 162 = 2,816. Note that there are no negative literals; e.g. -1 is not a literal, rather it is the literal 1 preceded by the unary minus operator.
6
http://en.wikipedia.org/wiki/Backus-Naur%20form
288
34.2.5 Delimiters
Single delimiters are one of the following special characters:
& > ( ) * + , . / : ; < =
Compound delimiters are composed of two special characters, and they are the following ones:
=> .. ** := /= >= <= << >> <>
34.2.6 Comments
Comments in Ada start with two consecutive hyphens (--) and end in the end of line.
--This is a comment in a full line My_Savings := My_Savings * 10.0; --This is a comment in a line after a sentece My_Savings := My_Savings * --This is a comment inserted inside a sentence 1_000_000.0;
7 8 9 10
289
Lexical elements
return reverse select separate some (Ada 2012) subtype synchronized (Ada 2005)
for function
290
See also
34.3.1 Wikibook
Ada Programming13 Ada Programming/Delimiters14 Ada Programming/Keywords15
13 14 15 16
291
35 Keywords
35.1 Language summary keywords
Language summary keywords Most Ada keywords have dierent functions depending on where they are used. A good example is for1 which controls the representation clause when used within a declaration part and controls a loop when used within an implementation. In Ada, a keyword is a reserved word, so it cannot be used as an identier. Some of them are used as attribute2 names.
1 2 3
293
Keywords abort abs abstract (Ada 95) accept access aliased (Ada 95) all and array at generic goto if in interface (Ada 2005) is limited loop mod package pragma private procedure protected (Ada 95) else elsif end entry exception exit new not null of or others out overriding (Ada 2005) tagged (Ada 95) task terminate then type return reverse select separate some (Ada 2012) subtype synchronized (Ada 2005)
for function
35.3.1 Wikibook
Ada Ada Ada Ada Programming4 Programming/Aspects5 Programming/Attributes6 Programming/Pragmas7
4 5 6 7
294
8 9 10 11 12 13
295
36 Delimiters
36.1 Single character delimiters
Single character delimiters &1 ampersand (also operator &2 )
3
apostrophe, tick (4 left parenthesis )5 right parenthesis *6 asterisk, multiply (also operator *7 ) +8 plus sign (also operator +9 ) ,10 comma 11 hyphen, minus (also operator -12 ) 13 . full stop, point, dot /14 solidus, divide (also operator /15 )
16
colon ;17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%26 http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%26 http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%27 http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%28 http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%29 http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%2A http://en.wikibooks.org/wiki/Ada%20Programming%2FOperators%2F%2A http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%2B http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%2B http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%2C http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2Fhttp://en.wikibooks.org/wiki/Ada%20Programming%2FOperators%2Fhttp://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2Fdot http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%2F http://en.wikibooks.org/wiki/Ada%20Programming%2FOperators%2F%2F http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%3A http://en.wikibooks.org/wiki/Ada%20Programming%2FDelimiters%2F%3B
297
Delimiters semicolon <18 less than sign (also operator) =19 equal sign (also operator =20 ) >21 greater than sign (also operator)
22
vertical line
298
box
36.3 Others
Others The following ones are special characters but not delimiters. "34 quotation mark, used for string literals35 . #36 number sign, used in based numeric literals37 . The following special characters are unused in Ada code - they are illegal except within string literals and comments (they are used in the Reference Manual Backus-Naur syntax denition of Ada): [ left square bracket ] right square bracket { left curly bracket } right curly bracket
36.4.1 Wikibook
Ada Programming38
34 35 36 37 38
http://en.wikibooks.org/wiki/Ada%20Programming%2FSpecial%2F%22 Chapter 34.2.4 on page 289 http://en.wikibooks.org/wiki/Ada%20Programming%2FSpecial%2Fnumber%20sign Chapter 34.2.2 on page 288 http://en.wikibooks.org/wiki/Ada%20Programming
299
37 Operators
37.1 Standard operators
Standard operators Ada1 allows operator overloading2 for all standard operators and so the following summaries can only describe the suggested standard operations for each operator. It is quite possible to misuse any standard operator to perform something unusual. Each operator is either a keyword3 or a delimiter4 -- hence all operator pages are redirects to the appropriate keyword5 or delimiter6 . Operators have arguments which in the RM are called Left and Right for binary operators, Right for unary operators (indicating the position with respect to the operator symbol). The list is sorted from lowest precedence to highest precedence.
301
Operators <17 Less than x < y , (also special character <18 ) <=19 Less than or equal to (x y ), (also special character <=20 ) >21 Greater than (x > y ), (also special character >22 ) >=23 Greater than or equal to (x y ), (also special character >=24 )
302
/37 Divide x/y , (also special character /38 ) mod39 modulus (also keyword mod40 ) rem41 remainder (also keyword rem42 )
303
Operators not element of, var / type, e.g. if I not in Positive then, (also keywords not in)
37.4.1 Wikibook
Ada Programming53
53 54
http://en.wikibooks.org/wiki/Ada%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FAll%20Operators
304
38 Attributes
38.1 Language summary attributes
Language summary attributes The concept of attributes is pretty unique to Ada1 . Attributes allow you to get and sometimes set information about objects or other language entities such as types. A good example is the Size attribute. It describes the size of an object or a type in bits.
A : Natural := Integer Size; --A is now 32 (with the GNAT2 compiler for the x86 architecture)
However, unlike the sizeof operator from C3 /C++4 the Size attribute can also be set:
type Byte is range -128 .. 127; for Byte Size use 8; --The range fits into 8 bits but the --compiler is still free to choose. --Now we force the compiler to use 8 bits.
Of course not all attributes can be set. An attribute starts with a tick and is followed by its name. The compiler determines by context if the tick is the beginning of an attribute or of a character literal.
A : Character := Character Val (32) --A is now a space B : Character := ; --B is also a space
1 3 4 5 6
305
Attributes
38.2.1 A B
Access7 Address8 Adjacent9 Aft10 Alignment11 Base12 Bit_Order13 Body_Version14
38.2.2 C
Callable15 Caller16 Ceiling17 Class18 Component_Size19 Compose20 Constrained21 Copy_Sign22 Count23
38.2.3 D F
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
306
38.2.4 G L
Has_Same_Storage37 (Ada 2012) Identity38 Image39 Input40 Large41 (Obsolescent) Last42 Last_Bit43 Leading_Part44 Length45
38.2.5 M
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
307
Attributes Machine_Radix51 Machine_Rounding52 (Ada 2005) Machine_Rounds53 Mantissa54 (Obsolescent) Max55 Max_Aligment_For_Allocation56 (Ada 2012) Max_Size_In_Storage_Elements57 Min58 Mod59 (Ada 2005) Model60 Model_Emin61 Model_Epsilon62 Model_Mantissa63 Model_Small64 Modulus65
38.2.6 O R
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
Old66 (Ada 2012) Output67 Overlaps_Storage68 (Ada 2012) Partition_ID69 Pos70 Position71 Pred72 Priority73 (Ada 2005)
http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Machine_Radix http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Machine_Rounding http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Machine_Rounds http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Mantissa http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Max http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Max_Aligment_For_ Allocation http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Max_Size_In_Storage_ Elements http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Min http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Mod http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Model http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Model_Emin http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Model_Epsilon http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Model_Mantissa http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Model_Small http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Modulus http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Old http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Output http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Overlaps_Storage http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Partition_ID http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Pos http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Position http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Pred http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Priority
308
38.2.7 S
Safe_Emax80 (Obsolescent) Safe_First81 Safe_Large82 (Obsolescent) Safe_Last83 Safe_Small84 (Obsolescent) Scale85 Scaling86 Signed_Zeros87 Size88 Small89 Storage_Pool90 Storage_Size91 Stream_Size92 (Ada 2005) Succ93
38.2.8 T V
Tag94 Terminated95
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Range http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Read http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Remainder http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Result http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Round http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Rounding http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Safe_Emax http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Safe_First http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Safe_Large http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Safe_Last http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Safe_Small http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Scale http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Scaling http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Signed_Zeros http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Small http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Storage_Pool http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Storage_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Stream_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Succ http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Tag http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Terminated
309
38.2.9 W Z
Wide_Image103 Wide_Value104 Wide_Wide_Image105 (Ada 2005) Wide_Wide_Value106 (Ada 2005) Wide_Wide_Width107 (Ada 2005) Wide_Width108 Width109 Write110
http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Truncation http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Unbiased_Rounding http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Unchecked_Access http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Val http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Valid http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Version http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wide_Image http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wide_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wide_Wide_Image http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wide_Wide_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wide_Wide_Width http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wide_Width http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Width http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Write http://en.wikibooks.org/w/index.php?title=Programming:Ada:Attributes&action=edit http://www.adacore.com/wp-content/files/auto_update/gnat-unw-docs/html/gnat_rm_3.html http://en.wikibooks.org/wiki/Ada%20Programming%2FGNAT
310
Implementation-dened attribute114 of the HP Ada115 compiler (formerly known as "DEC Ada"). ICC Implementation-dened attribute116 of the Irvine ICC117 compiler. PowerAda Implementation-dened attribute118 of OC Systems PowerAda119 . SPARCompiler Implementation-dened attribute120 of Sun s SPARCompiler Ada121 .
38.3.1 A D
Abort_Signal122 (GNAT) Address_Size123 (GNAT) Architecture124 (ICC) Asm_Input125 (GNAT) Asm_Output126 (GNAT) AST_Entry127 (GNAT, HP Ada) Bit128 (GNAT, HP Ada) Bit_Position129 (GNAT) CG_Mode130 (ICC) Code_Address131 (GNAT) Compiler_Key132 (SPARCompiler) Compiler_Version133 (SPARCompiler) Declared134 (ICC) Default_Bit_Order135 (GNAT) Dope_Address136 (SPARCompiler)
114 http://h71000.www7.hp.com/commercial/ada/ada_lrm.pdf 115 http://h71000.www7.hp.com/commercial/ada/ada_index.html 116 "4.2 ICC-Dened Attributes", ICC Ada Implementation Reference ICC Ada Version 8.2.5 for i960MC Targets, document version 2.11.4http://www.irvine.com/support/general/ 117 http://www.irvine.com/products.html 118 http://www.ocsystems.com/user_guide/powerada/html/powerada-117.html#HEADING117-0 119 http://www.ocsystems.com/prod_powerada.html http://docs.sun.com/app/docs/doc/802-3641/6i7h8si5i?a=view#F. 120 Implementation-Dependent_Characteristi-30 121 http://docs.sun.com/app/docs/coll/15.4 122 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Abort_Signal 123 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Address_Size 124 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Architecture 125 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Asm_Input 126 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Asm_Output 127 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27AST_Entry 128 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Bit 129 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Bit_Position 130 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27CG_Mode 131 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Code_Address 132 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Compiler_Key 133 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Compiler_Version 134 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Declared 135 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Default_Bit_Order 136 http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Dope_Address
311
38.3.2 E H
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
Elaborated138 (GNAT) Elab_Body139 (GNAT) Elab_Spec140 (GNAT) Emax141 (GNAT) Enabled142 (GNAT) Entry_Number143 (SPARCompiler) Enum_Rep144 (GNAT) Enum_Val145 (GNAT) Epsilon146 (GNAT) Exception_Address147 (ICC) Extended_Aft148 (PowerAda) Extended_Base149 (PowerAda) Extended_Digits150 (PowerAda) Extended_Fore151 (PowerAda) Extended_Image152 (PowerAda) Extended_Value153 (PowerAda) Extended_Width154 (PowerAda) Extended_Wide_Image155 (PowerAda) Extended_Wide_Value156 (PowerAda) Extended_Wide_Width157 (PowerAda) Fixed_Value158 (GNAT) Has_Access_Values159 (GNAT) Has_Discriminants160 (GNAT)
http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Dope_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Elaborated http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Elab_Body http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Elab_Spec http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Emax http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Enabled http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Entry_Number http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Enum_Rep http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Enum_Val http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Epsilon http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Exception_Address http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Aft http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Base http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Digits http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Fore http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Image http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Width http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Wide_Image http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Wide_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Extended_Wide_Width http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Fixed_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Has_Access_Values http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Has_Discriminants
312
38.3.3 I N
Img163 (GNAT) Integer_Value164 (GNAT) Invalid_Value165 (GNAT) Linear_Address166 (ICC) Low_Word167 (ICC) Machine_Size168 (GNAT, HP Ada) Max_Interrupt_Priority169 (GNAT) Max_Priority170 (GNAT) Maximum_Alignment171 (GNAT) Mechanism_Code172 (GNAT) Null_Parameter173 (GNAT, HP Ada)
38.3.4 O T
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
Object_Size174 (GNAT) Old175 (GNAT) Passed_By_Reference176 (GNAT) Pool_Address177 (GNAT) Range_Length178 (GNAT) Ref179 (SPARCompiler) Storage_Unit180 (GNAT) Stub_Type181 (GNAT) Target182 (ICC)
http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27High_Word http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Homogeneous http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Img http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Integer_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Invalid_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Linear_Address http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Low_Word http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Machine_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Max_Interrupt_ Priority http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Max_Priority http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Maximum_Alignment http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Mechanism_Code http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Null_Parameter http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Object_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Old http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Passed_By_Reference http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Pool_Address http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Range_Length http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Ref http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Storage_Unit http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Stub_Type http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Target
313
Attributes Target_Name183 (GNAT) Task_ID184 (SPARCompiler) Tick185 (GNAT) To_Address186 (GNAT) Type_Class187 (GNAT, HP Ada) Type_Key188 (SPARCompiler)
38.3.5 U Z
UET_Address189 (GNAT) Unconstrained_Array190 (GNAT) Universal_Literal_String191 (GNAT) Unrestricted_Access192 (GNAT, ICC) VADS_Size193 (GNAT) Value_Size194 (GNAT) Wchar_T_Size195 (GNAT) Word_Size196 (GNAT)
38.4.1 Wikibook
Ada Ada Ada Ada Programming197 Programming/Aspects198 Programming/Pragmas199 Programming/Keywords200
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Target_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Task_ID http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Tick http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27To_Address http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Type_Class http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Type_Key http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27UET_Address http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Unconstrained_Array http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Universal_Literal_ String http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Unrestricted_Access http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27VADS_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Value_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Wchar_T_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FAttributes%2F%27Word_Size http://en.wikibooks.org/wiki/Ada%20Programming http://en.wikibooks.org/wiki/Ada%20Programming%2FAspects Chapter 39 on page 317 Chapter 35 on page 293
314
38.5 References
References
315
39 Pragmas
39.1 Description
Description Pragmas1 control the compiler, i.e. they are compiler directives2 . They have the standard form of
pragma Name (Parameter_List);
39.2.1 A H
1 2 3 4 5 6 7 8 9 10 11
All_Calls_Remote5 Assert6 (Ada 2005) Assertion_Policy7 (Ada 2005) Asynchronous8 (Obsolescent since Ada 2012) Atomic9 (Obsolescent since Ada 2012) Atomic_Components10 (Obsolescent since Ada 2012) Attach_Handler11 (Obsolescent since Ada 2012)
Chapter 39 on page 317 http://en.wikipedia.org/wiki/Compiler%20directive Chapter 23 on page 219 http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%202012 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAll_Calls_Remote http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAssert http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAssertion_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAsynchronous http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAtomic http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAtomic_Components http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAttach_Handler
317
Pragmas Controlled12 Convention13 (Obsolescent since Ada 2012) CPU14 (Ada 2012) Default_Storage_Pool15 (Ada 2012) Detect_Blocking16 (Ada 2005) Discard_Names17 Dispatching_Domain18 (Ada 2012) Elaborate19 Elaborate_All20 Elaborate_Body21 Export22 (Obsolescent since Ada 2012)
39.2.2 I O
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Import23 (Obsolescent since Ada 2012) Independent24 (Ada 2012) Independent_Component25 (Ada 2012) Inline26 (Obsolescent since Ada 2012) Inspection_Point27 Interface28 (Obsolescent) Interrupt_Handler29 (Obsolescent since Ada 2012) Interrupt_Priority30 (Obsolescent since Ada 2012) Linker_Options31 List32 Locking_Policy33 Memory_Size34 (Obsolescent) No_Return35 (Ada 2005) (Obsolescent since Ada 2012)
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FControlled http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FConvention http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCPU http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDefault_Storage_Pool http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDetect_Blocking http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDiscard_Names http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDispatching_Domain http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FElaborate http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FElaborate_All http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FElaborate_Body http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FIndependent http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FIndependent_Component http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInline http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInspection_Point http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterface http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterrupt_Handler http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterrupt_Priority http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLinker_Options http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FList http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLocking_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FMemory_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Return
318
Normalize_Scalars36 Optimize37
39.2.3 P R
Pack38 (Obsolescent since Ada 2012) Page39 Partition_Elaboration_Policy40 (Ada 2005) Preelaborable_Initialization41 (Ada 2005) Preelaborate42 Priority43 (Obsolescent since Ada 2012) Priority_Specic_Dispatching44 (Ada 2005) Prole45 (Ada 2005) Pure46 Queueing_Policy47 Relative_Deadline48 (Ada 2005) Remote_Call_Interface49 Remote_Types50 Restrictions51 Reviewable52
39.2.4 S Z
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
319
Pragmas System_Name58 (Obsolescent) Task_Dispatching_Policy59 Unchecked_Union60 (Ada 2005) Unsuppress61 (Ada 2005) Volatile62 Volatile_Components63
39.3.1 A C
Abort_Defer75 (GNAT)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSystem_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTask_Dispatching_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FUnchecked_Union http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FUnsuppress http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FVolatile http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FVolatile_Components http://en.wikibooks.org/w/index.php?title=Ada_Programming/Pragmas&action=edit http://www.adacore.com/wp-content/files/auto_update/gnat-unw-docs/html/gnat_rm_2.html http://en.wikibooks.org/wiki/Ada%20Programming%2FGNAT http://h71000.www7.hp.com/commercial/ada/ada_lrm.pdf http://h71000.www7.hp.com/commercial/ada/ada_index.html "2.2 ICC-Dened Pragmas", ICC Ada Implementation Reference ICC Ada Version 8.2.5 for i960MC Targets, document version 2.11.4.http://www.irvine.com/support/general/ http://www.irvine.com/products.html http://www.ocsystems.com/user_guide/powerada/html/powerada-106.html#HEADING106-0 http://www.ocsystems.com/prod_powerada.html http://docs.sun.com/app/docs/doc/802-3641/6i7h8si5i?a=view#F. Implementation-Dependent_Characteristi-2 http://docs.sun.com/app/docs/coll/15.4 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAbort_Defer
320
Ada_8376 (GNAT) Ada_9577 (GNAT) Ada_0578 (GNAT) Ada_200579 (GNAT) Ada_1280 (GNAT) Ada_201281 (GNAT) Annotate82 (GNAT) Assume_No_Invalid_Values83 (GNAT) Ast_Entry84 (GNAT, HP Ada) Bit_Pack85 (SPARCompiler) Built_In86 (SPARCompiler) Byte_Pack87 (SPARCompiler) C_Pass_By_Copy88 (GNAT) Call_Mechanism89 (ICC) Canonical_Streams90 (GNAT) Check91 (GNAT) Check_Name92 (GNAT) Check_Policy93 (GNAT) CM_Info94 (PowerAda) Comment95 (GNAT) Common_Object96 (GNAT, HP Ada) Compatible_Calls97 (ICC) Compile_Time_Error98 (GNAT) Compile_Time_Warning99 (GNAT) Complete_Representation100 (GNAT)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAda_83 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAda_95 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAda_05 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAda_2005 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAda_12 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAda_2012 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAnnotate http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAssume_No_Invalid_Values http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FAst_Entry http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FBit_Pack http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FBuilt_In http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FByte_Pack http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FC_Pass_By_Copy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCall_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCanonical_Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCheck http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCheck_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCheck_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCM_Info http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FComment http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCommon_Object http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCompatible_Calls http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCompile_Time_Error http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCompile_Time_Warning http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FComplete_Representation
321
Pragmas Complex_Representation101 (GNAT) Component_Alignment102 (GNAT, HP Ada) Compress103 (ICC) Constrain_Private104 (ICC) Convention_Identier105 (GNAT) CPP_Class106 (GNAT) CPP_Constructor107 (GNAT) CPP_Virtual108 (GNAT) CPP_Vtable109 (GNAT)
39.3.2 D H
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
Data_Mechanism110 (ICC) Debug111 (GNAT) Debug_Policy112 (GNAT) Delete_Subprogram_Entry113 (ICC) Elaboration_Checks114 (GNAT) Eliminate115 (GNAT) Error116 (SPARCompiler) Export_Exception117 (GNAT, HP Ada) Export_Function118 (GNAT, HP Ada, SPARCompiler) Export_Mechanism119 (ICC) Export_Object120 (GNAT, HP Ada, SPARCompiler) Export_Procedure121 (GNAT, HP Ada, SPARCompiler) Export_Value122 (GNAT) Export_Valued_Procedure123 (GNAT, HP Ada) Extend_System124 (GNAT)
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FComplex_Representation http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FComponent_Alignment http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCompress http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FConstrain_Private http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FConvention_Identifier http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCPP_Class http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCPP_Constructor http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCPP_Virtual http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FCPP_Vtable http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FData_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDebug http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDebug_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FDelete_Subprogram_Entry http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FElaboration_Checks http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FEliminate http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FError http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Exception http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Function http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Object http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Procedure http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Value http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExport_Valued_Procedure http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExtend_System
322
Extensions_Allowed125 (GNAT) External126 (GNAT, SPARCompiler) External_Name127 (ICC, SPARCompiler) External_Name_Casing128 (GNAT) Fast_Math129 (GNAT) Favor_Top_Level130 (GNAT) Finalize_Storage_Only131 (GNAT) Float_Representation132 (GNAT, HP Ada) Foreign133 (ICC) Generic_Mechanism134 (ICC) Generic_Policy135 (SPARCompiler)
39.3.3 I L
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
i960_Intrinsic136 (ICC) Ident137 (GNAT, HP Ada) Images138 (PowerAda) Implemented139 , previously named Implemented_By_Entry (GNAT) Implicit_Code140 (SPARCompiler) Implicit_Packing141 (GNAT) Import_Exception142 (GNAT, HP Ada) Import_Function143 (GNAT, HP Ada, SPARCompiler) Import_Mechanism144 (ICC) Import_Object145 (GNAT, HP Ada, SPARCompiler) Import_Procedure146 (GNAT, HP Ada, SPARCompiler) Import_Valued_Procedure147 (GNAT, HP Ada) Include148 (SPARCompiler)
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExtensions_Allowed http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExternal http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExternal_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FExternal_Name_Casing http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FFast_Math http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FFavor_Top_Level http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FFinalize_Storage_Only http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FFloat_Representation http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FForeign http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FGeneric_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FGeneric_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2Fi960_Intrinsic http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FIdent http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImages http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImplemented http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImplicit_Code http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImplicit_Packing http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport_Exception http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport_Function http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport_Object http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport_Procedure http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FImport_Valued_Procedure http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInclude
323
Pragmas Initialize149 (SPARCompiler) Initialize_Scalars150 (GNAT) Inline_Always151 (GNAT) Inline_Generic152 (GNAT, HP Ada) Inline_Only153 (SPARCompiler) Instance_Policy154 (SPARCompiler) Interface_Constant155 (ICC) Interface_Information156 (PowerAda) Interface_Mechanism157 (ICC) Interface_Name158 (GNAT, HP Ada, ICC, SPARCompiler) Interrupt_State159 (GNAT) Invariant160 (GNAT) Keep_Names161 (GNAT) Label162 (ICC) License163 (GNAT) Link_With164 (GNAT, ICC, SPARCompiler) Linker_Alias165 (GNAT) Linker_Constructor166 (GNAT) Linker_Destructor167 (GNAT) Linker_Section168 (GNAT) Long_Float169 (GNAT: OpenVMS, HP Ada)
39.3.4 M P
Machine_Attribute170 (GNAT) Main171 (GNAT) Main_Storage172 (GNAT, HP Ada)
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInitialize http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInitialize_Scalars http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInline_Always http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInline_Generic http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInline_Only http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInstance_Policy http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterface_Constant http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterface_Information http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterface_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterface_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInterrupt_State http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FInvariant http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FKeep_Names http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLabel http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLicense http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLink_With http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLinker_Alias http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLinker_Constructor http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLinker_Destructor http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLinker_Section http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FLong_Float http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FMachine_Attribute http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FMain http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FMain_Storage
324
No_Body173 (GNAT) No_Image174 (SPARCompiler) No_Strict_Aliasing175 (GNAT) No_Suppress176 (PowerAda) No_Reorder177 (ICC) No_Zero178 (ICC) Noinline179 (ICC) Non_Reentrant180 (SPARCompiler) Not_Elaborated181 (SPARCompiler) Not_Null182 (ICC) Obsolescent183 (GNAT) Optimize_Alignment184 (GNAT) Optimize_Code185 (SPARCompiler) Optimize_Options186 (ICC) Ordered187 (GNAT) Parameter_Mechanism188 (ICC) Passive189 (GNAT, HP Ada, SPARCompiler) Persistent_BSS190 (GNAT) Physical_Address191 (ICC) Polling192 (GNAT) Postcondition193 (GNAT) Precondition194 (GNAT) Preserve_Layout195 (PowerAda) Prole_Warnings196 (GNAT) Propagate_Exceptions197 (GNAT)
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Body http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Image http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Strict_Aliasing http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Suppress http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Reorder http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNo_Zero http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNoinline http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNon_Reentrant http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNot_Elaborated http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FNot_Null http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FObsolescent http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FOptimize_Alignment http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FOptimize_Code http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FOptimize_Options http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FOrdered http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FParameter_Mechanism http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPassive http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPersistent_BSS http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPhysical_Address http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPolling http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPostcondition http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPrecondition http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPreserve_Layout http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FProfile_Warnings http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPropagate_Exceptions
325
Pragmas Protect_Registers198 (ICC) Protected_Call199 (ICC) Protected_Return200 (ICC) Psect_Object201 (GNAT, HP Ada) Pure_Function202 (GNAT) Put203 (ICC) Put_Line204 (ICC)
39.3.5 R S
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
Reserve_Registers205 (ICC) Restriction_Warnings206 (GNAT) RTS_Interface207 (SPARCompiler) SCCS_ID208 (PowerAda) Share_Body209 (SPARCompiler) Share_Code210 (SPARCompiler) Share_Generic211 (GNAT, HP Ada) Shareable212 (ICC) Short_Circuit_And_Or213 (GNAT) Short_Descriptors214 (GNAT) Simple_Storage_Pool_Type215 (GNAT) Simple_Task216 (ICC) Source_File_Name217 (GNAT) Source_File_Name_Project218 (GNAT) Source_Reference219 (GNAT) Stack_Size220 (ICC) Static_Elaboration221 (ICC)
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FProtect_Registers http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FProtected_Call http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FProtected_Return http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPsect_Object http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPure_Function http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPut http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FPut_Line http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FReserve_Registers http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FRestriction_Warnings http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FRTS_Interface http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSCCS_ID http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FShare_Body http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FShare_Code http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FShare_Generic http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FShareable http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FShort_Circuit_And_Or http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FShort_Descriptors http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSimple_Storage_Pool_Type http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSimple_Task http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSource_File_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSource_File_Name_Project http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSource_Reference http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FStack_Size http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FStatic_Elaboration
326
Static_Elaboration_Desired222 (GNAT) Stream_Convert223 (GNAT) Style_Checks224 (GNAT) Subtitle225 (GNAT) Suppress_All226 (GNAT, HP Ada, PowerAda, SPARCompiler) Suppress_Elaboration_Checks227 (SPARCompiler) Suppress_Exception_Locations228 (GNAT) Suppress_Initialization229 (GNAT) System_Table230 (ICC)
39.3.6 T Z
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
Task_Attributes231 (SPARCompiler) Task_Info232 (GNAT) Task_Name233 (GNAT) Task_Storage234 (GNAT, HP Ada) Test_Case235 (GNAT) Thread_Body236 (GNAT) Thread_Local_Storage237 (GNAT) Time_Slice238 (GNAT, HP Ada, ICC) Time_Slice_Attributes239 (ICC) Title240 (GNAT, HP Ada) Unimplemented_Unit241 (GNAT) Universal_Aliasing242 (GNAT) Universal_Data243 (GNAT) Unmodied244 (GNAT)
http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FStatic_Elaboration_Desired http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FStream_Convert http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FStyle_Checks http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSubtitle http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSuppress_All http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSuppress_Elaboration_ Checks http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSuppress_Exception_ Locations http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSuppress_Initialization http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FSystem_Table http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTask_Attributes http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTask_Info http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTask_Name http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTask_Storage http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTest_Case http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FThread_Body http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FThread_Local_Storage http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTime_Slice http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTime_Slice_Attributes http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FTitle http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FUnimplemented_Unit http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FUniversal_Aliasing http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FUniversal_Data http://en.wikibooks.org/wiki/Ada%20Programming%2FPragmas%2FUnmodified
327
Pragmas Unreferenced245 (GNAT) Unreferenced_Objects246 (GNAT) Unreserve_All_Interrupts247 (GNAT) Unsigned_Literal248 (ICC) Use_VADS_Size249 (GNAT) Validity_Checks250 (GNAT) Warning251 (SPARCompiler) Warnings252 (GNAT, SPARCompiler) Weak_External253 (GNAT) Wide_Character_Encoding254 (GNAT)
39.4.1 Wikibook
Ada Ada Ada Ada Programming255 Programming/Aspects256 Programming/Attributes257 Programming/Keywords258
328
Ada 2005 2.8 Pragmas261 Annex L: (informative) Language-Dened Pragmas262 Ada 2012 2.8 Pragmas263 Annex L: (informative) Language-Dened Pragmas264
39.5 References
References
329
40 Libraries
40.1 Predened Language Libraries
Predened Language Libraries The library which comes with Ada in general and GNAT1 in particular. Ada s built in library is quite extensive and well structured. These chapters too are more reference like. Standard2 Ada3 Interfaces4 System5 GNAT6
331
40.3.1 Wikibook
Ada Programming14
40.3.3 Resources
A collection of Tools and Libraries15 maintained by the Ada Resource Association. es:Programacin en Ada/Unidades predenidas16
14 15 16
332
41 Libraries: Standard
The Standard package is implicit. This means two things: 1. You do not need to with or use the package, in fact you cannot (see below). It s always available (except where hidden by a homograph, RM 8.3 (8) {http://www. adaic.org/resources/add_content/standards/05rm/html/RM-8-3.html} ). 2. Standard may contain constructs which are not quite legal Ada (like the denitions of Character and Wide_Character). A with clause mentioning Standard references a user-dened package Standard that hides the predened one. So do not do this. However any library unit hidden by a homograph can be made visible again by qualifying its name with Standard, like e.g. Standard.My_Unit.
41.1 Implementation
Implementation Since the package Standard is very important for portability, here are some examples for various compilers: The package Standard1 from ISO 86522 . The package Standard3 from GNAT4 . The package Standard5 from Rational Apex6 . The package Standard7 from ObjectAda8 The Standard9 denitions for AppletMagic10
41.2 Portability
Portability The only mandatory types in Standard are Boolean, Integer and its subtypes, Float, Character, Wide_Character, Wide_Wide_Character, String, Wide_String, Wide_Wide_String, Duration. There is an implementation permission in RM A.1 (51) {http:// www.adaic.org/resources/add_content/standards/05rm/html/RM-A-1.html} that there may be more integer and oating point types and an implementation advice RM A.1 (52) {http://www.adaic.org/resources/add_content/standards/05rm/html/
1 2 3 4 5 6 7 8 9 10 http://en.wikibooks.org/wiki/%2FRM http://en.wikipedia.org/wiki/ISO%208652 http://en.wikibooks.org/wiki/%2FGNAT http://en.wikipedia.org/wiki/GNAT http://en.wikibooks.org/wiki/%2FApex http://www-306.ibm.com/software/awdtools/developer/ada http://en.wikibooks.org/wiki/%2FObjectAda http://www.aonix.com/objectada.html http://en.wikibooks.org/wiki/%2FAppletMagic http://www.sofcheck.com/products/adamagic.html#appletmagic
333
Libraries: Standard RM-A-1.html} about the names to be chosen. There even is no requirement that those additional types must have dierent sizes. So it is e.g. legal for an implementation to provide two types Long_Integer and Long_Long_Integer which both have the same range and size. Note that the ranges and sizes of these types can be dierent in every platform (except of course for Boolean and [[Wide_]Wide_]Character). There is an implementation requirement that the size of type Integer is at least 16 bits, and that of Long_Integer at least 32 bits (if present) RM 3.5.4 (21..22) {http://www.adaic.org/resources/add_content/ standards/05rm/html/RM-3-5-4.html} . So if you want full portability of your types, do not use types from Standard (except where you must, see below), rather dene you own types. A compiler will reject any type declaration whose range it cannot satisfy. This means e.g. if you need a 64-bit type and nd that with your current implementation Standard.Long_Long_Integer is such a type, when porting your program to another implementation, this type may be shorter, but the compiler will not tell you - and your program will most probably crash. However, when you dene your own type like
type My_Integer_64 is range -(2**63) .. +(2**63 - 1);
then, when porting to an implementation that cannot satisfy this range, the compiler will reject your program. The type Integer is mandatory when you use [[wide] wide] strings or exponentiation x**i. This is why some projects even dene their own strings, but this means throwing out the child with the bath tub. Using Integer with strings and exponentiation will normally not lead to portability issues.
41.3.1 Wikibook
Ada Programming11 Ada Programming/Libraries#Predened Language Libraries12
11 12
334
335
42 Libraries: Ada
The Ada package is only an anchor or namespace for Ada s standard library. Most compilers will not allow you to add new packages to the Ada hierarchy and even if your compiler allows it you should not do so since all package names starting with Ada. are reserved for future extensions.
42.1.1 A C
1 2 3 4 5 6 7 8 9 10 11 12 13
Ada.Assertions2 (Ada 2005) Ada.Asynchronous_Task_Control3 Ada.Calendar4 Ada.Calendar.Arithmetic5 (Ada 2005) Ada.Calendar.Formatting6 (Ada 2005) Ada.Calendar.Time_Zones7 (Ada 2005) Ada.Characters8 Ada.Characters.Conversions9 (Ada 2005) Ada.Characters.Handling10 Ada.Characters.Latin_111 Ada.Command_Line12 Ada.Complex_Text_IO13 (Ada 2005)
Chapter 23 on page 219 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Assertions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Asynchronous_Task_ Control http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Calendar http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Calendar.Arithmetic http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Calendar.Formatting http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Calendar.Time_Zones http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters. Conversions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Handling http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Latin_1 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Command_Line http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Complex_Text_IO
337
Libraries: Ada Ada.Containers14 (Ada 2005) Ada.Containers.Doubly_Linked_Lists15 (Ada 2005) Ada.Containers.Generic_Array_Sort16 (Ada 2005 generic procedure) Ada.Containers.Generic_Constrained_Array_Sort17 (Ada 2005 generic procedure) Ada.Containers.Hashed_Maps18 (Ada 2005) Ada.Containers.Hashed_Sets19 (Ada 2005) Ada.Containers.Indenite_Doubly_Linked_Lists20 (Ada 2005) Ada.Containers.Indenite_Hashed_Maps21 (Ada 2005) Ada.Containers.Indenite_Hashed_Sets22 (Ada 2005) Ada.Containers.Indenite_Ordered_Maps23 (Ada 2005) Ada.Containers.Indenite_Ordered_Sets24 (Ada 2005) Ada.Containers.Indenite_Vectors25 (Ada 2005) Ada.Containers.Ordered_Maps26 (Ada 2005) Ada.Containers.Ordered_Sets27 (Ada 2005) Ada.Containers.Vectors28 (Ada 2005)
42.1.2 D F
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Ada.Decimal29 Ada.Direct_IO30 Ada.Directories31 (Ada 2005) Ada.Directories.Information32 (Ada 2005) Ada.Dispatching33 (Ada 2005)
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Doubly_ Linked_Lists http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Generic_ Array_Sort http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Generic_ Constrained_Array_Sort http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Hashed_ Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Hashed_ Sets http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers. Indefinite_Doubly_Linked_Lists http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers. Indefinite_Hashed_Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers. Indefinite_Hashed_Sets http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers. Indefinite_Ordered_Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers. Indefinite_Ordered_Sets http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers. Indefinite_Vectors http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Ordered_ Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Ordered_ Sets http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers.Vectors http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Decimal http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Direct_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Directories http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Directories. Information http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Dispatching
338
Ada.Dispatching.EDF34 (Ada 2005) Ada.Dispatching.Round_Robin35 (Ada 2005) Ada.Dynamic_Priorities36 Ada.Environment_Variables37 (Ada 2005) Ada.Exceptions38 Ada.Execution_Time39 (Ada 2005) Ada.Execution_Time.Timers40 (Ada 2005) Ada.Execution_Time.Group_Budgets41 (Ada 2005) Ada.Finalization42 Ada.Float_Text_IO43 Ada.Float_Wide_Text_IO44 Ada.Float_Wide_Wide_Text_IO45 (Ada 2005)
42.1.3 G R
Ada.Integer_Text_IO46 Ada.Integer_Wide_Text_IO47 Ada.Integer_Wide_Wide_Text_IO48 (Ada 2005) Ada.Interrupts49 Ada.Interrupts.Names50 Ada.IO_Exceptions51 Ada.Numerics52 Ada.Numerics.Complex_Arrays53 (Ada 2005) Ada.Numerics.Complex_Elementary_Functions54
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Dispatching.EDF http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Dispatching.Round_ Robin http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Dynamic_Priorities http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Environment_ Variables http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Exceptions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Execution_Time http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Execution_Time. Timers http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Execution_Time. Group_Budgets http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Finalization http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Float_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Float_Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Float_Wide_Wide_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Integer_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Integer_Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Integer_Wide_Wide_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Interrupts http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Interrupts.Names http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.IO_Exceptions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Complex_ Arrays http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Complex_ Elementary_Functions
339
Libraries: Ada Ada.Numerics.Complex_Types55 Ada.Numerics.Discrete_Random56 Ada.Numerics.Elementary_Functions57 Ada.Numerics.Float_Random58 Ada.Numerics.Generic_Complex_Arrays59 (Ada 2005) Ada.Numerics.Generic_Complex_Elementary_Functions60 Ada.Numerics.Generic_Complex_Types61 Ada.Numerics.Generic_Elementary_Functions62 Ada.Numerics.Generic_Real_Arrays63 (Ada 2005) Ada.Numerics.Real_Arrays64 (Ada 2005)
42.1.4 R S
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
Ada.Real_Time65 Ada.Real_Time.Timing_Events66 (Ada 2005) Ada.Sequential_IO67 Ada.Storage_IO68 Ada.Streams69 Ada.Streams.Stream_IO70 Ada.Strings71 Ada.Strings.Bounded72 Ada.Strings.Bounded.Hash73 (Ada 2005 generic function) Ada.Strings.Fixed74 Ada.Strings.Fixed.Hash75 (Ada 2005 generic function)
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Complex_ Types http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Discrete_ Random http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Elementary_ Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Float_ Random http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Generic_ Complex_Arrays http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Generic_ Complex_Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Generic_ Complex_Types http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Generic_ Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Generic_ Real_Arrays http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Real_Arrays http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Real_Time http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Real_Time.Timing_ Events http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Sequential_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Storage_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Streams.Stream_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Bounded http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Bounded.Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Fixed http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Fixed.Hash
340
Ada.Strings.Hash76 (Ada 2005 generic function) Ada.Strings.Maps77 Ada.Strings.Maps.Constants78 Ada.Strings.Unbounded79 Ada.Strings.Unbounded.Hash80 (Ada 2005 generic function) Ada.Strings.Wide_Bounded81 Ada.Strings.Wide_Bounded.Wide_Hash82 (Ada 2005 generic function) Ada.Strings.Wide_Fixed83 Ada.Strings.Wide_Fixed.Wide_Hash84 (Ada 2005 generic function) Ada.Strings.Wide_Hash85 (Ada 2005 generic function) Ada.Strings.Wide_Maps86 Ada.Strings.Wide_Maps.Wide_Constants87 Ada.Strings.Wide_Unbounded88 Ada.Strings.Wide_Unbounded.Wide_Hash89 (Ada 2005 generic function) Ada.Strings.Wide_Wide_Bounded90 (Ada 2005) Ada.Strings.Wide_Wide_Bounded.Wide_Wide_Hash91 (Ada 2005 generic function) Ada.Strings.Wide_Wide_Fixed92 (Ada 2005) Ada.Strings.Wide_Wide_Fixed.Wide_Wide_Hash93 (Ada 2005 generic function) Ada.Strings.Wide_Wide_Hash94 (Ada 2005 generic function) Ada.Strings.Wide_Wide_Maps95 (Ada 2005) Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants96 (Ada 2005)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Maps. Constants http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Unbounded http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Unbounded. Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Bounded http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Bounded. Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Fixed http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Fixed. Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Maps. Wide_Constants http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_ Unbounded http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_ Unbounded.Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Bounded http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Bounded.Wide_Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Fixed http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Fixed.Wide_Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Maps http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Maps.Wide_Wide_Constants
341
Libraries: Ada Ada.Strings.Wide_Wide_Unbounded97 (Ada 2005) Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Hash98 (Ada 2005 generic function) Ada.Synchronous_Task_Control99
42.1.5 T U
Ada.Tags100 Ada.Tags.Generic_Dispatching_Constructor101 (generic function) Ada.Task_Attributes102 Ada.Task_Identication103 Ada.Task_Termination104 (Ada 2005) Ada.Text_IO105 Ada.Text_IO.Bounded_IO106 (Ada 2005) Ada.Text_IO.Complex_IO107 Ada.Text_IO.Decimal_IO108 (Nested package of Ada.Text_IO ) Ada.Text_IO.Editing109 Ada.Text_IO.Enumeration_IO110 (Nested package of Ada.Text_IO111 ) Ada.Text_IO.Fixed_IO112 (Nested package of Ada.Text_IO ) Ada.Text_IO.Float_IO113 (Nested package of Ada.Text_IO ) Ada.Text_IO.Integer_IO114 (Nested package of Ada.Text_IO ) Ada.Text_IO.Modular_IO115 (Nested package of Ada.Text_IO ) Ada.Text_IO.Text_Streams116 Ada.Text_IO.Unbounded_IO117 (Ada 2005) Ada.Unchecked_Conversion118 (generic function)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Unbounded http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Unbounded.Wide_Wide_Hash http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Synchronous_Task_ Control http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Tags http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Tags.Generic_ Dispatching_Constructor http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Task_Attributes http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Task_Identification http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Task_Termination http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Bounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Complex_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Decimal_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Editing http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Enumeration_ IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Fixed_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Float_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Integer_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Modular_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Text_Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.Unbounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Unchecked_Conversion
342
42.1.6 W Z
Ada.Wide_Characters120 (Ada 2005) Ada.Wide_Text_IO121 Ada.Wide_Text_IO.Bounded_IO122 (Ada 2005) Ada.Wide_Text_IO.Complex_IO123 Ada.Wide_Text_IO.Decimal_IO124 (Nested package of Ada.Wide_Text_IO ) Ada.Wide_Text_IO.Editing125 Ada.Wide_Text_IO.Enumeration_IO126 (Nested package of Ada.Wide_Text_IO ) Ada.Wide_Text_IO.Fixed_IO127 (Nested package of Ada.Wide_Text_IO ) Ada.Wide_Text_IO.Float_IO128 (Nested package of Ada.Wide_Text_IO ) Ada.Wide_Text_IO.Integer_IO129 (Nested package of Ada.Wide_Text_IO ) Ada.Wide_Text_IO.Modular_IO130 (Nested package of Ada.Wide_Text_IO ) Ada.Wide_Text_IO.Text_Streams131 Ada.Wide_Text_IO.Unbounded_IO132 (Ada 2005) Ada.Wide_Wide_Characters133 (Ada 2005) Ada.Wide_Wide_Text_IO134 (Ada 2005) Ada.Wide_Wide_Text_IO.Bounded_IO135 (Ada 2005) Ada.Wide_Wide_Text_IO.Complex_IO136 (Ada 2005) Ada.Wide_Wide_Text_IO.Decimal_IO137 (Nested package of Ada.Wide_Wide_Text_IO )
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Unchecked_ Deallocation http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Characters http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Bounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Complex_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Decimal_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO.Editing http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Enumeration_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO.Fixed_ IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO.Float_ IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Integer_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Modular_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO.Text_ Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO. Unbounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Characters http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Bounded_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Complex_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Decimal_IO
343
Libraries: Ada Ada.Wide_Wide_Text_IO.Editing138 (Ada 2005) Ada.Wide_Wide_Text_IO.Enumeration_IO139 (Nested package of Ada.Wide_Wide_Text_IO ) Ada.Wide_Wide_Text_IO.Fixed_IO140 (Nested package of Ada.Wide_Wide_Text_IO ) Ada.Wide_Wide_Text_IO.Float_IO141 (Nested package of Ada.Wide_Wide_Text_IO ) Ada.Wide_Wide_Text_IO.Integer_IO142 (Nested package of Ada.Wide_Wide_Text_IO ) Ada.Wide_Wide_Text_IO.Modular_IO143 (Nested package of Ada.Wide_Wide_Text_IO ) Ada.Wide_Wide_Text_IO.Text_Streams144 (Ada 2005) Ada.Wide_Wide_Text_IO.Unbounded_IO145 (Ada 2005)
138 139 140 141 142 143 144 145 146 147 148
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Editing http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Enumeration_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Fixed_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Float_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Integer_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Modular_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Text_Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO. Unbounded_IO http://en.wikipedia.org/wiki/GNAT http://en.wikibooks.org/w/index.php?title=Ada_Programming/Libraries/Ada&action=edit http://gcc.gnu.org/onlinedocs/gnat_rm/The-GNAT-Library.html
344
42.2.1 A K
Ada.Characters.Latin_9149 (GNAT) Ada.Characters.Wide_Latin_1150 (GNAT) Ada.Characters.Wide_Latin_9151 (GNAT) Ada.Characters.Wide_Wide_Latin_1152 (GNAT) Ada.Characters.Wide_Wide_Latin_9153 (GNAT) Ada.Command_Line.Environment154 (GNAT) Ada.Command_Line.Remove155 (GNAT) Ada.Direct_IO.C_Streams156 (GNAT) Ada.Exceptions.Is_Null_Occurrence157 (GNAT child function) Ada.Exceptions.Traceback158 (GNAT)
42.2.2 L Q
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
Ada.Long_Float_Text_IO159 (GNAT) Ada.Long_Float_Wide_Text_IO160 (GNAT) Ada.Long_Integer_Text_IO161 (GNAT) Ada.Long_Integer_Wide_Text_IO162 (GNAT) Ada.Long_Long_Float_Text_IO163 (GNAT) Ada.Long_Long_Float_Wide_Text_IO164 (GNAT) Ada.Long_Long_Integer_Text_IO165 (GNAT) Ada.Long_Long_Integer_Wide_Text_IO166 (GNAT) Ada.Numerics.Long_Complex_Elementary_Functions167 (GNAT)
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Latin_9 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Wide_ Latin_1 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Wide_ Latin_9 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Wide_ Wide_Latin_1 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Characters.Wide_ Wide_Latin_9 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Command_Line. Environment http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Command_Line.Remove http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Direct_IO.C_Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Exceptions.Is_Null_ Occurrence http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Exceptions.Traceback http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Float_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Float_Wide_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Integer_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Integer_Wide_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Long_Float_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Long_Float_ Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Long_Integer_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Long_Long_Integer_ Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Long_ Complex_Elementary_Functions
345
Libraries: Ada Ada.Numerics.Long_Complex_Types168 (GNAT) Ada.Numerics.Long_Elementary_Functions169 (GNAT) Ada.Numerics.Long_Long_Complex_Elementary_Functions170 (GNAT) Ada.Numerics.Long_Long_Complex_Types171 (GNAT) Ada.Numerics.Long_Long_Elementary_Functions172 (GNAT) Ada.Numerics.Short_Complex_Elementary_Functions173 (GNAT) Ada.Numerics.Short_Complex_Types174 (GNAT) Ada.Numerics.Short_Elementary_Functions175 (GNAT)
42.2.3 R Z
Ada.Sequential_IO.C_Streams176 (GNAT) Ada.Short_Float_Text_IO177 (GNAT) Ada.Short_Float_Wide_Text_IO178 (GNAT) Ada.Short_Integer_Text_IO179 (GNAT) Ada.Short_Integer_Wide_Text_IO180 (GNAT) Ada.Short_Short_Integer_Text_IO181 (GNAT) Ada.Short_Short_Integer_Wide_Text_IO182 (GNAT) Ada.Streams.Stream_IO.C_Streams183 (GNAT) Ada.Strings.Unbounded.Text_IO184 (GNAT) Ada.Strings.Wide_Unbounded.Wide_Text_IO185 (GNAT)
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Long_ Complex_Types http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Long_ Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Long_Long_ Complex_Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Long_Long_ Complex_Types http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Long_Long_ Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Short_ Complex_Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Short_ Complex_Types http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Numerics.Short_ Elementary_Functions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Sequential_IO.C_ Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Short_Float_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Short_Float_Wide_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Short_Integer_Text_ IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Short_Integer_Wide_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Short_Short_Integer_ Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Short_Short_Integer_ Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Streams.Stream_IO.C_ Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Unbounded. Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_ Unbounded.Wide_Text_IO
346
42.3.1 Wikibook
Ada Ada Ada Ada Ada Programming190 Programming/Libraries191 Programming/Libraries/Standard192 Programming/Libraries/System193 Programming/Libraries/Interfaces194
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Strings.Wide_Wide_ Unbounded.Wide_Wide_Text_IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Text_IO.C_Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Text_IO.C_ Streams http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Wide_Wide_Text_IO.C_ Streams http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331 Chapter 41 on page 333 Chapter 44 on page 351 Chapter 43 on page 349
347
43 Libraries: Interfaces
The Interfaces package helps in interfacing with other programming languages. Ada is one of the few languages where interfacing with other languages is part of the language standard. The language standard denes the interfaces for C1 , Cobol2 and Fortran3 . Of course any implementation might dene further interfaces GNAT4 for example denes an interface to C++5 . Interfacing with other languages is actually provided by pragma , pragma and pragma
349
43.2.1 Wikibook
Ada Ada Ada Ada Ada Programming21 Programming/Libraries22 Programming/Libraries/Standard23 Programming/Libraries/Ada24 Programming/Libraries/System25
19 20 21 22 23 24 25
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FInterfaces.VxWorks http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FInterfaces.VxWorks.IO http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331 Chapter 41 on page 333 Chapter 42 on page 337 Chapter 44 on page 351
350
44 Libraries: System
351
45 Libraries: GNAT
The GNAT package hierarchy denes several units for general purpose programming provided by the GNAT compiler. It is distributed along with the compiler and uses the same license. GNAT-4-ObjectAda1 is a project for porting the GNAT library to the ObjectAda compiler.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
353
Libraries: GNAT GNAT.Current_Exception19 GNAT.Debug_Pools20 GNAT.Debug_Utilities21 GNAT.Directory_Operations22 GNAT.Directory_Operations.Iteration23 GNAT.Dynamic_HTables24 GNAT.Dynamic_Tables25 GNAT.Exception_Actions26 GNAT.Exceptions27 GNAT.Exception_Traces28 GNAT.Expect29 GNAT.Float_Control30 GNAT.Heap_Sort31 GNAT.Heap_Sort_A32 GNAT.Heap_Sort_G33 GNAT.HTable34 GNAT.IO35 GNAT.IO_Aux36 GNAT.Lock_Files37 GNAT.MD538 GNAT.Memory_Dump39 GNAT.Most_Recent_Exception40 GNAT.OS_Lib41 GNAT.Perfect_Hash_Generators42
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Current_Exception http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Debug_Pools http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Debug_Utilities http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Directory_ Operations http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Directory_ Operations.Iteration http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Dynamic_HTables http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Dynamic_Tables http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Exception_Actions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Exceptions http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Exception_Traces http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Expect http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Float_Control http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Heap_Sort http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Heap_Sort_A http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Heap_Sort_G http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.HTable http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.IO http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.IO_Aux http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Lock_Files http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.MD5 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Memory_Dump http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Most_Recent_ Exception http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.OS_Lib http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Perfect_Hash_ Generators
354
GNAT.Regexp43 GNAT.Registry44 GNAT.Regpat45 GNAT.Secondary_Stack_Info46 GNAT.Semaphores47 GNAT.Signals48 GNAT.Sockets49 (GNAT.Sockets examples50 ) GNAT.Sockets.Constants51 GNAT.Sockets.Linker_Options52 GNAT.Sockets.Thin53 GNAT.Source_Info54 GNAT.Spelling_Checker55 GNAT.Spitbol56 GNAT.Spitbol.Patterns57 GNAT.Spitbol.Table_Boolean new58 GNAT.Spitbol.Table_Integer59 GNAT.Spitbol.Table_VString new60 GNAT.Strings61 GNAT.String_Split62 GNAT.Table63 GNAT.Task_Lock64 GNAT.Threads65 GNAT.Traceback66
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Regexp http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Registry http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Regpat http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Secondary_Stack_ Info http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Semaphores http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Signals http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Sockets http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Sockets_examples http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Sockets.Constants http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Sockets.Linker_ Options http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Sockets.Thin http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Source_Info http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Spelling_Checker http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Spitbol http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Spitbol.Patterns http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Spitbol.Table_ Boolean%20new http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Spitbol.Table_ Integer http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Spitbol.Table_ VString%20new http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Strings http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.String_Split http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Table http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Task_Lock http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Threads http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGNAT.Traceback
355
45.2.2 Wikibook
Ada Programming70 Ada Programming/Libraries71
67 68 69 70 71
356
46 Libraries: Multi-Purpose
AdaCL, Ada Class Library1 Filtering of text les, string tools, process control, command line parsing, CGI, garbage collector, components. Matreshka2 Core components for information system development: Unicode support (case conversions and folding, collation, normalization); regular expression engine; XML processor; FastCGI, SQL database access. paran3 "A suite of Ada 2005 generics to facilitate iterative and recursive parallelism".4 Features include load-balancing and monitoring of stacks.
46.1.1 Wikibook
Ada Programming6 Ada Programming/Libraries7
46.1.3 References
1 2 3 4 6 7
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FAdaCL http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FMatreshka http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FParaffin Iterative and recursive parallelism generics for Ada 2005 5 . . Retrieved 2012-08-28 http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331
357
47 Libraries: Container
The following Libraries help you store and manage objects inside container classes: Booch Components1 the most complete of all container class libraries (at least when used with AdaCL, Ada Class Library2 ). AdaCL, Ada Class Library3 A Booch Components4 extension pack for storing indenite objects. Charles5 Build on the C++ STL and therefore very easy to learn for C++ developers. AI3026 Proof of concept for Ada.Containers7 Ada.Containers8 This language feature is only available in Ada 2005 Stephe s Ada Library9 dynamic arrays, lists, trees
47.1.1 Wikibook
Ada Programming10 Ada Programming/Libraries11
1 2 3 4 5 6 7 8 9 10 11
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FContainer%2FBooch http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FAdaCL http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FAdaCL http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FContainer%2FBooch http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FContainer%2FCharles http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FContainer%2FAI302 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FAda.Containers http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FSAL http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331
359
48 Libraries: GUI
The following libraries can be used to make Graphical User Interfaces: CLAW1 Commercial GUI toolkit for Windows. Introductory Edition2 is distributed under GMGPL3 . GtkAda4 Binding to the popular GTK+ toolkit. GWindows5 RAD GUI Development Framework for Windows. Qt4Ada6 An Ada2005 binding to Qt4. Under CeCILL license V2. QtAda7 An Ada2005 binding to the Qt libraries and associated tools. Under GPL and GMGPL8 (commercially supported) licenses. libAgar9 Ada bindings for the libagar10 OpenGL GUI library (BSD license). TASH11 TclAdaSHell, An Ada binding to Tcl/Tk. GPL with "Linking Exception".
48.1.1 Wikibook
Ada Programming12 Ada Programming/Libraries13
361
Libraries: GUI
14 15
362
49.1.1 Wikibook
Ada Programming6 Ada Programming/Libraries7 Programming:CORBA8
1 2 3 4 5 6 7 8
http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FDistributed%2FGLADE http://www.adaic.org/standards/95lrm/html/RM-E.html http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FDistributed%2FPolyORB http://en.wikibooks.org/wiki/Programming%3ACORBA http://www.adaic.org/standards/95lrm/html/RM-E.html http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331 http://en.wikibooks.org/wiki/Programming%3ACORBA
363
50 Libraries: Databases
The following libraries help you in Database programming:
365
366 MySQL ODBC Oracle PostSQLite greSQL 3 Sybase Notes Yes Yes Yes Yes Other Bidatabase nary packages Debian2 3.x, 4.x Yes Yes Yes Debian4 Threadsafe connection pools Embedded SQL preprocessor ? ? ? ? Yes ? ? ?
Library
License
Libraries: Databases
APQ1
1 2 3 4 5
Yes
Yes
Yes ? ? ?
gnatcoll_db2ada generates thick Ada bindings to a specied database schema. Requires Ada 2005. Windows only? OpenSUSE9 , Fedora10
Matreshka SQL8
BSD
367
7 8 9 10
368 ? ? Yes ? ? ? ? ? none Yes Yes Yes Yes Yes Yes IBM MiDB/2, crosoft SQLite2 Windows
Libraries: Databases
ODBC11 GPL
Windows only. Depends on Win32Ada. Very simple. Binding to Qt: requires C++
11 12
http://pobry.blogspot.fr/p/ada-contributions.html http://www.qtada.com/
Yes
Yes
SOCIAda14
Boost
Yes
Yes
Yes
SQLite bindings are intended for static linking with the SQLite3 amalgation. ODBC bindings support 32- and 64-bit platforms Requires C++. Yes ?
369
13 14 15
51 Libraries: Web
The following libraries help you in Internet or Web programming: AdaCL, Ada Class Library1 Powerful CGI implementation. XML/Ada2 XML and Unicode support. AWS3 A full-featured Web-Server. Matreshka4 FastCGI, XML, Unicode and localization support.
51.1.1 Wikibook
Ada Programming5 Ada Programming/Libraries6
1 2 3 4 5 6
371
52.1.1 Wikibook
Ada Programming5 Ada Programming/Libraries6
1 2 3 4 5 6
Chapter 18 on page 147 http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FAdaCL http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FIO%2FXML%2FAda http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FMultiPurpose%2FMatreshka http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331
373
53 Platform Support
Ada is known to be very portable, but there is sometimes a necessity of using a specic platform feature. For that matter, there are some non-standard libraries. Linux1 Windows2 POSIX systems3 Virtual machines4 Java5 .NET6
53.1.1 Wikibook
Ada Programming7
1 2 3 4 5 6 7
Chapter 54 on page 377 Chapter 55 on page 379 http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FPOSIX Chapter 56 on page 381 http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FVM%2FJava http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FVM%2FdotNET http://en.wikibooks.org/wiki/Ada%20Programming
375
54 Platform: Linux
The following libraries help you when you target the Linux Platform. Florist1 POSIX.5 binding. It will let you perform Linux system calls in the POSIX subset. Ncurses2 text terminal library. Texttools3 ncurses-based library for the Linux console. GtkAda4 GUI library (actually multiplatform).
54.1.1 Wikibook
Ada Programming5 Ada Programming/Libraries6
1 2 3 4 5 6 7 8 9
http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FPOSIX http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FNcurses http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FTexttools http://en.wikibooks.org/wiki/Ada%20Programming%2FLibraries%2FGUI%2FGtkAda http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331 http://www.pegasoft.ca/resources/boblap/book.html http://www.cs.kuleuven.be/~dirk/ada-belgium/events/06/060226-fosdem-4-ada-in-debian. pdf http://en.wikibooks.org/wiki/User%3ALudovic%20Brenta
377
55 Platform: Windows
The following Libraries and Tools help you when you target the MS-Windows Platform. GWindows1 Win32 binding CLAW2 Another Win32 binding that works with any Ada 95 compiler. An introductory edition is available free of charge for non-commercial use. GNATCOM3 COM/DCOM/ActiveX binding GNAVI4 Visual RAD5 (Rapid application development6 ) Development environment /Console/7 Libraries for console I/O. /Visual C++ - GNAT interface/8 Guide for calling Ada functions from C++ using GNAT and Visual C++.
55.1.1 Wikibook
Ada Programming9 Ada Programming/Libraries10
1 2 3 4 5 6 7 8 9 10
http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FWindows%2Fwin32binding http://www.rrsoftware.com/html/prodinf/claw/claw.htm http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FWindows%2Fwin32binding http://en.wikibooks.org/wiki/Ada%20Programming%2FPlatform%2FWindows%2Fwin32binding http://en.wikipedia.org/wiki/Rapid_application_development http://en.wikipedia.org/wiki/Rapid%20application%20development http://en.wikibooks.org/wiki/%2FConsole%2F http://en.wikibooks.org/wiki/%2FVisual%20C%2B%2B%20-%20GNAT%20interface%2F http://en.wikibooks.org/wiki/Ada%20Programming Chapter 40 on page 331
379
56.1.1 Wikibook
Ada Programming3 Ada Programming/Libraries4
1 2 3 4
381
57 Portals
57.1 Forges of open-source projects
Forges of open-source projects SourceForge1 Currently there are 200 Ada projects hosted at SourceForge including the example programs for Ada Programming2 wikibook. GitHub3 A source code repository based on Git with many recent developments. Ada-centric forges There are some Ada-centric forges hosted by Ada associations and individuals: http://forge.ada-ru.org http://www.ada-france.org:8081 http://codelabs.ch http://scm.ada.cx BerliOS4
383
Portals Collections of Ada source code AdaBasis10 AdaBasis consists of about 560 MB of public domain source code and documents, mainly taken from the Public Ada Library (PAL). The software has been classied and is presented in a hierarchical manner, separated in dierent application domains, and, for some domains, with an additional multi-faceted searching facility. The intent is to provide students, teachers and researchers with a large collection of reusable Ada components and systems for use in language and software engineering courses. AdaBasis was set up by the Programming Languages Group of the Institut fr Informatik at the University of Stuttgart, Germany. They plan to enlarge the library in the future, and welcome free public domain contributions. For more informations or to make suggestions please contact adabasis@informatik.uni-stuttgart.de11 The Public Ada Library (PAL)12 The PAL is a library of Ada and VHDL software, information, and courseware that contains over 1 BILLION bytes of material (mainly in compressed form). All items in the PAL have been released to the public with unlimited distribution, and, in most cases (the exceptions are shareware), the items are freeware. [ftp //ftp.cs.kuleuven.ac.be/pub/Ada-Belgium/cdrom/index.html Ada and Software Engineering Library Version 2 (ASE2)] : The ASE2 Library contains over 1.1GB of material on Ada and Software Engineering assembled through a collaboration with over 60 organizations. Walnut Creek CDROM once sold copies of this library. Nowadays it is no longer maintained but is still hosted in the Ada Belgium FTP server. It may contain useful resources, but it is highly redundant with other libraries. AdaPower13 A directory and collection of Ada tools and resources.
57.4.1 Wikibook
Ada Programming14 Ada Programming/Tutorials15 Ada Programming/Wikis16
384
385
58 Tutorials
This page contains a list of other Ada tutorials on the Net. 1. Ada Programming1 , available on Wikibooks, is currently the only tutorial based on the Ada 20052 standard and currently being updated to Ada 20123 . 2. Lovelace4 is a free (no-charge), self-directed Ada 95 tutorial available on the World Wide Web (WWW). Lovelace assumes that the user already knows another algorithmic programming language, such as C, C++, or Pascal. Lovelace is interactive and contains many short sections, most of which end with a question to help ensure that users understand the material. Lovelace can be used directly from the WWW, downloaded, or run from CD-ROM. Lovelace was developed by David A. Wheeler. 3. AdaTutor5 is an interactive Ada 95 tutorial distributed as a public-domain Ada program. A web edition6 of the tutorial is also available. 4. The Ada-95: A guide for C and C++ programmers7 is a short hypertext tutorial for programmers who have a C or C++ style programming language background. It was written by Simon Johnston, with some additional text by Tucker Taft. PDF edition8 . 5. Dale Stanbrough s Introduction9 is a set of notes that provide a simple introduction to Ada. This material has been used for a few years as a simple introduction to the language. 6. Coronado Enterprises Ada 95 Tutorial: shareware edition10 , commercial edition11 .
1 2 3 4 5 6 7 8 9 10 11
http://en.wikibooks.org/wiki/Ada%20Programming Chapter 23 on page 219 http://en.wikibooks.org/wiki/Ada%20Programming%2FAda%202012 http://www.dwheeler.com/lovelace/ http://www.adatutor.com/ http://zhu-qy.blogspot.com.es/2012/08/adatutor.html http://www.adahome.com/Ammo/Cplpl2Ada.html http://home.agh.edu.pl/~jpi/download/ada/guide-c2ada.pdf http://goanna.cs.rmit.edu.au/~dale/ada/aln.html http://www.infres.enst.fr/~pautet/Ada95/a95list.htm http://www.coronadoenterprises.com/tutorials/ada95/index.html
387
59 Web 2.0
Here is a list of Web 2.01 resources about Ada:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
http://en.wikipedia.org/wiki/Web%202.0 http://www.reddit.com/r/ada/ http://www.reddit.com/r/ada/.rss http://www.adacore.com/category/developers-center/gems/ http://www.adacore.com/rss/gems http://planet.ada.cx/ http://planet.ada.cx/rss20.xml http://ada-programming.blogspot.com/ http://ada-programming.blogspot.com/feeds/posts/default http://blog.kickin-the-darkness.com/search/label/Ada http://blog.kickin-the-darkness.com/feeds/posts/default http://www.archeia.com/ http://www.archeia.com/rss_feed.html http://adrianhoe.com/adrianhoe/category/software_development/ada/ http://adrianhoe.com/adrianhoe/feed/rss/ http://stackoverflow.com/questions/tagged/ada http://www.linkedin.com/groups?gid=114211 http://www.tek-tips.com/threadminder.cfm?pid=199
389
Web 2.0
390
Programacin en Ada43 , in Spanish Programmation Ada44 , in French Ada45 , in Italian Wikiquote: Programming languages Ada46 Wikiversity: Ada course47 (you can enroll!)
59.0.9 Projects
AdaCL52 The Ada 95 Booch Components53 The GNU Ada Compiler54 ASIS55 GLADE56 Florist57 GNAT GCC Wiki58 RTEMSAda59 AVR-Ada60 - Ada compiler for Atmel microcontrollers (Arduinos) Web 2.061
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
http://en.wikibooks.org/wiki/%3Aes%3AProgramaci%F3n_en_Ada http://en.wikibooks.org/wiki/%3Afr%3AProgrammation_Ada http://en.wikibooks.org/wiki/%3Ait%3AAda http://en.wikiquote.org/wiki/Programming_languages#Ada http://en.wikiversity.org/wiki/Ada http://wikibook-ada.sourceforge.net http://www.rosettacode.org/wiki/Ada http://en.literateprograms.org/Category:Programming_language:Ada http://en.wikipedia.org/wiki/literate%20programming http://adacl.sourceforge.net/index.php http://booch95.sourceforge.net/pmwiki.php http://gnuada.sourceforge.net http://gnat-asis.sourceforge.net http://gnat-glade.sourceforge.net http://gnat-florist.sourceforge.net http://gcc.gnu.org/wiki/GNAT http://www.rtems.com/wiki/index.php/RTEMSAda http://avr-ada.sourceforge.net/ http://en.wikibooks.org/wiki/Category%3AAda%20Programming
391
60 Contributors
Edits 1 1 1 64 1 2 1 1 1 1 1 7 1 14 56 1 2 44 3 3 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User A101121 ALK2 AdRiley3 Adrignola4 Alan.poindexter5 Alisonken16 Ammon7 Andreas Ipp8 Aramael9 Arny10 Arthurvogel11 Avicennasis12 Benjstarratt13 Carsrac14 CarsracBot15 Chouclac16 Cspurrier17 Darklama18 David Hoos19 Derbeth20 Dhenry21
http://en.wikibooks.org/w/index.php?title=User:A10112 http://en.wikibooks.org/w/index.php?title=User:ALK http://en.wikibooks.org/w/index.php?title=User:AdRiley http://en.wikibooks.org/w/index.php?title=User:Adrignola http://en.wikibooks.org/w/index.php?title=User:Alan.poindexter http://en.wikibooks.org/w/index.php?title=User:Alisonken1 http://en.wikibooks.org/w/index.php?title=User:Ammon http://en.wikibooks.org/w/index.php?title=User:Andreas_Ipp http://en.wikibooks.org/w/index.php?title=User:Aramael http://en.wikibooks.org/w/index.php?title=User:Arny http://en.wikibooks.org/w/index.php?title=User:Arthurvogel http://en.wikibooks.org/w/index.php?title=User:Avicennasis http://en.wikibooks.org/w/index.php?title=User:Benjstarratt http://en.wikibooks.org/w/index.php?title=User:Carsrac http://en.wikibooks.org/w/index.php?title=User:CarsracBot http://en.wikibooks.org/w/index.php?title=User:Chouclac http://en.wikibooks.org/w/index.php?title=User:Cspurrier http://en.wikibooks.org/w/index.php?title=User:Darklama http://en.wikibooks.org/w/index.php?title=User:David_Hoos http://en.wikibooks.org/w/index.php?title=User:Derbeth http://en.wikibooks.org/w/index.php?title=User:Dhenry
393
Contributors 12 2 1 2 17 1 1 1 1 2 97 8 1 1 2 3 1 1 1 5 34 1 2 4 1 Dirk Hnniger22 Dmitry-kazakov23 Doug24 DougP25 Dragontamer26 Fraterm27 Friess28 Frikk29 Frodet30 Geocachernemesis31 GeorgBauhaus32 Godunko33 Hagindaz34 Herbythyme35 JMatthews36 James Dennett37 Jclee38 Jcreem39 Jenous40 Jesselang41 Jguk42 Jlaire43 Jlenthe44 Jomegat45 Kayau46
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
http://en.wikibooks.org/w/index.php?title=User:Dirk_H%C3%BCnniger http://en.wikibooks.org/w/index.php?title=User:Dmitry-kazakov http://en.wikibooks.org/w/index.php?title=User:Doug http://en.wikibooks.org/w/index.php?title=User:DougP http://en.wikibooks.org/w/index.php?title=User:Dragontamer http://en.wikibooks.org/w/index.php?title=User:Fraterm http://en.wikibooks.org/w/index.php?title=User:Friess http://en.wikibooks.org/w/index.php?title=User:Frikk http://en.wikibooks.org/w/index.php?title=User:Frodet http://en.wikibooks.org/w/index.php?title=User:Geocachernemesis http://en.wikibooks.org/w/index.php?title=User:GeorgBauhaus http://en.wikibooks.org/w/index.php?title=User:Godunko http://en.wikibooks.org/w/index.php?title=User:Hagindaz http://en.wikibooks.org/w/index.php?title=User:Herbythyme http://en.wikibooks.org/w/index.php?title=User:JMatthews http://en.wikibooks.org/w/index.php?title=User:James_Dennett http://en.wikibooks.org/w/index.php?title=User:Jclee http://en.wikibooks.org/w/index.php?title=User:Jcreem http://en.wikibooks.org/w/index.php?title=User:Jeffinous http://en.wikibooks.org/w/index.php?title=User:Jesselang http://en.wikibooks.org/w/index.php?title=User:Jguk http://en.wikibooks.org/w/index.php?title=User:Jlaire http://en.wikibooks.org/w/index.php?title=User:Jlenthe http://en.wikibooks.org/w/index.php?title=User:Jomegat http://en.wikibooks.org/w/index.php?title=User:Kayau
394
Krischik47 Kwhitefoot48 Larry Luther49 LesmanaZimmer50 Lincher51 Lodacom52 Ludovic Brenta53 Maciej Sobczak54 Mahanga55 ManuelGR56 Mike.lifeguard57 Moskvax58 Nikai59 Okellogg60 Oleszkie61 Panic2k462 Panzon63 Parallelized64 Paxton65 Per.sandberg66 QuiteUnusual67 RamaccoloBot68 Randhol69 Recent Runes70 Red4tribe71
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
http://en.wikibooks.org/w/index.php?title=User:Krischik http://en.wikibooks.org/w/index.php?title=User:Kwhitefoot http://en.wikibooks.org/w/index.php?title=User:Larry_Luther http://en.wikibooks.org/w/index.php?title=User:LesmanaZimmer http://en.wikibooks.org/w/index.php?title=User:Lincher http://en.wikibooks.org/w/index.php?title=User:Lodacom http://en.wikibooks.org/w/index.php?title=User:Ludovic_Brenta http://en.wikibooks.org/w/index.php?title=User:Maciej_Sobczak http://en.wikibooks.org/w/index.php?title=User:Mahanga http://en.wikibooks.org/w/index.php?title=User:ManuelGR http://en.wikibooks.org/w/index.php?title=User:Mike.lifeguard http://en.wikibooks.org/w/index.php?title=User:Moskvax http://en.wikibooks.org/w/index.php?title=User:Nikai http://en.wikibooks.org/w/index.php?title=User:Okellogg http://en.wikibooks.org/w/index.php?title=User:Oleszkie http://en.wikibooks.org/w/index.php?title=User:Panic2k4 http://en.wikibooks.org/w/index.php?title=User:Panzon http://en.wikibooks.org/w/index.php?title=User:Parallelized http://en.wikibooks.org/w/index.php?title=User:Paxton http://en.wikibooks.org/w/index.php?title=User:Per.sandberg http://en.wikibooks.org/w/index.php?title=User:QuiteUnusual http://en.wikibooks.org/w/index.php?title=User:RamaccoloBot http://en.wikibooks.org/w/index.php?title=User:Randhol http://en.wikibooks.org/w/index.php?title=User:Recent_Runes http://en.wikibooks.org/w/index.php?title=User:Red4tribe
395
Contributors 5 1 1 3 2 5 1 5 1 711 2 2 3 3 1 1 3 5 1 1 3 1 1 1 Robert Horning72 Rosen73 Rursus74 SQL75 Sam76 Sjw77 Sparre78 Spongebob8879 Stephen leake80 Suruena81 Swhalen82 The bellman83 Thenub31484 Tkoskine85 Tobias Bergemann86 Van der Hoorn87 Venullian88 VillemtheVillain!89 Vito Genovese90 Warinthepocket91 WhirlWind92 Wikibob93 Xania94 robot95
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
http://en.wikibooks.org/w/index.php?title=User:Robert_Horning http://en.wikibooks.org/w/index.php?title=User:Rosen http://en.wikibooks.org/w/index.php?title=User:Rursus http://en.wikibooks.org/w/index.php?title=User:SQL http://en.wikibooks.org/w/index.php?title=User:Sam http://en.wikibooks.org/w/index.php?title=User:Sjw http://en.wikibooks.org/w/index.php?title=User:Sparre http://en.wikibooks.org/w/index.php?title=User:Spongebob88 http://en.wikibooks.org/w/index.php?title=User:Stephen_leake http://en.wikibooks.org/w/index.php?title=User:Suruena http://en.wikibooks.org/w/index.php?title=User:Swhalen http://en.wikibooks.org/w/index.php?title=User:The_bellman http://en.wikibooks.org/w/index.php?title=User:Thenub314 http://en.wikibooks.org/w/index.php?title=User:Tkoskine http://en.wikibooks.org/w/index.php?title=User:Tobias_Bergemann http://en.wikibooks.org/w/index.php?title=User:Van_der_Hoorn http://en.wikibooks.org/w/index.php?title=User:Venullian http://en.wikibooks.org/w/index.php?title=User:VillemtheVillain%21 http://en.wikibooks.org/w/index.php?title=User:Vito_Genovese http://en.wikibooks.org/w/index.php?title=User:Warinthepocket http://en.wikibooks.org/w/index.php?title=User:WhirlWind http://en.wikibooks.org/w/index.php?title=User:Wikibob http://en.wikibooks.org/w/index.php?title=User:Xania http://en.wikibooks.org/w/index.php?title=User:%E3%82%BF%E3%83%81%E3%82%B3%E3%83%9E_ robot
396
List of Figures
GFDL: Gnu Free Documentation License. http://www.gnu.org/licenses/fdl. html cc-by-sa-3.0: Creative Commons Attribution ShareAlike 3.0 License. http:// creativecommons.org/licenses/by-sa/3.0/ cc-by-sa-2.5: Creative Commons Attribution ShareAlike 2.5 License. http:// creativecommons.org/licenses/by-sa/2.5/ cc-by-sa-2.0: Creative Commons Attribution ShareAlike 2.0 License. http:// creativecommons.org/licenses/by-sa/2.0/ cc-by-sa-1.0: Creative Commons Attribution ShareAlike 1.0 License. http:// creativecommons.org/licenses/by-sa/1.0/ cc-by-2.0: Creative Commons Attribution 2.0 License. http://creativecommons. org/licenses/by/2.0/ cc-by-2.0: Creative Commons Attribution 2.0 License. http://creativecommons. org/licenses/by/2.0/deed.en cc-by-2.5: Creative Commons Attribution 2.5 License. http://creativecommons. org/licenses/by/2.5/deed.en cc-by-3.0: Creative Commons Attribution 3.0 License. http://creativecommons. org/licenses/by/3.0/deed.en GPL: GNU General Public License. http://www.gnu.org/licenses/gpl-2.0.txt LGPL: GNU Lesser General Public License. http://www.gnu.org/licenses/lgpl. html PD: This image is in the public domain. ATTR: The copyright holder of this le allows anyone to use it for any purpose, provided that the copyright holder is properly attributed. Redistribution, derivative work, commercial use, and all other use is permitted. EURO: This is the common (reverse) face of a euro coin. The copyright on the design of the common face of the euro coins belongs to the European Commission. Authorised is reproduction in a format without relief (drawings, paintings, lms) provided they are not detrimental to the image of the euro. LFK: Lizenz Freie Kunst. http://artlibre.org/licence/lal/de CFR: Copyright free use. EPL: Eclipse Public License. http://www.eclipse.org/org/documents/epl-v10. php Copies of the GPL, the LGPL as well as a GFDL are included in chapter Licenses96 . Please note that images in the public domain do not require attribution. You may click on the image numbers in the following table to open the webpage of the images in your webbrower.
96
397
List of Figures
ManuelGR97
GFDL
97
http://en.wikibooks.org/wiki/User%3AManuelGR
398
61 Licenses
61.1 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Copyright 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a programto make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) oer you this License giving you legal permission to copy, distribute and/or modify it. For the developers and authors protection, the GPL clearly explains that there is no warranty for this free software. For both users and authors sake, the GPL requires that modied versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modied versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it eectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program nonfree. The precise terms and conditions for copying, distribution and modication follow. TERMS AND CONDITIONS 0. Denitions. This License refers to version 3 of the GNU General Public License. Copyright also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. The Program refers to any copyrightable work licensed under this License. Each licensee is addressed as you. Licensees and recipients may be individuals or organizations. To modify a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a modied version of the earlier work or a work based on the earlier work. A covered work means either the unmodied Program or a work based on the Program. To propagate a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modication), making available to the public, and in some countries other activities as well. To convey a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays Appropriate Legal Notices to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The source code for a work means the preferred form of the work for making modications to it. Object code means any non-source form of a work. A Standard Interface means an interface that either is an ocial standard dened by a recognized standards body, or, in the case of interfaces specied for a particular programming language, one that is widely used among developers working in that language. The System Libraries of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A Major Component, in this context, means a major essential component (kernel, window system, and so on) of the specic operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The Corresponding Source for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the works System Libraries, or generalpurpose tools or generally available free programs which are used unmodied in performing those activities but which are not part of the work. For example, Corresponding Source includes interface denition les associated with source les for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specically designed to require, such as by intimate data communication or control ow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly arms your unlimited permission to run the unmodied Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users Legal Rights From AntiCircumvention Law. No covered work shall be deemed part of an eective technological measure under any applicable law fullling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modication of the work as a means of enforcing, against the works users, your or third parties legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Programs source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may oer support or warranty protection for a fee. 5. Conveying Modied Source Versions. You may convey a work based on the Program, or the modications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: * a) The work must carry prominent notices stating that you modied it, and giving a relevant date. * b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modies the requirement in section 4 to keep intact all notices. * c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. * d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an aggregate if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilations users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: * a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source xed on a durable physical medium customarily used for software interchange. * b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written oer, valid for at least three years and valid for as long as you oer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. * c) Convey individual copies of the object code with a copy of the written oer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. * d) Convey the object code by oering access from a designated place (gratis or for a charge), and oer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a dierent server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to nd the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. * e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being oered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A User Product is either (1) a consumer product, which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, normally used refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or nonconsumer uses, unless such uses represent the only signicant mode of use of the product. Installation Information for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modied versions of a covered work in that User Product from a modied version of its Corresponding Source. The information must suce to ensure that the continued functioning of the modied object code is in no case prevented or interfered with solely because modication has been made. If you convey an object code work under this section in, or with, or specically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a xed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modied object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modied or installed by the recipient, or for the User Product in which it has been modied or installed. Access to a network may be denied when the modication itself materially and adversely aects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. Additional permissions are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: * a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or * b) Requiring preservation of specied reasonable legal notices or author attributions in
that material or in the Appropriate Legal Notices displayed by works containing it; or * c) Prohibiting misrepresentation of the origin of that material, or requiring that modied versions of such material be marked in reasonable ways as dierent from the original version; or * d) Limiting the use for publicity purposes of names of licensors or authors of the material; or * e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or * f) Requiring indemnication of licensors and authors of that material by anyone who conveys the material (or modied versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered further restrictions within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source les, a statement of the additional terms that apply to those les, or a notice indicating where to nd the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and nally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder noties you of the violation by some reasonable means, this is the rst time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9 Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An entity transaction is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the partys predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable eorts. You may not impose any further restrictions on the exercise of the rights granted or armed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, oering for sale, or importing the Program or any portion of it 11. Patents. A contributor is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributors contributor version. A contributors essential patent claims are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modication of the contributor version. For purposes of this denition, control includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributors essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a patent license is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To
grant such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benet of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. Knowingly relying means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipients use of the covered work in a country, would infringe one or more identiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specic copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is discriminatory if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specic products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be avail-
able to you under applicable patent law. 12. No Surrender of Others Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Aero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Aero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Aero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program species that a certain numbered version of the GNU General Public License or any later version applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program species that a proxy can decide which future versions of the GNU General Public License can be used, that proxys public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or dierent permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source le to most eectively state the exclusion of warranty; and each le should have at least
the copyright line and a pointer to where the f notice is found. <one line to give the programs name and a br idea of what it does.> Copyright (C) <yea <name of author> This program is free software: you can redistribu it and/or modify it under the terms of the GN General Public License as published by the Fr Software Foundation, either version 3 of the cense, or (at your option) any later version. This program is distributed in the hope th it will be useful, but WITHOUT ANY WA RANTY; without even the implied warranty MERCHANTABILITY or FITNESS FOR A PA TICULAR PURPOSE. See the GNU General Pub License for more details. You should have received a copy of the GNU G eral Public License along with this program. If n see <http://www.gnu.org/licenses/>. Also add information on how to contact you by el tronic and paper mail. If the program does terminal interaction, make output a short notice like this when it starts in interactive mode: <program> Copyright (C) <year> <name of a thor> This program comes with ABSOLUTEL NO WARRANTY; for details type show w. This free software, and you are welcome to redistribute under certain conditions; type show c for detai The hypothetical commands show w and show should show the appropriate parts of the Gene Public License. Of course, your programs co mands might be dierent; for a GUI interface, y would use an about box. You should also get your employer (if you wo as a programmer) or school, if any, to sign copyright disclaimer for the program, if n essary. For more information on this, a how to apply and follow the GNU GPL, s <http://www.gnu.org/licenses/>. The GNU General Public License does not perm incorporating your program into proprietary p grams. If your program is a subroutine library, y may consider it more useful to permit linking p prietary applications with the library. If this what you want to do, use the GNU Lesser Gene Public License instead of this License. But r please read <http://www.gnu.org/philosophy/wh not-lgpl.html>.
has been approved by an organization as the a thoritative denition of a standard. You may add a passage of up to ve words as Front-Cover Text, and a passage of up to 25 wor as a Back-Cover Text, to the end of the list of Cov Texts in the Modied Version. Only one passage Front-Cover Text and one of Back-Cover Text m be added by (or through arrangements made b any one entity. If the Document already includ a cover text for the same cover, previously add by you or by arrangement made by the same ent you are acting on behalf of, you may not add a other; but you may replace the old one, on expli permission from the previous publisher that add the old one. The author(s) and publisher(s) of the Document not by this License give permission to use th names for publicity for or to assert or imply dorsement of any Modied Version. 5. COMBI ING DOCUMENTS You may combine the Document with other do ments released under this License, under the term dened in section 4 above for modied versio provided that you include in the combination of the Invariant Sections of all of the original d uments, unmodied, and list them all as Invaria Sections of your combined work in its license n tice, and that you preserve all their Warranty D claimers. The combined work need only contain one copy this License, and multiple identical Invariant S tions may be replaced with a single copy. If the are multiple Invariant Sections with the same nam but dierent contents, make the title of each su section unique by adding at the end of it, in par theses, the name of the original author or publish of that section if known, or else a unique numb Make the same adjustment to the section titles the list of Invariant Sections in the license not of the combined work. In the combination, you must combine any sectio Entitled "History" in the various original do ments, forming one section Entitled "History"; li wise combine any sections Entitled "Acknowled ments", and any sections Entitled "Dedication You must delete all sections Entitled "Endor ments". 6. COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Do ment and other documents released under this cense, and replace the individual copies of this cense in the various documents with a single co that is included in the collection, provided that y follow the rules of this License for verbatim copyi of each of the documents in all other respects. You may extract a single document from such a c lection, and distribute it individually under this cense, provided you insert a copy of this Licen into the extracted document, and follow this cense in all other respects regarding verbatim cop ing of that document. 7. AGGREGATION WIT INDEPENDENT WORKS A compilation of the Document or its derivativ with other separate and independent documents works, in or on a volume of a storage or distributi medium, is called an "aggregate" if the copyright sulting from the compilation is not used to limit t legal rights of the compilations users beyond wh the individual works permit. When the Docume is included in an aggregate, this License does n apply to the other works in the aggregate which a not themselves derivative works of the Documen If the Cover Text requirement of section 3 is app cable to these copies of the Document, then if t Document is less than one half of the entire agg gate, the Documents Cover Texts may be plac on covers that bracket the Document within t aggregate, or the electronic equivalent of cove if the Document is in electronic form. Otherw they must appear on printed covers that brack the whole aggregate. 8. TRANSLATION Translation is considered a kind of modication, you may distribute translations of the Docume under the terms of section 4. Replacing Invaria Sections with translations requires special perm sion from their copyright holders, but you may clude translations of some or all Invariant Sectio in addition to the original versions of these Inva ant Sections. You may include a translation of th License, and all the license notices in the Docume and any Warranty Disclaimers, provided that y
also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. 9. TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, or distribute it is void, and will automatically terminate your rights under this License. However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and nally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder noties you of the violation by some reasonable means, this is the rst time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the vi-
olation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, receipt of a copy of some or all of the same material does not give you any rights to use it. 10. FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/. Each version of the License is given a distinguishing version number. If the Document species that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specied version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. If the Document species that a proxy can decide which future versions of this License can be used, that proxys public statement of acceptance of a version permanently autho-
rizes you to choose that version for the Document. 11. RELICENSING "Massive Multiauthor Collaboration Site" (or "MMC Site") means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server. A "Massive Multiauthor Collaboration" (or "MMC") contained in the site means any set of copyrightable works thus published on the MMC site. "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 license published by Creative Commons Corporation, a not-for-prot corporation with a principal place of business in San Francisco, California, as well as future copyleft versions of that license published by that same organization. "Incorporate" means to publish or republish a Document, in whole or in part, as part of another Document. An MMC is "eligible for relicensing" if it is licensed under this License, and if all works that were rst published under this License somewhere other than this MMC, and subsequently incorporated in whole or in part into the MMC, (1) had no cover texts or invariant sections, and (2) were thus incorporated prior to November 1, 2008. The operator of an MMC Site may republish an MMC contained in the site under CC-BY-SA on the
same site at any time before August 1, 2009, provided the MMC is eligible for relicensing. ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (C) YEAR YOUR NAME. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with . . Texts." line with this: with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.
GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Denitions. As used herein, this License refers to version 3 of the GNU Lesser General Public License, and the GNU GPL refers to version 3 of the GNU General Public License. The Library refers to a covered work governed by this License, other than an Application or a Combined Work as dened below. An Application is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Dening a subclass of a class dened by the Library is deemed a mode of using an interface provided by the Library. A Combined Work is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the Linked Version. The Minimal Corresponding Source for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The Corresponding Application Code for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the
System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modied Versions. If you modify a copy of the Library, and, in your modications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modied version: * a) under this License, provided that you make a good faith eort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or * b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header le that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: * a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. * b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, eectively do not restrict modication of the portions of the Library contained in the Combined Work and reverse en-
gineering for debugging such modications, if you also do each of the following: * a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. * b) Accompany the Combined Work with a copy of the GNU GPL and this license document. * c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. * d) Do one of the following: o 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modied version of the Linked Version to produce a modied Combined Work, in the manner specied by section 6 of the GNU GPL for conveying Corresponding Source. o 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the users computer system, and (b) will operate properly with a modied version of the Library that is interface-compatible with the Linked Version. * e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modied version of the Combined Work produced by recombining or relinking the Application with a modied version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specied by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries.
You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: * a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. * b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to nd the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may dier in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it species that a certain numbered version of the GNU Lesser General Public License or any later version applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it species that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxys public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.