Ada Reference Manual, ISO/IEC 8652:2007(E) Ed.

3

Ada Reference Manual
ISO/IEC 8652:1995(E) with Technical Corrigendum 1 and Amendment 1

Language and Standard Libraries

Copyright © 1992, 1993, 1994, 1995 Intermetrics, Inc. Copyright © 2000 The MITRE Corporation, Inc. Copyright © 2004, 2005, 2006 AXE Consultants Copyright © 2004, 2005, 2006 Ada-Europe

Ada Reference Manual - Language and Standard Libraries Copyright © 1992, 1993, 1994, 1995, Intermetrics, Inc. This copyright is assigned to the U.S. Government. All rights reserved. This document may be copied, in whole or in part, in any form or by any means, as is or with alterations, provided that (1) alterations are clearly marked as alterations and (2) this copyright notice is included unmodified in any copy. Compiled copies of standard library units and examples need not contain this copyright notice so long as the notice is included in all copies of source code and documentation.

Technical Corrigendum 1 Copyright © 2000, The MITRE Corporation. All Rights Reserved. This document may be copied, in whole or in part, in any form or by any means, as is, or with alterations, provided that (1) alterations are clearly marked as alterations and (2) this copyright notice is included unmodified in any copy. Any other use or distribution of this document is prohibited without the prior express permission of MITRE. You use this document on the condition that you indemnify and hold harmless MITRE, its Board of Trustees, officers, agents, and employees, from any and all liability or damages to yourself or your hardware or software, or third parties, including attorneys' fees, court costs, and other related costs and expenses, arising out of your use of this document irrespective of the cause of said liability. MITRE MAKES THIS DOCUMENT AVAILABLE ON AN "AS IS" BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, CAPABILITY, EFFICIENCY MERCHANTABILITY, OR FUNCTIONING OF THIS DOCUMENT. IN NO EVENT WILL MITRE BE LIABLE FOR ANY GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, EVEN IF MITRE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

Amendment 1 Copyright © 2004, 2005, 2006, AXE Consultants. All Rights Reserved. This document may be copied, in whole or in part, in any form or by any means, as is, or with alterations, provided that (1) alterations are clearly marked as alterations and (2) this copyright notice is included unmodified in any copy. Any other use or distribution of this document is prohibited without the prior express permission of AXE. You use this document on the condition that you indemnify and hold harmless AXE, its board, officers, agents, and employees, from any and all liability or damages to yourself or your hardware or software, or

third parties, including attorneys' fees, court costs, and other related costs and expenses, arising out of your use of this document irrespective of the cause of said liability. AXE MAKES THIS DOCUMENT AVAILABLE ON AN "AS IS" BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, CAPABILITY, EFFICIENCY MERCHANTABILITY, OR FUNCTIONING OF THIS DOCUMENT. IN NO EVENT WILL AXE BE LIABLE FOR ANY GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, EVEN IF AXE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

Consolidated Standard Copyright © 2004, 2005, 2006, Ada-Europe. This document may be copied, in whole or in part, in any form or by any means, as is, or with alterations, provided that (1) alterations are clearly marked as alterations and (2) this copyright notice is included unmodified in any copy. Any other use or distribution of this document is prohibited without the prior express permission of Ada-Europe. You use this document on the condition that you indemnify and hold harmless Ada-Europe and its Board from any and all liability or damages to yourself or your hardware or software, or third parties, including attorneys' fees, court costs, and other related costs and expenses, arising out of your use of this document irrespective of the cause of said liability. ADA-EUROPE MAKES THIS DOCUMENT AVAILABLE ON AN "AS IS" BASIS AND MAKES NO WARRANTY, EXPRESS OR IMPLIED, AS TO THE ACCURACY, CAPABILITY, EFFICIENCY MERCHANTABILITY, OR FUNCTIONING OF THIS DOCUMENT. IN NO EVENT WILL ADAEUROPE BE LIABLE FOR ANY GENERAL, CONSEQUENTIAL, INDIRECT, INCIDENTAL, EXEMPLARY, OR SPECIAL DAMAGES, EVEN IF ADA-EUROPE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

Table of Contents
Table of Contents............................................................................................................i Foreword to this version of the Ada Reference Manual ...........................................xi Foreword.......................................................................................................................xii Introduction .................................................................................................................xiii Section 1: General..........................................................................................................1
1.1 Scope .............................................................................................................................................1 1.1.1 Extent ......................................................................................................................................1 1.1.2 Structure .................................................................................................................................2 1.1.3 Conformity of an Implementation with the Standard.........................................................4 1.1.4 Method of Description and Syntax Notation.......................................................................5 1.1.5 Classification of Errors .........................................................................................................7 1.2 Normative References ..................................................................................................................8 1.3 Definitions......................................................................................................................................8

Section 2: Lexical Elements..........................................................................................9
2.1 Character Set.................................................................................................................................9 2.2 Lexical Elements, Separators, and Delimiters.........................................................................11 2.3 Identifiers .....................................................................................................................................12 2.4 Numeric Literals ..........................................................................................................................13 2.4.1 Decimal Literals ...................................................................................................................13 2.4.2 Based Literals ......................................................................................................................14 2.5 Character Literals .......................................................................................................................14 2.6 String Literals ..............................................................................................................................15 2.7 Comments....................................................................................................................................15 2.8 Pragmas .......................................................................................................................................16 2.9 Reserved Words..........................................................................................................................18

Section 3: Declarations and Types ............................................................................19
3.1 Declarations.................................................................................................................................19 3.2 Types and Subtypes ...................................................................................................................20 3.2.1 Type Declarations................................................................................................................22 3.2.2 Subtype Declarations ..........................................................................................................23 3.2.3 Classification of Operations...............................................................................................24 3.3 Objects and Named Numbers....................................................................................................25 3.3.1 Object Declarations .............................................................................................................26 3.3.2 Number Declarations...........................................................................................................28 3.4 Derived Types and Classes .......................................................................................................29 3.4.1 Derivation Classes...............................................................................................................32 3.5 Scalar Types ................................................................................................................................34 3.5.1 Enumeration Types .............................................................................................................38 3.5.2 Character Types...................................................................................................................39 3.5.3 Boolean Types .....................................................................................................................40 3.5.4 Integer Types .......................................................................................................................40 3.5.5 Operations of Discrete Types.............................................................................................43 3.5.6 Real Types ............................................................................................................................44 3.5.7 Floating Point Types ...........................................................................................................45 3.5.8 Operations of Floating Point Types...................................................................................47

i

10 November 2006

Table of Contents

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 3.5.9 Fixed Point Types................................................................................................................ 47 3.5.10 Operations of Fixed Point Types..................................................................................... 49 3.6 Array Types ................................................................................................................................. 50 3.6.1 Index Constraints and Discrete Ranges ........................................................................... 52 3.6.2 Operations of Array Types ................................................................................................. 54 3.6.3 String Types......................................................................................................................... 55 3.7 Discriminants .............................................................................................................................. 55 3.7.1 Discriminant Constraints ................................................................................................... 58 3.7.2 Operations of Discriminated Types .................................................................................. 59 3.8 Record Types.............................................................................................................................. 60 3.8.1 Variant Parts and Discrete Choices .................................................................................. 62 3.9 Tagged Types and Type Extensions ........................................................................................ 64 3.9.1 Type Extensions.................................................................................................................. 67 3.9.2 Dispatching Operations of Tagged Types........................................................................ 68 3.9.3 Abstract Types and Subprograms .................................................................................... 71 3.9.4 Interface Types .................................................................................................................... 72 3.10 Access Types............................................................................................................................ 75 3.10.1 Incomplete Type Declarations ......................................................................................... 77 3.10.2 Operations of Access Types............................................................................................ 80 3.11 Declarative Parts ...................................................................................................................... 84 3.11.1 Completions of Declarations ........................................................................................... 84

Section 4: Names and Expressions ........................................................................... 87
4.1 Names .......................................................................................................................................... 87 4.1.1 Indexed Components.......................................................................................................... 88 4.1.2 Slices .................................................................................................................................... 89 4.1.3 Selected Components ........................................................................................................ 90 4.1.4 Attributes.............................................................................................................................. 92 4.2 Literals ......................................................................................................................................... 93 4.3 Aggregates .................................................................................................................................. 94 4.3.1 Record Aggregates ............................................................................................................. 94 4.3.2 Extension Aggregates ........................................................................................................ 97 4.3.3 Array Aggregates ................................................................................................................ 98 4.4 Expressions .............................................................................................................................. 101 4.5 Operators and Expression Evaluation ................................................................................... 102 4.5.1 Logical Operators and Short-circuit Control Forms ..................................................... 103 4.5.2 Relational Operators and Membership Tests ................................................................ 104 4.5.3 Binary Adding Operators ................................................................................................. 107 4.5.4 Unary Adding Operators .................................................................................................. 108 4.5.5 Multiplying Operators ....................................................................................................... 109 4.5.6 Highest Precedence Operators ....................................................................................... 111 4.6 Type Conversions .................................................................................................................... 112 4.7 Qualified Expressions.............................................................................................................. 116 4.8 Allocators .................................................................................................................................. 117 4.9 Static Expressions and Static Subtypes................................................................................ 119 4.9.1 Statically Matching Constraints and Subtypes.............................................................. 122

Section 5: Statements ............................................................................................... 123
5.1 Simple and Compound Statements - Sequences of Statements ........................................ 123 5.2 Assignment Statements........................................................................................................... 124 5.3 If Statements ............................................................................................................................. 126 5.4 Case Statements....................................................................................................................... 127 5.5 Loop Statements ...................................................................................................................... 128 5.6 Block Statements ..................................................................................................................... 130 Table of Contents 10 November 2006 ii

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 5.7 Exit Statements .........................................................................................................................130 5.8 Goto Statements .......................................................................................................................131

Section 6: Subprograms ...........................................................................................133
6.1 Subprogram Declarations ........................................................................................................133 6.2 Formal Parameter Modes .........................................................................................................135 6.3 Subprogram Bodies..................................................................................................................136 6.3.1 Conformance Rules...........................................................................................................137 6.3.2 Inline Expansion of Subprograms ...................................................................................139 6.4 Subprogram Calls .....................................................................................................................140 6.4.1 Parameter Associations....................................................................................................142 6.5 Return Statements ....................................................................................................................143 6.5.1 Pragma No_Return ............................................................................................................145 6.6 Overloading of Operators ........................................................................................................146 6.7 Null Procedures ........................................................................................................................147

Section 7: Packages ..................................................................................................149
7.1 Package Specifications and Declarations..............................................................................149 7.2 Package Bodies ........................................................................................................................150 7.3 Private Types and Private Extensions....................................................................................151 7.3.1 Private Operations.............................................................................................................154 7.4 Deferred Constants...................................................................................................................156 7.5 Limited Types ............................................................................................................................157 7.6 User-Defined Assignment and Finalization ...........................................................................158 7.6.1 Completion and Finalization.............................................................................................161

Section 8: Visibility Rules .........................................................................................165
8.1 Declarative Region....................................................................................................................165 8.2 Scope of Declarations ..............................................................................................................166 8.3 Visibility......................................................................................................................................167 8.3.1 Overriding Indicators ........................................................................................................170 8.4 Use Clauses...............................................................................................................................171 8.5 Renaming Declarations ............................................................................................................172 8.5.1 Object Renaming Declarations ........................................................................................172 8.5.2 Exception Renaming Declarations ..................................................................................173 8.5.3 Package Renaming Declarations.....................................................................................174 8.5.4 Subprogram Renaming Declarations ..............................................................................174 8.5.5 Generic Renaming Declarations ......................................................................................176 8.6 The Context of Overload Resolution ......................................................................................177

Section 9: Tasks and Synchronization ....................................................................181
9.1 Task Units and Task Objects...................................................................................................181 9.2 Task Execution - Task Activation............................................................................................184 9.3 Task Dependence - Termination of Tasks..............................................................................185 9.4 Protected Units and Protected Objects ..................................................................................187 9.5 Intertask Communication.........................................................................................................190 9.5.1 Protected Subprograms and Protected Actions ............................................................191 9.5.2 Entries and Accept Statements........................................................................................192 9.5.3 Entry Calls ..........................................................................................................................195 9.5.4 Requeue Statements .........................................................................................................198 9.6 Delay Statements, Duration, and Time ...................................................................................199 9.6.1 Formatting, Time Zones, and other operations for Time ..............................................202 9.7 Select Statements .....................................................................................................................208 9.7.1 Selective Accept ................................................................................................................209

iii

10 November 2006

Table of Contents

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 9.7.2 Timed Entry Calls .............................................................................................................. 211 9.7.3 Conditional Entry Calls..................................................................................................... 212 9.7.4 Asynchronous Transfer of Control ................................................................................. 213 9.8 Abort of a Task - Abort of a Sequence of Statements .......................................................... 214 9.9 Task and Entry Attributes........................................................................................................ 215 9.10 Shared Variables .................................................................................................................... 216 9.11 Example of Tasking and Synchronization ........................................................................... 217

Section 10: Program Structure and Compilation Issues ....................................... 219
10.1 Separate Compilation............................................................................................................. 219 10.1.1 Compilation Units - Library Units .................................................................................. 219 10.1.2 Context Clauses - With Clauses .................................................................................... 222 10.1.3 Subunits of Compilation Units ...................................................................................... 224 10.1.4 The Compilation Process ............................................................................................... 226 10.1.5 Pragmas and Program Units.......................................................................................... 227 10.1.6 Environment-Level Visibility Rules ............................................................................... 228 10.2 Program Execution................................................................................................................. 229 10.2.1 Elaboration Control......................................................................................................... 231

Section 11: Exceptions ............................................................................................. 235
11.1 Exception Declarations.......................................................................................................... 235 11.2 Exception Handlers ................................................................................................................ 235 11.3 Raise Statements.................................................................................................................... 236 11.4 Exception Handling ................................................................................................................ 237 11.4.1 The Package Exceptions ................................................................................................ 238 11.4.2 Pragmas Assert and Assertion_Policy ......................................................................... 240 11.4.3 Example of Exception Handling .................................................................................... 241 11.5 Suppressing Checks.............................................................................................................. 242 11.6 Exceptions and Optimization ................................................................................................ 245

Section 12: Generic Units ......................................................................................... 247
12.1 Generic Declarations.............................................................................................................. 247 12.2 Generic Bodies ....................................................................................................................... 249 12.3 Generic Instantiation.............................................................................................................. 250 12.4 Formal Objects ....................................................................................................................... 252 12.5 Formal Types .......................................................................................................................... 254 12.5.1 Formal Private and Derived Types ................................................................................ 255 12.5.2 Formal Scalar Types ....................................................................................................... 257 12.5.3 Formal Array Types......................................................................................................... 258 12.5.4 Formal Access Types ..................................................................................................... 259 12.5.5 Formal Interface Types................................................................................................... 259 12.6 Formal Subprograms ............................................................................................................. 260 12.7 Formal Packages .................................................................................................................... 262 12.8 Example of a Generic Package ............................................................................................. 264

Section 13: Representation Issues .......................................................................... 267
13.1 Operational and Representation Items ................................................................................ 267 13.2 Pragma Pack ........................................................................................................................... 270 13.3 Operational and Representation Attributes......................................................................... 271 13.4 Enumeration Representation Clauses ................................................................................. 277 13.5 Record Layout ........................................................................................................................ 278 13.5.1 Record Representation Clauses.................................................................................... 278 13.5.2 Storage Place Attributes ................................................................................................ 280 13.5.3 Bit Ordering ..................................................................................................................... 281

Table of Contents

10 November 2006

iv

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 13.6 Change of Representation .....................................................................................................282 13.7 The Package System ..............................................................................................................283 13.7.1 The Package System.Storage_Elements ......................................................................285 13.7.2 The Package System.Address_To_Access_Conversions ..........................................286 13.8 Machine Code Insertions .......................................................................................................286 13.9 Unchecked Type Conversions ..............................................................................................287 13.9.1 Data Validity .....................................................................................................................288 13.9.2 The Valid Attribute...........................................................................................................289 13.10 Unchecked Access Value Creation.....................................................................................290 13.11 Storage Management............................................................................................................290 13.11.1 The Max_Size_In_Storage_Elements Attribute ..........................................................293 13.11.2 Unchecked Storage Deallocation ................................................................................294 13.11.3 Pragma Controlled.........................................................................................................295 13.12 Pragma Restrictions .............................................................................................................295 13.12.1 Language-Defined Restrictions ...................................................................................296 13.13 Streams ..................................................................................................................................297 13.13.1 The Package Streams ...................................................................................................297 13.13.2 Stream-Oriented Attributes ..........................................................................................298 13.14 Freezing Rules ......................................................................................................................303

The Standard Libraries ..............................................................................................305 Annex A (normative) Predefined Language Environment ......................................307
A.1 The Package Standard.............................................................................................................309 A.2 The Package Ada......................................................................................................................313 A.3 Character Handling ..................................................................................................................313 A.3.1 The Packages Characters, Wide_Characters, and Wide_Wide_Characters...............314 A.3.2 The Package Characters.Handling..................................................................................314 A.3.3 The Package Characters.Latin_1.....................................................................................317 A.3.4 The Package Characters.Conversions ...........................................................................322 A.4 String Handling.........................................................................................................................324 A.4.1 The Package Strings.........................................................................................................324 A.4.2 The Package Strings.Maps ..............................................................................................324 A.4.3 Fixed-Length String Handling..........................................................................................327 A.4.4 Bounded-Length String Handling ...................................................................................336 A.4.5 Unbounded-Length String Handling...............................................................................343 A.4.6 String-Handling Sets and Mappings ...............................................................................348 A.4.7 Wide_String Handling.......................................................................................................348 A.4.8 Wide_Wide_String Handling ............................................................................................351 A.4.9 String Hashing...................................................................................................................353 A.5 The Numerics Packages ..........................................................................................................354 A.5.1 Elementary Functions.......................................................................................................355 A.5.2 Random Number Generation ...........................................................................................358 A.5.3 Attributes of Floating Point Types ..................................................................................363 A.5.4 Attributes of Fixed Point Types .......................................................................................367 A.6 Input-Output..............................................................................................................................367 A.7 External Files and File Objects ...............................................................................................367 A.8 Sequential and Direct Files .....................................................................................................369 A.8.1 The Generic Package Sequential_IO...............................................................................369 A.8.2 File Management ...............................................................................................................370 A.8.3 Sequential Input-Output Operations ...............................................................................372 A.8.4 The Generic Package Direct_IO.......................................................................................373 A.8.5 Direct Input-Output Operations .......................................................................................374 A.9 The Generic Package Storage_IO...........................................................................................375 v 10 November 2006 Table of Contents

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual A.10 Text Input-Output................................................................................................................... 375 A.10.1 The Package Text_IO ..................................................................................................... 377 A.10.2 Text File Management .................................................................................................... 382 A.10.3 Default Input, Output, and Error Files .......................................................................... 383 A.10.4 Specification of Line and Page Lengths ...................................................................... 384 A.10.5 Operations on Columns, Lines, and Pages ................................................................. 385 A.10.6 Get and Put Procedures................................................................................................. 388 A.10.7 Input-Output of Characters and Strings....................................................................... 389 A.10.8 Input-Output for Integer Types...................................................................................... 391 A.10.9 Input-Output for Real Types .......................................................................................... 393 A.10.10 Input-Output for Enumeration Types ......................................................................... 396 A.10.11 Input-Output for Bounded Strings.............................................................................. 397 A.10.12 Input-Output for Unbounded Strings ......................................................................... 398 A.11 Wide Text Input-Output and Wide Wide Text Input-Output............................................... 399 A.12 Stream Input-Output .............................................................................................................. 400 A.12.1 The Package Streams.Stream_IO ................................................................................. 400 A.12.2 The Package Text_IO.Text_Streams............................................................................. 403 A.12.3 The Package Wide_Text_IO.Text_Streams .................................................................. 403 A.12.4 The Package Wide_Wide_Text_IO.Text_Streams ....................................................... 403 A.13 Exceptions in Input-Output................................................................................................... 404 A.14 File Sharing............................................................................................................................. 405 A.15 The Package Command_Line............................................................................................... 405 A.16 The Package Directories ....................................................................................................... 407 A.17 The Package Environment_Variables.................................................................................. 414 A.18 Containers .............................................................................................................................. 417 A.18.1 The Package Containers................................................................................................ 417 A.18.2 The Package Containers.Vectors ................................................................................. 417 A.18.3 The Package Containers.Doubly_Linked_Lists .......................................................... 431 A.18.4 Maps................................................................................................................................. 440 A.18.5 The Package Containers.Hashed_Maps ...................................................................... 445 A.18.6 The Package Containers.Ordered_Maps ..................................................................... 448 A.18.7 Sets .................................................................................................................................. 452 A.18.8 The Package Containers.Hashed_Sets ........................................................................ 458 A.18.9 The Package Containers.Ordered_Sets ....................................................................... 462 A.18.10 The Package Containers.Indefinite_Vectors ............................................................. 466 A.18.11 The Package Containers.Indefinite_Doubly_Linked_Lists ...................................... 467 A.18.12 The Package Containers.Indefinite_Hashed_Maps .................................................. 467 A.18.13 The Package Containers.Indefinite_Ordered_Maps ................................................. 468 A.18.14 The Package Containers.Indefinite_Hashed_Sets.................................................... 468 A.18.15 The Package Containers.Indefinite_Ordered_Sets................................................... 468 A.18.16 Array Sorting ................................................................................................................. 469

Annex B (normative) Interface to Other Languages................................................ 471
B.1 Interfacing Pragmas ................................................................................................................ 471 B.2 The Package Interfaces........................................................................................................... 474 B.3 Interfacing with C and C++ ..................................................................................................... 475 B.3.1 The Package Interfaces.C.Strings .................................................................................. 482 B.3.2 The Generic Package Interfaces.C.Pointers.................................................................. 485 B.3.3 Pragma Unchecked_Union .............................................................................................. 488 B.4 Interfacing with COBOL .......................................................................................................... 490 B.5 Interfacing with Fortran........................................................................................................... 496

Annex C (normative) Systems Programming........................................................... 499
C.1 Access to Machine Operations .............................................................................................. 499 Table of Contents 10 November 2006 vi

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual C.2 Required Representation Support..........................................................................................500 C.3 Interrupt Support......................................................................................................................500 C.3.1 Protected Procedure Handlers ........................................................................................502 C.3.2 The Package Interrupts ....................................................................................................504 C.4 Preelaboration Requirements .................................................................................................506 C.5 Pragma Discard_Names ..........................................................................................................507 C.6 Shared Variable Control ..........................................................................................................507 C.7 Task Information ......................................................................................................................509 C.7.1 The Package Task_Identification ....................................................................................509 C.7.2 The Package Task_Attributes..........................................................................................511 C.7.3 The Package Task_Termination ......................................................................................513

Annex D (normative) Real-Time Systems .................................................................515
D.1 Task Priorities...........................................................................................................................515 D.2 Priority Scheduling ..................................................................................................................517 D.2.1 The Task Dispatching Model ...........................................................................................517 D.2.2 Task Dispatching Pragmas ..............................................................................................519 D.2.3 Preemptive Dispatching ...................................................................................................520 D.2.4 Non-Preemptive Dispatching...........................................................................................521 D.2.5 Round Robin Dispatching................................................................................................522 D.2.6 Earliest Deadline First Dispatching ................................................................................524 D.3 Priority Ceiling Locking ...........................................................................................................526 D.4 Entry Queuing Policies ............................................................................................................528 D.5 Dynamic Priorities ....................................................................................................................529 D.5.1 Dynamic Priorities for Tasks ...........................................................................................529 D.5.2 Dynamic Priorities for Protected Objects.......................................................................531 D.6 Preemptive Abort......................................................................................................................532 D.7 Tasking Restrictions ................................................................................................................533 D.8 Monotonic Time ........................................................................................................................535 D.9 Delay Accuracy.........................................................................................................................538 D.10 Synchronous Task Control ...................................................................................................539 D.11 Asynchronous Task Control .................................................................................................540 D.12 Other Optimizations and Determinism Rules......................................................................541 D.13 Run-time Profiles....................................................................................................................542 D.13.1 The Ravenscar Profile ....................................................................................................543 D.14 Execution Time.......................................................................................................................544 D.14.1 Execution Time Timers...................................................................................................546 D.14.2 Group Execution Time Budgets ....................................................................................548 D.15 Timing Events .........................................................................................................................550

Annex E (normative) Distributed Systems ...............................................................553
E.1 Partitions ...................................................................................................................................553 E.2 Categorization of Library Units...............................................................................................554 E.2.1 Shared Passive Library Units ..........................................................................................555 E.2.2 Remote Types Library Units ............................................................................................556 E.2.3 Remote Call Interface Library Units ................................................................................557 E.3 Consistency of a Distributed System.....................................................................................558 E.4 Remote Subprogram Calls ......................................................................................................559 E.4.1 Pragma Asynchronous .....................................................................................................561 E.4.2 Example of Use of a Remote Access-to-Class-Wide Type ...........................................561 E.5 Partition Communication Subsystem ....................................................................................563

Annex F (normative) Information Systems ...............................................................567
F.1 Machine_Radix Attribute Definition Clause ...........................................................................567

vii

10 November 2006

Table of Contents

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual F.2 The Package Decimal............................................................................................................... 568 F.3 Edited Output for Decimal Types ........................................................................................... 569 F.3.1 Picture String Formation.................................................................................................. 570 F.3.2 Edited Output Generation ................................................................................................ 574 F.3.3 The Package Text_IO.Editing........................................................................................... 578 F.3.4 The Package Wide_Text_IO.Editing................................................................................ 581 F.3.5 The Package Wide_Wide_Text_IO.Editing ..................................................................... 581

Annex G (normative) Numerics ................................................................................. 583
G.1 Complex Arithmetic................................................................................................................. 583 G.1.1 Complex Types ................................................................................................................. 583 G.1.2 Complex Elementary Functions ..................................................................................... 588 G.1.3 Complex Input-Output ..................................................................................................... 591 G.1.4 The Package Wide_Text_IO.Complex_IO ...................................................................... 594 G.1.5 The Package Wide_Wide_Text_IO.Complex_IO............................................................ 594 G.2 Numeric Performance Requirements .................................................................................... 594 G.2.1 Model of Floating Point Arithmetic................................................................................. 595 G.2.2 Model-Oriented Attributes of Floating Point Types ...................................................... 596 G.2.3 Model of Fixed Point Arithmetic ..................................................................................... 597 G.2.4 Accuracy Requirements for the Elementary Functions ............................................... 599 G.2.5 Performance Requirements for Random Number Generation .................................... 601 G.2.6 Accuracy Requirements for Complex Arithmetic ......................................................... 601 G.3 Vector and Matrix Manipulation ............................................................................................. 603 G.3.1 Real Vectors and Matrices............................................................................................... 603 G.3.2 Complex Vectors and Matrices ....................................................................................... 608

Annex H (normative) High Integrity Systems ........................................................... 619
H.1 Pragma Normalize_Scalars..................................................................................................... 619 H.2 Documentation of Implementation Decisions ...................................................................... 620 H.3 Reviewable Object Code ......................................................................................................... 620 H.3.1 Pragma Reviewable.......................................................................................................... 620 H.3.2 Pragma Inspection_Point ................................................................................................ 621 H.4 High Integrity Restrictions ...................................................................................................... 622 H.5 Pragma Detect_Blocking ........................................................................................................ 624 H.6 Pragma Partition_Elaboration_Policy ................................................................................... 625

Annex J (normative) Obsolescent Features............................................................. 627
J.1 Renamings of Ada 83 Library Units........................................................................................ 627 J.2 Allowed Replacements of Characters.................................................................................... 627 J.3 Reduced Accuracy Subtypes.................................................................................................. 628 J.4 The Constrained Attribute ....................................................................................................... 629 J.5 ASCII .......................................................................................................................................... 629 J.6 Numeric_Error .......................................................................................................................... 630 J.7 At Clauses ................................................................................................................................. 630 J.7.1 Interrupt Entries ................................................................................................................ 630 J.8 Mod Clauses ............................................................................................................................. 632 J.9 The Storage_Size Attribute...................................................................................................... 632 J.10 Specific Suppression of Checks .......................................................................................... 632 J.11 The Class Attribute of Untagged Incomplete Types........................................................... 633 J.12 Pragma Interface .................................................................................................................... 633 J.13 Dependence Restriction Identifiers...................................................................................... 633 J.14 Character and Wide_Character Conversion Functions ..................................................... 634

Annex K (informative) Language-Defined Attributes .............................................. 635

Table of Contents

10 November 2006

viii

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

Annex L (informative) Language-Defined Pragmas .................................................651 Annex M (informative) Summary of Documentation Requirements.......................653
M.1 Specific Documentation Requirements.................................................................................653 M.2 Implementation-Defined Characteristics...............................................................................655 M.3 Implementation Advice............................................................................................................661

Annex N (informative) Glossary .................................................................................669 Annex P (informative) Syntax Summary ...................................................................675 Annex Q (informative) Language-Defined Entities...................................................703
Q.1 Language-Defined Packages ..................................................................................................703 Q.2 Language-Defined Types and Subtypes ...............................................................................705 Q.3 Language-Defined Subprograms ...........................................................................................709 Q.4 Language-Defined Exceptions ...............................................................................................717 Q.5 Language-Defined Objects .....................................................................................................718

Index ............................................................................................................................723

ix

10 November 2006

Table of Contents

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

Foreword to this version of the Ada Reference Manual
The International Standard for the programming language Ada is ISO/IEC 8652:1995(E). The Ada Working Group ISO/IEC JTC 1/SC 22/WG 9 is tasked by ISO with the work item to interpret and maintain the International Standard and to produce Technical Corrigenda, as appropriate. The technical work on the International Standard is performed by the Ada Rapporteur Group (ARG) of WG 9. In September 2000, WG 9 approved and forwarded Technical Corrigendum 1 to SC 22 for ISO approval, which was granted in February 2001. Technical Corrigendum 1 was published in June 2001. In October 2002, WG 9 approved a schedule and guidelines for the preparation of an Amendment to the International Standard. WG 9 approved the scope of the Amendment in June 2004. In April 2006, WG 9 approved and forwarded the Amendment to SC 22 for approval, which was granted in August 2006. Final ISO/IEC approval is expected by early 2007. The Technical Corrigendum lists the individual changes that need to be made to the text of the International Standard to correct errors, omissions or inconsistencies. The corrections specified in Technical Corrigendum 1 are part of the International Standard ISO/IEC 8652:1995(E). Similarly, Amendment 1 lists the individual changes that need to be made to the text of the International Standard to add new features as well as correct errors. When ISO published Technical Corrigendum 1, it did not also publish a document that merges the changes from the Technical Corrigendum into the text of the International Standard. It is not known whether ISO will publish a document that merges the changes from Technical Corrigendum and Amendment 1 into the text of the International Standard. However, ISO rules require that the project editor for the International Standard be able to produce such a document on demand. This version of the Ada Reference Manual is what the project editor would provide to ISO in response to such a request. It incorporates the changes specified in the Technical Corrigendum and Amendment into the text of ISO/IEC 8652:1995(E). It should be understood that the publication of any ISO document involves changes in general format, boilerplate, headers, etc., as well as a review by professional editors that may introduce editorial changes to the text. This version of the Ada Reference Manual is therefore neither an official ISO document, nor a version guaranteed to be identical to an official ISO document, should ISO decide to reprint the International Standard incorporating an approved Technical Corrigendum and Amendment. It is nevertheless a best effort to be as close as possible to the technical content of such an updated document. In the case of a conflict between this document and Amendment 1 as approved by ISO (or between this document and Technical Corrigendum 1 in the case of paragraphs not changed by Amendment 1; or between this document and the original 8652:1995 in the case of paragraphs not changed by either Amendment 1 or Technical Corrigendum 1), the other documents contain the official text of the International Standard ISO/IEC 8652:1995(E) and its Amendment. As it is very inconvenient to have the Reference Manual for Ada specified in three documents, this consolidated version of the Ada Reference Manual is made available to the public.
0.1/1 0.2/1

0.3/2

0.4/1

0.5/2

0.6/2

0.7/2

0.8/2

xi

10 November 2006

Foreword to this version of the Ada Reference Manual

Annexes A to J form an integral part of this International Standard. Publication as an International Standard requires approval by at least 75 % of the national bodies casting a vote. ISO/IEC JTC 1. National bodies that are members of ISO or IEC participate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. also take part in the work. Draft International Standards adopted by the joint technical committee are circulated to national bodies for voting. Annexes K to Q are for information only. Information Technology.ISO/IEC 8652:2007(E) Ed. governmental and non-governmental. ISO and IEC have established a joint technical committee. Other international organizations. ISO and IEC technical committees collaborate in fields of mutual interest. 3 — Ada Reference Manual Foreword 1 ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. 2 3 4/2 5/2 Foreword 10 November 2006 xii . This consolidated edition updates the second edition (ISO 8652:1995). In the field of information technology. International Standard ISO/IEC 8652 was prepared by Joint Technical Committee ISO/IEC JTC 1. in liaison with ISO and IEC.

Concern for the human programmer was also stressed during the design. of private types. and efficiency. the language offers support for separate compilation of program units in a way that facilitates program development and maintenance. and standardized packages oriented toward supporting important application areas. and which provides the same degree of checking between units as within a unit.ISO/IEC 8652:2007(E) Ed. and the syntax of the language avoids the use of encoded forms in favor of more English-like constructs. and of generic units are directly related to this idea. 6/2 7 8 9 xiii 10 November 2006 Introduction . This gives an introduction to the changes and new features in Ada 2005 (compared with the 1995 edition). while at the same time retaining the original emphasis on reliability. Above all. Other available Ada documents include: • Ada 95 Rationale. programming as a human activity. plus various annotations. error-prone notations have been avoided. Hence emphasis was placed on program readability over ease of writing. type extension and the hierarchical library enable a program to be modified while minimizing disturbance to existing tested and trusted components. 1 2 3/2 3. an attempt was made to keep to a relatively small number of underlying concepts integrated in a consistent and systematic way while continuing to avoid the pitfalls of excessive involution. which has ramifications in many other aspects of the language. Like many other human activities. the development of programs is becoming ever more decentralized and distributed. maintainability. 3 — Ada Reference Manual Introduction This is the Ada Reference Manual. • This paragraph was deleted. compilers can ensure that operations on variables are compatible with the properties intended for objects of the type. Since the type of a variable is invariant. The AARM contains all of the text in the consolidated Ada Reference Manual. Finally. The annotations include detailed rationale for individual rules and explanations of some of the more arcane interactions among the rules. Programmers unfamiliar with Ada 95 should read this first. and explains the rationale behind them. Consequently. Programmers should read this rationale before reading this Standard in depth. the rules of the language require that program variables be explicitly declared and that their type be specified. and efficiency. The concepts of packages. An allied concern is the maintenance of programs to match changing requirements. Furthermore. and explains the rationale behind them. the ability to assemble a program from independently produced software components continues to be a central idea in the design. This gives an introduction to the new features of Ada incorporated in the 1995 edition of this Standard. and others who wish to study the fine details. The need for languages that promote reliability and simplify maintenance is well established. It is intended primarily for compiler writers. • The Annotated Ada Reference Manual (AARM).1/2 4/1 5/2 Design Goals Ada was originally designed with three overriding concerns: program reliability and maintenance. The design especially aims to provide language constructs that correspond intuitively to the normal expectations of users. For example. • Ada 2005 Rationale. validation test writers. The 1995 revision to the language was designed to provide greater flexibility and extensibility. This amended version provides further flexibility and adds more standardized packages within the framework provided by the 1995 revision. additional control over storage management and synchronization.

Subprogram and package units may be compiled separately and arranged in hierarchies of parent and child units giving fine control over visibility of the logical properties and their detailed implementation. Such tasks may be implemented on multicomputers. For example. It may have parameters. There are two kinds of subprograms: procedures and functions. allows a program to be designed. The language provides means whereby individual organizations can construct their own libraries. A protected unit may define a single protected object or a protected type permitting the creation of several similar objects.ISO/IEC 8652:2007(E) Ed. Language Summary 11 An Ada program is composed of one or more program units. and a body. Simple mutual exclusion is provided automatically. A function is the means of invoking the computation of a value. to provide a controlled means of passing information between the procedure and the point of call. but in addition will return a result. A package is the basic unit for defining a collection of logically related entities. A protected entry specifies a Boolean expression (an entry barrier) that must be True before the body of the entry is executed. and the ability to compile units separately. Program Units A subprogram is the basic unit for expressing an algorithm. A task unit is the basic unit for defining a task whose sequence of actions may be executed concurrently with those of other tasks. update variables. packages (which define collections of entities). A procedure is the means of invoking a series of actions. For example. or produce some output. Any proposed construct whose implementation was unclear or that required excessive machine resources was rejected. multiprocessors. force these inefficiencies on all machines and on all programs. and tested as a set of largely independent software components. A protected operation can either be a subprogram or an entry. written. task units (which define concurrent computations). protected units (which define operations for the coordinated sharing of data between tasks). and more elaborate sharing protocols can be defined. Each program unit normally consists of two parts: a specification. All libraries are structured in a hierarchical manner. a package can be used to define a set of type declarations and associated operations. Most program units can be compiled separately. it may read data. It is similar to a procedure. This distinction of the specification and body. Every construct of the language was examined in the light of present implementation techniques. A task unit may define either a single executing task or a task type permitting the creation of any number of similar tasks. containing the implementation details. An Ada program will normally make use of a library of program units of general utility. Program units may be subprograms (which define executable algorithms). or with interleaved execution on a single processor. or that lead to the inefficient use of storage or execution time. The text of a separately compiled program unit must name the library units it requires. 3 — Ada Reference Manual 10 No language can avoid the problem of efficiency. 12 13 14 15 16 17 18 19/2 Introduction 10 November 2006 xiv . A protected unit is the basic unit for defining protected operations for the coordinated use of data shared between tasks. Portions of a package can be hidden from the user. or generic units (which define parameterized forms of packages and subprograms). containing the information that must be visible to other units. Languages that require over-elaborate compilers. thus allowing access only to the logical properties expressed by the package specification. which need not be visible to other units. this enables the logical decomposition of a subsystem into individual components.

An assignment statement changes the value of a variable. The enumeration types Boolean. Execution of a program unit may encounter error situations in which normal program execution cannot continue. and access types) and composite types (including array and record types). An enumeration type defines an ordered set of distinct enumeration literals. for example a list of states or an alphabet of characters. To deal with such error situations. For example. One form of the select statement allows a selective wait for one of several alternative rendezvous. A called task may accept an entry call by executing a corresponding accept statement. a constant. task units. and Wide_Wide_Character are predefined. whereupon the body of the entry is executed. blocking the caller until the operation can be performed. packages. A procedure call invokes execution of a procedure after associating any actual parameters provided at the call with the corresponding formal parameters. The declarative part associates names with declared entities. A delay statement delays the execution of a task for a specified duration or until a specified time. Case statements and if statements allow the selection of an enclosed sequence of statements based on the value of an expression or on the value of a condition. it requests an operation on a task or on a protected object. A loop statement specifies that a sequence of statements is to be executed repeatedly as directed by an iteration scheme. protected units. the statements of a program unit can be textually followed by exception handlers that specify the actions to be taken when the error situation arises. For example. which characterizes a set of values and a set of applicable operations. The sequence of statements describes a sequence of actions that are to be performed. a name may denote a type.ISO/IEC 8652:2007(E) Ed. which defines the logical entities to be used in the program unit. An entry call on a protected object is processed when the corresponding entry barrier evaluates to true. and a sequence of statements. An entry call statement is written as a procedure call statement. or an exception. a variable. an arithmetic computation may exceed the maximum allowed value of a number. which defines the execution of the program unit. A block statement comprises a sequence of statements preceded by the declaration of local entities used by the statements. Certain statements are associated with concurrent execution. or an attempt may be made to access an array component by using an incorrect index value. 20 21 22 23 24 25 26 27 28 29 30 31 32/2 xv 10 November 2006 Introduction . Exceptions can be raised explicitly by a raise statement. Data Types Every object in the language has a type. The requeue statement permits the provision of a service as a number of related activities with preference control. The loop statement provides the basic iterative mechanism in the language. A declarative part also introduces the names and parameters of other nested subprograms. numeric. The main classes of types are elementary types (comprising enumeration. which specifies the actions then to be performed as part of the rendezvous with the calling task. Character. or until an exit statement is encountered. The statements are executed in succession (unless a transfer of control causes execution to continue from another place). 3 — Ada Reference Manual Declarations and Statements The body of a program unit generally contains two parts: a declarative part. Other forms of the select statement allow conditional or timed entry calls and the asynchronous transfer of control in response to some triggering event. and generic units to be used in the program unit. Wide_Character.

Access types allow the construction of linked data structures. Wide_String. This provides a reliable form of multiple inheritance. which denote sets of consecutive integers. and components of one object may designate the same or other objects. A private type can be defined in a package so that only the logically necessary properties are made visible to the users of the type. 34/2 35 36 37 38 38. task. Exact computations use integer types. Input-output is supported for values of user-defined as well as of predefined types. Class-wide operations may be defined that accept as a parameter an operand of any type in a derivation class. From any type a new type may be defined by derivation. A value of an access type represents a reference to an object declared as aliased or to an object created by the evaluation of an allocator. A record is an object with named components of possibly different types. 3 — Ada Reference Manual 33 Numeric types provide a means of performing exact or approximate numerical computations. so that the specific type of an operand within a derivation class can be identified at run time. Task and protected types are also forms of composite types.1/2 39 40 41/2 42/2 Introduction 10 November 2006 xvi . Interface types provide abstract models from which other interfaces and types may be composed and derived. The array types String. Several variables of an access type may designate the same object. or implementation-dependent aspects. and Wide_Wide_String are predefined. or floating point types. Composite types allow definitions of structured objects with related components. The concept of a type is further refined by the concept of a subtype. arrays with a limited set of index values. The composite types in the language include arrays and records. or that the components of a record are to be represented using a given storage layout. the user can specify that objects of a given type must be represented with a given number of bits. and Duration are predefined. passed as parameters.ISO/IEC 8652:2007(E) Ed. with relative bounds on the error. Private types permit restricted views of a type. For record and private types. Record. and protected types may have special components called discriminants which parameterize the type. Subtypes can be used to define subranges of scalar types. Types that support these object-oriented capabilities of class-wide operations and type extension must be tagged. Variant record structures that depend on the values of discriminants can be defined within a record type. Approximate computations use either fixed point types. The full structural details that are externally irrelevant are then only available within the package and any child units. Access types also permit references to subprograms to be stored. Other features allow the controlled use of low level. Float. The numeric types Integer. An array is an object with indexed components of the same type. Standard means of representing values in display form are also provided. The predefined environment of the language provides for input-output and other capabilities by means of standard library packages. Other Facilities Aspect clauses can be used to specify the mapping between types and features of an underlying machine. including the direct insertion of machine code. implicit dispatching is performed based on the tag of the operand. For example. Both the elements in such linked data structures and their relation to other elements can be altered during program execution. and ultimately dereferenced as part of an indirect call. A type. with absolute bounds on the error. nonportable. the derivatives may be extensions of the parent type. together with its derivatives (both direct and indirect) form a derivation class. whereby a user can constrain the set of allowed values of a type. When an operation of a tagged type is applied to an operand whose specific type is not known until run time. and records and private types with particular discriminant values. Interface types may also be implemented by task types and protected types thereby enabling concurrent programming and inheritance to be merged.

1.). lists. See Annex B. 42. • Additional support was added for interfacing to other languages. interfacing to other languages. and highintegrity systems.1. and access to the execution environment. interrupt handling. random number generation. See clause 10. “High Integrity Systems” 52 53 54 55 56 57 57. “Numerics” Annex H. A.2. See clause 9. 3 — Ada Reference Manual The predefined standard library packages provide facilities such as string manipulation.10.5. The generic parameters can be types and subprograms (as well as objects and packages) and so allow general algorithms and data structures to be defined that are applicable to all types of a given class. The following significant changes with respect to the 1995 edition are incorporated: 57.1/2 Amendment 1 modifies the 1995 International Standard by making changes and additions that improve the capability of the language and the reliability of programs written in the language. numerical computation. See clause 3. “Real-Time Systems” Annex E. and 7. the language provides a powerful means of parameterization of program units.2/2 xvii 10 November 2006 Introduction . 3.7. mathematical functions. maps. and both the objectoriented and real-time capabilities. • Access types were extended to allow an access value to designate a subprogram or an object declared by an object declaration as opposed to just an object allocated on a heap. “Distributed Systems” Annex F.5.4.9.1 and 12. distributed systems. called generic program units. derived types. “Information Systems” Annex G. A. In particular the changes were designed to improve the portability of programs. See the discussions of classes.1/2 42. etc. • The Specialized Needs Annexes were added to provide specific support for certain application areas: • • • • • • 44/2 45/2 46/2 47/2 48/2 49/2 50/2 51/2 Annex C. and private extensions in clauses 3. 3.4. the following major language changes were incorporated: • Support for standard 8-bit and 16-bit characters was added. tagged types.6.3.3. Finally. • Efficient data-oriented synchronization was provided by the introduction of protected types. See clauses 2. record extensions. containers of various kinds (vectors.2/2 43 Language Changes This amended International Standard updates the edition of 1995 which replaced the first edition of 1987. and A.1.ISO/IEC 8652:2007(E) Ed.4. In the 1995 edition. “Systems Programming” Annex D.3. 3. • The library structure was extended to allow library units to be organized into a hierarchy of parent and child units. Additional forms of generic formal parameters were allowed as described in clauses 12. The specialized annexes define further predefined library packages and facilities with emphasis on areas such as real-time scheduling. • The type model was extended to include facilities for object-oriented programming with dynamic polymorphism.

3.1 and 10.10. D. and 7. and 8. and A. See clauses 9.5.6/2 57.5.3. 6.ISO/IEC 8652:2007(E) Ed.13.6. and constructor functions. These include new syntax which detects accidental overloading.5.1.15.6. See clause 3.3.14. See clauses 3. D. The Numerics Annex now includes support for real and complex vectors and matrices as previously defined in ISO/IEC 13813:1997 plus further basic operations for linear algebra. An alternative notation for calling operations more akin to that used in other languages has also been added.11/2 • The overall reliability of the language has been enhanced by a number of improvements.4/2 57.7/2 57. See clause G. and support for control of CPU time utilization.1. as well as pragmas for making assertions and giving better control over the suppression of checks. Execution support now includes the 32-bit character set. a comprehensive container library. See clauses 6. 3.4. Introduction 10 November 2006 xviii .2. A.2. See clauses D.2. See clauses 3. A.3. support for timing events.10. 57.4. constants.2.17.1.3.1.6.4. • Two of the Specialized Needs Annexes have been considerably enhanced: • 57.1.5. Anonymous access types are now permitted more freely and anonymous access-to-subprogram types are introduced. • The object-oriented model has been improved by the addition of an interface facility which provides multiple inheritance and additional flexibility for type extensions. 3. A.18. and D. • Access types have been further extended to unify properties such as the ability to access constants and to exclude null values. • The control of structure and visibility has been enhanced to permit mutually dependent references between units and finer control over access from the private part of a package. A.9.1. and access to environment variables. See clauses 2. A. 11. improved string handling.5.10/2 • 57. 3. file and directory management. and A.8/2 57. See clauses 3.3/2 • Support for program text is extended to cover the entire ISO/IEC 10646:2003 repertoire. and 11. further dispatching policies such as Round Robin and Earliest Deadline First. See clause 4. limited types have been made more useful by the provision of aggregates.16.5/2 57.3. • The predefined environment has been extended to include additional time and calendar operations. 3 — Ada Reference Manual 57. 3. 3. See clauses 4.9/2 The Real-Time Systems Annex now includes the Ravenscar profile for high-integrity systems. In addition.1.4. and 7.3.10.

as is the !keywords line. use square brackets [ ] to indicate text to be omitted and curly braces { } to indicate text to be added. Please use a descriptive “Subject” in your e-mail message. clause or subclause number. If appropriate. a Technical Corrigendum will be issued in accordance with the procedures. pp is the paragraph number where applicable.org. When correcting typographical errors or making minor wording suggestions. and limit each message to a single comment. and yy-mm-dd is the date the comment was sent.ss(pp) !from Author Name yy-mm-dd !keywords keywords related to topic !discussion text of discussion where ss.ss is the section. the Project Editor will initiate the defect correction procedure. Comments should use the following format: !topic Title summarizing comment !reference Ada 2005 RMss. and provide enough context to make the nature of the suggestion selfevident or put additional information in the body of the comment.ISO/IEC 8652:2007(E) Ed. if appropriate. 3 — Ada Reference Manual Instructions for Comment Submission Informal comments on this International Standard may be sent via e-mail to ada-comment@adaauth. National Bodies may submit a Defect Report to ISO/IEC JTC 1/SC 22 for resolution under the JTC 1 procedures. A response will be provided and. The date is optional. please put the correction directly as the topic of the comment. 61 58/1 59 60/2 62/1 63 64 65 xix 10 November 2006 Introduction . for example: !topic [c]{C}haracter !topic it[']s meaning is not defined Formal requests for interpretations and for reporting defects in this International Standard may be made in accordance with the ISO/IEC JTC 1 Directives and the ISO/IEC JTC 1/SC 22 policy for interpretations.

A. J. J. Månsson (TELIA Research: Sweden). J. Taft. W. M. Roubine (Verdix: France). McHugh (Secure Systems — consultant). Brosgol (consultant). Wichmann (Safety-Critical Systems — NPL: UK). G. Inc. J. White. Källberg (CelsiusTech: Sweden). van Katwijk (Delft University of Technology: The Netherlands). J. Christine M. Technical Director.ISO/IEC 8652:2007(E) Ed. P. S. E. 3 — Ada Reference Manual Acknowledgements for the Ada 95 edition of the Ada Reference Manual 66 This International Standard was prepared by the Ada 9X Mapping/Revision Team based at Intermetrics. Evans (consultant). Especially valuable contributions came from the chairman of the ARG. R. E. S. TeleSoft). Barnes (consultant). B. R. R. Mathis. Strohmeier (Swiss Fed Inst of Technology: Switzerland). Garrity. Vladik (Prospeks s. Woodger. R. A. M. A.: Czech Republic). Duff (Oak Tree Software). Chairman of DRs and XRG (University of Stuttgart: Germany). Michell (Multiprocessor Toolsmiths: Canada). Leroy (France). O. Taft (USA). Thanks go out to all of the members of the ISO/IEC JTC 1/SC 22/WG 9 Ada Rapporteur Group. T. FSU). A. Dismukes (TeleSoft). Kruchten (Rational). Goodenough (Real-Time/Systems Programming — SEI). Anderson at the Air Force Phillips Laboratory (Kirtland AFB. Dritz (Numerics — Argonne National Laboratory). Vasilescu (Grumman). Tartan. Gargaro (Distributed Systems — Computer Sciences). Barnes (consultant: UK). Heilbrunner (University of Salzburg: Austria). Ploedereder (Germany).1/1 The editor [R. the Ada 9X Implementation Analysis Team (New York University) and the Ada community-at-large. Kamrad II (Unisys). 71. the Ada 9X User/Implementer Teams (AETECH.3/1 Introduction 10 November 2006 xx . This work was regularly reviewed by the Ada 9X Distinguished Reviewers and the members of the Ada 9X Rapporteur Group (XRG): E. P. Goodenough (SEI). Hilfinger (UC/Berkeley). W. NM) was the project manager. B. Convenor of ISO/IEC JTC 1/SC 22 Working Group 9. Tokar (Tartan). Bardin (Hughes). Lester (Portsmouth Polytechnic: UK). 67 68 69 70 71 Acknowledgements for the Corrigendum version of the Ada Reference Manual 71. whose work on creating and editing the wording corrections was critical to the entire process. Shafer. J. K. B. Brett (DEC). Pazy (consultant). Kaufman (Russia). Brukardt (USA)] would like to thank the many people whose hard work and assistance has made this revision possible. O. Program Manager. Dismukes (USA). Carlson. V. D. B. J. D. S. M. Special thanks also go to the convener of ISO/IEC JTC 1/SC 22/WG 9. C. The following consultants to the Ada 9X Project contributed to the Specialized Needs Annexes: T. Michell (Canada). G. L. Rosenfeld. Power (Boeing). J. J. Kamrad (USA). S. N. K. Taylor (consultant: UK).2/1 71. Special thanks go to R. whose extremely detailed reviews kept the editor on his toes. Ishihata (Japan). B. Tokar (USA). B. which has included: W.. R. T. Mills (US Air Force). Brukardt (RR Software). Gargaro (Computer Sciences). C. Gerhardt (ESL). Other valuable feedback influencing the revision process was provided by the Ada 9X Language Precision Team (Odyssey Research Associates). Baker (Real-Time/Systems Programming — SEI. and other members too numerous to mention. Pogge (US Navy).o. J. M.r. The Ada 9X Project was sponsored by the Ada Joint Program Office. M. Special thanks go to R. without whose help and support the corrigendum and this consolidated reference manual would not have been possible. Barnes (UK) and K. Van Vlierberghe (OFFIS: Belgium). M. P. Moore (USA). Brosgol (consultant). Edwards. J. Ploedereder. Hilliard. Landwehr (CCI: Germany). Cohen (IBM). Dewar (NYU). who kept the process moving. Duff (USA) for his explanations of the previous system of formatting of these documents during the tedious conversion to more modern formats. L.

3 — Ada Reference Manual Acknowledgements for the Amendment version of the Ada Reference Manual The editor [R. Dewar (USA). M. Schonberg (USA). who always seemed to have a suggestion when we were stuck. Especially valuable contributions came from the chairman of the ARG. Heaney (USA) requires special thanks for his tireless work on the containers packages. Taft (USA). J. K. Vardanega (Italy). and T. E. and who also was usually able to provide the valuable service of explaining why things were as they are. who kept the process on schedule.P. Barnes (UK) whose careful reviews found many typographical errors. Michell (Canada). Special thanks go to Ada-Europe and the Ada Resource Association. J. Other ARG members who contributed were: R.4/2 71. Brukardt (USA)] would like to thank the many people whose hard work and assistance has made this revision possible. 71. G. Finally. Leroy (France). who pushed many of the real-time proposals to completion. E. Moore (USA). Thanks go out to all of the members of the ISO/IEC JTC 1/SC 22/WG 9 Ada Rapporteur Group. Ishihata (Japan). without whose help and support the Amendment and this consolidated reference manual would not have been possible. who guided the document through the standardization process. who found many obscure problems with the proposals. Rosen (France). Baird (USA). whose work on creating and editing the wording corrections was critical to the entire process. S. Dismukes (USA). P. T. J. S. Burns (UK). Ploedereder (Germany). Duff (USA). R.6/2 xxi 10 November 2006 Introduction . Tokar (USA). and A. special thanks go to the convener of ISO/IEC JTC 1/SC 22/WG 9.ISO/IEC 8652:2007(E) Ed.5/2 71. J.

whereas the International Standard is formatted for A4 paper (210-by-297mm). Technical Corrigendum 1. and nn is an insertion number. except: • This list of Changes is not included in the International Standard. Deleted paragraphs are indicated by the text This paragraph was deleted. while paragraphs with a version number of /2 were changed by Amendment 1 or were more recent editorial corrections. and so on. Changes to the original 8652:1995 can be identified by the version number following the paragraph number.1/1 77. 76 77 77. In addition. thus. Paragraph numbers of unchanged paragraphs are the same as in the original Ada Reference Manual. the page breaks are in different places. or editorial corrections. For instance.2.nn. the first paragraph inserted after paragraph 8 is numbered 8. In addition. 3 — Ada Reference Manual Changes 72 73 74 75 The International Standard is the same as this version of the Reference Manual.3/2 This document has been revised with the corrections specified in Technical Corrigendum 1 (ISO/IEC 8652:1995/COR.1:2007). • The title page(s) are different in the International Standard. Deleted paragraphs include empty paragraphs that were numbered in the original Ada Reference Manual.1. Paragraphs with a version number of /1 were changed by Technical Corrigendum 1 or were editorial corrections at that time. Paragraphs not so marked are unchanged by Amendment 1. • The “Acknowledgements” page is not included in the International Standard. a variety of editorial errors have been corrected.2/2 Using this version of the Ada Reference Manual 77. • The text in the running headers and footers on each page is slightly different in the International Standard. • The “Foreword to this version of the Ada Reference Manual” clause is not included in the International Standard. some versions of this document include revision bars near the paragraph numbers.ISO/IEC 8652:2007(E) Ed. the second paragraph inserted is numbered 8.4/2 Introduction 10 November 2006 xxii . where pp is the number of the preceding paragraph. the paragraph numbers are of the form pp. • This document is formatted for 8.5-by-11-inch paper.1:2001) and Amendment 1 (ISO/IEC 8652/AMD. • The “Using this version of the Ada Reference Manual” clause is not included in the International Standard. Where paragraphs are inserted. 77.

ISO/IEC 8652:2007(E) Ed. concurrent programming. a predefined environment of standard packages is provided. including facilities for. The language also covers systems programming. The language includes facilities to define packages of related types. numeric elementary functions. Ed. The operations may be implemented as subprograms using conventional sequential control structures. 1 1. and operations.1 Scope This International Standard specifies the form and meaning of programs written in Ada. The language includes a complete facility for the support of real-time. Errors can be signaled as exceptions and handled explicitly. • The effect of translating and executing such a program.1. • The manner in which program units may be combined to form Ada programs. The packages may be parameterized and the types may be extended to support the construction of libraries of reusable. Its purpose is to promote the portability of Ada programs to a variety of data processing systems. Finally. 1 2 1. 3 — Ada Reference Manual INTERNATIONAL STANDARD ISO/IEC 8652:2007(E). and random number generation. and the manner in which they are to be documented. among others. with a facility to support separate compilation. or as entries that include synchronization of concurrent threads of control as part of their invocation. adaptable software components. • The language-defined library units that a conforming implementation is required to supply. this requires precise control over the representation of data and access to system-dependent properties. The language treats modularity in the physical sense as well. 3 Information technology — Programming Languages — Ada Section 1: General Ada is a programming language designed to support the construction of long-lived. • The permissible variations within the standard. string manipulation. highly reliable software systems.1 Extent This International Standard specifies: • The form of a program written in Ada. objects. inputoutput. 1 2 3 4 5 6 1 10 November 2006 .

“Obsolescent Features” The following Specialized Needs Annexes define features that are needed by certain application areas: • Annex C.1.1. except that the material in each of the items listed below is informative: • Text under a NOTES or Examples heading. “Numerics” • Annex H. “Systems Programming” • Annex D. The core of the Ada language consists of: • Sections 1 through 13 • Annex A. “Distributed Systems” • Annex F. • Each clause or subclause whose title starts with the word “Example” or “Examples”. “Real-Time Systems” • Annex E. 7 8 9 10 11 12 13 14 15 16 17 1. • The size or speed of the object code. All implementations shall conform to the core language. 8 9 10 11 12 13 14 15 1. “Interface to Other Languages” • Annex J. 3 — Ada Reference Manual 7 • Those violations of the standard that a conforming implementation is required to detect.2 Structure 1 2 3 4 5 6 This International Standard contains thirteen sections. or the relative execution speed of different language constructs. • The form or contents of any listings produced by implementations. • The means whereby translation or execution of programs is invoked and the executing units are controlled. In addition. fourteen annexes. • Those violations of the standard that a conforming implementation is not required to detect.1 Extent 10 November 2006 2 . in particular. • The effect of unspecified execution. “High Integrity Systems” The core language and the Specialized Needs Annexes are normative. and an index. “Predefined Language Environment” • Annex B. the form or contents of error or warning messages. “Information Systems” • Annex G. This International Standard does not specify: • The means whereby a program written in Ada is transformed into object code executable by a processor. • The size of a program or program unit that will exceed the capacity of a particular conforming implementation.ISO/IEC 8652:2007(E) Ed. an implementation may conform separately to one or more Specialized Needs Annexes. and the effect of attempting to translate or execute a program containing such violations.

Each section. Implementation Requirements 32 Additional requirements for conforming implementations. Implementation Permissions 35 Additional permissions given to the implementer. text is labeled with the following headings: Syntax 18 19 20 21 22 23 24 Syntax rules (indented). “Language-Defined Pragmas” • M. including overload resolution. “Syntax Summary” Each section is divided into clauses and subclauses that have a common structure. Dynamic Semantics 29 A definition of the run-time effect of each construct.5). Post-Compilation Rules 28 Rules that are enforced before running a partition. Metrics 34 Metrics that are specified for the time/space properties of the execution of certain language constructs. A partition is legal if its compilation units are legal and it obeys all of the Post-Compilation Rules. “Language-Defined Attributes” • Annex L. 3 — Ada Reference Manual The following Annexes are informative: • Annex K. “Glossary” • Annex P. After the introductory text.ISO/IEC 8652:2007(E) Ed.1. Documentation Requirements 33 Documentation requirements for conforming implementations.1. Erroneous Execution 31 Situations that result in erroneous execution (see 1. Static Semantics 27 A definition of the compile-time effect of each construct.1. Name Resolution Rules 25 Compile-time rules that are used in name resolution. 36 3 10 November 2006 Structure 1. Bounded (Run-Time) Errors 30 Situations that result in bounded (run-time) errors (see 1. “Implementation-Defined Characteristics” • Annex N.5). Legality Rules 26 Rules that are enforced at compile time.2. clause. and subclause first introduces its subject.2 . A construct is legal if it obeys all of the Legality Rules.

• Identify all programs or program units that contain errors whose detection is required by this International Standard.7). A conforming implementation of this International Standard shall produce for the execution of a given Ada program a set of interactions with the external environment whose order and timing are consistent with the definitions and requirements of this International Standard for the semantics of the given program. An implementation that conforms to this Standard shall support each capability required by the core language as specified. The following are defined as external interactions: • Any interaction with an external file (see A. This material is informative. • Identify all programs or program units that are so large as to exceed the capacity of the implementation (or raise an appropriate exception at run time). an implementation that conforms to this Standard may conform to one or more Specialized Needs Annexes (or to none). NOTES 1 Notes emphasize consequences of the rules described in the (sub)clause or elsewhere.6). This material is informative. 1. • Supply all language-defined library units required by this International Standard. provided that they are not so large as to exceed the capacity of the implementation. • Any result returned or exception propagated from a main subprogram (see 10.8).ISO/IEC 8652:2007(E) Ed. • Any read or update of an atomic or volatile object (see C. Conformance to a Specialized Needs Annex means that each capability required by the Annex is provided as specified.3 Conformity of an Implementation with the Standard Implementation Requirements 1 2 A conforming implementation shall: • Translate and correctly execute legal programs written in Ada. The external effect of the execution of an Ada program is defined in terms of its interactions with its external environment. In addition. • Contain no variations except those explicitly permitted by this International Standard. It is implementation defined whether or not a given recommendation is obeyed.2) or an exported subprogram (see Annex B) to an external caller. 1. 3 — Ada Reference Manual Implementation Advice 37 Optional advice given to the implementer. which code_statements cause external interactions is implementation defined. • Any call on an imported subprogram (see Annex B). • The values of imported and exported objects (see Annex B) at the time of any other interaction with the external environment.1. • Specify all such variations in the manner prescribed by this International Standard. or those that are impossible or impractical to avoid given the implementation's execution environment. Examples 38 39 Examples illustrate the possible forms of the constructs described. not a requirement. • The execution of certain code_statements (see 13. The word “should” is used to indicate that the advice is a recommendation. including any parameters passed to it.2 Structure 10 November 2006 4 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .1.

library unit. Thus the two following rules are equivalent.ISO/IEC 8652:2007(E) Ed. NOTES 2 The above requirements imply that an implementation conforming to this Standard may support some of the capabilities required by a Specialized Needs Annex without supporting all required capabilities. If an implementation wishes to provide implementation-defined extensions to the functionality of a language-defined library unit. it should normally do so by adding children to the library unit.1. or pragma (respectively) specified in a Specialized Needs Annex unless the provided construct is either as specified in the Specialized Needs Annex or is more limited in capability than that required by the Annex.2. it shall not provide any attribute. 3 — Ada Reference Manual An implementation conforming to this International Standard may provide additional attributes. the set of possible effects is specified. simple_return_statement ::= return [expression].3 . A program that attempts to use an unsupported capability of an Annex shall either be identified by the implementation before run time or shall raise an exception at run time. for example: array • Square brackets enclose optional items. and the implementation may choose any effect in the set. some containing embedded underlines. or by providing some mechanism for the user to determine what happens in a particular case. for example: case_statement 1 2 3 4 5 6 7 8 9/2 • Boldface words are used to denote reserved words. it should raise Program_Error if feasible. are used to denote syntactic categories. Implementation Advice 18 19 If an implementation detects the use of an unsupported Specialized Needs Annex feature at run time. However. simple_return_statement ::= return. but documentation is not required for unspecified situations. library unit.4 Method of Description and Syntax Notation The form of an Ada program is described by means of a context-free syntax together with contextdependent requirements expressed by narrative rules. | return expression. The context-free syntax of the language is described using a simple variant of Backus-Naur Form. or pragma having the same name as an attribute. library units. In particular: • Lower case words in a sans-serif font.1. In such cases. The implementation-defined characteristics are summarized in M. 20 21 22 1. 5 10 November 2006 Conformity of an Implementation with the Standard 1. The meaning of Ada programs is described by means of narrative rules defining both the effects of each construct and the composition rules for constructs. Implementations shall document their behavior in implementation-defined situations. The implementation may choose to document implementation-defined behavior either by documenting what happens in general. Documentation Requirements 17 Certain aspects of the semantics are defined to be either implementation defined or unspecified. and pragmas.

conversions. with conversion of the results to some subtypes.4 Method of Description and Syntax Notation 10 November 2006 6 . inclusively. the evaluations. The special characters for which names are defined in this International Standard (see 2. For example. NOTES 3 The syntax rules describing structured constructs are presented in a form that corresponds to the recommended paragraphing. A construct is a piece of text (explicit or implicit) that is an instance of a syntactic category defined under “Syntax”. not “GREEK CAPITAL LETTER EPSILON”. like_this. The delimiters. Note that the effect of a program can depend on the order chosen by the implementation. reserved words. compound delimiters. so long as each expression is evaluated before converting or checking its value. the character E in the definition of exponent is the character whose name is “LATIN CAPITAL LETTER E”. and checks may be arbitrarily interspersed. For example.2/2 15 16 17 18 19 20 [else sequence_of_statements] end if. for example. in which case it stands for itself: constraint ::= scalar_constraint | composite_constraint discrete_choice_list ::= discrete_choice {| discrete_choice} 13 14 • If the name of any syntactic category starts with an italicized part. A syntactic category is a nonterminal in the grammar defined in BNF under “Syntax. The italicized part is intended to convey some semantic information. 3 — Ada Reference Manual 10 • Curly brackets enclose a repeated item. the repetitions occur from left to right as with an equivalent left-recursive rule. When this International Standard mentions the conversion of some character or sequence of characters to upper case. or any construct appearing within it.ISO/IEC 8652:2007(E) Ed. This can happen. For example subtype_name and task_name are both equivalent to name alone. term ::= factor {multiplying_operator factor} term ::= factor | term multiplying_operator factor 11 12 • A vertical line separates alternative items unless it occurs immediately after an opening curly bracket.1) belong to the same range. A constituent of a construct is the construct itself. When evaluations are defined to happen in an arbitrary order. The item may appear zero or more times.1. it means the character or sequence of characters obtained by using locale-independent full case folding. 1. or with some run-time checks. an if_statement is defined as: if_statement ::= if condition then sequence_of_statements {elsif condition then sequence_of_statements} 14. and numeric_literals are exclusively made of the characters whose code position is between 16#20# and 16#7E#. as defined by documents referenced in the note in section 1 of ISO/IEC 10646:2003. this means that the implementation shall arrange for these actions to occur in a way that is equivalent to some sequential order. Whenever the run-time semantics defines certain actions to happen in an arbitrary order. if two actual parameters of a given call have side effects. Thus the two following rules are equivalent.” Names of syntactic categories are set in a different font. it is equivalent to the category name without the italicized part.1/2 14. following the rules that result from that sequential order.

The possible effects of a given bounded error are specified for each such error. permitted. Like bounded errors. Every Ada compiler is required to generate code that raises the corresponding exception if such an error situation arises during program execution. in particular. but in any case one possible effect of a bounded error is the raising of the exception Program_Error. When operating in a nonstandard mode. the language rules define certain kinds of errors as leading to erroneous execution. These errors correspond to any violation of a rule given in this International Standard. 3 — Ada Reference Manual 4 The line breaks and indentation in the syntax rules indicate the recommended line breaks and indentation in the corresponding constructs. in the standard mode. Unlike bounded errors. the fact that a program is legal does not mean. The language rules define certain kinds of errors that need not be detected either prior to or during run time. the effect is in general not predictable. the implementation need not detect such errors either prior to or during run time. In particular. 11 7 10 November 2006 Method of Description and Syntax Notation 1. Implementation Permissions 1 2 3 4 5 6 7 8 9 10 An implementation may provide nonstandard modes of operation.ISO/IEC 8652:2007(E) Ed. or post compilation rules. • Bounded errors. The rules are further classified as either compile time rules. an implementation shall support a standard mode that conforms to the requirements of this International Standard. • Erroneous execution. legal. Typically these modes would be selected by a pragma or by a command line switch when the compiler is invoked. on the other hand. or may be postponed until the time a compilation unit is incorporated into a partition of a program. such as an excessive number of warnings or violation of coding style guidelines. Similarly. depending on whether a violation has to be detected at the time a compilation unit is submitted to the compiler. in a nonstandard mode. allowed. In any case. The corresponding error situations are associated with the names of the predefined exceptions. violation of any rule that uses the terms shall. per se. the implementation may apply special optimizations or alternative algorithms that are only meaningful for programs that satisfy certain criteria specified by the implementation. The preferred places for other line breaks are after semicolons. 21 1. • Errors that are required to be detected at run time by the execution of an Ada program.1.5 Classification of Errors Implementation Requirements The language definition classifies errors into several different categories: • Errors that are required to be detected prior to run time by every Ada implementation. The errors of this category are called bounded errors. the implementation may reject compilation_units that do not conform to additional requirements associated with the mode. all legal compilation_units shall be accepted. there is no language-specified bound on the possible effect of erroneous execution. other than those listed below. that the program is free from other forms of error. then an implementation is allowed (although not required) to report this fact at compilation time.4 . Any program that contains such an error is not a legal Ada program.1. but if not detected. If such an error situation is certain to arise in every execution of a construct. the range of possible effects shall be bounded. or illegal belongs to this category. In addition to bounded errors.

supplemented by Technical Corrigendum 1:2001 and Technical Corrigendum 2:2004.1. constitute provisions of this International Standard. Information processing — 8-bit single-byte coded character sets — Part 1: Latin alphabet No. All standards are subject to revision. Informal descriptions of some terms are also given in Annex N. their environments and system software interfaces — Extensions for the programming language C to support new character data types. ISO/IEC 14882:2003. 2 3/2 4/2 5 5. it should raise Program_Error. ISO/IEC 9899:1999. Information technology — ISO 7-bit coded character set for information interchange.2 Normative References 1 The following standards contain provisions which.5 Classification of Errors 10 November 2006 8 . ISO/IEC 10646:2003. 1. ISO/IEC 8859-1:1987. ISO/IEC 1539-1:2004.ISO/IEC 8652:2007(E) Ed. Information technology — Control functions for coded graphic character sets. ISO/IEC TR 19769:2004. Members of IEC and ISO maintain registers of currently valid International Standards.1/2 6 7/2 8/2 9/2 10/2 1. ISO 8601:2004. ISO/IEC 646:1991. through reference in this text. 1. Mathematical terms not defined in this International Standard are to be interpreted according to the CRC Concise Encyclopedia of Mathematics. indicated by italic type. Information technology — Programming languages. At the time of publication. the editions indicated were valid. 1.3 Definitions 1/2 Terms are defined throughout this International Standard. Second Edition. Information technology — Programming languages — COBOL. ISO/IEC 1989:2002. Programming languages — C. Other terms not defined in this International Standard are to be interpreted according to the Webster's Third New International Dictionary of the English Language. Information technology — Programming languages — Fortran — Part 1: Base language. Terms explicitly defined in this International Standard are not to be presumed to refer implicitly to similar terms defined elsewhere. 3 — Ada Reference Manual Implementation Advice 12 If an implementation detects a bounded error or erroneous execution. Data elements and interchange formats — Information interchange — Representation of dates and times. and parties to agreements based on this International Standard are encouraged to investigate the possibility of applying the most recent editions of the standards indicated below. Programming languages — C++. ISO/IEC 6429:1992. “Glossary”. Information technology — Universal Multiple-Octet Coded Character Set (UCS).

2/2 Any character whose General Category is defined to be “Letter. letter_modifier 9. mark_spacing_combining 9. each plane comprising 65536 characters.3/2 Any character whose General Category is defined to be “Letter. Uppercase”.ISO/IEC 8652:2007(E) Ed. 4/2 4.1/2 5/2 6/2 7/2 8/2 letter_uppercase Any character whose General Category is defined to be “Letter. 9 10 November 2006 Lexical Elements 2 . Titlecase”. Other”. The actual set of graphic symbols used by an implementation for the visual representation of the text of an Ada program is not specified. Uppercase Mapping. A character whose relative code position in its plane is 16#FFFE# or 16#FFFF# is not allowed anywhere in the text of a program.4/2 Any character whose General Category is defined to be “Mark. Characters are categorized as follows: This paragraph was deleted. Syntax 1/2 Paragraphs 2 and 3 were deleted.1/2 Any character whose General Category is defined to be “Letter. Modifier”. mark_non_spacing 9. The description of the language definition in this International Standard uses the character properties General Category. 1 2. Simple Uppercase Mapping. Pragmas.1 Character Set The character repertoire for the text of an Ada program consists of the entire coding space described by the ISO/IEC 10646:2003 Universal Multiple-Octet Coded Character Set.5/2 Any character whose General Category is defined to be “Mark. Non-Spacing”. each composed of characters. letter_titlecase 9. The semantics of an Ada program whose text is not in Normalization Form KC (as defined by section 24 of ISO/IEC 10646:2003) is implementation defined. are also described in this section. letter_lowercase 9/2 Any character whose General Category is defined to be “Letter.1/2 The coded representation for characters is implementation defined (it need not be a representation defined within ISO/IEC 10646:2003). the rules of composition are given in this section. A character is defined by this International Standard for each cell in the coding space described by ISO/IEC 10646:2003. regardless of whether or not ISO/IEC 10646:2003 allocates a character to that cell. which provide certain information for the compiler. Lowercase”. Static Semantics 3. 3 — Ada Reference Manual Section 2: Lexical Elements The text of a program consists of the texts of one or more compilations. Spacing Combining”. letter_other 9. and Special Case Condition of the documents referenced by the note in section 1 of ISO/IEC 10646:2003. The text of a compilation is a sequence of lexical elements. This coding space is organized in planes.

2/2 punctuation_connector Any character whose General Category is defined to be “Punctuation.1/2 number_letter Any character whose General Category is defined to be “Number. and which is not defined to be a format_effector. dot. 11/2 separator_space Any character whose General Category is defined to be “Separator.1/2 other_control Any character whose General Category is defined to be “Other. 13. 13. 10. – . Letter”. 16#0A# (LINE FEED). 16#0B# (LINE TABULATION). and whose relative code position in its plane is neither 16#FFFE# nor 16#FFFF#. and the characters in categories separator_line and separator_paragraph. 16#85# (NEXT LINE). 16#0C# (FORM FEED).2/2 other_private_use Any character whose General Category is defined to be “Other. Private Use”. Control”. < = > _ | / ! % name colon semicolon less-than sign equals sign greater-than sign low line. name quotation mark number sign ampersand apostrophe. 3 — Ada Reference Manual number_decimal 10/2 Any character whose General Category is defined to be “Number. Space”. multiply plus sign comma hyphen-minus. 15/2 The following names are used when referring to certain characters (the first name is that given in ISO/IEC 10646:2003): graphic symbol " # & ' ( ) * + . other_surrogate. format_effector. Surrogate”. minus full stop. 12/2 separator_line Any character whose General Category is defined to be “Separator. divide exclamation point percent sign 2. 10. 13. Connector”. underline vertical line solidus. point graphic symbol : . 13/2 format_effector The characters whose code positions are 16#09# (CHARACTER TABULATION).ISO/IEC 8652:2007(E) Ed. Decimal”.3/2 other_format Any character whose General Category is defined to be “Other. tick left parenthesis right parenthesis asterisk. other_private_use.3/2 other_surrogate Any character whose General Category is defined to be “Other. 10. Paragraph”. Line”.1 Character Set 10 November 2006 10 . Format”. 16#0D# (CARRIAGE RETURN). 12. 14/2 graphic_character Any character that is not in the categories other_control.1/2 separator_paragraph Any character whose General Category is defined to be “Separator.

2 Lexical Elements. ** := /= >= <= << >> <> Each of the special characters listed for single character delimiters is a single delimiter except if this character is used as a character of a compound delimiter. A delimiter is either one of the following characters: & ' ( ) * + . a reserved word. However. reserved word. the representation for an end of line is implementation defined. 3 — Ada Reference Manual Implementation Permissions This paragraph was deleted. One or more separators are allowed between any two adjacent lexical elements. a string_literal. a string_literal. A separator is any of a separator_space. a format_effector. character_literal. • The character whose code position is 16#09# (CHARACTER TABULATION) is a separator except within a comment. 2 The language does not specify the source representation of programs. Separators. < = > | 1 2/2 3/2 4/2 5/2 6 7 8/2 9 10 11 12 or one of the following compound delimiters each composed of two adjacent special characters => . before the first of each compilation. as follows: • A separator_space is a separator except within a comment. At least one separator is required between an identifier. / : . or a character_literal. In some cases an explicit separator is required to separate adjacent lexical elements. string_literal.. In general. 16/2 17/2 18 2. a sequence of one or more format_effectors other than the character whose code position is 16#09# (CHARACTER TABULATION) signifies at least one end of line. 11 10 November 2006 Character Set 2. or after the last. The meaning of a program depends only on the particular sequences of lexical elements that form its compilations. a reserved word. Each lexical element is formed from a sequence of characters. or a numeric_literal and an adjacent identifier. or numeric_literal.1 . The text of a compilation is divided into lines. and is either a delimiter. • The end of a line is always a separator. or the end of a line. other_private_use. a numeric_literal. The text of each compilation is a sequence of separate lexical elements. an identifier. or a comment. – . excluding comments. NOTES 1 The characters in categories other_control. and Delimiters Static Semantics The text of a program consists of the texts of one or more compilations.ISO/IEC 8652:2007(E) Ed. and other_surrogate are only allowed in comments. or as a character of a comment. a character_literal. or numeric_literal.

an identifier shall not contain two consecutive characters in category punctuation_connector. 3 — Ada Reference Manual 13 The following names are used when referring to compound delimiters: delimiter => .ISO/IEC 8652:2007(E) Ed. or end with a character in that category. ** := /= >= <= << >> <> name arrow double dot double star. The maximum supported line length and lexical element length are implementation defined.2 Lexical Elements.3 Identifiers 1 Identifiers are used as names.. not counting any characters used to signify the end of a line. 2. An implementation shall support lexical elements of at least 200 characters in length. exponentiate assignment (pronounced: “becomes”) inequality (pronounced: “not equal”) greater than or equal less than or equal left label bracket right label bracket box Implementation Requirements 14 An implementation shall support lines of at least 200 characters in length. 2. Syntax 2/2 identifier ::= identifier_start {identifier_start | identifier_extend} identifier_start ::= letter_uppercase | letter_lowercase | letter_titlecase | letter_modifier | letter_other | number_letter identifier_extend ::= mark_non_spacing | mark_spacing_combining | number_decimal | punctuation_connector | other_format 3/2 3.1/2 4/2 After eliminating the characters in category other_format. Separators. and Delimiters 10 November 2006 12 .

2 3 2.1/2 Examples of identifiers: Count X Get_Symbol Snobol_4 X1 Page_Count Πλάτων -.1 Decimal Literals A decimal_literal is a numeric_literal in the conventional decimal notation (that is. an integer literal is a numeric_literal without a point. The type of a real literal is universal_real.Tchaikovsky θ φ -. an implementation may support other upper/lower case equivalence rules for identifiers.4 Numeric Literals There are two kinds of numeric_literals.ISO/IEC 8652:2007(E) Ed. Syntax 1 decimal_literal ::= numeral [.3/2 In a nonstandard mode.4. the base is ten). • The remaining sequence of characters is converted to upper case. An exponent indicates the power of ten by which the value of the decimal_literal without the exponent is to be multiplied to obtain the value of the decimal_literal with the exponent. real literals and integer literals. NOTES 3 Identifiers differing only in the use of corresponding upper and lower case letters are considered the same.1/2 5. Implementation Permissions 5/2 5. Examples 6 6. After applying these transformations.Plato Чайковский -.2/2 5. 3 — Ada Reference Manual Static Semantics Two identifiers are considered the same if they consist of the same sequence of characters after applying the following transformations (in this order): • The characters in category other_format are eliminated.3 6 7 . with the same meaning.1/2 5 An exponent for an integer literal shall not have a minus sign. to accommodate local conventions. an identifier shall not be identical to a reserved word (in upper case). 13 10 November 2006 Identifiers 2. Static Semantics An underline character in a numeric_literal does not affect its meaning.Angles Ethelyn Marion Store_Next_Item 7 8/2 2. The letter E of an exponent can be written either in lower case or in upper case.numeral] [exponent] numeral ::= digit {[underline] digit} exponent ::= E [+] numeral | E – numeral digit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 2 3 4 4. Syntax 1 numeric_literal ::= decimal_literal | based_literal NOTES 4 The type of an integer literal is universal_integer. A real literal is a numeric_literal that includes a point.

4. Syntax 2 character_literal ::= 'graphic_character' NOTES 5 A character_literal is an enumeration literal of a character type.real literals 2.0 2. An exponent indicates the power of the base by which the value of the based_literal without the exponent is to be multiplied to obtain the value of the based_literal with the exponent.1111_1111_1110#E11 -.5.1 Decimal Literals 10 November 2006 14 .integer literals of value 224 -.2 Based Literals 1 A based_literal is a numeric_literal expressed in a form that specifies the base explicitly. The extended_digits A through F can be written either in lower case or in upper case.5 Character Literals 1 A character_literal is formed by enclosing a graphic character between two apostrophe characters. Syntax 2 based_literal ::= base # based_numeral [. respectively. See 3.456 123_456 -. Static Semantics 7 The conventional meaning of based notation is assumed. are in decimal notation.0 1E6 0.0 0 0.4. 3 — Ada Reference Manual Examples 8 9 Examples of decimal literals: 12 12. The extended_digits A through F represent the digits ten through fifteen.integer literals of value 255 -. 3 2.ISO/IEC 8652:2007(E) Ed. if any.14159_26 -.based_numeral] # [exponent] base ::= numeral based_numeral ::= extended_digit {[underline] extended_digit} extended_digit ::= digit | A | B | C | D | E | F Legality Rules 3 4 5 6 The base (the numeric value of the decimal numeral preceding the first #) shall be at least two and at most sixteen. The base and the exponent. with the same meaning.2. The value of each extended_digit of a based_literal shall be less than the base.FF#E+2 16#FF# 016#0ff# 2#1110_0000# 2#1. Examples 8 9 10 Examples of based literals: 2#1111_1111# 16#E#E1 16#F.integer literals 3.real literals of value 4095.

ISO/IEC 8652:2007(E) Ed.1). %.a null string literal -. Syntax 1 string_literal ::= "{string_element}" string_element ::= "" | non_quotation_mark_graphic_character 2 3 4 A string_element is either a pair of quotation marks (""). in the given order. 7 No transformation is performed on the sequence of characters of a string_literal.6 String Literals A string_literal is formed by a sequence of graphic characters (possibly none) enclosed between two quotation marks used as string brackets. and any other string_element being reproduced in the sequence. with a string_element that is "" becoming a single quotation mark in the sequence of characters. Examples 5 6 7 7. Syntax 1 comment ::= --{non_end_of_line_character} 2 3 A comment may appear on any line of a program.3). values of a string type (see 4. NOTES 6 An end of line cannot appear in a string_literal.Big numbers .1/2 Examples of string literals: "Message of the day:" "" " " "A" """" -.2). or a single graphic_character other than a quotation mark.7 Comments A comment starts with two adjacent hyphens and extends up to the end of the line. 3 — Ada Reference Manual Examples Examples of character literals: 'A' 'L' '∞' '*' 'Л' '‫'א‬ ''' 'Λ' ' ' -. and } are allowed in string literals" "Archimedes said ""Εύρηκα""" "Volume of cylinder (πr²h) = " 2. -. A null string literal is a string_literal with no string_elements between the quotation marks.infinity and aleph. and array subaggregates (see 4.Various els. 4 5/2 2.5 . 15 10 November 2006 Character Literals 2. They are used to represent operator_symbols (see 6.three string literals of length 1 8 9/2 "Characters such as $.3. Static Semantics The sequence of characters of a string_literal is formed from the sequence of string_elements between the bracketing quotation marks.

There are language-defined pragmas that give instructions for optimization.7 Comments 10 November 2006 16 . pragma_argument_association})]. any pragma_argument_associations without a pragma_argument_identifier shall precede any associations with a pragma_argument_identifier.the first two hyphens start the comment 2. Inside such a pragma. listing control. Examples 5 6 Examples of comments: -. but not within a formal_part or discriminant_part. Additional syntax rules and placement restrictions exist for specific pragmas. • At any place where the syntax rules allow a construct defined by a syntactic category whose name ends with "declaration". The name or expression of a pragma_argument_association is a pragma argument. etc.two or more consecutive lines ---------------. "clause". pragma_argument_association ::= [pragma_argument_identifier =>] name | [pragma_argument_identifier =>] expression 3 4 In a pragma.8 Pragmas 1 A pragma is a compiler directive. comments do not influence the meaning of a program. or one of the syntactic categories variant or exception_handler. "statement".the last sentence above echoes the Algol 68 report end. 3 — Ada Reference Manual Static Semantics 4 The presence or absence of comments has no influence on whether a program is legal or illegal. Pragmas are only allowed at the following places in a program: 5 6 7 • After a semicolon delimiter. Syntax 2 pragma ::= pragma identifier [(pragma_argument_association {. 2. Also at any place where a compilation_unit would be allowed. -. The name of a pragma is the identifier following the reserved word pragma. their sole purpose is the enlightenment of the human reader.processing of Line is complete -.ISO/IEC 8652:2007(E) Ed. then it has no effect on the semantics of the program. Furthermore.a long comment may be split onto -. the only rules that apply are the Syntax Rules. or "alternative". An implementation may support additional (implementation-defined) pragmas. but not in place of such a construct. Static Semantics 8 9 10 11 If an implementation does not recognize the name of a pragma. An identifier specific to a pragma is an identifier that is used in a pragma argument with special meaning for that pragma.

or that optional optimizations should be turned off. A pragma Page is allowed anywhere a pragma is allowed. It gives advice to the implementation as to whether time or space is the primary optimization criterion. It is implementation defined how this advice is followed. Implementation Requirements 12 The implementation shall give a warning message for an unrecognized pragma name. this execution consists of the evaluation of each evaluable pragma argument in an arbitrary order. removing. Space. except as follows: • A pragma used to complete a declaration. to the end of the compilation. that is. the program should still be legal. It specifies that the program text which follows the pragma should start on a new page (if the compiler is currently producing a listing). or Off as the single argument. pragma Page. or for a pragma at the place of a compilation_unit. Page. The pragma itself is always listed if the compiler is producing a listing. implementation-defined pragmas should have no semantic effect for error-free programs. Normally. Other pragmas are defined throughout this International Standard. such as a pragma Import. pragma Optimize(identifier). This pragma is allowed anywhere a pragma is allowed. An implementation may ignore an unrecognized pragma even if it violates some of the Syntax Rules. A pragma Optimize takes one of the identifiers Time. • A pragma used to configure the environment by adding. and Optimize pragmas are as follows: pragma List(identifier). 3 — Ada Reference Manual Dynamic Semantics Any pragma that appears at the place of an executable construct is executed. 25 26 27 17 10 November 2006 Pragmas 2.8 . and should still have the same semantics. an implementation should not define pragmas that can make an illegal program legal. Unless otherwise specified for a particular pragma. the name of an implementation-defined pragma shall differ from those of the language-defined pragmas. or replacing library_items. It specifies that listing of the compilation is to be continued or suspended until a List pragma with the opposite argument is given within the same compilation. and it applies until the end of the immediately enclosing declarative region. Implementation Advice 14 15 Normally. Syntax 16 17 18 19 The forms of List. if the implementation-defined pragmas are removed from a working program.ISO/IEC 8652:2007(E) Ed. Implementation Permissions 13 An implementation may provide implementation-defined pragmas. Static Semantics 20 21 22 23 24 A pragma List takes one of the identifiers On or Off as the single argument. This pragma is allowed anywhere a pragma is allowed. if detecting the syntax error is too complex. and are summarized in Annex L.

abort abs abstract accept access aliased all and array at begin body case constant declare delay delta digits do else elsif end entry exception exit for function generic goto if in interface is limited loop mod new not null of or others out overriding package pragma private procedure protected raise range record rem renames requeue return reverse select separate subtype synchronized tagged task terminate then type until use when while with xor 3 NOTES 8 The reserved words appear in lower case boldface in this International Standard.import C putchar function 2.turn off listing generation Optimize(Off).generate code for Set_Mask inline Import(C. The following are the reserved words. Lower case boldface is also used for a reserved word in a string_literal used as an operator_symbol.ISO/IEC 8652:2007(E) Ed.turn off optional optimizations Inline(Set_Mask). -. -.1. 2. Within a program. -. and one or more characters in category other_format may be inserted within or at the end of the reserved word. some or all of the letters of a reserved word may be in upper case. External_Name => "putchar"). 3 — Ada Reference Manual Examples 28 29/2 Examples of pragmas: pragma pragma pragma pragma List(Off).4). except when used in the designator of an attribute (see 4.8 Pragmas 10 November 2006 18 .9 Reserved Words Syntax 1/1 2/2 This paragraph was deleted. -. This is merely a convention — programs may be written in whatever typeface is desired and available. Put_Char.

a subprogram_body. or may be supposed to occur at a given place in the text as a consequence of the semantics of another construct (an implicit declaration).3). A view consists of an identification of the entity (the entity of the view). 5 6/2 7 8 19 10 November 2006 Declarations and Types 3 .5)). For each declaration. a declaration also contains the definition for the entity itself (a renaming_declaration is an example of a declaration that does not define a new entity.ISO/IEC 8652:2007(E) Ed. Syntax 1 2 basic_declaration ::= type_declaration | object_declaration | subprogram_declaration | null_procedure_declaration | renaming_declaration | generic_declaration defining_identifier ::= identifier 3/2 | subtype_declaration | number_declaration | abstract_subprogram_declaration | package_declaration | exception_declaration | generic_instantiation 4 Static Semantics A declaration is a language construct that associates a name with (a view of) an entity. the view. In most cases. A declaration may appear explicitly in the program text (an explicit declaration). In addition. an entry_declaration. All declarations contain a definition for a view of an entity. Each of the following is defined to be a declaration: any basic_declaration. 1 3. plus view-specific characteristics that affect the use of the entity through that view (such as mode of access to an object. but sometimes by a defining_character_literal or defining_operator_symbol. and the associated entity (see 8. the name is said to denote the declaration. Within its scope. the language rules define a certain region of text called the scope of the declaration (see 8. a discriminant_specification. a component_declaration.1 Declarations The language defines several kinds of named entities that are declared by declarations. At such places the identifier is said to be a name of the entity (the direct_name or selector_name). and in most cases. an extended_return_statement is a declaration of its defining_identifier. 3 — Ada Reference Manual Section 3: Declarations and Types This section describes the types in the language and the rules for declaring constants. there are places where it is possible to use the identifier to refer to the declaration. the view.6). the entity itself. usually by a defining_identifier. or visibility to components of a type). There are several forms of declaration. an entry_index_specification. a parameter_specification. and the associated entity. a loop_parameter_specification.2). The entity's name is defined by the declaration. and only there. and named numbers. Most declarations associate an identifier with a declared entity. the view it defines. The declaration is said to declare the name. A basic_declaration is a form of declaration defined as follows. formal parameter names and defaults for a subprogram. these places are defined by the visibility rules (see 8. an enumeration_literal_specification. but instead defines a view of an existing entity (see 8. variables. a generic_formal_parameter_declaration. a choice_parameter_specification.

Types are grouped into categories of types.5. These are collectively called usage names.2 Types and Subtypes Static Semantics 1 A type is characterized by a set of values. and defining_operator_symbol for the defining occurrence of a name. subcomponent. subcomponent. and operator_symbols.2. 3 — Ada Reference Manual 9 As an alternative to an identifier. NOTES 1 At compile time. An incomplete or partial view is considered a composite type. interface types. Where other subcomponents are excluded. record extensions.1). Dynamic Semantics 10 11 The process by which a construct achieves its run-time effect is called execution. and a function can be declared with an operator_symbol as its name (see 6.1 Declarations 10 November 2006 20 . or initialization of other components. the elaboration of the declaration creates the entity. or part of objects and values of the type. or a component of another subcomponent. or any set of its subcomponents. task types. an enumeration literal can be declared with a character_literal as its name (see 3. At run time. The elementary types are the scalar types (discrete and real) and the access types (whose values provide access to objects or subprograms). The term subcomponent is used in this International Standard in place of the term component to indicate either a component. these are collectively called defining names. a part of an object or value is used to mean the whole object or value. defining_character_literal. Discriminants can be thought of as parameters of the type. An object of a given type is a run-time entity that contains (has) a value of the type. constraints.3) of a type. The full view (see 3. character_literals. Certain composite types (and views thereof) have special components called discriminants whose values affect the presence.ISO/IEC 8652:2007(E) Ed. and a set of primitive operations which implement the fundamental aspects of its semantics. the declaration of an entity declares the entity. Real types are either floating point types or fixed point types. The terms direct_name and selector_name are used for usage occurrences of identifiers.1/2 5/2 6/2 3.1) of a type with a very restricted usage. Elementary types are those whose values are logically indivisible. even if the full view is not. The syntax rules use the terms defining_identifier. the term component is used instead. providing support for data abstraction. This process is also called elaboration for declarations and evaluation for expressions. One of the terms execution. A private type or private extension represents a partial view (see 7. or evaluation is defined by this International Standard for each construct that has a run-time effect.1). An incomplete type represents an incomplete view (see 3. The terms component. There exist several language-defined categories of types (see NOTES below). elaboration. providing support for recursive data structures. Most categories of types form classes of types. composite types are those whose values are composed of component values. and protected types.1) of a type represents its complete definition. reflecting the similarity of their values and primitive operations. Similarly. 12 3. array types. The composite types are the record types. Discrete types are either integer types or are defined by enumeration of their values (enumeration types). There can be multiple views of a type with varying sets of operations. 2/2 3 4/2 4.10. and part are also applied to a type meaning the component.

These language-defined categories are organized like this: all types elementary scalar discrete enumeration character boolean other enumeration integer signed integer modular integer real floating point fixed point ordinary fixed point decimal fixed point access access-to-object access-to-subprogram composite untagged array string other array record task protected tagged (including interfaces) nonlimited tagged record limited tagged limited tagged record 7/2 8/2 9 10/2 11/2 12/2 21 10 November 2006 Types and Subtypes 3. The given type is called the type of the subtype.6. the following are examples of “interesting” language-defined categories: abstract.ISO/IEC 8652:2007(E) Ed. character. Such values belong to the subtype.10). access-toobject. NOTES 2 Any set of types can be called a “category” of types. task. Special syntax is provided to define types in each of these classes. and any set of types that is closed under derivation (see 3. scalar.3). composite. access. decimal fixed point. nonlimited. A subtype is called an unconstrained subtype if its type has unknown discriminants. only certain categories and classes are used in the description of the rules of the language — generally those that have their own particular set of primitive operations (see 3. In addition to these classes.1 for discriminant_constraints. but the subtype does not impose such a constraint. The set of possible values for an object of an access type can also be subjected to a condition that excludes the null value (see 3. ordinary fixed point. access-to-subprogram. or discriminant constraints. 3 — Ada Reference Manual The set of possible values for an object of a given type can be subjected to a condition that is called a constraint (the case of a null constraint that specifies no restriction is also included). The set of values of a subtype consists of the values of its type that satisfy its constraint and any exclusion of the null value. However. and 3. discrete.4) can be called a “class” of types. index. A subtype of a given type is a combination of the type. real.2 . modular. numeric. incomplete.5). 3. boolean. integer.5 for range_constraints. string. and certain attributes specific to the subtype. or if its type allows range. private. protected. tagged. record. (untagged) record. the rules for which values satisfy a given kind of constraint are given in 3.2. enumeration. signed integer. Similarly. or that correspond to a set of types that are matched by a given kind of generic formal type (see 12.1 for index_constraints. The following are examples of “interesting” language-defined classes: elementary. the subtype is called a constrained subtype (since it has no unconstrained characteristics). limited.7. floating point. array. interface. the associated constraint is called the constraint of the subtype. fixed point. a constraint on values of the type. otherwise.

and uses such pseudo-names at places where the syntax normally requires an identifier. | task_type_declaration | protected_type_declaration type_definition ::= enumeration_type_definition | real_type_definition | record_type_definition | derived_type_definition 3 4/2 | integer_type_definition | array_type_definition | access_type_definition | interface_type_definition Legality Rules 5 A given type shall not have a subcomponent whose type is the given type itself. which represent other categorization dimensions.5. they are partial or incomplete views of some full type. The type_definition. if any. as specified in 4. The remainder of the type_declaration defines the remaining characteristics of (the view of) the type. according to what classes the type belongs. protected_definition. A type defined by a type_declaration is a named type. “Operators and Expression Evaluation”. root_integer.7. The type defined by such a declaration is anonymous — it has no nameable subtypes. this International Standard sometimes refers to the type of T as simply “the type T”. For explanatory purposes. and universal_integer) are the types that are defined in a predefined library package called Standard. Certain other forms of declaration also include type definitions as part of the declaration for an object. Integer. The declaration of a full type also declares the full view of the type. such as “numeric” and “discriminated”. The predefined types (for example the types Boolean. but do not fit into the above strictly hierarchical picture. 3. or an anonymous type that is defined by an access_definition or as part of declaring an object of the type. this International Standard sometimes refers to an anonymous type by a pseudo-name. Types declared by other forms of type_declaration are not separate types. or access_definition that defines a full type is called a full type definition. is called a full type. this 3. A named type that is declared by a full_type_declaration. For a named type whose first subtype is T.ISO/IEC 8652:2007(E) Ed. defines the discriminants of the type (see 3. “Discriminants”). Syntax 2 type_declaration ::= full_type_declaration | incomplete_type_declaration | private_type_declaration | private_extension_declaration full_type_declaration ::= type defining_identifier [known_discriminant_part] is type_definition. task_definition. 3 — Ada Reference Manual synchronized tagged tagged task tagged protected 13/2 There are other categories. The known_discriminant_part. written in italics. The definition of a type implicitly declares certain predefined operators that operate on the type.1 Type Declarations 1 A type_declaration declares a type and its first subtype. such a type has one or more nameable subtypes.2 Types and Subtypes 10 November 2006 22 7/2 8/2 9 10 . Static Semantics 6 The defining_identifier of a type_declaration denotes the first subtype of the type.2. Wide_Character.

72 array(1 . Black) range 1 . Blue. If the subtype_indication does not include a constraint. Yellow. Dynamic Semantics 8 The elaboration of a subtype_declaration consists of the elaboration of the subtype_indication.3. 14 15 16 3. its type is anonymous — it has no nameable subtypes. 72. Examples 11 Examples of type definitions: (White. Yellow. Although names do not directly denote types. For an example of the definition of an anonymous type. Syntax 1 subtype_declaration ::= subtype defining_identifier is subtype_indication. The elaboration of a subtype_indication that includes a constraint proceeds as follows: 9 23 10 November 2006 Type Declarations 3. a phrase like “the type Column” is sometimes used in this International Standard to refer to the type of Column.2). Green. see the declaration of the array Color_Table in 3. NOTES 3 Each of the above examples declares a named type. Other named subtypes of the type can be declared with subtype_declarations (see 3. Each elaboration of a full type definition creates a distinct type and its first subtype.2.1 . The identifier given denotes the first subtype of the type. Red. as defined by a subtype_indication.. Brown.. 3 — Ada Reference Manual package also includes the (implicit) declarations of their predefined operators. type Column is range 1 . 10) of Integer 12 13 Examples of type declarations: type Color is (White. subtype_indication ::= [null_exclusion] subtype_mark [constraint] subtype_mark ::= subtype_name constraint ::= scalar_constraint | composite_constraint scalar_constraint ::= range_constraint | digits_constraint | delta_constraint composite_constraint ::= index_constraint | discriminant_constraint Name Resolution Rules 2 3/2 4 5 6 7 A subtype_mark shall resolve to denote a subtype. Brown.2. Dynamic Semantics The elaboration of a full_type_declaration consists of the elaboration of the full type definition. Black)..1. 10) of Integer..ISO/IEC 8652:2007(E) Ed. the new subtype has the same (possibly null) constraint as that denoted by the subtype_mark. where Column denotes the first subtype of the type. The package Standard is described in A. Green.1. The elaboration of a subtype_indication creates a new subtype. Blue.2 Subtype Declarations A subtype_declaration declares a subtype of some previously declared type. The type determined by a subtype_mark is the type of the subtype denoted by the subtype_mark. Red. type Table is array(1 .2.

These rules are such that if a constraint is compatible with a subtype.1 see 3. Blue. Examples 12 13 14 15/2 Examples of subtype declarations: subtype subtype subtype subtype subtype subtype subtype subtype Rainbow Red_Blue Int Small_Int Up_To_K Square Male Binop_Ref is is is is is is is is Color range Red .ISO/IEC 8652:2007(E) Ed. Person(Sex => M). • A check is then made that the constraint is compatible with the subtype denoted by the subtype_mark. Integer. The condition imposed by a constraint is the condition obtained after elaboration of the constraint.10 3.1). Matrix(1 . On the other hand. the inherited (see 3.. or other language-defined operation such as assignment or a membership test. the enumeration literals (which are considered parameterless functions — see 3. that operates on a type.1 see 3. Rainbow. or if it has an access parameter or access result type (see 6.3 Classification of Operations Static Semantics 1/2 An operation operates on a type T if it yields a value of type T.2 Subtype Declarations 10 November 2006 24 .1 and 3. if it has an operand whose expected type (see 8. 10). • For a derived type. • For a specific type declared immediately within a package_specification.3). The rules defining compatibility are given for each form of constraint in the appropriate subclause.2.1) designating T. and J.3) other implicitly declared primitive subprograms of the type. K.1). Integer range -10 . not null Binop_Ptr. even if the subtype is already constrained. 2 3 4 5 6 7/2 8 3. • For an enumeration type.4) user-defined subprograms. 1 ..9. • For a nonformal type. 3 — Ada Reference Manual 10 11 • The constraint is first elaborated.6.6 see 3. The exception Constraint_Error is raised if any check of compatibility fails. Column range 1 . The primitive subprograms of a specific type are defined as follows: • The predefined operators of the type (see 4.10.5. NOTES 4 A scalar_constraint may be applied to a subtype of an appropriate scalar type (see 3.1 ----- see 3. plus any user-defined primitive subprograms. -. A predefined operator..6) is T.. is called a predefined operation of the type.2.5. a composite_constraint may be applied to a composite subtype (or an access-to-composite subtype) only if the composite subtype is unconstrained (see 3.see 3. A primitive subprogram whose designator is an operator_symbol is called a primitive operator.7. The primitive operations of a type are the predefined operations of the type. then the condition imposed by the constraint cannot contradict any condition already imposed by the subtype on its values. 10.5).. 10.2. any subprograms not covered above that are explicitly declared immediately within the same declarative region as the type and that override (see 8. any subprograms (in addition to the enumeration literals) that are explicitly declared immediately within the same package_specification and that operate on the type. 3.5.2.

or entry index. • a loop parameter. At the place where a view of an object is defined. The following (and no others) represent constants: • an object declared by an object_declaration with the reserved word constant.6.1). Prior to reclaiming the storage for an object. • a choice parameter of an exception_handler. • an entry index of an entry_body. Static Semantics 1 All of the following are objects: • the entity declared by an object_declaration. The value of a constant object cannot be changed between its initialization and its finalization. • a component. A subtype is an indefinite subtype if it is an unconstrained array subtype. • the dereference of an access-to-constant value. • a generic formal object. The value of an object is read when the value of any part of the object is evaluated. a view of an object is either a constant or a variable. or if it has unknown discriminants or unconstrained discriminants without 25 10 November 2006 Objects and Named Numbers 3. slice. evaluating an allocator. or view conversion of another object. whereas the value of a variable object can be changed. • the result of evaluating a function_call or an aggregate. • a formal parameter of a subprogram. slice. An object is either a constant object or a variable object. Whether a view of an object is constant or variable is determined by the definition of the view. it always is if the nominal subtype is an indefinite subtype. Similarly.6). • the return object created as the result of evaluating a function_call (or the equivalent operator invocation — see 6. • the result of dereferencing an access-to-object value (see 4.3 Objects and Named Numbers Objects are created at run time and contain a value of a given type. • a discriminant. 3 — Ada Reference Manual 3. choice parameter. its subtype) can be more restrictive than the nominal subtype of the view. or when the value of an enclosing object is evaluated. An object can be created and initialized as part of elaborating a declaration. A constant view of a variable object cannot be used to modify the value of the variable. or passing a parameter by copy. or view conversion of a constant. aggregate. entry. or when an assignment is performed to an enclosing object. The value of a variable is updated when an assignment is performed to any part of the variable. • a formal parameter or generic formal object of mode in. or generic subprogram. a nominal subtype is associated with the view. The object's actual subtype (that is. • the result of evaluating an aggregate. • a loop parameter. • a selected_component. it is finalized if necessary (see 7. indexed_component. The terms constant and variable by themselves refer to constant and variable views of objects.ISO/IEC 8652:2007(E) Ed. All views of a constant object are constant. or function_call.3 2 3 4 5 6 7 8 9 10/2 11 12 13 14 15 16 17 18 19 20 21 22 23 .1).

4.3 Objects and Named Numbers 10 November 2006 26 . in the same order as the list. the object_declaration may include the definition of the (anonymous) type of the object. between its initialization and finalization. or protected object. For a discriminated or array object. 25 26 3. Static Semantics 6 An object_declaration with the reserved word constant declares a constant object. | single_task_declaration | single_protected_declaration defining_identifier_list ::= defining_identifier {.ISO/IEC 8652:2007(E) Ed. The rules for deferred constant declarations are given in clause 7. NOTES 5 A constant cannot be the target of an assignment operation. If it has a subtype_indication or an array_type_definition that defines an indefinite subtype. nor be passed as an in out or out parameter.1). if any. A component cannot have an indefinite nominal subtype. optionally. if the nominal subtype is constrained then so is the actual subtype.3. This expression is called the initialization expression. 7 3. the type expected for the expression is that of the object. Any declaration that includes a defining_identifier_list with more than one defining_identifier is equivalent to a series of declarations each containing one defining_identifier from the list. | defining_identifier_list : [aliased] [constant] access_definition [:= expression]. The remainder of this International Standard relies on this equivalence. For an array. an additional constraint or explicit initialization expression is necessary (see 3. 24 A named number provides a name for a numeric value known at compile time.7). Otherwise it is called a deferred constant declaration. an explicit initial value given by an initialization expression. 6 The nominal and actual subtypes of an elementary object are always the same. The rules for full constant declarations are given in this subclause. | defining_identifier_list : [aliased] [constant] array_type_definition [:= expression]. 3 — Ada Reference Manual defaults (see 3. A class-wide subtype is defined to have unknown discriminants. Legality Rules 5/2 An object_declaration without the reserved word constant declares a variable object. Syntax 2/2 object_declaration ::= defining_identifier_list : [aliased] [constant] subtype_indication [:= expression]. An indefinite subtype does not by itself provide enough information to create an object. It is declared by a number_declaration. then there shall be an initialization expression. with the rest of the text of the declaration copied for each declaration in the series. then it is called a full constant declaration.1 Object Declarations 1 An object_declaration declares a stand-alone object with a given nominal subtype and. otherwise the subtype is a definite subtype (all elementary subtypes are definite subtypes). If it has an initialization expression.3. and is therefore an indefinite subtype. task. explanations are given for declarations with a single defining_identifier. defining_identifier} Name Resolution Rules 3 4 For an object_declaration with an expression following the compound delimiter :=.

then if this subtype is indefinite or the object is constant the actual subtype of this object is constrained. When not constrained by its initial value. For an object_declaration without an initialization expression. As described in 5. If the object_declaration includes an initialization expression. 2. single_task_declaration. there is an implicit component (an entry queue) corresponding to each entry.8. the (explicit) initial value is obtained by evaluating the expression and converting it to the nominal subtype (which might raise Constraint_Error — see 4. Dynamic Semantics 8/2 8. • For a (definite) composite subtype. the implicit initial value of each component with a default_expression is obtained by evaluation of this expression and conversion to the component's nominal subtype (which might raise Constraint_Error — see 4. evaluations and assignments are performed in an arbitrary order subject to the following restrictions: • Assignment to any part of the object is preceded by the evaluation of the value that is to be assigned. with its implicit initial value being an empty queue. or if it has an initialization expression that includes a name denoting the current instance of the type or denoting an access discriminant.2 and 7. access_definition. the actual and nominal subtypes of the object are the same. The subtype_indication. 9/2 10 11 12 13 14 15 16/2 17 18/2 19/2 20/2 For the third step above. any per-object constraints (see 3. The constraint is determined by the bounds or discriminants (if any) of its initial value. Initialize and Adjust procedures can be called. or single_protected_declaration is first elaborated. the object is initialized by default. Any initial values (whether explicit or implicit) are assigned to the object or to the corresponding subcomponents.8) are elaborated and any implicit initial values for the object or for its subcomponents are obtained as determined by the nominal subtype. A component of an object is said to require late initialization if it has an access discriminant value constrained by a per-object expression. When an object is initialized by default. 20.1 . This creates the nominal subtype (and the anonymous type in the last four cases).6. or full type definition of an object_declaration defines the nominal subtype of the object. any implicit initial values are those determined by the component's nominal subtype. • For a protected or task subtype.ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual The subtype_indication.6). and. The object is created. the object is said to be constrained by its initial value.1).1/2 If a composite object declared by an object_declaration has an unconstrained nominal subtype. If its actual subtype is constrained. any initial values for the object or its subcomponents are determined by the implicit initial values defined for its nominal subtype.3. if there is not an initialization expression. The object_declaration declares an object of the type of the nominal subtype. “Type Conversions”). access_definition. 3.1/2 27 10 November 2006 Object Declarations 3. unless the component is a discriminant of a constrained subtype (the previous case). as follows: • The implicit initial value for an access subtype is the null value of the access type. For each component that does not have a default_expression. • The implicit initial (and only) value for each discriminant of a constrained discriminated subtype is defined by the subtype. This paragraph was deleted. The elaboration of an object_declaration proceeds in the following sequence of steps: 1.6. or is in an excluded variant (see 3. the object is called a constrained object. array_type_definition.

3. access String := Hello'Access. 3. • The assignments to any components.10.1 30 31/2 Examples of variable declarations: Count. world.see 3. Boolean := False. Integer range 0 . a newly created scalar object might have a value that does not belong to its subtype (see 13.1 and H. In the absence of an explicit initialization...9. • The evaluation of the default_expression for any component that depends on a discriminant is preceded by the assignment to that discriminant. a stand-alone object is an object declared by an object_declaration.ISO/IEC 8652:2007(E) Ed. because if an object's nominal subtype is indefinite. 9 The type of a stand-alone object cannot be abstract (see 3. φ : : : : : : : Integer. choice_parameter_specification. Syntax 2 number_declaration ::= defining_identifier_list : constant := static_expression.". then assignments to parts of the component occurring earlier in the order of the component declarations must precede the initial value evaluations of the component occurring later. Real := Dispersion(1. 32 33/2 Examples of constant declarations: Limit Low_Limit Tolerance Hello_Msg : : : : constant constant constant constant Integer := 10_000. nor is an object that is created by an allocator.. Similar definitions apply to “stand-alone constant” and “stand-alone variable.2/2 • The evaluation of a default_expression that includes the name of a discriminant is preceded by the assignment to that discriminant. an explicit initial value is required.the multiple object declaration John. or a formal_object_declaration is not called a stand-alone object. Paul : not null Person_Name := new Person(Sex => M).3. parameter_specification. An object declared by a loop_parameter_specification. +π.10.is equivalent to the two single object declarations in the order given John : not null Person_Name := new Person(Sex => M). NOTES 7 Implicit initial values are not defined for an indefinite subtype. not requiring late initialization must precede the initial value evaluations for any components requiring late initialization.3). -. Max) of Color.2 3.4/2 21 22 23 24 25 26 27/2 28 29/2 Example of a multiple object declaration: -. Paul : not null Person_Name := new Person(Sex => M). entry_index_specification. aliased String := "Hi.. 8 As indicated above.1 Object Declarations 10 November 2006 28 . Bit_Vector(1 . including implicit components. 3 — Ada Reference Manual 20.see 3. Integer := Limit/10.9.” A subcomponent of an object is not a stand-alone object. -. if two components both require late initialization. 10) := (others => True). Sum Size Sorted Color_Table Option Hello θ.1).3/2 20. -.2 Number Declarations 1 A number_declaration declares a named number.15). Examples 20. There is no implicit initial value defined for a scalar subtype. 10_000 := 0. Float range -π . array(1 .

Max/6. but not classes of types.4 Derived Types and Classes A derived_type_definition defines a derived type (and its first subtype) whose characteristics are derived from those of a parent type. 1. By saying that a particular group of types forms a class. Eins : constant := 2.0*Ada. and interface are all categories of types. for example. 2**16.9.5) -. and possibly from progenitor types.1) prior to being specified as the parent type in a derived_type_definition — the full_type_declarations for the parent type and any of its subcomponents have to precede the derived_type_definition. The value denoted by the named number is the value of the static_expression.4). A derived type has one parent type and zero or more progenitor types. 3 — Ada Reference Manual Name Resolution Rules The static_expression given for a number_declaration is expected to be of any numeric type. A class of types is a set of types that is closed under derivation. converted to the corresponding universal type. The interface_list defines the progenitor types (see 3. abstract.Numerics. A type shall be completely defined (see 3. Legality Rules 3 The static_expression given for a number declaration shall be a static expression. Syntax 1/2 1.3. The named number denotes a value of type universal_real if the type of the static_expression is a real type. Examples 7 Examples of number declarations: Two_Pi Max Max_Line_Size Power_16 One. limited.Pi.1/2 derived_type_definition ::= 2/2 [abstract] [limited] new parent_subtype_indication [[and interface_list] record_extension_part] Legality Rules The parent_subtype_indication defines the parent subtype. that is. The more general term category of types is used for a set of types whose defining characteristics are not necessarily inherited by derivatives.ISO/IEC 8652:2007(E) Ed. as defined by clause 4. 3/2 4 29 10 November 2006 Number Declarations 3.2 . we are saying that all derivatives of a type in the set inherit the characteristics that define that set.11. if the parent or a progenitor type of a derived type belongs to a class.9. then so does the derived type. its type is the parent type. Un. : : : : constant constant constant constant := := := := 500. Dynamic Semantics 5 6 The elaboration of a number_declaration has no effect.a real number (see A.the integer 65_536 -.the integer 83 -. Static Semantics 4 The named number denotes a value of type universal_integer if the type of the static_expression is an integer type.an integer number -.three different names for 1 8 9 10/2 3. -.

ISO/IEC 8652:2007(E) Ed. the discriminants are said to be inherited. these components. there is a corresponding predefined operator of the derived type. Static Semantics 5. and hence the characteristics defining these classes are inherited by derived types from their parent or progenitor types: signed integer. each discriminant of the parent type (implicitly declared in the same order with the same specifications) — in the latter case. access-to-subprogram. in the order indicated above. whether implicit or explicit. or if the parent subtype is unconstrained. Each nondiscriminant component. the derived type is called a record extension of the parent type. non-array composite.4 Derived Types and Classes 10 November 2006 30 . pool-specific access-to-variable. the base range of the derived type is the same as that of the parent type. modular integer. then the components.10) if and only if the parent subtype excludes null. untagged record. entry. protected subprograms. An interface_list shall be provided only if the parent type is a tagged type. are also unknown in the derived type. occur immediately within the declarative region of the type. the value of each bound of its range is replaced by the corresponding value of the derived type. tagged. boolean. If the reserved word limited appears in a derived_type_definition. A record_extension_part shall be provided if and only if the parent type is a tagged type. if there is one. The first subtype of the derived type excludes null (see 3. and protected subprograms are said to be inherited. following the parent subtype_indication. array. nonlimited. For a scalar type. then the derived type also belongs to that class. then the set of possible values of the derived type is a copy of the set of possible values of the parent type.1/2 6 The first subtype of the derived type is unconstrained if a known_discriminant_part is provided in the declaration of the derived type. protected subprograms. The following sets of types. and entries. or if unknown in the parent. general access-to-variable. • For each user-defined primitive subprogram (other than a user-defined equality operator below) of the parent type or of a progenitor type that already exists at the place derived_type_definition. decimal fixed. • If the parent type is an elementary type or an array type. character. • If the parent type is a composite type other than an array type. The characteristics of the derived type are defined as follows: • If the parent type or a progenitor type belongs to a class of types. access-toconstant. string. task. 12 • 13 14 • Declarations of components. otherwise. Otherwise. ordinary fixed. as well as any higher-level sets composed from them. are classes in this sense. the parent type shall be a limited type. • For each predefined operator of the parent type. • This paragraph was deleted. the constraint of the first subtype corresponds to that of the parent subtype in the following sense: it is the same as that of the parent subtype except that for a range constraint (implicit or explicit). enumeration. if any. Primitive user-defined equality operators — of of of see the the the 15/2 16 17/2 3. and entries that are declared for the derived type are as follows: • 6. protected. entries. there exists a corresponding inherited primitive subprogram derived type with the same defining name. and protected subprogram of the parent type. Each component declared in a record_extension_part.1/2 7 8/2 9 10 11 The discriminants specified by a new known_discriminant_part. implicitly declared in the same order with the same declarations. floating point. and synchronized tagged. 3 — Ada Reference Manual 5/2 If there is a record_extension_part.

For a given subtype of the parent or progenitor type. 3 — Ada Reference Manual parent type and any progenitor types are also inherited by the derived type. and the inherited operator would have a profile that is type conformant with the profile of the corresponding predefined equality operator. then only those expressions that do not depend on a discriminant are evaluated. Dynamic Semantics 22/2 23/2 24 25 The elaboration of a derived_type_definition creates the derived type and its first subtype.ISO/IEC 8652:2007(E) Ed. Any type mismatch due to the systematic replacement of the parent or progenitor type by the derived type is handled as part of the normal type conversion associated with parameter passing — see 6.5. 26 27/2 31 10 November 2006 Derived Types and Classes 3. except when the derived type is a nonlimited record extension. The profile of an inherited subprogram (including an inherited enumeration literal) is obtained from the profile of the corresponding (user-defined) primitive subprogram of the parent or progenitor type. 19 • • 20 21 The same formal parameters have default_expressions in the profile of the inherited subprogram.5. the corresponding subtype of the derived type is defined as follows: • 18/2 If the declaration of the derived type has neither a known_discriminant_part nor a record_extension_part.1. extended to the derived type using the equivalent of an extension_aggregate with the original result as the ancestor_part and null record as the record_component_association_list.3.4 and 3.4. Otherwise.3) or a formal_derived_type_definition (see 12.4 .5. and consists of the elaboration of the subtype_indication and the record_extension_part. the inherited subprogram is implicitly declared later or not at all. a call on the corresponding primitive subprogram of the parent or progenitor type is performed. If the derived type is a record extension. For the execution of a call on an inherited subprogram.4. in that they are implicitly derived from a corresponding root numeric type (see 3. as explained in 7. If a primitive subprogram of the parent or progenitor type is visible at the place of the derived_type_definition.1. then the corresponding subtype is the first subtype of the derived type. the result of calling the subprogram of the parent or progenitor is converted to the derived type.6).2). then the corresponding inherited subprogram is implicitly declared immediately after the derived_type_definition. if any. If the result type of the inherited subprogram is the derived type.1). the normal conversion of each actual parameter to the subtype of the corresponding formal parameter (see 6. then the corresponding subtype has a constraint that corresponds (as defined above for the first subtype of the derived type) to that of the given subtype. the user-defined equality operator is not inherited. but is rather incorporated into the implementation of the predefined equality operator of the record extension (see 4. All numeric types are derived types.6). If the subtype_indication depends on a discriminant. Such a derived type is a partial view of the corresponding full or actual type. or in the case of a null extension.5. If the derived type has a new known_discriminant_part but is not a record extension. in this case. then the corresponding subtype is constrained to those values that when converted to the parent type belong to the given subtype (see 4.1) that is of the parent or progenitor type with a corresponding subtype of the derived type. A derived type can also be defined by a private_extension_declaration (see 7.1) performs any necessary type conversion as well. after systematic replacement of each subtype of its profile (see 6.

Key.3.3). it is derived indirectly from any type from which its parent type is derived. and hence cannot be a primitive subprogram and cannot be inherited by a derived type.2/2 Examples of derived type declarations: type Local_Coordinate is new Coordinate. or a universal type.the inherited subprograms have the following specifications: -procedure Get_Key(K : out Special_Key). the right operand of the predefined exponentiation operator is of the predefined type Integer (see 4. then the parent and the derived type share the same storage pool. type extension. there is a null access value for the derived type and it is the implicit initial value for the type. 14 If the parent type is a boolean type.. If the parent type is an integer type. or completely replaced with a new set of discriminants. Every type is either a specific type. 19 It is illegal for the parent type of a derived_type_definition to be a synchronized tagged type. See 3. Static Semantics 2/2 A derived type is derived from its parent type directly.ISO/IEC 8652:2007(E) Ed.same range as Positive 38 type Special_Key is new Key_Manager.1/2 35.10. 12 A generic subprogram is not a subprogram. types can be grouped into derivation classes.4. This follows from their equivalence to parameterless functions.9. and hence can be inherited. 3. however. 15 Any discriminants of the parent type are either all inherited. the predefined relational operators of the derived type deliver a result of the predefined type Boolean (see 4.1 -. never defines an interface type.see 7.5. 16 For an inherited subprogram. 13 If the parent type is an access type. A derived type.two different types -. On the other hand. type Counter is new Positive. or a full type definition embedded in another construct.5. Examples 36 37 28 29 30 31 32 33 34 35 35. a class-wide type. protected type.Y : Special_Key) return Boolean. interface type.see 3. the subtype of a formal parameter of the derived type need not have any value in common with the first subtype of the derived type. task type.4 Derived Types and Classes 10 November 2006 32 .6). type Midweek is new Day range Tue . to act as representatives for an entire class of types.1 -. 3 — Ada Reference Manual NOTES 10 Classes are closed under derivation — any class that contains a type also contains its derivatives. as follows: 3/2 3. -. A derived_type_definition.5. 11 Evaluating an inherited enumeration literal is equivalent to evaluating the corresponding enumeration literal of the parent type. The derivation class of types for a type T (also called the class rooted at T) is the set consisting of T (the root type of the class) and all types derived from T (directly or indirectly) plus any associated universal or class-wide types (defined below). and then converting the result to the derived type. A specific type is one defined by a type_declaration. if any. -.2).1 Derivation Classes 1 In addition to the various language-defined classes of types. Thu. -function "<"(X. a formal_type_declaration. Class-wide and universal types are implicitly defined. 17 If the reserved word abstract is given in the declaration of a type. Operations available for a given class of types are available for the derived types in that class. the type is abstract (see 3. or formal derived type is also derived from every ancestor of each of its progenitor types. 18 An interface type that has a progenitor type “is derived from” that type. an instance of a generic subprogram can be a primitive subprogram.

then S'Class is a first subtype. A specific type T2 is defined to be a descendant of a type T1 if T2 is the same as T1. respectively).9). or the literal null) is “universal” in that it is acceptable where some particular type in the class is expected (see 8. These are analogous to class-wide types for these language-defined elementary classes. However. For universal_integer and universal_real. a value of a universal type (including an integer or real numeric_literal. In addition. and are referred to in this standard as respectively. The set of values of a universal type is the undiscriminated union of the set of values possible for any definable type in the associated class. The set of values for a class-wide type T'Class is the discriminated union of the set of values of each specific type in the derivation class rooted at T (the tag acts as the implicit discriminant — see 3.ISO/IEC 8652:2007(E) Ed.2.6) to the predefined operators of the corresponding root types (root_integer and root_real.9. named respectively root_integer and root_real. universal_fixed. Hence.6).1 . universal types have no primitive subprograms of their own. Every untagged type has a unique ultimate ancestor. An inherited component (including an inherited discriminant) of a derived type is inherited from a given ancestor of the type if the corresponding component was inherited by each derived type in the chain of derivations going back to the given ancestor. The integer and real numeric classes each have a specific root type in addition to their universal type. then an actual parameter of any type in the corresponding class is acceptable. As with class-wide types. Like class-wide types. 3 — Ada Reference Manual Class-wide types Class-wide types are defined for (and belong to) each derivation class rooted at a tagged type (see 3. universal_real. An ultimate ancestor of a type is an ancestor of that type that is not itself a descendant of any other type. NOTES 20 Because operands of a universal type are acceptable to the predefined operators of any type in their class. Similarly. fixed point. ambiguity can result. If S is a first subtype. an actual parameter of any type in the derivation class rooted at T is acceptable (see 8.4. as explained in 3. If a type T2 is a descendant of a type T1. operands of a class-wide type T'Class can be used as part of a dispatching call on a primitive subprogram of the type T. A class-wide or universal type is said to cover all of the types in its class. However. the numeric universal types are defined to be descendants of the root types of their classes. A specific type covers only itself. and access classes. S'Class is the subtype_mark for a corresponding subtype of the tagged class-wide type T'Class.9). the predefined operators of root_integer will be preferred over those of other specific integer types. their “universality” allows them to be used as operands with the primitive subprograms of any type in the corresponding class. if a formal parameter is of a universal type. or if T2 is derived (directly or indirectly) from T1. A class-wide type T2'Class is defined to be a descendant of type T1 if T2 is a descendant of T1. this potential ambiguity is resolved by giving a preference (see 8. real. Class-wide types have no primitive subprograms of their own. The only components (including discriminants) of T'Class that are visible are those of T. 4 5 6/2 7 8 9 10/2 11 12 13 14 33 10 November 2006 Derivation Classes 3. Such types are called “classwide” because when a formal parameter is defined to be of a class-wide type T'Class. then T1 is called an ancestor of T2. thereby resolving the ambiguity.6). Given a subtype S of a tagged type T. in an apparently ambiguous expression like 1+4<7 where each of the literals is of type universal_integer. Universal types Universal types are defined for (and belong to) the integer. and universal_access. universal_integer.

and is in the subset of values specified by the range. the type of the range shall resolve to that of the type determined by the subtype_mark of the subtype_indication. either directly or as part of some other scalar_constraint. the simple_expressions of the range (likewise. A value belongs to a range if it is of the type of the range. Syntax 2 3 range_constraint ::= range range range ::= range_attribute_reference | simple_expression . A range with lower bound L and upper bound R is described by “L . All scalar types are ordered.5 Scalar Types 1 Scalar types comprise enumeration types. If R is less than L. For a range of a given type. Otherwise. inclusive.ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 3. the evaluation of the range consists of the evaluation of the range_attribute_reference. all relational operators are predefined for their values. then the range is a null range. that is. and converts them to the type of the range. and real types. The range of a constrained scalar subtype is the range associated with the range constraint of the subtype. 9 3. Dynamic Semantics 7 8 A range is compatible with a scalar subtype if and only if it is either a null range or each bound of the range belongs to the range of the subtype. A range_constraint is compatible with a scalar subtype if and only if its range is compatible with the subtype. the simple_expressions of the equivalent range for a range_attribute_reference) are expected to be of the type of the range. The range of an unconstrained scalar subtype is the base range of its type.. The evaluation of a range determines a lower bound and an upper bound. The elaboration of a range_constraint consists of the evaluation of the range. simple_expression 4 A range has a lower bound and an upper bound and specifies a subset of the values of some scalar type (the type of the range). If simple_expressions are given to specify bounds. the evaluation of the range evaluates these simple_expressions in an arbitrary order. Static Semantics 6 The base range of a scalar type is the range of finite values of the type that can be represented in every unconstrained object of the type. Enumeration types and integer types are called discrete types. Name Resolution Rules 5 For a subtype_indication containing a range_constraint. the range specifies the values of the type from the lower bound to the upper bound. One range is included in another if all values that belong to the first range also belong to the second. Integer types and real types are called numeric types. If a range_attribute_reference is given. and specifies an empty set of values. it is also the range supported at a minimum for intermediate values during the evaluation of expressions involving predefined operators of the type. each value of a discrete type has a position number which is an integer value.5 Scalar Types 10 November 2006 34 . A constrained scalar subtype is one to which a range constraint applies. integer types. A value satisfies a range constraint if it belongs to the associated range.. R”.

the function returns the result of subtracting one from the value of Arg. The value of this attribute is of the type of S. 3 — Ada Reference Manual Attributes For every scalar subtype S. that is. Right : S'Base) return S'Base 10 11 12 13 14 15 16 17 The function returns the lesser of the values of the two parameters. The value of this attribute is of the type of S. exponent.. This unconstrained subtype is called the base subtype of the type. For a floating point type. the function returns the result of adding small to the value of Arg. the function returns the machine number (as defined in 3.2/2 The function returns an image of the value of Arg. leading zeros. Constraint_Error is raised if there is no such machine number. The image of an integer value is the corresponding decimal literal.5. Constraint_Error is raised if there is no such value of the type. a sequence of characters representing the value in display form.5. the function returns the result of adding one to the value of Arg.4/2 35 10 November 2006 Scalar Types 3.5 . S'Min denotes a function with the following specification: function S'Min(Left. The lower bound of the result is one.1/2 27. the function returns the value whose position number is one more than that of the value of Arg. 27. Right : S'Base) return S'Base 18 19 20 The function returns the greater of the values of the two parameters. For an integer type. S'Base denotes an unconstrained subtype of the type of S. the following attributes are defined: S'First S'Last S'Range S'Base S'Min S'First denotes the lower bound of the range of S. S'Last denotes the upper bound of the range of S.ISO/IEC 8652:2007(E) Ed.3/2 27. S'Succ S'Succ denotes a function with the following specification: function S'Succ(Arg : S'Base) return S'Base 21 22 23 For an enumeration type. For a floating point type. For a fixed point type. S'Wide_Wide_Image S'Wide_Wide_Image denotes a function with the following specification: function S'Wide_Wide_Image(Arg : S'Base) return Wide_Wide_String 27 27. S'Pred S'Pred denotes a function with the following specification: function S'Pred(Arg : S'Base) return S'Base 24 25 26 For an enumeration type. S'Last.7) immediately below the value of Arg. S'Max S'Max denotes a function with the following specification: function S'Max(Left. For a fixed point type. or trailing spaces. S'Range is equivalent to the range S'First . but with a single leading character that is either a minus sign or a space. Constraint_Error is raised if there is no such machine number. Constraint_Error is raised if there is no such value of the type. the function returns the result of subtracting small from the value of Arg. For an integer type. without underlines.7) immediately above the value of Arg. the function returns the machine number (as defined in 3. the function returns the value whose position number is one less than that of the value of Arg.

It denotes zero for a subtype that has a null range.1/2 S'Wide_Wide_Value S'Wide_Wide_Value denotes a function with the following specification: function S'Wide_Wide_Value(Arg : Wide_Wide_String) return S'Base 39. 3 — Ada Reference Manual 27. a decimal point. 35 36 S'Image S'Image denotes a function with the following specification: function S'Image(Arg : S'Base) return String 37/2 The function returns an image of the value of Arg as a String. For a nongraphic character (a value of a character type that has no enumeration literal associated with it). Its type is universal_integer. S'Wide_Image S'Wide_Image denotes a function with the following specification: function S'Wide_Image(Arg : S'Base) return Wide_String 27.2/2 3. The image has the same sequence of character as defined for S'Wide_Wide_Image if all the graphic characters are defined in Wide_Character.8) digits after the decimal point (but one if S'Digits is one). The image has the same sequence of graphic characters as that defined for S'Wide_Wide_Image if all the graphic characters are defined in Character.7/2 28 29 30/2 The function returns an image of the value of Arg as a Wide_String. the sign of the exponent (either + or –). S'Wide_Wide_Width S'Wide_Wide_Width denotes the maximum length of a Wide_Wide_String returned by S'Wide_Wide_Image over all values of the subtype S.5. and S'Aft (see 3. otherwise the sequence of characters is implementation defined (but no shorter than that of S'Wide_Wide_Image for the same value of Arg). one or more digits before the decimal point (with no redundant leading zeros). then the leading character is a minus sign for a negatively signed zero. Its type is universal_integer. The image of a floating point value is a decimal real literal best approximating the value (rounded away from zero if halfway between) with a single leading character that is either a minus sign or a space.5. 37. neither leading nor trailing spaces are included. the image of the nongraphic character identified as nul is “NUL” — the quotes are not part of the image). The lower bound of the result is one. S'Wide_Width S'Wide_Width denotes the maximum length of a Wide_String returned by S'Wide_Image over all values of the subtype S.6/2 27. and two or more digits (with leading zeros if necessary) representing the exponent.5 Scalar Types 10 November 2006 36 . It denotes zero for a subtype that has a null range. an upper case E. The lower bound of the result is one. Its type is universal_integer. S'Digits–1 (see 3. a decimal point. The image of a fixed point value is a decimal real literal best approximating the value (rounded away from zero if halfway between) with a single leading character that is either a minus sign or a space. a single digit (that is nonzero unless the value is zero).1/2 38 39 39. S'Width S'Width denotes the maximum length of a String returned by S'Image over all values of the subtype S. Paragraphs 31 through 34 were moved to Wide_Wide_Image.5/2 The image of an enumeration value is either the corresponding identifier in upper case or the corresponding character literal (including the two apostrophes). the result is a corresponding languagedefined name in upper case (for example.ISO/IEC 8652:2007(E) Ed. otherwise the sequence of characters is implementation defined (but no shorter than that of S'Wide_Wide_Image for the same value of Arg).10) digits after the decimal point. It denotes zero for a subtype that has a null range. If S'Signed_Zeros is True.

if the sequence of characters of the parameter (ignoring leading and trailing spaces) has the syntax of an 54 55/2 37 10 November 2006 Scalar Types 3. 3 — Ada Reference Manual This function returns a value given an image of the value as a Wide_Wide_String. ignoring any leading or trailing spaces.7/2 39. if the sequence of characters of the parameter (ignoring leading and trailing spaces) has the syntax of an enumeration literal and if it corresponds to a literal of the type of S (or corresponds to the result of S'Wide_Wide_Image for a nongraphic character of the type). For the evaluation of a call on S'Value for an enumeration subtype S. For the evaluation of a call on S'Wide_Value for an enumeration subtype S.12/2 40 41 This function returns a value given an image of the value as a Wide_String. the evaluation of a call on S'Wide_Value with Arg of type Wide_String is equivalent to a call on S'Wide_Wide_Value for a corresponding Arg of type Wide_Wide_String.4/2 39. The sign of a zero value is preserved (positive if none has been specified) if S'Signed_Zeros is True.11/2 39. For the evaluation of a call on S'Wide_Wide_Value for an integer subtype S. otherwise Constraint_Error is raised. otherwise Constraint_Error is raised. if the sequence of characters of the parameter (ignoring leading and trailing spaces) has the syntax of one of the following: • numeric_literal • numeral. For the evaluation of a call on S'Wide_Wide_Value for a real subtype S.10/2 39.9/2 39.ISO/IEC 8652:2007(E) Ed. then that value is the result.3/2 39. otherwise Constraint_Error is raised. ignoring any leading or trailing spaces. with an optional leading sign character (plus or minus for a signed type.numeral[exponent] • base#based_numeral. and if the corresponding numeric value belongs to the base range of the type of S.#[exponent] • base#. the result is the corresponding enumeration value. For the evaluation of a call on S'Wide_Wide_Value for an enumeration subtype S. For a numeric subtype S.6/2 39.8/2 39. the result is the corresponding enumeration value.based_numeral#[exponent] with an optional leading sign character (plus or minus). otherwise Constraint_Error is raised. S'Wide_Value S'Wide_Value denotes a function with the following specification: function S'Wide_Value(Arg : Wide_String) return S'Base 39.5/2 39. Paragraphs 44 through 51 were moved to Wide_Wide_Value. if the sequence of characters of the parameter (ignoring leading and trailing spaces) has the syntax of an integer literal. only plus for a modular type).5 . 42 43/2 S'Value S'Value denotes a function with the following specification: function S'Value(Arg : String) return S'Base 52 53 This function returns a value given an image of the value as a String.[exponent] • . and the corresponding numeric value belongs to the base range of the type of S. then that value is the result. ignoring any leading or trailing spaces. if the sequence of characters of the parameter (ignoring leading and trailing spaces) has the syntax of an enumeration literal and if it corresponds to a literal of the type of S (or corresponds to the result of S'Wide_Image for a value of the type).

.0 .. These values can. as do S'Wide_Value(S'Wide_Image(V)) and S'Wide_Wide_Value(S'Wide_Wide_Image(V)). the result delivered by the attributes Succ. If a scalar subtype S has a nonnull range. the actual parameters of the attributes Succ. Static Semantics 6 Each enumeration_literal_specification is the explicit declaration of the corresponding enumeration literal: it declares a parameterless function. for example. Pred. and Value might not belong to the subtype. the evaluation of a call on S'Value with Arg of type String is equivalent to a call on S'Wide_Wide_Value for a corresponding Arg of type Wide_Wide_String. Implementation Permissions 56/2 An implementation may extend the Wide_Wide_Value.. and whose result type is the enumeration type.. Value. Wide_Wide_Image. +999. Syntax 2 enumeration_type_definition ::= (enumeration_literal_specification {.5. X + 1 0. For a numeric subtype S.1 -.ISO/IEC 8652:2007(E) Ed. Pred..5 Scalar Types 10 November 2006 38 . and Image attributes of a floating point type to support special values such as infinities and NaNs. Examples 57 58 59 60 61 Examples of ranges: -10 . S'Last-1 3. Wide_Image. 10 X .0*Pi Red . Wide_Value. S'First and S'Last belong to this range.. whose defining name is the defining_identifier or defining_character_literal.a null range -.0 range S'First+1 . NOTES 21 The evaluation of S'First or S'Last never raises an exception. and Image need not belong to the subtype. 22 For a subtype of a scalar type. 2.0 . None of these expressions ever raise Constraint_Error.6) 62 63 Examples of range constraints: range -999.1 Enumeration Types 1 An enumeration_type_definition defines an enumeration type.5. S'Value(S'Image(V)) equals V. the result is the corresponding enumeration value. otherwise Constraint_Error is raised.a range attribute reference (see 3. Green 1 .. 3 — Ada Reference Manual enumeration literal and if it corresponds to a literal of the type of S (or corresponds to the result of S'Image for a value of the type). always be assigned to a variable of subtype S.see 3. enumeration_literal_specification}) enumeration_literal_specification ::= defining_identifier | defining_character_literal defining_character_literal ::= character_literal Legality Rules 3 4 5 The defining_identifiers and defining_character_literals listed in an enumeration_type_definition shall be distinct. 23 For any value V (including any nongraphic character) of an enumeration subtype S. 3. similarly. 0 Table'Range -.

'?'. subtype Rainbow is Color range Red .1. Fri.Red and Green are overloaded 13 14 type Hexa type Mixed is ('A'. The predefined type Character is a character type whose values correspond to the 256 code positions of Row 00 (also known as Latin-1) of the ISO/IEC 10646:2003 Basic Multilingual Plane (BMP). When called. Wide_Value. 'C'. these names are given in the definition of type Character in A. None.5.. is ('A'. 'B'. Spades). Value. The predefined order relations between values of the enumeration type follow the order of corresponding position numbers. then qualification by the name of the enumeration type is one way to resolve the ambiguity (see 4. Red. and Wide_Wide_Value.6). 15 16 subtype Weekday is Day range Mon . '%'). Urgent). Hearts. Tue. the type of the enumeration literal has to be determinable from the context (see 8. B. but are set in italics. (White. Examples 10 11 12 Examples of enumeration types and subtypes: type type type type type type Day Suit Gender Level Color Light is is is is is is (Mon.1 . NOTES 24 If an enumeration literal occurs in a context that does not otherwise suffice to determine the type of the literal. F).2 Character Types Static Semantics An enumeration type is said to be a character type if at least one of its enumeration literals is a character_literal. Green). Wide_Wide_Image. Dynamic Semantics 7 8 9 The elaboration of an enumeration_type_definition creates the enumeration type and its first subtype. Each of the graphic characters of Row 00 of the BMP has a corresponding character_literal in Character. 3 — Ada Reference Manual Each enumeration literal corresponds to a distinct value of the enumeration type. (M. If the same defining_identifier or defining_character_literal is specified in more than one enumeration_type_definition. 'E'. Green. which is constrained to the base range of the type. Thu. -. the position number of the value of each subsequent enumeration literal is one more than that of its predecessor in the list. which is not usable as an enumeration literal. subtype Major is Suit range Hearts . 'D'..5. Yellow. not the Light 3. the corresponding enumeration literals are said to be overloaded. (Low. but which is usable with the attributes Image. the parameterless function associated with an enumeration literal returns the corresponding value of the enumeration type. (Clubs. Blue.7). (Red.the Color Red. Fri. 'F'). Spades. Sun). Medium. Amber. Diamonds. and to a distinct position number.ISO/IEC 8652:2007(E) Ed. -. Wed. “The Package Standard”. 'B'. Black). Wide_Image. 1 2/2 39 10 November 2006 Enumeration Types 3. Sat.. Each of the nongraphic positions of Row 00 (0000-001F and 007F-009F) has a corresponding language-defined name. '*'. Brown. The position number of the value of the first listed enumeration literal is zero. Blue. At any place where an overloaded enumeration literal occurs in the text of a program.

5. Each of the graphic_characters has a corresponding character_literal.3 Boolean Types Static Semantics 1 There is a predefined enumeration type named Boolean. 3. Each of the graphic_characters has a corresponding character_literal in Wide_Wide_Character. NOTES 25 The language-defined library package Characters. Implementation Permissions 3. declared in the visible part of package Standard. or a modular integer type. 3 — Ada Reference Manual 3/2 The predefined type Wide_Character is a character type whose values correspond to the 65536 code positions of the ISO/IEC 10646:2003 Basic Multilingual Plane (BMP). the internal codes of the characters can be specified by an enumeration_representation_clause as explained in clause 13. such a type corresponds to an unsigned type with wrap-around semantics. The predefined type Wide_Wide_Character is a character type whose values correspond to the 2147483648 code positions of the ISO/IEC 10646:2003 character set. The first 256 values of Wide_Character have the same character_literal or language-defined name as defined for Character. 'X'.3.4. 'D'. 'M'). Examples 6 7 8 9 Example of a character type: type Roman_Digit is ('I'. It has the two enumeration literals False and True ordered with the relation False < True.1/2 3. they are not usable as enumeration literals. these names are usable only with the attributes (Wide_)Wide_Image and (Wide_)Wide_Value. Each of the graphic characters of the BMP has a corresponding character_literal in Wide_Character. it defines either a signed integer type. The characters whose code position is larger than 16#FF# and which are not graphic_characters have language-defined names which are formed by appending to the string "Hex_" the representation of their code position in hexadecimal as eight extended digits. 'L'.3) includes the declaration of constants denoting control characters.Latin_1 (see A. 26 A conventional character set such as EBCDIC can be declared as a character type. The first 65536 values of Wide_Wide_Character have the same character_literal or language-defined name as defined for Wide_Character. Syntax 2 integer_type_definition ::= signed_integer_type_definition | modular_type_definition 3. Any descendant of the predefined type Boolean is called a boolean type.ISO/IEC 8652:2007(E) Ed.4 Integer Types 1 An integer_type_definition defines an integer type.2 Character Types 10 November 2006 40 . 'C'. and special characters of the predefined type Character. lower case characters. A modular type is an integer type with all arithmetic modulo a specified positive modulus.5. Implementation Advice 5/2 This paragraph was deleted. 3.2/2 4/2 This paragraph was deleted.5. As with other language-defined names. 'V'. The base range of a signed integer type includes at least the values of the specified range.

Integer has two predefined subtypes. but is instead determined by the range or modulus specified by the integer_type_definition. allowing their use with the operations of any integer type. static_simple_expression modular_type_definition ::= mod static_expression Name Resolution Rules 3 4 Each simple_expression in a signed_integer_type_definition is expected to be of any integer type. For every modular subtype S. and their values shall be in the range System. There is a predefined signed integer subtype named Integer. The position number of an integer value is equal to the value.5.ISO/IEC 8652:2007(E) Ed. or no greater than System. A modular_type_definition also defines a constrained first subtype of the type with a range that is the same as the base range of the type. 8 9 10 11 12 13 A type defined by an integer_type_definition is implicitly derived from root_integer. whose base range is System.3/2 41 10 November 2006 Integer Types 3. It is constrained to the base range of its type. Static Semantics 6 7 The set of values for a signed integer type is the (infinite) set of mathematical integers. converted to the type being defined.Max_Int. inclusive. The set of values for a modular integer type are the values from 0 to one less than the modulus. However. Integer literals are all of the type universal_integer. they need not be of the same type.Max_Binary_Modulus if a power of 2.2/2 This function returns Arg mod S'Modulus.Max_Int. System.. with a range whose bounds are given by the values of the simple_expressions.Min_Int . and shall be no greater than System. The expression of a modular_type_definition shall be static. A signed_integer_type_definition also defines a constrained first subtype of the type. the universal type (see 3. as a value of the type of S. System. Legality Rules 5 The simple_expressions of a signed_integer_type_definition shall be static.. the following attributes are defined: S'Mod S'Mod denotes a function with the following specification: function S'Mod (Arg : universal_integer) return S'Base 14 15 16/2 16.Min_Int .. though only values of the base range of the type are fully supported for run-time operations.4 . and its value (the modulus) shall be positive. 16... declared in the visible part of package Standard. A signed_integer_type_definition defines an integer type whose base range includes at least the values of the simple_expressions and is symmetric about zero.1) for the class rooted at root_integer. Integer'Last. 3 — Ada Reference Manual signed_integer_type_definition ::= range static_simple_expression . declared in the visible part of package Standard: subtype Natural is Integer range 0 . Integer'Last. excepting possibly an extra negative value. The expression in a modular_type_definition is likewise expected to be of any integer type. subtype Positive is Integer range 1 . an anonymous predefined (specific) integer type.4. A modular_type_definition defines a modular type whose base range is from zero to one less than the given modulus.Max_Nonbinary_Modulus if not. the base range of the new type is not inherited from root_integer.1/2 16.

+2**31–1. implementations may support non-binary modulus values greater than System.Max_Binary_Modulus shall be at least 2**16. a nonstandard integer type might have an asymmetric base range or it might not be allowed as an array or loop index (a very long integer). For any integer type. the exception Constraint_Error is raised by the execution of an operation that cannot deliver the correct result because it is outside the base range of the type. However. if the result of the execution of a predefined operator (see 4. 3 — Ada Reference Manual 17 S'Modulus S'Modulus yields the modulus of the type of S. Implementation Requirements 20 21 22 In an implementation. System. the range of Integer shall include the range –2**15+1 .. Dynamic Semantics 18 19 The elaboration of an integer_type_definition creates the integer type and its first subtype. There need not be a named integer type corresponding to each distinct base range supported by an implementation. Different predefined integer types are allowed to have the same base range. Short_Short_Integer. the result is reduced modulo the modulus of the type to a value that is within the base range of the type.1/1 3.5. if any. It is implementation defined which specific values greater than System. so long as the correct result is produced. Constraint_Error is raised by the operators "/". Long_Integer.Max_Nonbinary_Modulus. +2**15–1. For example. etc. For a modular type. Implementation Permissions 23 24 For the execution of a predefined operation of a signed integer type. this permission is exercised. rather than one less than the modulus.Max_Nonbinary_Modulus. as a value of the type universal_integer. whose first subtypes have names of the form Short_Integer. then its range shall include the range –2**31+1 . An implementation may provide nonstandard integer types. An implementation may provide additional predefined signed integer types. It is implementation defined for which powers of 2. An implementation may place arbitrary restrictions on the use of such types. the range of Short_Integer (if provided) should be no wider than Integer. In any case. such types are not permitted as explicit_generic_actual_parameters for formal scalar types — see 12.5) is outside the base range of the type. 25 26 27 27. declared in the visible part of Standard. are supported. Similarly.2.. "rem". For a signed integer type. The range of each first subtype should be the base range of its type. Corresponding recommendations apply to any other predefined integer types. the high bound of the base range of a modular type whose modulus is one less than a power of 2 may be equal to the modulus. For a one's complement machine.4 Integer Types 10 November 2006 42 . descendants of root_integer that are declared outside of the specification of package Standard. and "mod" if the right operand is zero. the implementation need not raise Constraint_Error if the result is outside the base range of the type. the range of Integer should be no wider than that of Long_Integer. If Long_Integer is predefined for an implementation. it is implementation defined whether operators that are predefined for “any integer type” are defined for a particular nonstandard integer type.5. For a one's complement machine. Long_Long_Integer.ISO/IEC 8652:2007(E) Ed. Any type descended from a nonstandard integer type is also nonstandard. which need not have all the standard characteristics of a type defined by an integer_type_definition. if any.

An implementation for a two's complement machine should support modular types with a binary modulus up to System. xor.4 8 . 2_000. Max. For the evaluation of a call on S'Val. the following attributes are defined: S'Pos S'Pos denotes a function with the following specification: function S'Pos(Arg : S'Base) return universal_integer 1 2 3 This function returns the position number of the value of Arg. “Operators and Expression Evaluation”). functions are defined that provide bit-wise shifting and rotating.2).ISO/IEC 8652:2007(E) Ed.5. -.2). or. subtype Buffer_Size is Integer range 0 ..".. type Byte type Hash_Index is mod 256.5 Operations of Discrete Types Static Semantics For every discrete subtype S. However.. signed integer types match "type T is range <>. if there is no value in the base range of its type with the given position number. An implementation should support a nonbinary modulus up to Integer'Last. subtype Small_Int is Integer range -10 . Instead. these same operators are predefined. if the value of the operand does not correspond to the internal code for any enumeration literal of its type (perhaps due to an uninitialized variable). In addition.an unsigned byte is mod 97. “The Context of Overload Resolution”) allow expressions of the type universal_integer whenever an integer type is expected. Other integer types have no literals.5. and not)." (see 12. 10. Examples 28 29 30 31 32 Examples of integer types and subtypes: type Page_Num is range 1 . 28 The same arithmetic operators are predefined for all signed integer types defined by a signed_integer_type_definition (see 4.modulus is prime 33 34 35 36 3. type Line_Size is range 1 . for the unsigned types declared in the language-defined package Interfaces (see B. subtype Column_Ptr is Line_Size range 1 . 43 10 November 2006 Integer Types 3. as a value of type universal_integer. Implementation Advice 7 For the evaluation of a call on S'Pos for an enumeration subtype.. S'Val S'Val denotes a function with the following specification: function S'Val(Arg : universal_integer) return S'Base 4 5 6 This function returns a value of the type of S whose position number equals the value of Arg. NOTES 27 Integer literals are of the anonymous predefined integer type universal_integer.5. Max_Line_Size. 3 — Ada Reference Manual Implementation Advice An implementation should support Long_Integer in addition to Integer if the target machine supports 32bit (or longer) arithmetic.6. the overload resolution rules (see 8. This is particularly important for enumeration types with noncontiguous internal codes specified by an enumeration_representation_clause. plus bit-wise logical operators (and.5. No other named integer subtypes are recommended for package Standard. appropriate named integer subtypes should be provided in the library package Interfaces (see B. 29 Modular types match a generic_formal_parameter_declaration of the form "type T is mod <>.Max_Int*2+2. -. Constraint_Error is raised.2). then the implementation should raise Program_Error. For modular types.. 10.

5). as well as the binary and unary adding operators – and +. the universal type for the class of fixed point types. 3 — Ada Reference Manual NOTES 30 Indexing and loop iteration use values of discrete types. and the exponentiation operator.For the types and subtypes declared in subclause 3.5 Operations of Discrete Types 10 November 2006 44 . Hence. an anonymous predefined (specific) real type. Rainbow'First = Red. the multiplying operators. The other predefined operations are described in Section 4. Real literals are all of the type universal_real. 3. the universal type (see 3. for an integer type they include type conversion to and from other numeric types. Color'Last = Black Rainbow'Last = Blue Color'Succ(Blue) = Rainbow'Succ(Blue) = Brown Color'Pos(Blue) = Rainbow'Pos(Blue) = 4 Color'Val(0) = Rainbow'Val(0) = White 3. Certain multiplying operators have a result type of universal_fixed (see 4.5. for a boolean type they include the short-circuit control forms and the logical operators. all real types. The assignment operation is described in 5. 31 The predefined operations of a discrete type include the assignment operation. the membership tests. whether floating point or fixed point.ISO/IEC 8652:2007(E) Ed. similarly.2.5. are in the derivation class rooted at root_real. the actual parameter of the attribute Pos need not belong to the subtype. and with absolute bounds for fixed point types. 33 For a subtype of a discrete type. and the relational operators.1) for the class rooted at root_real. 32 As for all types.1 the following hold: -----Color'First = White.5.6 Real Types 1 Real types provide approximations to the real numbers. Implementation Requirements 6 An implementation shall perform the run-time evaluation of a use of a predefined operator of root_real with an accuracy at least as great as that of any floating point type definable by a floating_point_definition.5.4. Dynamic Semantics 4 5 The elaboration of a real_type_definition consists of the elaboration of the floating_point_definition or the fixed_point_definition. with relative bounds on errors for floating point types. allowing the result of the multiplication or division to be used where any specific fixed point type is expected. objects of a discrete type have Size and Address attributes (see 13. the result delivered by the attribute Val might not belong to the subtype.3). Syntax 2 real_type_definition ::= floating_point_definition | fixed_point_definition Static Semantics 3 A type defined by a real_type_definition is implicitly derived from root_real. allowing their use with the operations of any real type. the unary operator abs. The following relations are satisfied (in the absence of an exception) by these attributes: 9 10 11 12 13 S'Val(S'Pos(X)) = X S'Pos(S'Val(N)) = N Examples 14 15 16 17 Examples of attributes of discrete subtypes: -. qualification.

Each simple_expression of a real_range_specification shall also be static. 7/2 8 9 3. which need not have all the standard characteristics of a type defined by a real_type_definition. Other real types have no literals. 3 — Ada Reference Manual Implementation Permissions For the execution of a predefined operation of a real type.2). For example.6) allow expressions of the type universal_real whenever a real type is expected. the implementation need not raise Constraint_Error if the result is outside the base range of the type. it is implementation defined whether operators that are predefined for “any real type” are defined for a particular nonstandard real type.5. static_simple_expression Name Resolution Rules 2 3 The requested decimal precision. An implementation may provide nonstandard real types. the requested decimal precision shall be no greater than System. A floating_point_definition is illegal if the implementation does not support a floating point type that satisfies the requested decimal precision and range. Each simple_expression of a real_range_specification is expected to be of any real type.ISO/IEC 8652:2007(E) Ed.. so long as the correct result is produced. An implementation may place arbitrary restrictions on the use of such types. Any type descended from a nonstandard real type is also nonstandard. such types are not permitted as explicit_generic_actual_parameters for formal scalar types — see 12.2.Max_Digits. real literals are of the anonymous predefined real type universal_real. the overload resolution rules (see 8. Legality Rules 4 5 The requested decimal precision shall be specified by a static expression whose value is positive and no greater than System. Syntax 1 floating_point_definition ::= digits static_expression [real_range_specification] real_range_specification ::= range static_simple_expression . However. If the real_range_specification is omitted. the error bound is specified as a relative precision by giving the required minimum number of significant decimal digits. Static Semantics 6 7 The set of values for a floating point type is the (infinite) set of rational numbers. The machine numbers of a floating point type are the values of the type that can be represented exactly in every unconstrained 8 45 10 November 2006 Real Types 3.5. This expression is expected to be of any integer type.6 .7 Floating Point Types For floating point types. or it might not conform to the accuracy model (see G. or the Machine_Overflows attribute of the type is False (see G. or its predefined operations might wrap around or “saturate” rather than overflow (modular or saturating arithmetic). the types need not be the same.5. is specified by the value of the expression given after the reserved word digits. which is the minimum number of significant decimal digits required for the floating point type.2).Max_Base_Digits. NOTES 34 As stated. a nonstandard real type might have an asymmetric or unsigned base range. In any case. descendants of root_real that are declared outside of the specification of package Standard.

the precision of Float should be no greater than that of Long_Float. NOTES 35 If a floating point subtype is unconstrained. 3 — Ada Reference Manual variable of the type.ISO/IEC 8652:2007(E) Ed. +10. appropriate named floating point subtypes should be provided in the library package Interfaces (see B. then its requested decimal precision shall be at least 11. Implementation Permissions 15 16 An implementation is allowed to provide additional predefined floating point types. the precision of Short_Float (if provided) should be no greater than Float.0**(4*D) where D is the requested decimal precision. unconstrained.0**(4*D) . except that it can include some extra negative values in some implementations. 18 3. floating point subtype named Float. The safe range might include other values as well. However. Similarly. A floating_point_definition also defines a first subtype of the type. Short_Short_Float. The base range (see 3. Instead. A floating_point_definition defines a floating point type whose base decimal precision is no less than the requested decimal precision. Otherwise. Implementation Requirements 14 In an implementation that supports floating point types with 6 or more digits of precision.. Implementation Advice 17 An implementation should support Long_Float in addition to Float if the target machine supports 11 or more digits of precision. Long_Long_Float.5) of a floating point type is symmetric around zero.2). then the subtype is constrained to a range whose bounds are given by a conversion of the values of the simple_expressions of the real_range_specification to the type being defined. The attributes Safe_First and Safe_Last give the actual bounds of the safe range.7 Floating Point Types 10 November 2006 46 . If a real_range_specification is given. The safe range of a floating point type is that part of its base range for which the accuracy corresponding to the base decimal precision is preserved by all predefined operations. No other named floating point subtypes are recommended for package Standard. never Range_Checks. the safe (and base) range of the type includes at least the values of the range –10.5. If a real_range_specification is not given. Corresponding recommendations apply to any other predefined floating point types. There need not be a named floating point type corresponding to each distinct base decimal precision supported by an implementation. declared in the visible part of package Standard. whose (unconstrained) first subtypes have names of the form Short_Float. 9 The base decimal precision of a floating point type is the number of decimal digits of precision representable in objects of the type. If Long_Float is predefined for an implementation. the subtype is unconstrained. also its base range) includes at least the values of the simple expressions given in the real_range_specification. declared in the visible part of Standard. If a real_range_specification is given. the safe range of the floating point type (and hence. Long_Float. There is a predefined. Dynamic Semantics 10 11 12 13 The elaboration of a floating_point_definition creates the floating point type and its first subtype. then assignments to variables of the subtype involve only Overflow_Checks. etc. Different predefined floating point types are allowed to have the same base decimal precision. the requested decimal precision for Float shall be at least 6.

their values shall be positive. the unary operator abs.0. The requested decimal precision of the base subtype of a floating point type T is defined to be the largest value of d for which ceiling(d * log(10) / log(T'Machine_Radix)) + g <= T'Model_Mantissa where g is 0 if Machine_Radix is a positive power of 10 and 1 otherwise.a subtype with a smaller range 19 20 21 22 3. For a type defined by a decimal_fixed_point_definition (a decimal fixed point type). 1.ISO/IEC 8652:2007(E) Ed. -. The error bound of a fixed point type is specified as an absolute value. the expressions given after the reserved words delta and digits shall be static. or a decimal fixed point type.5. The value of this attribute is of the type universal_integer.0. 7 47 10 November 2006 Floating Point Types 3.0 . 1.3)..0E35. 3 — Ada Reference Manual Examples Examples of floating point types and subtypes: type Coefficient is digits 10 range -1.3. Other attributes of floating point types are defined in A. 3 4 3. Syntax 1 fixed_point_definition ::= ordinary_fixed_point_definition | decimal_fixed_point_definition ordinary_fixed_point_definition ::= delta static_expression real_range_specification decimal_fixed_point_definition ::= delta static_expression digits static_expression [real_range_specification] digits_constraint ::= digits static_expression [range_constraint] Name Resolution Rules 2 3 4 5 For a type defined by a fixed_point_definition. certain multiplying operators. and explicit conversion to and from other numeric types. qualification. the number of significant decimal digits for its first subtype (the digits of the first subtype) is specified by the expression given after the reserved word digits.5.0 . Legality Rules 6 In a fixed_point_definition or digits_constraint. 1. this expression is expected to be of any real type. type Real is digits 8.0 . the delta of the type is specified by the value of the expression given after the reserved word delta. the membership tests. 1 2/1 NOTES 36 The predefined operations of a floating point type include the assignment operation. They also include the relational operators and the following predefined arithmetic operators: the binary and unary adding operators – and +.5. and the exponentiation operator. type Mass is digits 7 range 0.7 . subtype Probability is Real range 0.. this expression is expected to be of any integer type. objects of a floating point type have Size and Address attributes (see 13. 37 As for all types. called the delta of the fixed point type..9 Fixed Point Types A fixed point type is either an ordinary fixed point type.5.8 Operations of Floating Point Types Static Semantics The following attribute is defined for every floating point subtype S: S'Digits S'Digits denotes the requested decimal precision for the subtype S.

If a real_range_specification is given. where D is the value of the expression. A decimal_fixed_point_definition defines a decimal fixed point type whose base range includes at least the range –(10**digits–1)*delta . Constraint_Error is raised. For a type defined by an ordinary_fixed_point_definition (an ordinary fixed point type). the range of the first subtype is –(10**digits–1)*delta . The elaboration of a digits_constraint consists of the elaboration of the range_constraint. Dynamic Semantics 13 14 15 16 17 18 The elaboration of a fixed_point_definition creates the fixed point type and its first subtype. with each bound of its range given by the closer to zero of: • the value of the conversion to the fixed point type of the corresponding expression of the real_range_specification. The base range of the type does not necessarily include the specified bounds themselves.. the bounds of the first subtype are given by a conversion of the values of the expressions of the real_range_specification. 9 +(10**digits–1)*delta.5) of a fixed point type is symmetric around zero. 10 A fixed_point_definition is illegal if the implementation does not support a fixed point type with the given small and specified range or digits. and if it specifies (explicitly or implicitly) a range that is compatible with the subtype. a check is made that the bounds of the range are both in the range –(10**D– 1)*delta . +(10**digits–1)*delta. except possibly for an extra negative value in some implementations. the small equals the delta. If not specified. +(10**D–1)*delta. both bounds of the range shall be in the range –(10**digits–1)*delta . 19 3. 3 — Ada Reference Manual 8/2 The set of values of a fixed point type comprise the integral multiples of a number called the small of the type. the small of an ordinary fixed point type is an implementation-defined power of two less than or equal to the delta. where D is the value of the (static) expression given after the reserved word digits.. if so specified. +(10**digits–1)*delta. if any. For a digits_constraint on a decimal fixed point subtype with a given delta. Otherwise. If this check fails. the delta shall be a power of 10. +(10**D–1)*delta. If a real_range_specification is given. if it does not have a range_constraint. A decimal_fixed_point_definition also defines a constrained first subtype of the type. An ordinary_fixed_point_definition defines an ordinary fixed point type whose base range includes at least all multiples of small that are between the bounds specified in the real_range_specification. it shall be no greater than the delta of the type. • the corresponding bound of the base range.. the subtype_mark shall denote a decimal fixed point subtype. For a decimal fixed point type. A digits_constraint is compatible with a decimal fixed point subtype if the value of the expression is no greater than the digits of the subtype.. Static Semantics 11 12 The base range (see 3.3). then it specifies an implicit range –(10**D–1)*delta . If a range_constraint is given. The machine numbers of a fixed point type are the values of the type that can be represented exactly in every unconstrained variable of the type. the small may be specified by an attribute_definition_clause (see 13. An ordinary_fixed_point_definition also defines a constrained first subtype of the type.ISO/IEC 8652:2007(E) Ed.9 Fixed Point Types 10 November 2006 48 . For a subtype_indication with a digits_constraint..5.

using 1 bit for the sign and 15 bits for fraction. -. Implementation Permissions 20 Implementations are permitted to support only smalls that are a power of two. Note however that conformance with the Information Systems Annex requires support for decimal smalls.01 28 3. 3 — Ada Reference Manual Implementation Requirements The implementation shall support at least 24 bits of precision (including the sign bit) for fixed point types.0–2. 1 2/1 S'Delta S'Fore 3 4 S'Aft 5 The following additional attributes are defined for every decimal fixed point subtype S: 6 49 10 November 2006 Fixed Point Types 3.3). 255. Salary'Last = 10.Fine_Delta 25 26 27 type Money is delta 0. S'Fore yields the minimum number of characters needed before the decimal point for the decimal representation of any value of the subtype S.0 .0**(–15). (This minimum number does not include superfluous zeros or underlines. Examples 23 24 Examples of fixed point types and subtypes: type Volt is delta 0.. 1. and is at least 2. all decimal fixed point type declarations can be disallowed.. in which case the attribute yields the value one..0. The value of this attribute is of the type universal_real.01. Small may be specified for nonderived ordinary fixed point types via an attribute_definition_clause (see 13. (S'Aft is the smallest positive integer N for which (10**N)*S'Delta is greater than or equal to one. The value of this attribute is of the type universal_real.9 . --type -A pure fraction which requires all the available space in a word can be declared as the type Fraction: Fraction is delta System.01 digits 15.5. such a type could have a signed 16-bit representation.1. but includes a one-character prefix that is either a minus sign or a space.0**13 – 0. such as: 21 22 type Fraction is delta 2.0 .decimal fixed point subtype Salary is Money digits 10. assuming that the representation does not include an exponent.ISO/IEC 8652:2007(E) Ed.) The value of this attribute is of the type universal_integer. unless the delta of the subtype S is greater than 0. -.Fine_Delta range -1. S'Aft yields the number of decimal digits needed after the decimal point to accommodate the delta of the subtype S. Fraction'Last = 1.0 .0**8 – 0. NOTES 38 The base range of an ordinary fixed point type need not include the specified bounds themselves so that the range specification can be given in a natural way.5..0.0.0 . and decimal fixed point type declarations with digits up to at least 18. the expression of such a clause shall be static.10 Operations of Fixed Point Types Static Semantics The following attributes are defined for every fixed point subtype S: S'Small S'Small denotes the small of the type of S.) The value of this attribute is of the type universal_integer.0**(-15) range -1. In particular.125 range 0.0 – System.Money'Last = 10. resulting in a base range of –1. S'Delta denotes the delta of the fixed point subtype S. With 2's complement hardware. 1. 1.

• For a subtype defined by a subtype_indication without a digits_constraint. the membership tests.3). The scale indicates the position of the point relative to the rightmost significant digits of values of subtype S. objects of a fixed point type have Size and Address attributes (see 13. and the unary operator abs. • The digits of a base subtype is the largest integer D such that the range –(10**D– 1)*delta . Other attributes of fixed point types are defined in A. for example. and explicit conversion to and from other numeric types.4. The value of this attribute is of the type universal_integer. defined as the value N such that S'Delta = 10.0 then S'Aft is 1 while S'Scale is 0. 3 — Ada Reference Manual 7 S'Digits S'Digits denotes the digits of the decimal fixed point subtype S.10 Operations of Fixed Point Types 10 November 2006 50 . Syntax 2 array_type_definition ::= unconstrained_array_definition | constrained_array_definition unconstrained_array_definition ::= array(index_subtype_definition {. 42 As for all types. S'Round denotes a function with the following specification: function S'Round(X : universal_real) return S'Base 12 13 S'Round 14 The function returns the value obtained by rounding X (away from 0. multiplying operators. index_subtype_definition}) of component_definition index_subtype_definition ::= subtype_mark range <> constrained_array_definition ::= array (discrete_subtype_definition {. 8 9 10 11 S'Scale S'Scale denotes the scale of the subtype S. The name for a component of an array uses one or more index values belonging to specified discrete types. which corresponds to the number of decimal digits that are representable in objects of the subtype. NOTES 39 All subtypes of a fixed point type will have the same value for the Delta attribute. +(10**D–1)*delta is included in the base range of the type.5. in the absence of delta_constraints (see J. Its value is determined as follows: • For a first subtype or a subtype defined by a subtype_indication with a digits_constraint.5. 40 S'Scale is not always the same as S'Aft for a decimal subtype.0**(–N). qualification. The value of this attribute is of the type universal_integer.3). The value of an array object is a composite value consisting of the values of the components.. 15 16 17 18 3.6 Array Types 1 An array object is a composite object consisting of components which all have the same subtype. They also include the relational operators and the following predefined arithmetic operators: the binary and unary adding operators – and +. 41 The predefined operations of a fixed point type include the assignment operation.ISO/IEC 8652:2007(E) Ed. the digits is the value of the expression given after the reserved word digits. if S'Delta = 1. if X is midway between two values of the type of S). the digits of the subtype is the same as that of the subtype denoted by the subtype_mark in the subtype_indication. discrete_subtype_definition}) of component_definition discrete_subtype_definition ::= discrete_subtype_indication | range 3 4 5 6 3.

the values of the lower and upper bounds for each index belong to the corresponding index subtype of its type. except for null arrays (see 3. The possible values for a given index are all the values between the lower and upper bounds. The length of a one-dimensional array is the length of its only dimension. and the subtype of the components. For each object of this array type. this range of values is called the index range. inclusive. its type (the index type) shall be discrete.1). An array_type_definition defines an array type and its first subtype.6. A one-dimensional array has a distinct component for each possible index value.6 . The subtype defined by the subtype_indication of a component_definition (the component subtype) shall be a definite subtype. The discrete subtype defined by a discrete_subtype_definition is either that defined by the subtype_indication. 3 — Ada Reference Manual component_definition ::= [aliased] subtype_indication | [aliased] access_definition Name Resolution Rules 7/2 For a discrete_subtype_definition that is a range. A constrained_array_definition defines an array type with a constrained first subtype. The bounds of an array are the bounds of its index ranges. Each index_subtype_definition defines the corresponding index subtype to be the subtype denoted by the subtype_mark. The order of the indices is significant. The constraint of the first subtype consists of the bounds of the index ranges. This paragraph was deleted. the discrete_subtype_definition defines a subtype of the type of the range. the type and position of each index. 12 13 14 15 16 17 18 19 51 10 November 2006 Array Types 3. The length of a dimension of an array is the number of values of the index range of the dimension (zero for a null range). the lower and upper bounds for each index. then the discrete_subtype_definition defines a subtype of the predefined type Integer with bounds given by a conversion to Integer of the bounds of the range. or a subtype determined by the range as follows: • If the type of the range resolves to root_integer. with the bounds given by the range. which discrete type shall be determined without using any context other than the bounds of the range itself (plus the preference for root_integer — see 8. An unconstrained_array_definition defines an array type with an unconstrained first subtype. the number of indices. The compound delimiter <> (called a box) of an index_subtype_definition stands for an undefined range (different objects of the type need not have the same bounds). as well as the corresponding index range for the constrained first subtype. Static Semantics 9 10 11/2 An array is characterized by the number of indices (the dimensionality of the array). A multidimensional array has a distinct component for each possible sequence of index values that can be formed by selecting one value for each index position (in the given order). the range shall resolve to be of some specific discrete type. • Otherwise. the type and position of each index.ISO/IEC 8652:2007(E) Ed. and the subtype of the components are as in the type definition. Each discrete_subtype_definition defines the corresponding index subtype.6). Legality Rules 8 Each index_subtype_definition or discrete_subtype_definition in an array_type_definition defines an index subtype.

80. -.. others => '-'). and consists of the elaboration of the subtype_indication or the evaluation of the range. -.5. discrete_range}) discrete_range ::= discrete_subtype_indication | range 3...). 29 30/2 Examples of object declarations with array type definitions: Grid : array(1 . then each component of the array is aliased (see 3. Msg_Table : constant array(Error_Code) of access constant String := (Too_Big => new String'("Result too big"). and consists of the elaboration of any discrete_subtype_definitions and the component_definition. this means that all components have the same bounds and hence the same length.see 4.3. Dynamic Semantics 21 The elaboration of an array_type_definition creates the array type and its first subtype.Page is constrained by its initial value to (1. 3 — Ada Reference Manual 20 The component_definition of an array_type_definition defines the nominal subtype of the components.10). Examples 22/2 23 24 25 26 Examples of type declarations with unconstrained array definitions: type type type type Vector Matrix Bit_Vector Roman is is is is array(Integer array(Integer array(Integer array(Positive range range range range <>) <>..see 3. of Roman_Digit.50) 3. A consequence of this is that each object whose object_declaration contains an array_type_definition is of its own unique type. If the reserved word aliased appears in the component_definition.. others => ' ')).. NOTES 43 All components of an array have the same subtype.1 Index Constraints and Discrete Ranges 1 An index_constraint determines the range of possible values for every index of an array subtype.2 27 28 Examples of type declarations with constrained array definitions: type Table is array(1 . <>) <>) of Real. In particular.ISO/IEC 8652:2007(E) Ed. 1 . The elaboration of a component_definition in an array_type_definition consists of the elaboration of the subtype_indication or access_definition. Mix : array(Color range Red .. Integer range <>) of Real. Green) of Boolean. for an array of components that are one-dimensional arrays.an array of arrays (1 | 50 => Line'(1 | Line'Last => '+'. The elaboration of any discrete_subtype_definitions and the elaboration of the component_definition are performed in an arbitrary order.6.8. and thereby the corresponding array bounds. 49 => Line'(1 | Line'Last => '|'. type Line is array(1 . Syntax 2 3 index_constraint ::= (discrete_range {.3 2 .6 Array Types 10 November 2006 52 . type Schedule is array(Day) of Boolean. 44 Each elaboration of an array_type_definition creates a distinct array type. 10) of Integer. Too_Small => . The elaboration of a discrete_subtype_definition that contains one or more per-object expressions is defined in 3. of Boolean.. 100) of Boolean.. -. Max_Line_Size) of Character. Page : array(Positive range <>) of Line := -. The elaboration of a discrete_subtype_definition that does not contain any per-object expressions creates the discrete subtype.

46 Even if an array value does not satisfy the index constraint of an array subtype. so long as the length of each dimension of the array value and the array subtype match. If any of the discrete_ranges defines a null range.2. An array value satisfies an index_constraint if at each index position the array value and the index_constraint have the same index bounds. the index_constraint shall provide a discrete_range for each index of the array type. N. -. Examples 7 8 9 10 Examples of array declarations including an index constraint: Board : Matrix(1 . Static Semantics 5 A discrete_range defines a range whose bounds are given by the range.. in either case. See 4. 1 . 3 — Ada Reference Manual Name Resolution Rules The type of a discrete_range is the type of the subtype defined by the subtype_indication.Null_Line. or an unconstrained access subtype whose designated subtype is an unconstrained array subtype. or by the range of the subtype defined by the subtype_indication.. -. 1 . 31). end record. Length). 11 12 13 14 15 16 17 Example of array declaration with a constrained array subtype: My_Schedule : Schedule. Null_Line : Var_Line(0). 1 . N). in an arbitrary order. NOTES 45 The elaboration of a subtype_indication consisting of a subtype_mark followed by an index_constraint checks the compatibility of the index_constraint with the subtype_mark (see 3. having no components.6 Rectangle : Matrix(1 . or the type of the range. any array thus constrained is a null array. The elaboration of an index_constraint consists of the evaluation of the discrete_range(s).2).N need not be static Filter : Bit_Vector(0 .6. -.. each discrete_range shall resolve to be of the type of the corresponding index.6.ISO/IEC 8652:2007(E) Ed. 8.. For an index_constraint.1 . 8). 30).5) with the corresponding index subtype. 20. Dynamic Semantics 6 An index_constraint is compatible with an unconstrained array subtype if and only if the index range defined by each discrete_range is compatible (see 3. Constraint_Error is not raised on conversion to the array subtype. Inverse : Matrix(1 .... The evaluation of a discrete_range consists of the elaboration of the subtype_indication or the evaluation of the range. Legality Rules 4 An index_constraint shall appear only in a subtype_indication whose subtype_mark denotes either an unconstrained array subtype. -.Image is a null array 18 53 10 November 2006 Index Constraints and Discrete Ranges 3.see 3..all arrays of type Schedule have the same bounds Example of record type with a component that is an array: type Var_Line(Length : Natural) is record Image : String(1 .

. and A'Length. For a one-dimensional array type. string literals are defined if the component type is a character type. its type is universal_integer. The value of N shall be positive (nonzero) and no greater than the dimensionality of the array. the predefined relational operators.6. if the component type is boolean.3). A'First(N) denotes the lower bound of the N-th index range. A'Last.. qualification. then column-major order should be used instead (see B. The following relation is satisfied (except for a null array) by the above attributes if the index type is an integer type: 12 13 14 15 A'Length(N) = A'Last(N) . A'Last(N). if a pragma Convention(Fortran. they also include assignment and the predefined equality operators. consistent with the notation used for multidimensional array aggregates (see 4. A'Length denotes the number of values of the first index range (zero for a null range). A'Last denotes the upper bound of the first index range.2 Operations of Array Types 10 November 2006 54 . its type is the corresponding index type. 49 The predefined operations of an array type include the membership tests. or denotes a constrained array subtype: A'First A'First(N) A'Last A'Last(N) A'Range A'Range(N) A'Length A'First denotes the lower bound of the first index range. they include the predefined concatenation operators (if nonlimited) and.. Static Semantics 2/1 The following attributes are defined for a prefix A that is of an array type (after any implicit dereference). NOTES 47 The attribute_references A'First and A'First(1) denote the same value. its type is the corresponding index type.) applies to a multidimensional array type. if the component type is discrete. If the array type is not limited. A'Last(N) denotes the upper bound of the N-th index range. A similar relation exists for the attribute_references A'Last. Implementation Advice 11 An implementation should normally represent multidimensional arrays in row-major order. 3 — Ada Reference Manual 3.3.A'First(N) + 1 48 An array type is limited if its component type is limited (see 7.. 50 A component of an array can be named with an indexed_component. A value of an array type can be specified with an array_aggregate.. A'Range(N) is equivalent to the range A'First(N) . a slice of the array can be named. its type is the corresponding index type.5. and explicit conversion.2 Operations of Array Types Legality Rules 1 The argument N used in the attribute_designators for the N-th dimension of an array shall be a static expression of some integer type. except that the prefix A is only evaluated once. A'Range is equivalent to the range A'First . its type is universal_integer.5). its type is the corresponding index type. 3 4 5 6 7 8 9 10 A'Length(N) A'Length(N) denotes the number of values of the N-th index range (zero for a null range). except that the prefix A is only evaluated once. “Interfacing with Fortran”).ISO/IEC 8652:2007(E) Ed. 16/2 3. the predefined logical operators are also included. also. A'Range. For a one-dimensional array type. However.6.

40) Ninety_Six : constant Roman := "XCVI". 120 => '*' ). type Wide_Wide_String is array(Positive range <>) of Wide_Wide_Character. these ordering operators correspond to lexicographic order (see 4. Wide_String.2 and 3.3 String Types Static Semantics A one-dimensional array type whose component type is a character type is called a string type. -.2) are defined for all string types.Question'First = 1. Syntax 1/2 discriminant_part ::= unknown_discriminant_part | known_discriminant_part unknown_discriminant_part ::= (<>) known_discriminant_part ::= (discriminant_specification {. A discriminant of an object is a component of the object. type Wide_String is array(Positive range <>) of Wide_Character.7 Discriminants A composite type (other than an array or interface type) can have discriminants.6.. An unknown_discriminant_part in the declaration of a view of a type specifies that the discriminants of the type are unknown for the given view. String. -. There are three predefined string types.Question'Length = 20 (the number of 6 7 8 3.6.see 3. as for all nonlimited one-dimensional array types. A known_discriminant_part specifies the discriminants of a composite type.1): --Filter'First = Rectangle'Last(1) = 0 20 Filter'Last = Rectangle'Last(2) = 31 30 Filter'Length = 32 17 18 3. The concatenation operator & is predefined for string types.6 : String(1 .2).6 and 4. Question'Last = 20 -.5. >. discriminant_specification}) discriminant_specification ::= defining_identifier_list : [null_exclusion] subtype_mark [:= default_expression] | defining_identifier_list : access_definition [:= default_expression] default_expression ::= expression 2/2 3 4 5/2 6 55 10 November 2006 Operations of Array Types 3. type String is array(Positive range <>) of Character. <=.ISO/IEC 8652:2007(E) Ed. Examples 1 2/2 3 4/2 5 Examples of string objects: Stars Question characters) Ask_Twice : String := Question & Question. all subtypes of such a view are indefinite subtypes..5. which parameterize the type. The ordering operators <. NOTES 51 String literals (see 2. and >= are predefined for string types. each indexed by values of the predefined subtype Positive.6. -. these are declared in the visible part of package Standard: subtype Positive is Integer range 1 . and Wide_Wide_String.. 3 — Ada Reference Manual Examples Examples (using arrays declared in the examples of subclause 3. as for all one-dimensional discrete array types. Integer'Last.2 . and is either of a discrete type or an access type.constrained to (1. 120) := (1 . : constant String := "How many characters?"..

When inherited or constrained to equal some new discriminant. A discriminant corresponds to itself as well.3). 18 3. The type of the default_expression. Two discriminants also correspond if there is some common discriminant to which they both correspond. or it may be defined by an access_definition. each discriminant of the parent type is either inherited. or for a type that is a descendant of an explicitly limited record type. as is a type that inherits (known) discriminants.7 Discriminants 10 November 2006 56 . the subtype of the discriminant shall be statically compatible (see 4. • If the parent type is not a tagged type. No default_expressions are permitted in a known_discriminant_part in a declaration 9/2 9.ISO/IEC 8652:2007(E) Ed. For a type defined by a derived_type_definition. if a known_discriminant_part is provided in its declaration. if any. then each discriminant of the derived type shall be used in the constraint defining the parent subtype. in which case the subtype_mark shall denote a discrete or access subtype. for an access discriminant shall be convertible to the anonymous access type of the discriminant (see 4. then: • The parent subtype shall be constrained. Static Semantics 13 14 15 16 17 A discriminant_specification declares a discriminant. If a discriminant of a parent type is constrained to a specific value by a derived_type_definition. This paragraph was deleted. In addition to the places where Legality Rules normally apply (see 12. in which case the discriminant's subtype is the anonymous access-to-variable subtype defined by the access_definition. the parent discriminant and the discriminant of the derived type are said to correspond. then that discriminant is said to be specified by that derived_type_definition. A type declared with a known_discriminant_part is called a discriminated type. • If a discriminant is used in the constraint defining the parent subtype. 3 — Ada Reference Manual Name Resolution Rules 7 The expected type for the default_expression of a discriminant_specification is that of the corresponding discriminant. this rule applies also in the private part of an instance of a generic unit. the subtype_mark denotes its subtype unless it is an access discriminant.6). A discriminant that is defined by an access_definition is called an access discriminant and is of an anonymous access type. or constrained to the value of an expression.9.1) with the subtype of the corresponding parent discriminant.1/2 of a tagged type or a generic formal type. The subtype of a discriminant may be defined by an optional null_exclusion and a subtype_mark. 11/2 12 For a type defined by a derived_type_definition. constrained to equal some new discriminant of the derived type. 10/2 A discriminant_specification for an access discriminant may have a default_expression only in the declaration for a task or protected type. Default_expressions shall be provided either for all or for none of the discriminants of a known_discriminant_part. Legality Rules 8/2 A discriminant_part is only permitted in a declaration for a composite type that is not an array or interface type (this includes generic formal types).

see 3.. its access_definition is elaborated when the value of the access discriminant is defined: by evaluation of its default_expression. or none) as its parent (or ancestor) type.6 57 10 November 2006 Discriminants 3. end record. Each value of a discriminated type includes a value for each component of the type that does not depend on a discriminant. Rows. A type declared without a discriminant_part has no discriminants. A component depends on a discriminant if: • Its component_definition depends on the discriminant. the values of the discriminants of such a variable cannot be changed after initialization.3). 55 A discriminant that is of a named access type is not called an access discriminant. either by explicit constraint or by their initial value. and the constraint of the parent_subtype_indication depends on the discriminant. since the name of a discriminant is a constant. unless it is a derived type. NOTES 52 If a discriminated type has default_expressions for its discriminants. end record. such a type has the same sort of discriminants (known. Dynamic Semantics 19 20 21 22 23 24 25 26 For an access discriminant. then unconstrained variables of the type are permitted. then all variables of the type are constrained. Examples 27/2 28 29 30 31 Examples of discriminated types: type Buffer(Size : Buffer_Size := 100) record Pos : Buffer_Size := 0. unknown. or • It is a component inherited as part of a derived_type_definition.ISO/IEC 8652:2007(E) Ed. Size). Any subtype of a type with unknown discriminants is an unconstrained and indefinite subtype (see 3.. Value : String(1 . A tagged class-wide type also has unknown discriminants. 54 Assignment to a discriminant of an object (after its initialization) is not allowed.4 32 33 type Matrix_Rec(Rows..2 and 3. The values of discriminants determine which other component values are present in the value of the discriminated type. 53 The default_expression for a discriminant of a type is evaluated when an object of an unconstrained subtype of the type is created. or on a discriminant that corresponds to it. or • It is a subcomponent of a component that depends on the discriminant. is -. its first subtype is unconstrained. and the values of the discriminants can be changed by an assignment to such a variable. A component_definition depends on a discriminant if its constraint depends on the discriminant. A type declared with a known_discriminant_part is said to have known discriminants.see 3. or by an assignment that initializes the enclosing object. A type declared with an unknown_discriminant_part is said to have unknown discriminants. If defaults are not provided for the discriminants.5. this includes the discriminants themselves. Columns : Integer) is record Mat : Matrix(1 . Columns).7 . 34 -. Note however that the value of a discriminant can be changed by assigning to the enclosing object. that term is used only for discriminants defined by an access_definition. or • It is declared in a variant_part that is governed by the discriminant. 1 . 3 — Ada Reference Manual A constraint that appears within the definition of a discriminated type depends on a discriminant of the type if it names the discriminant as a bound or discriminant value. neither assignment_statements nor assignments inherent in passing as an in out or out parameter are allowed. presuming it is an unconstrained variable. by elaboration of a discriminant_constraint. if derived.

end record. this rule is checked presuming all formal access types of the generic might be general access types. However. any positional associations shall precede any named associations.discriminants used to parameterize the task type (see 9. The expected type for the expression in a discriminant_association is that of the associated discriminant(s). end Worker.7 Discriminants 10 November 2006 58 . Syntax 2 discriminant_constraint ::= (discriminant_association {. Right : Square(Number). task type Worker(Prio : System. in the case of an access subtype. these rules apply also in the private part of an instance of a generic unit. and all untagged discriminated formal types of the generic might have default_expressions for their discriminants.1 Discriminant Constraints 1 A discriminant_constraint specifies the values of the discriminants for a given discriminated type. a discriminant_constraint is illegal if the designated type has a partial view that is constrained or. Buf : access Buffer) is -. 3 — Ada Reference Manual 35 36 type Square(Side : Integer) is new Matrix_Rec(Rows => Side.Priority.1 entry Fill.1) pragma Priority(Prio). 37/2 3. For a positional association. Name Resolution Rules 5 Each selector_name of a named discriminant_association shall resolve to denote a discriminant of the subtype being constrained. discriminant_association}) discriminant_association ::= [discriminant_selector_name {| discriminant_selector_name} =>] expression 3 4 A discriminant_association is said to be named if it has one or more discriminant_selector_names. Legality Rules 6 7/2 A discriminant_constraint is only allowed in a subtype_indication whose subtype_mark denotes either an unconstrained discriminated subtype. or an unconstrained access subtype whose designated subtype is an unconstrained discriminated subtype. In addition to the places where Legality Rules normally apply (see 12. In a discriminant_constraint.7. A discriminant_constraint shall provide exactly one value for each discriminant of the subtype being constrained. it is otherwise said to be positional. the associated discriminant is the one whose discriminant_specification occurred in the corresponding position in the known_discriminant_part that defined the discriminants of the subtype being constrained. Columns => Side).ISO/IEC 8652:2007(E) Ed. entry Drain. A named discriminant_association with more than one selector_name is allowed only if the named discriminants are all of the same type. the discriminants so named are the associated discriminants of the named association. 8 3.3). -. has default_expressions for its discriminants.see D. type Double_Square(Number : Integer) is record Left : Square(Number). for a general access subtype. In a generic body.

ISO/IEC 8652:2007(E) Ed. a Square has to be constrained 14 15 3. Message : Buffer. For the elaboration of a discriminant_constraint.2 Operations of Discriminated Types If a discriminated type has default_expressions for its discriminants. Examples 10 11 12 13 Examples (using types declared above in clause 3. and the discriminants of such a variable can be changed by assignment to the variable. and False otherwise. always 5 by 5 illegal. the following attribute is defined: A'Constrained Yields the value True if A denotes a constant. always 200 characters (explicit discriminant value) unconstrained. the expression of a named association is evaluated (and converted) once for each associated discriminant. Basis : Square(5).6).7. ------constrained.1 . A composite value satisfies a discriminant constraint if and only if each discriminant of the composite value has the value imposed by the discriminant constraint. 3 — Ada Reference Manual The expression associated with an access discriminant shall be of a type convertible to the anonymous access type.7): Large : Buffer(200). Dynamic Semantics 9 A discriminant_constraint is compatible with an unconstrained discriminated subtype if each discriminant value belongs to the subtype of the corresponding discriminant. an attribute is provided to determine whether the corresponding actual parameter is constrained or unconstrained. The result of each evaluation and conversion is the value imposed by the constraint for the associated discriminant. a value. For a formal parameter of such a type. 4 59 10 November 2006 Discriminant Constraints 3. initially 100 characters (default discriminant value) constrained. NOTES 56 The rules of the language ensure that a discriminant of an object always has a value. Illegal : Square. Erroneous Execution 2 3 The execution of a construct is erroneous if the construct has a constituent that is a name denoting a subcomponent that depends on discriminants. or a constrained variable. either from explicit or implicit initialization. the expressions in the discriminant_associations are evaluated in an arbitrary order and converted to the type of the associated discriminant (which might raise Constraint_Error — see 4. then unconstrained variables of the type are permitted.7. and the value of any of these discriminants is changed by this execution between evaluating the name and the last use (within this execution) of the subcomponent denoted by the name. Static Semantics 1 For a prefix A that is of a discriminated type (after any implicit dereference).

The identifiers of all components of a record type shall be distinct. 10 11 12 13 3. The value of a record object is a composite value consisting of the values of the components. but not within the discriminant_part. a name that denotes a component. If the name of the current instance of a type (see 8. and the attribute_reference shall appear alone. if any. Besides components declared by component_declarations. Within a type_declaration. or the constraint of the parent subtype in a derived_type_definition then its name shall appear alone as a direct_name (not as part of a larger expression or expanded name). the bounds of an entry family. protected subprogram. 3 — Ada Reference Manual 3. or entry of the type is allowed only in the following cases: • A name that denotes any component.ISO/IEC 8652:2007(E) Ed. Name Resolution Rules 7 The expected type for the default_expression. Syntax 2 3 record_type_definition ::= [[abstract] tagged] [limited] record_definition record_definition ::= record component_list end record | null record 4 component_list ::= component_item {component_item} | {component_item} variant_part | null. A discriminant shall not be used to define the constraint of a scalar component.8 Record Types 10 November 2006 60 . 5/1 6 component_item ::= component_declaration | aspect_clause component_declaration ::= defining_identifier_list : component_definition [:= default_expression]. • A name that denotes a noninherited discriminant is allowed within the declaration of the type. Each component_declaration declares a component of the record type. then it shall appear as a direct_name that is the prefix of an attribute_reference whose result is of an access type. protected subprogram. If the discriminant is used to define the constraint of a component.8 Record Types 1 A record object is a composite object consisting of named components. the components of a record type include any components declared by discriminant_specifications of the record type declaration. Legality Rules 8/2 9/2 This paragraph was deleted. in a component_declaration is the type of the component. or entry is allowed within a representation item that occurs within the declaration of the composite type.6) is used to define the constraint of a component.

3. If the reserved word aliased appears in the component_definition. or if any of its components are limited (see 7. including the subtype compatibility check (see 3. The elaboration of a component_declaration consists of the elaboration of the component_definition.1. For the elaboration of a component_definition of a component_declaration or the discrete_subtype_definition of an entry_declaration for an entry family (see 9. If the component_list of a record type is defined by the reserved word null and there are no discriminants. if the constraint or range is a per-object constraint. then the elaboration consists of the evaluation of any included expression that is not part of a per-object expression.1).6) has to be a definite subtype. 16 17 18/2 18. Each such expression is evaluated once unless it is part of a named association in a discriminant constraint. subtype_indication. For other expressions. in which case it is evaluated once for each associated discriminant.2). The elaboration of a component_list consists of the elaboration of the component_items and variant_part.2). and explicit conversion.5). and consists of the elaboration of the record_definition. each per-object expression of the constraint is evaluated. as explained in 3. When a per-object constraint is elaborated (as part of creating an object). if it is in a variant_part — see 3. if any. 3 — Ada Reference Manual Static Semantics If a record_type_definition includes the reserved word limited. The elaboration of a record_definition consists of the elaboration of its component_list. If the record type is nonlimited. The component_definition of a component_declaration defines the (nominal) subtype of the component. in the order in which they appear. qualification. Any checks associated with the enclosing subtype_indication or discrete_subtype_definition are performed. 58 The default_expression of a record component is only evaluated upon the creation of a default-initialized object of the record type (presuming the object has the component. A record_definition of null record is equivalent to record null. On the other hand.5.2) includes a name that denotes a discriminant of the type.3.8 . 59 The subtype defined by a component_definition (see 3. they also include assignment and the predefined equality operators. the values determined during the elaboration of the component_definition or entry_declaration are used. and the associated subtype is created. NOTES 57 A component_declaration with several identifiers is equivalent to a sequence of single component_declarations. 60 If a record type does not have a variant_part.1/2 14 15 The elaboration of a record_type_definition creates the record type and its first subtype. 62 The predefined operations of a record type include membership tests. or discrete_subtype_definition is elaborated. if any. the type is called an explicitly limited record type.1/1 19 20 21 22 23 24 61 10 November 2006 Record Types 3.10). then the access_definition. Within the definition of a composite type. and the constraint or range being defined is called a per-object constraint. Dynamic Semantics 13. if a component_definition or discrete_subtype_definition (see 9.2. 61 A record type is limited if it has the reserved word limited in its definition.5. if the component subtype is defined by an access_definition or if the constraint or range of the subtype_indication or discrete_subtype_definition is not a per-object constraint. end record. the expression containing the name is called a per-object expression. then the record type has no components and all records of the type are null records. then the component is aliased (see 3.ISO/IEC 8652:2007(E) Ed. or that is an attribute_reference whose prefix denotes the current instance of the type. then the same components are present in all values of the type.

Year : Integer range 0 . A value of a record can be specified with a record_aggregate. 31. 3 — Ada Reference Manual 25/2 63 A component of a record can be named with a selected_component. type Complex is record Re : Real := 0. Examples 26 27 Examples of record type declarations: type Date is record Day : Integer range 1 . and C are implicitly initialized to zero 3.ISO/IEC 8652:2007(E) Ed.. 4000. The discrete_choice others shall appear alone in a discrete_choice_list. The expressions and discrete_ranges given as discrete_choices in a variant_part shall be static. end record. 28 29 30 31 Examples of record variables: Tomorrow.0. shall be the last one in the enclosing construct. -. B. Legality Rules 7 8 The discriminant of the variant_part shall be of a discrete type. Month : Month_Name. 3. C : Complex.. A.8 Record Types 10 November 2006 62 . B. Yesterday : Date. Im : Real := 0.8.both components of A. Syntax 2 variant_part ::= case discriminant_direct_name is variant {variant} end case. and such a discrete_choice_list.0.1 Variant Parts and Discrete Choices 1 A record type with a variant_part specifies alternative lists of components. Each variant defines the components for the value or values of the discriminant covered by its discrete_choice_list. if it appears. 3 variant ::= when discrete_choice_list => component_list discrete_choice_list ::= discrete_choice {| discrete_choice} discrete_choice ::= expression | discrete_range | others Name Resolution Rules 4 5 6 The discriminant_direct_name shall resolve to denote a discriminant (called the discriminant of the variant_part) specified in the known_discriminant_part of the full_type_declaration that contains the variant_part. The expected type for each discrete_choice in a variant is the type of the discriminant of the variant_part. end record.

end record. The possible values of the discriminant of a variant_part shall be covered as follows: • If the discriminant is of a static constrained scalar subtype. each value of the base range of the type of the discriminant shall be covered (either explicitly or by others). Closed). included in the component_list of the given variant.1 . • Otherwise. Disk. end case.7) to the discriminant of the variant_part. • The discrete_choice others covers all values of its expected type that are not covered by previous discrete_choice_lists of the same construct.ISO/IEC 8652:2007(E) Ed. • If the type of the discriminant is a descendant of a generic formal scalar type then the variant_part shall have an others discrete_choice. • A discrete_choice that is a discrete_range covers all values (possibly none) that belong to the range. In addition. type State is (Open. This rule applies in turn to any further variant that is. Drum). The elaboration of a variant_part consists of the elaboration of the component_list of each variant in the order in which they appear. type Peripheral(Unit : Device := Disk) is record Status : State. 3 — Ada Reference Manual A discrete_choice is defined to cover a value in the following cases: • A discrete_choice that is an expression covers a value if the value equals the value of the expression converted to the expected type. the discriminant of a derived type governs a variant_part and its variants if it corresponds (see 3. A discrete_choice_list covers a value if one of its discrete_choices covers the value. itself. Examples 21 22 Example of record type with a variant part: type Device is (Printer.8. Dynamic Semantics 19 20 A record value contains the values of the components of a particular variant only if the value of the discriminant governing the variant is covered by the discrete_choice_list of the variant. The discriminant of a variant_part is said to govern the variant_part and its variants. Page_Size. Static Semantics 9 10 11 12 13 14 15 16 17 18 If the component_list of a variant is specified by null. 23 24 25 63 10 November 2006 Variant Parts and Discrete Choices 3. the variant has no components.. case Unit is when Printer => Line_Count : Integer range 1 . then each non-others discrete_choice shall cover only values in that subtype. Two distinct discrete_choices of a variant_part shall not cover the same value. when others => Cylinder : Cylinder_Index. and each value of that subtype shall be covered by some discrete_choice (either explicitly or by others). Track : Track_Number.

4). 3 — Ada Reference Manual 26 27 Examples of record subtypes: subtype Drum_Unit is Peripheral(Drum). A record extension is defined by a derived_type_definition with a record_extension_part (see 3.8. For a tagged type that is local to a generic package body and with all of its ancestors (if any) also local to the generic body. additional primitive subprograms may be defined. can be declared in the visible part of a package (see 7. pragma Preelaborable_Initialization(Tag). function function function function function Expanded_Name(T : Tag) return String. No_Tag : constant Tag. or simply a type extension. => Printer). which is a partial view of a record extension or of a synchronized tagged type.1).1/2 7/2 7. 28 29 Examples of constrained record variables: Writer Archive : Peripheral(Unit : Disk_Unit. or a non-interface synchronized tagged type (see 3.1/2 function Descendant_Tag(External : String. Static Semantics 2/2 A record type or private type that has the reserved word tagged in its declaration is called a tagged type. Ancestor : Tag) return Tag. which may include the definition of additional components. Internal_Tag(External : String) return Tag. as for any derived type.3) or in a generic formal part (see 12. 2. Wide_Wide_Expanded_Name(T : Tag) return Wide_Wide_String. The tag of a specific tagged type identifies the full_type_declaration of the type. In addition. an interface type is a tagged type. the language does not specify whether repeated instantiations of the generic body result in distinct tags.9.2). subtype Disk_Unit is Peripheral(Disk). If a declaration for a tagged type occurs within a generic_package_declaration.Tags is pragma Preelaborate(Tags).9.1/2 3 4/2 5 6/2 6. Wide_Expanded_Name(T : Tag) return Wide_String. and is a record extension or a private extension of some other tagged type.5.ISO/IEC 8652:2007(E) Ed. Every type extension is also a tagged type. using a tag to control which body to execute is called dispatching.9. as is a task or protected type derived from an interface (see 3. and inherited primitive subprograms may be overridden. then the corresponding type declarations in distinct instances of the generic package are associated with distinct tags. 3. When deriving from a tagged type.9. is sufficient to uniquely identify the type among all descendants of the same ancestor.4). based on inheritance with extension and run-time polymorphism via dispatching operations. The derived type is called an extension of its ancestor types.1). Ancestor : Tag) return Boolean. and for a type extension. type Tag is private. function Is_Descendant_At_Same_Level(Descendant.1 Variant Parts and Discrete Choices 10 November 2006 64 .9 Tagged Types and Type Extensions 1 Tagged types and type extensions support object-oriented programming. A private extension. An object of a tagged type has an associated (run-time) tag that identifies the specific tagged type used to create the object originally. The tag of an operand of a class-wide tagged type T'Class controls which subprogram body is to be executed when a primitive subprogram of type T is applied to the operand (see 3. External_Tag(T : Tag) return String. The following language-defined library package exists: package Ada. 3.

and the order of the returned tags is unspecified.ISO/IEC 8652:2007(E) Ed. then No_Tag is returned. The function External_Tag returns a string to be used in an external representation for the given tag. or raises Tag_Error if the given string is not the external tag for any specific type of the partition.2/2 12. it was not declared by a derived_type_declaration). in upper case.Tags. Wide_Wide_Expanded_Name. The function Descendant_Tag returns the (internal) tag for the type that corresponds to the given external tag and is both a descendant of the type identified by the Ancestor tag and has the same accessibility level as the identified ancestor. The function Expanded_Name (respectively. it returns False. However. 12/2 12. type Tag_Array is array (Positive range <>) of Tag. then the values of S'Class are only those that when converted to the type T belong to S.4/2 8 9 No_Tag is the default initial value of type Tag. private .9 . Tag_Error is raised if External is not the external tag for such a type. Wide_Expanded_Name. a null array is returned. otherwise.3/2 12. Tag_Error is also raised if the specific type identified is a library-level type whose tag has not yet been created (see 13. starting with a root library unit. Each tag appears in the result exactly once. The function Interface_Ancestor_Tags returns an array containing the tag of each interface ancestor type of the type whose tag is T.4/2 13 14 15 65 10 November 2006 Tagged Types and Type Extensions 3. 3 — Ada Reference Manual function Parent_Tag (T : Tag) return Tag.1/2 The function Internal_Tag returns a tag that corresponds to the given external tag. other than T itself. If not. The function Is_Descendant_At_Same_Level returns True if the Descendant tag identifies a type that is both a descendant of the type identified by Ancestor and at the same accessibility level. Tag_Error : exception. 7. For every subtype S of a tagged type T (specific or class-wide). the sequence of characters is implementation defined. if S is constrained. If the type whose tag is T has no interface ancestors. The lower bound of the returned array is 1.3/2 7. Wide_Expanded_Name) returns the same sequence of graphic characters as that defined for Wide_Wide_Expanded_Name. but no shorter than that returned by Wide_Wide_Expanded_Name for the same value of the argument. -. The function Parent_Tag returns the tag of the parent type of the type whose tag is T.1/2 11 11.14). then S'Class is the same as S).not specified by the language end Ada. and External_Tag has lower bound 1. The function Wide_Wide_Expanded_Name returns the full expanded name of the first subtype of the specific type identified by the tag.2/2 7... The string returned by the functions Expanded_Name.3). The result is implementation defined if the type is declared within an unnamed block_statement. If the type does not have a parent type (that is. Tag_Error is also raised if the specific type identified is a library-level type whose tag has not yet been created. the following attributes are defined: S'Class S'Class denotes a subtype of the class-wide type (called T'Class in this International Standard) for the class rooted at T (or if S already denotes a class-wide subtype. if all the graphic characters are defined in Character (respectively. S'Class is unconstrained. function Interface_Ancestor_Tags (T : Tag) return Tag_Array. 9. Wide_Character).1/2 10/2 10.1/2 12. The call External_Tag(S'Tag) is equivalent to the attribute_reference S'External_Tag (see 13.

• The tag of an object of a class-wide tagged type is that of its initialization expression. with function Constructor (Params : not null access Parameters) return T is abstract. 17 Given a prefix X that is of a class-wide tagged type (after any implicit dereference).Generic_Dispatching_Constructor (The_Tag : Tag. An instance of Tags. type Parameters (<>) is limited private. Dynamic Semantics 19 20 The tag associated with an object of a tagged type is determined as follows: • The tag of a stand-alone object. 3. 18 18.2/2 The following language-defined generic function exists: generic type T (<>) is abstract tagged limited private. Generic_Dispatching_Constructor). pragma Preelaborate(Generic_Dispatching_Constructor). Params : not null access Parameters) return T'Class.2/2 25. • The tag of an object created by an allocator for an access type with a specific designated tagged type T.Generic_Dispatching_Constructor or to any subprogram declared in package Tags identifies either a type that is not library-level and whose tag has not been created (see 13. External_Tag. identifies T. Erroneous Execution 21 22 23 24/2 25 25.Generic_Dispatching_Constructor raises Tag_Error if The_Tag does not represent a concrete descendant of T or if the innermost master (see 7. Interface_Ancestor_Tag. a component. 3 — Ada Reference Manual 16 S'Tag S'Tag denotes the tag of the type T (or if T is class-wide. or an aggregate of a specific tagged type T identifies T. • The tag of the result returned by a function whose result type is a specific tagged type T identifies T. or Parent_Tag if any tag passed is No_Tag. it dispatches to the primitive function denoted by the formal Constructor for the type identified by The_Tag. Otherwise. the tag of the root type of the corresponding class).ISO/IEC 8652:2007(E) Ed.6. Is_Descendant_At_Same_Level. pragma Convention(Intrinsic. The function Constructor is expected to create the object given a reference to an object of type Parameters. function Ada.3/2 Tags. • The tag of the result returned by a function with a class-wide result type is that of the return object. The value of this attribute is of type Tag.1/2 18. The value of this attribute is of type Tag. The tag of a value is the tag of the associated object (see 6. The tag is preserved by type conversion and by parameter passing. then execution is erroneous.9 Tagged Types and Type Extensions 10 November 2006 66 .Tags. the following attribute is defined: X'Tag X'Tag denotes the tag of X. and returns the result. Expanded_Name.1/2 25.14).2).Generic_Dispatching_Constructor provides a mechanism to create an object of an appropriate type from just a tag value.1) of this descendant is not also a master of the instance. Tag_Error is raised by a call of Descendant_Tag. passing Params. or a type that does not exist in the partition at the time of the call. 18. Any exception raised by the function is propagated.3/2 If an internal tag provided to an instance of Tags.

9 5 . Y : Real := 0. or a non-interface synchronized tagged type.Generic_Dispatching_Constructor is sometimes known as a factory.ISO/IEC 8652:2007(E) Ed. end record. Static Semantics 3/2 4/2 A record extension is a null extension if its declaration has no known_discriminant_part and its record_extension_part includes no component_declarations. This means that objects of a class-wide type have to be explicitly initialized (whether created by an object_declaration or an allocator).1 Type Extensions Every type extension is a tagged type.7). type Expression is tagged null record. Examples Examples of tagged record types: type Point is tagged record X. This paragraph was deleted. a tagged type shall not be declared as a descendant of a formal type declared within the formal part of the generic unit.Components will be added by each extension 31 32 33 3. -. Implementation Advice 26/2 Internal_Tag should return the tag of a type whose innermost master is the master of the point of the function call..1/2 67 The capability provided by Tags. Dynamic Semantics 4. NOTES 64 A type declared with the reserved word tagged should normally be declared in a package_specification. If the parent type or any progenitor is nonlimited. its tag never changes.0. or the body of any of its descendant library units. In addition to the places where Legality Rules normally apply (see 12.9. and is a record extension or a private extension of some other tagged type. 65 Once an object has been created.9. 26. these rules apply also in the private part of an instance of a generic unit. or if there is no such type whose innermost master is a master of the point of the function call.1/2 27 28 29 30/2 30. 3 — Ada Reference Manual Implementation Permissions The implementation of Internal_Tag and Descendant_Tag may raise Tag_Error if no specific type corresponding to the string External passed as a parameter exists in the partition at the time the function is called. Syntax 1/2 record_extension_part ::= with record_definition Legality Rules 2 The parent type of a record extension shall not be a class-wide type nor shall it be a synchronized tagged type (see 3. 67 10 November 2006 Tagged Types and Type Extensions 3. then each of the components of the record_extension_part shall be nonlimited. and that aggregates have to be explicitly qualified with a specific type when their expected type is class-wide.4). so that new primitive subprograms can be declared for it. 66 Class-wide types are defined to have unknown discriminants (see 3.3). Within the body of a generic unit.1/2 The elaboration of a record_extension_part consists of the elaboration of the record_definition.

providing there is a new known_discriminant_part in the enclosing type declaration. end record. 3.0–7. A dispatching operation can be called using a statically determined controlling tag.No additional components needed for these extensions Tree : Expr_Ptr := -. end record. Run-time polymorphism is achieved when a dispatching operation is called by a dispatching call.2) at the end of the declaration list where the type is declared are called dispatching operations. primitive subprograms are inherited and are overridable. 12 13 14 15 16 17 3. -.9): type Painted_Point is new Point with record Paint : Color := White. in which case the call dispatches to a body that is determined at run time.2 Dispatching Operations of Tagged Types 1/2 The primitive subprograms of a tagged type. Right => new Subtraction'( Left => new Literal'(Value => 13. Paint => Black). such a call is termed a dispatching call.0 + (13. and the stream attributes of a specific tagged type that are available (see 13. type Addition is new Binary_Operation with null record.0. the subprograms declared by formal_abstract_subprogram_declarations.1 Type Extensions 10 November 2006 68 .) 71 Each visible component of a record extension has to have a unique name. Alternatively.8. whether the component is (visibly) inherited from the parent type or declared in the record_extension_part (see 8. the controlling tag can be dynamically determined. type Subtraction is new Binary_Operation with null record. -. a name that denotes a component defined within the record_extension_part is not allowed within the record_extension_part. but new primitive subprograms cannot be added. Similarly. the properties of the operands and the context of a particular call on a dispatching operation determine how the controlling tag is determined.3).see 3. It is permissible to use a name that denotes a discriminant of the record extension.0). type Literal is new Expression with record -. end record.13. As explained below. 69 When an extension is declared immediately within a body.a leaf in an Expression tree Value : Real. (The full rule is given in 3. in which case the body to be executed is determined at compile time.A tree representation of “5.0))). 3 — Ada Reference Manual NOTES 68 The term “type extension” refers to a type as a whole. Right => new Literal'(Value => 7.ISO/IEC 8652:2007(E) Ed.10 type Binary_Operation is new Expression with record -. 70 A name that denotes a component (including a discriminant) of the parent type is not allowed within the record_extension_part.9.an internal node in an Expression tree Left. The term “extension part” refers to the piece of text that defines the additional components (if any) the type extension has relative to its specified ancestor type.9.Components X and Y are inherited Origin : constant Painted_Point := (X | Y => 0.0)” new Addition'( Left => new Literal'(Value => 5. Examples 10 11 6 7/2 8 9 Examples of record extensions (of types defined above in 3. Right : Expr_Ptr. and hence whether or not the call is a dispatching call. -.0). type Expr_Ptr is access all Expression'Class.

dynamically tagged. all of whose controlling operands (if any) are tag indeterminate. • The name or expression is dynamically tagged if it is of a class-wide type. if the 8 9/1 10/2 69 10 November 2006 Dispatching Operations of Tagged Types 3. then the object designated by the expression shall not be dynamically tagged unless it is a controlling operand in a call on a dispatching operation. Similarly.2 . when used as a controlling operand. A qualified_expression or parenthesized expression is statically.). If the dispatching operation overrides an inherited subprogram. then the expression or name shall not be dynamically tagged unless it is a controlling operand in a call on a dispatching operation. and the context can similarly control dispatching. if the call is to a function with access result type designating T. the controlling operand is the object designated by the actual parameter.. if it is a call with a controlling result or controlling access result.ISO/IEC 8652:2007(E) Ed.9. then the call has a controlling result — the context of the call can control the dispatching. • The name or expression is tag indeterminate if it is a call with a controlling result or controlling access result. dynamically by its tag at run time. A name or expression of a tagged type is either statically tagged. dynamically. In the declaration of a dispatching operation of a tagged type. it shall be subtype conformant with the inherited subprogram. rather than the actual parameter itself. or from context. If the expected type for an expression or name is some specific tagged type. respectively. The default convention of a dispatching operation that overrides an inherited primitive operation is the convention of the inherited operation. where X is of a class-wide type. it has at least one statically tagged controlling operand. it shall statically match the first subtype of the tagged type. is of the form X'Access. this is determined as follows: • The name or expression is statically tagged if it is of a specific tagged type and. Legality Rules 2/2 3 4/2 5/2 6/2 7/1 A call on a dispatching operation shall not have both dynamically tagged and statically tagged controlling operands. the object is statically or dynamically tagged according to whether the designated type of the type of the expression is specific or class-wide. or indeterminately tagged according to its operand. The convention of an inherited dispatching operation is the convention of the corresponding primitive operation of the parent or progenitor type. ignoring enclosing parentheses. or tag indeterminate. For other kinds of names and expressions.. according to whether. Similarly. the object is dynamically tagged if the expression. For an object that is designated by an expression whose expected type is an anonymous access-to-specific tagged type.1). respectively. where T denotes a class-wide subtype. if the expected type for an expression is an anonymous access-to-specific tagged type. everywhere a subtype of the tagged type appears as a subtype of the profile (see 6. then the call has a controlling access result. or it is a call with a controlling result or controlling access result and at least one dynamically tagged controlling operand. the corresponding formal parameter is called a controlling formal parameter. A controlling operand in a call on a dispatching operation of a tagged type T is one whose corresponding formal parameter is of type T or is of an anonymous access type with designated type T. If the call is to a (primitive) function with result type T. A type_conversion is statically or dynamically tagged according to whether the type determined by the subtype_mark is specific or class-wide. Otherwise. the tag that controls dispatching is determined statically by the operand's (specific) type. 3 — Ada Reference Manual Static Semantics A call on a dispatching operation is a call whose name or prefix denotes the declaration of a dispatching operation. If the controlling formal parameter is an access parameter. or is of the form new T'(.

19 20/2 • For the execution of a call on a dispatching operation.1/2 20. If the corresponding operation is explicitly declared for this type. then the action comprises an invocation of the explicit body for the operation.14). the action is the same as the action for the corresponding operation of the parent type. Constraint_Error is raised unless the call is a function_call whose name denotes the declaration of an equality operator (predefined or user defined) that returns Boolean.1/2 12 13 14 For the execution of a call on a dispatching operation of a type T.1 and 9. shall have a subtype that excludes null. 3 — Ada Reference Manual operation overrides multiple inherited operations. 3. and no subprogram_body is executed. Dynamic Semantics 11. then its controlling tag value is determined by the controlling tag value of this enclosing call. If there is more than one dynamically tagged controlling operand. then the action comprises a call on this entry or protected subprogram.2 Dispatching Operations of Tagged Types 10 November 2006 70 20.9. • If one or more controlling operands are dynamically tagged. If the corresponding operation is implicitly declared for this type: • if the operation is implemented by an entry or protected subprogram (see 9. then: • If the call has a controlling result or controlling access result and is itself. qualified.2/2 . If this check fails. any access parameter of the renamed subprogram or the generic subprogram that corresponds to a controlling access parameter of the dispatching operation. if any.ISO/IEC 8652:2007(E) Ed. a check is made that they all have the same tag. or dereferenced) is the expression of an assignment_statement whose target is of a class-wide type. the controlling tag value is statically determined to be the tag of type T. and the actual parameters of the entry or protected subprogram being given by the remaining actual parameters of the call. • If all of the controlling operands (if any) are tag-indeterminate. An explicitly declared dispatching operation shall not be of convention Intrinsic. 11/2 The default_expression for a controlling formal parameter of a dispatching operation shall be tag indeterminate.4). For example. then the controlling tag value is not statically determined. then they shall all have the same convention.1/2 If the call has a controlling result or controlling access result and (possibly parenthesized. a (possibly parenthesized or qualified) controlling operand of an enclosing call on a dispatching operation of a descendant of type T. nor after deriving a record extension from it. with the target object being given by the first actual parameter of the call. A given subprogram shall not be a dispatching operation of two or more distinct tagged types. Otherwise. • 15 16 17/2 18/2 18. The explicit declaration of a primitive subprogram of a tagged type shall occur before the type is frozen (see 13. then its controlling tag value is determined by the target. • otherwise. nor after a body. in which case the result of the call is defined to indicate inequality. If a dispatching operation is defined by a subprogram_renaming_declaration or the instantiation of a generic subprogram. the controlling tag value determines which subprogram body is executed. even if the declaration occurs in a private part. then the controlling tag value is statically determined to be the tag of T. new dispatching operations cannot be added after objects or values of the type exist. the action performed is determined by the properties of the corresponding dispatching operation of the specific type identified by the controlling tag value. The controlling tag value is defined as follows: • If one or more controlling operands are statically tagged. This check is performed prior to evaluating any tagindeterminate controlling operands. but is rather determined by the tags of the controlling operands. or designates.

then: • If the type is abstract or untagged. Because objects of an abstract type cannot be created. Legality Rules 1. The class-wide type (see 3. if the type is a generic formal type. In addition. If it is a primitive subprogram of a tagged type. Rules for tagged type membership tests are described in 4. 75 A call through an access-to-subprogram value is never a dispatching call. If a type has an implicitly declared primitive subprogram that is inherited or is the predefined equality operator. then the tagged type shall be abstract. • Otherwise.1/2 Interface types (see 3. but is intended to be overridden at some point when inherited.2 . the subprogram need not be overridden for the formal type itself.4) are abstract types. have a full type that is a null extension. A call on an abstract subprogram shall be a dispatching call. or if a type other than a null extension inherits a function with a controlling result. for a type declared in the visible part of a package. and the corresponding primitive subprogram of the parent or ancestor type is abstract or is a function with a controlling access result. in the case of a private extension inheriting a function with a controlling result.9. a dispatching call to an abstract subprogram always dispatches to some overriding body.5. the subprogram shall be overridden with a nonabstract subprogram or. even if the access value designates a dispatching operation. it does not matter whether that tag is determined statically or dynamically.3 Abstract Types and Subprograms An abstract type is a tagged type intended for use as an ancestor of other types. a nonabstract version will necessarily be provided by the actual type. 21 22/2 23 24 3.9. Static Semantics 1. 2/2 3/2 4/2 5/2 6/2 7 71 10 November 2006 Dispatching Operations of Tagged Types 3. a tagged type that has the reserved word abstract in its declaration is an abstract type.2. Such a subprogram is said to require overriding. and it does not matter whether the subprogram's declaration is visible at the place of the call. the implicitly declared subprogram is abstract. nondispatching calls to an abstract subprogram are not allowed.2. A subprogram declared by an abstract_subprogram_declaration or a formal_abstract_subprogram_declaration (see 12. An abstract subprogram is a subprogram that has no body. 3 — Ada Reference Manual NOTES 72 The body to be executed for a call on a dispatching operation is determined by the tag. the overriding may be either in the visible or the private part.1) rooted at an abstract type is not itself an abstract type. However. but which is not allowed to have objects of its own. Similarly a call whose prefix denotes a subprogram_renaming_declaration cannot be a dispatching call unless the renaming itself is the declaration of a primitive subprogram.4.2/2 Only a tagged type shall have the reserved word abstract in its declaration. Controlling tag determination for an assignment_statement is described in 5. Syntax 1/2 abstract_subprogram_declaration ::= [overriding_indicator] subprogram_specification is abstract.ISO/IEC 8652:2007(E) Ed.9. 73 This subclause covers calls on dispatching subprograms of a tagged type.6) is an abstract subprogram. 74 A dispatching call can dispatch to a body whose declaration is not visible at the place of the call.

Dynamic Semantics 9 10 11/2 11. end Sets. representing alternative implementations of a set. but impose an upper bound on the largest element representable.4 Interface Types 1/2 An interface type is an abstract tagged type that provides a restricted form of multiple inheritance. trading off space for flexibility. Syntax 2/2 interface_type_definition ::= [limited | task | protected | synchronized] interface [and interface_list] 3/2 interface_list ::= interface_subtype_mark {and interface_subtype_mark} 3. a primitive function with a controlling result shall not be declared in the private part. 77 A class-wide type is never abstract.2) shall not be abstract. the tag of such an object will identify some nonabstract type in the class. one could then derive various (nonabstract) extensions of the type. If a generic formal type is abstract.ISO/IEC 8652:2007(E) Ed. Right : Set) return Set is abstract. while another might use a hash table. Even if a class is rooted at an abstract type.9. The type of a component shall not be abstract. or of an object created by an object_declaration or an allocator. NOTES 76 Abstractness is not inherited. unless it is overriding a function implicitly declared in the visible part. A tagged type. and an object of the class-wide type can be created. unless it is overriding an abstract subprogram implicitly declared in the visible part. shall not be abstract. If a partial view is not abstract. the corresponding full view shall not be abstract. Right : Set) return Set is abstract. to declare an abstract type. If the result type of a function is abstract. 3 — Ada Reference Manual 8 The type of an aggregate.3 Abstract Types and Subprograms 10 November 2006 72 . From : in out Set) is abstract. NOTES 78 Notes on the example: Given the above abstract type. function Intersection(Left. function Unit_Set(Element : Element_Type) return Set is abstract. Examples 12 13 14 15 Example of an abstract type representing a set of natural numbers: package Sets is subtype Element_Type is Natural. the reserved word abstract has to be used in the declaration of the type extension. 16 3. type Set is abstract tagged null record. Unchecked_Access. the class-wide type for the class is not abstract. The type of the target of an assignment operation (see 5. A generic actual subprogram shall not be an abstract subprogram unless the generic formal subprogram is declared by a formal_abstract_subprogram_declaration. the corresponding primitive subprogram of the actual shall not be abstract. For a tagged type declared in a visible part. then the function shall be abstract. The prefix of an attribute_reference for the Access. procedure Take(Element : out Element_Type. task type. or a generic formal object of mode in. One might use a bit vector.1/2 The elaboration of an abstract_subprogram_declaration has no effect.9. an abstract primitive subprogram shall not be declared in the private part. For an abstract type declared in a visible part. or Address attributes shall not denote an abstract subprogram. or protected type may have one or more interface types as ancestors. function Union(Left. then for each primitive subprogram of the formal that is not abstract. function Empty return Set is abstract.

as are synchronized interfaces and private extensions whose declaration includes the reserved word synchronized. a task type declared by a task declaration. A type derived from a nonlimited interface shall be nonlimited. or a synchronized interface. An interface_subtype_mark in an interface_list names a progenitor subtype. An interface derived from a synchronized interface shall include one of the reserved words task. These may be overridden with user-defined abstract equality operators. task.4 . 18/2 19/2 73 10 November 2006 Interface Types 3. any other type derived from a synchronized interface shall be a private extension. Legality Rules 4/2 5/2 6/2 7/2 8/2 9/2 All user-defined primitive subprograms of an interface type shall be abstract subprograms or null procedures. A task interface is an abstract task type. a limited interface. The type of a subtype named in an interface_list shall be an interface type. a protected interface. A task or protected type derived from an interface is a tagged type. An interface type has no components. 3 — Ada Reference Manual Static Semantics An interface type (also called an interface) is a specific abstract tagged type that is defined by an interface_type_definition. A protected interface is an abstract protected type.ISO/IEC 8652:2007(E) Ed.9. its type is the progenitor type. NOTES 79 Nonlimited interface types have predefined nonabstract equality operators. all task and protected interfaces are synchronized interfaces. a task interface. An interface type inherits user-defined primitive subprograms from each progenitor type in the same way that a derived type inherits user-defined primitive subprograms from its progenitor types (see 3. protected. any other type derived from a task interface shall be a private extension or a task type declared by a task declaration (see 9. respectively.4). and all synchronized interfaces are limited interfaces. An interface with the reserved word limited. any other type derived from a protected interface shall be a private extension or a protected type declared by a protected declaration (see 9. protected.1). In addition. An interface derived from a task interface shall include the reserved word task in its definition. Such a tagged type is called a synchronized tagged type. Dynamic Semantics 10/2 11/2 12/2 13/2 14/2 15/2 16/2 17/2 The elaboration of an interface_type_definition has no effect. or synchronized in its definition. An interface derived from a protected interface shall include the reserved word protected in its definition. these rules apply also in the private part of an instance of a generic unit.4).3). Such operators will then require an explicit overriding for any nonabstract descendant of the interface. In addition to the places where Legality Rules normally apply (see 12. or a protected type declared by a protected declaration. No type shall be derived from both a task interface and a protected interface. or synchronized in its definition is termed.

Number loop Remove_First(From. The two operands need not be of the same type in any given call. Person : out Person_Name) is abstract. Cashier.4 Interface Types 10 November 2006 74 . 27/2 28/2 29/2 30/2 31/2 32/2 3. begin for I in 1. Remove_First. Person : out Person_Name) is abstract. The Synchronized_Queue interface inherits the four dispatching operations from Queue and adds two additional dispatching operations. Cur_Count. procedure Transfer(From : in out Queue'Class.. Person : in Person_Name).. Transfer is also shown. Person). procedure Append(Q : in out Fast_Food_Queue..Add George (see 3. end loop.11 procedure Append_Wait(Q : in out Synchronized_Queue.see 9.9.. function Max_Count(Q : in Queue) return Natural is abstract. Counter : Fast_Food_Queue. Append(To. Append. George)... 22/2 23/2 24/2 25/2 26/2 This defines a Queue interface defining a queue of people. -. Counter). -. move George to the sandwich counter queue: Transfer (Cashier..10. as they are abstract..1 for Person_Name..ISO/IEC 8652:2007(E) Ed. Person : in Person_Name) is abstract. Person : in Person_Name) is abstract. Queue_Error : exception.. -. and Max_Count. This synchronized interface may only be implemented by a task or protected type. procedure Append(Q : in out Queue. Every non-abstract extension of Queue must provide implementations for at least its four dispatching operations. which wait if necessary rather than raising the Queue_Error exception. The body of a classwide operation.After payment. . . 3 — Ada Reference Manual Examples 20/2 21/2 Example of a limited interface and a synchronized interface extending it: type Queue is limited interface. Example use of the interface: type Fast_Food_Queue is new Queue with record ... procedure Remove_First_Wait(Q : in out Synchronized_Queue. Number : in Natural := 1) is Person : Person_Name. function Cur_Count(Q : in Queue) return Natural is abstract. Person : in Person_Name). .10.Remove_First raises Queue_Error if Count(Q) = 0 type Synchronized_Queue is synchronized interface and Queue. Person).1) to the cashier's queue: Append (Cashier. -. end Transfer. Any object of a type derived from Queue may be passed to Transfer as either the From or the To operand. function Cur_Count(Q : in Fast_Food_Queue) return Natural.) The Queue interface has four dispatching operations. function Max_Count(Q : in Fast_Food_Queue) return Natural. . and as such ensures safe concurrent access. procedure Remove_First(Q : in out Fast_Food_Queue.Append raises Queue_Error if Count(Q) = Max_Count(Q) -. procedure Remove_First(Q : in out Queue. To : in out Queue'Class. -.See 3. (A similar design could be created to define any kind of queue simply by replacing Person_Name by an appropriate type.

Syntax 1 access_type_definition ::= [null_exclusion] access_to_object_definition | [null_exclusion] access_to_subprogram_definition access_to_object_definition ::= access [general_access_modifier] subtype_indication general_access_modifier ::= all | constant access_to_subprogram_definition ::= access [protected] procedure parameter_profile | access [protected] function parameter_and_result_profile null_exclusion ::= not null access_definition ::= [null_exclusion] access [constant] subtype_mark | [null_exclusion] access [protected] procedure parameter_profile | [null_exclusion] access [protected] function parameter_and_result_profile Static Semantics 2/2 3 4 5 5. 3 — Ada Reference Manual An interface such as Queue can be used directly as the parent of a new type (as shown here). Associated with an access-to-object type is a storage pool.4 . an access value can designate either subprograms. C : out Character) is abstract. whose values designate subprograms. calls will dispatch to the implementations of Append and Remove_First for type Fast_Food_Queue. “Storage Management”. the implementation of the four inherited routines must be provided. whose values designate objects. Access-to-object types are further subdivided into pool-specific access types. access-to-object types. A storage pool is an area of storage used to hold dynamically allocated objects (called pool elements) created by allocators. Depending on its type.1/2 6/2 There are two kinds of access types.9. whose values can designate only the elements of their associated storage pool. as well as aliased objects created by declarations rather than allocators.1). procedure Write(Dev : in Serial_Device.11. storage pools are described further in 13.see 9. whose values can designate the elements of any storage pool. For Queue. -. objects created by allocators (see 4. or can be used as a progenitor when a type is derived. and aliased subcomponents of other objects.10 Access Types A value of an access type (an access value) provides indirect access to the object or subprogram it designates. Example of a task interface: type Serial_Device is task interface. several access types may share the same storage pool. and general access types. C : in Character) is abstract. In either case.1 procedure Read (Dev : in Serial_Device. the primitive operations of the interface are inherited. 33/2 34/2 35/2 The Serial_Device interface has two dispatching operations which are intended to be implemented by task entries (see 9. Inside the call of Transfer.ISO/IEC 8652:2007(E) Ed. 7/1 8 75 10 November 2006 Interface Types 3. and access-tosubprogram types. All descendants of an access type share the same storage pool. 36/2 3.8). or more generally aliased objects of an appropriate type.

the parameter_profile or parameter_and_result_profile denotes its designated profile. and “Ada” otherwise. a designated object cannot be updated through a value of such a type. otherwise it is constrained. For each access type. the subtype_indication defines the designated subtype of the access type. If the modifier is the reserved word all. If the modifier is the reserved word constant. as does a view conversion (see 4. In addition. the calling convention is “protected” if the reserved word protected appears.10. In addition. Aliased views are the ones that can be designated by an access value. Non-null values of an access-to-object type are obtained by evaluating an allocator. then the access type is a general access type. object_renaming_declaration. parameter_specification. there is a null access value designating no entity at all. then the type is an access-to-variable type. For a general access type. the parameter_profile or parameter_and_result_profile defines the designated profile of the access type. or formal_object_declaration has a null_exclusion. parameter_and_result_profile. or in the case of a general access-to-object type. a designated object can be both read and updated through a value of such a type. evaluating an attribute_reference for the Access or Unchecked_Access attribute of an aliased view of an object. If no general_access_modifier appears in the access_to_object_definition.9. The null value of an access type is the default initial value of the type. the subtype denoted by the subtype_indication excludes null if and only if the subtype denoted by the subtype_mark in the subtype_indication excludes null. the type is an access-to-constant type.1/2 If a subtype_indication. A null_exclusion in a construct specifies that the null value does not belong to the access subtype defined by the construct. a protected type. the subtype_mark denotes its designated subtype. Non-null values of an access-to-subprogram type are obtained by evaluating an attribute_reference for the Access attribute of a non-intrinsic subprogram. Finally. 3. discriminant_specification. 10 An access_to_object_definition defines an access-to-object type and its first subtype. 3 — Ada Reference Manual 9/2 A view of an object is defined to be aliased if it is defined by an object_declaration or component_definition with the reserved word aliased.1/2 14/1 14. only subprograms with this calling convention can be designated by values of the access type. then the type is an access-to-constant type. the anonymous access subtype defined by the access_definition for a controlling access parameter (see 3. the subtype_mark in that construct shall denote an access subtype that does not exclude null. or by a renaming of an aliased view. the dereference of an access-to-object value denotes an aliased view. the access subtype excludes null. 11 An access_to_subprogram_definition defines an access-to-subprogram type and its first subtype. There is a calling convention associated with the designated profile.2). See Annex B for how to override this default. Finally. By default.2) excludes null. Legality Rules 13/2 13. which can be obtained by (implicitly) converting the literal null to the access type. a formal parameter or generic formal object of a tagged type is defined to be aliased. or a type that has the reserved word limited in its full definition is also defined to be aliased. The first subtype of a type defined by an access_definition or an access_to_object_definition is unconstrained if the designated subtype is an unconstrained array or discriminated subtype. All subtypes of an access-to-subprogram type are constrained. otherwise it is an access-tovariable type. that is. which returns an access value designating a newly created object (see 3.ISO/IEC 8652:2007(E) Ed. the access type is a pool-specific access-to-variable type. If a general_access_modifier appears.10 Access Types 10 November 2006 76 .. for a subtype_indication without a null_exclusion.6) of an aliased view. The current instance of a limited tagged type. For an access-to-subprogram type. 12/2 An access_definition defines an anonymous general access type or an anonymous access-to-subprogram type. a task type. if the general_access_modifier constant appears.

this elaboration includes the elaboration of the subtype_indication.8. An access value satisfies a composite_constraint of an access subtype if it equals the null value of its type or if it designates an object whose value satisfies the constraint.see 3. For an accessto-object type. This permits mutually dependent and recursive access types. 3 — Ada Reference Manual Dynamic Semantics A composite_constraint is compatible with an unconstrained access subtype if it is compatible with the designated subtype.10.8. NOTES 80 Access values are called “pointers” or “references” in some other languages. An access value satisfies an exclusion of the null value if it does not equal the null value of its type.1 21 22/2 Example of an access subtype: subtype Drum_Ref is Peripheral_Ref(Drum).7.see 3. Give_Message := Other_Procedure'Access. 2/2 77 10 November 2006 Access Types 3.1 Incomplete Type Declarations There are no particular limitations on the designated type of an access type.")..8) for the access type.1 type Binop_Ptr is access all Binary_Operation'Class. procedure Default_Message_Procedure(M : in String). An object can be created in the storage pool of an access type by an allocator (see 4.1 and 3. -.all is optional) Give_Message. Give_Message : Message_Procedure := Default_Message_Procedure'Access. several access types can share the same pool. procedure Other_Procedure(M : in String).ISO/IEC 8652:2007(E) Ed. 82 Only index_constraints and discriminant_constraints can be applied to access types (see 3.call with parameter (.” See 13.9. -. -. In particular. which creates the designated subtype. 81 Each access-to-object type has an associated storage pool. Give_Message("File not found.all. The elaboration of an access_type_definition creates the access type and its first subtype.. -.1)..general access-to-class-wide..6. while deferring its full definition to a subsequent full_type_declaration. see 3. Examples 15/2 16 17/2 18 19 20 Examples of access-to-object types: type Peripheral_Ref is not null access Peripheral.1 23 24 25 26 Example of an access-to-subprogram type: type Message_Procedure is access procedure (M : in String := "Error!"). . A null_exclusion is compatible with any access subtype that does not exclude null. An incomplete_type_declaration can be used to introduce a type to be used as a designated type. -. the type of a component of the designated type can be another access type. .. A storage pool (roughly) corresponds to what some other languages call a “heap.call with no parameters 3. or even the same access type. ..11 for a discussion of pools. The elaboration of an access_definition creates an anonymous access type. Syntax 1 incomplete_type_declaration ::= type defining_identifier [discriminant_part] [is tagged].10 .

In these cases. it may also be used: • as the subtype_mark defining the subtype of a parameter or result of an access_to_subprogram_definition.2/2 2. If such a name occurs within the declaration list containing the completion of the incomplete view. Similarly.1). • as the subtype_mark in an access_definition. An incomplete view of a type is a limited view of the type (see 7. then the full_type_declaration shall occur later and immediately within this visible part or declarative_part.5). which shall be a full_type_declaration. then a full_type_declaration that completes it shall have a fully conforming (explicit) known_discriminant_part (see 6. the subtype_indication shall not have a null_exclusion or a constraint. Given an access type A whose designated type T is an incomplete view. or the declarative_part of the corresponding package_body.5/2 2. the dereference has the full view of T. If an incomplete_type_declaration has a known_discriminant_part.6/2 3 An incomplete_type_declaration requires a completion. the first subtype is unconstrained if a discriminant_part appears. it denotes a tagged incomplete view. it may also be used: • as the subtype_mark defining the subtype of a parameter in a formal_part.1/2 An incomplete_type_declaration declares an incomplete view of a type and its first subtype. in which case it denotes the full view of T. or inherited via derivation. • as the subtype_mark in the subtype_indication of a subtype_declaration.2/2 9/2 9.3/2 2. Legality Rules 2.2/2 3.3. If the incomplete_type_declaration occurs immediately within either the visible part of a package_specification or a declarative_part. 3 — Ada Reference Manual Static Semantics 2. either explicitly. then the full_type_declaration shall occur later and immediately within either the private part itself. If the incomplete_type_declaration occurs immediately within the private part of a given package_specification. the subtype_mark denotes an incomplete view except under the same two circumstances given above. such an attribute_reference is restricted to the uses allowed here. or • it occurs within the scope of a nonlimited_with_clause that mentions a library package in whose visible part the completion of T is declared.4/2 2. • as the prefix of an attribute_reference whose attribute_designator is Class. a dereference of a value of type A also has this incomplete view except when: • it occurs within the immediate scope of the completion of T. A name that denotes an incomplete view of a type may be used as follows: • as the subtype_mark in the subtype_indication of an access_to_object_definition. it declares a tagged incomplete view. If an incomplete_type_declaration includes the reserved word tagged.ISO/IEC 8652:2007(E) Ed. If such a name denotes a tagged incomplete view. the only form of constraint allowed in this subtype_indication is a discriminant_constraint. then a full_type_declaration that completes it shall declare a tagged type.1/2 8. if a subtype_mark denotes a subtype_declaration defining a subtype of an incomplete view T. If the incomplete_type_declaration includes the reserved word tagged. then a corresponding full_type_declaration is nevertheless allowed to have discriminants.10.1 Incomplete Type Declarations 10 November 2006 78 . If an incomplete_type_declaration has no discriminant_part (or an unknown_discriminant_part). 4/2 5/2 6 7/2 8/2 8.1/2 9.

Vehicle : Car_Name. NOTES 83 Within a declarative_part. Birth : Date. Next_Car : Car_Name := new Car. type Car is tagged record Number : Integer.. A prefix that denotes an object shall not be of an incomplete view. end record. case Sex is when M => Wife : Person_Name(Sex => F). Your_Car. it shall not be deferred to the package body. type Cell is record Value : Integer. null). Examples 12 13 Example of a recursive type: type Cell. Head Next : Link : Link := new Cell'(0. null. This is because a type has to be completely defined before it is frozen. George : Person_Name := new Person(M). Owner : Person_Name.incomplete type declaration type Car is tagged. then the completion of the incomplete view shall also occur immediately within the private part. 20). type Person(Sex : Gender) is record Name : String(1 . end record. end record. := Head. 14 15 16 17 Examples of mutually dependent access types: type Person(<>). when F => Husband : Person_Name(Sex => M). and the declaration occurs immediately within the private part of a package.incomplete type declaration type Person_Name is access Person.Succ. end case. 3 — Ada Reference Manual If any of the above uses occurs as part of the declaration of a primitive subprogram of the incomplete view. -. Dynamic Semantics 11/2 The elaboration of an incomplete_type_declaration has no effect. type Car_Name is access all Car'Class.Vehicle := Your_Car. Succ : Link. an incomplete_type_declaration and a corresponding full_type_declaration cannot be separated by an intervening body. -. My_Car. .. No other uses of a name that denotes an incomplete view of a type are allowed.see 4.3/2 9. -.8 18 19/2 20/2 21/2 22 23 79 10 November 2006 Incomplete Type Declarations 3. Pred : Link.1 . George.ISO/IEC 8652:2007(E) Ed. Age : Integer range 0 . -. Static Semantics 9.10.14).4/2 10/2 This paragraph was deleted.incomplete type declaration type Link is access Cell... and a body freezes all types declared prior to it in the same declarative_part (see 13. 130.

is the same as that of the operand.4). This ensures that the object will live at least as long as the access type.10. The accessibility rules for access types require that the accessibility level of an object designated by an access value be no deeper than that of the access type. • An entity or view defined by a declaration and created as part of its elaboration has the same accessibility level as the innermost master of the declaration except in the cases of renaming and derived access types described below.6.1/2 2. which in turn ensures that the access value cannot later designate an object that no longer exists.ISO/IEC 8652:2007(E) Ed. such as a subprogram_body. has an accessibility level: • The accessibility level of a given master is deeper than that of each dynamically enclosing master. Each master. are written in terms of accessibility levels. The Unchecked_Access attribute may be used to circumvent the accessibility rules. an object declared local to a called subprogram has a deeper accessibility level than an object declared local to the calling subprogram. The designated type or profile of the expected type of the attribute_reference is the expected type or profile for the prefix.1. since the Legality Rules do not cover certain cases involving access parameters and generic packages. A given accessibility level is said to be statically deeper than another if the given level is known at compile time (as defined below) to be deeper than the other for all possible executions.3/2 3/2 The accessibility rules. accessibility is enforced at compile time by Legality Rules. qualified_expression. and deeper than that of each master upon which the task executing the given master directly depends (see 9. or parenthesized expression.2 Operations of Access Types 1 The attribute Access is used to create access values designating aliased objects and non-intrinsic subprograms. As explained in 7. In most cases. Static Semantics 2.1. Run-time accessibility checks are also used.10). and each entity and view created by it.3).2 Operations of Access Types 10 November 2006 80 4 5 6 7/2 8 9/2 10/2 . • The accessibility level of a view conversion. Name Resolution Rules 2/2 For an attribute_reference with attribute_designator Access (or Unchecked_Access — see 13. the expected type shall be a single access type A such that: • A is an access-to-object type with designated type D and the type of the prefix is D'Class or is covered by D. • The accessibility level of an aggregate or the result of a function call (or equivalent use of an operator) that is used (in its entirety) to directly initialize part of an object is that of the object 3. For example. An accessibility level is deeper than another if it is more deeply nested at run time. 3 — Ada Reference Manual 3.10. The prefix of such an attribute_reference is never interpreted as an implicit_dereference or a parameterless function_call (see 4. which prevent dangling references.2/2 2. a master is the execution of a certain construct. A parameter of a master has the same accessibility level as the master. or • A is an access-to-subprogram type whose designated profile is type conformant with that of the prefix. which reflect the run-time nesting of masters. • The accessibility level of a view of an object or subprogram defined by a renaming_declaration is the same as that of the renamed view. The “accessibility” rules prevent dangling references (in the absence of uses of certain unchecked features — see Section 13).

for an allocator used to define the discriminant of an object. • The accessibility level of the anonymous access type of an access parameter specifying an access-to-subprogram type is deeper than that of any master.1/2 If the value of the access discriminant is determined by a record_component_association in an aggregate.ISO/IEC 8652:2007(E) Ed.4/2 13/2 13. For an allocator defining the value of an access parameter.10. the level of the object. except for an allocator of an anonymous access type that defines the value of an access parameter or an access discriminant. the accessibility level of the object.2/2 • 12. • The accessibility level of the anonymous access type of an access discriminant in the subtype_indication or qualified_expression of an allocator.4/2 In this last case. then prior to leaving the function.3/2 • The accessibility level of the anonymous access type of an access discriminant in any other context is that of the enclosing object.1/2 12/2 12. If the return statement completes normally by returning from the function. In other cases. • The accessibility level of an object created by an allocator is the same as that of the access type. or in the expression or return_subtype_indication of a return statement is determined as follows: • If the value of the access discriminant is determined by a discriminant_association in a subtype_indication. For one defining an access discriminant.1/2 11 11. the accessibility level of the object or subprogram designated by the associated value (or library level if the value is null). • The accessibility level of the anonymous access type defined by an access_definition of an object_renaming_declaration is the same as that of the renamed view. the level of the enclosing type. • The accessibility level of a view of an object or subprogram denoted by a dereference of an access value is the same as that of the access type. the accessibility level is that of the innermost master of the call. the allocated object is said to be a coextension of the object whose discriminant designates it. the accessibility level is determined as follows: • • • 12. as does the level of any coextensions (see below) of the return object. as well as of any object of which the discriminated object is itself a coextension or subcomponent. 3 — Ada Reference Manual being initialized. • Within a return statement. where the value of the access discriminant is determined by an object with an unconstrained nominal subtype. All coextensions of an object are finalized when the object is finalized (see 7.6. the accessibility level of the return object changes to be a level determined by the point of call. the accessibility level of an aggregate or the result of a function call is that of the innermost master that evaluates the aggregate or function call. • The accessibility level of the anonymous access type of an access parameter specifying an access-to-object type is the same as that of the view designated by the actual. all such anonymous access types have this same level.2 .1/2 14/2 for an allocator used to define the constraint in a subtype_declaration.3/2 14. • The accessibility level of a derived access type is the same as that of its ultimate ancestor. for an allocator used to define the constraint in a component_definition. • 10.1). the level of the subtype_declaration. the accessibility level of the object or subprogram designated by the associated value (or library level if the value is null). 12. 15 81 10 November 2006 Operations of Access Types 3.2/2 14. In other contexts. the accessibility level of the return object is that of the execution of the return statement. 14.1/2 14.

protected subprogram.10. X shall denote an aliased view of an object. The view denoted by the prefix X shall satisfy the following additional requirements. One accessibility level is defined to be statically deeper than another in the following cases: • For a master that is statically nested within another master. the current instance of the type is presumed to be an object created at a deeper level than that of the type.2/2 3. or a formal parameter or generic formal object of a tagged type. The following attribute is defined for a prefix X that denotes an aliased view of an object: X'Access X'Access yields an access value that designates the object denoted by X. the operand of a view conversion.1/2 17 18 18. then the view shall be a variable. as determined by the expected type. such an accessibility level is not considered to be statically deeper. The type of X'Access is an access-to-object type. The expected type shall be a general access type. than any other. 3 — Ada Reference Manual 16 • The accessibility level of a component. nor statically shallower. then the type of the view shall be covered by D. unless this subtype is indefinite. presuming the expected type for X'Access is the general access type A with designated type D: • If A is an access-to-variable type. parenthesized expression or qualified_expression is considered to be used in a context if the view conversion. The accessibility level of all library units is called the library level. and the designated subtype of A shall be unconstrained. the view may be either a constant or a variable. • The view shall not be a subcomponent that depends on discriminants of a variable whose nominal subtype is unconstrained. • The statically deeper relationship does not apply to the accessibility level of the anonymous type of an access parameter specifying an access-to-object type. all such anonymous access types have this same level. a library-level declaration or entity is one whose accessibility level is the library level. if A is an access-to-constant type. • For determining whether one level is statically deeper than another when within a generic package body.6) of a limited type within its definition. that is. • If A is a named access type and D is a tagged type. on the other hand. In the above rules. including possibly the current instance (see 8. • For determining whether one level is statically deeper than another when within the declarative region of a type_declaration. then the type of the view shall be D.2 Operations of Access Types 10 November 2006 82 . the accessibility level of the inner master is statically deeper than that of the outer master. 16. or entry of (a view of) a composite object is the same as that of (the view of) the composite object. or • D shall be discriminated in its full view and unconstrained in any partial view.1/2 27. run-time checks are needed in the case of more deeply nested instantiations. the generic package is presumed to be instantiated at the same level as where it was declared. then the type of the view shall be either D'Class or a type covered by D. and either: • the designated subtype of A shall statically match the nominal subtype of the view.1/2 19/2 20 21 22 23 24/1 25 26/2 27/2 27. if A is anonymous and D is tagged. or the variable is constrained by its initial value.ISO/IEC 8652:2007(E) Ed. parenthesized expression or qualified_expression itself is used in that context. • The accessibility level of the anonymous access type of an access parameter specifying an access-to-subprogram type is statically deeper than that of any master. if D is untagged.

The type of P'Access is an access-to-subprogram type (S). as might be appropriate for an iterator abstraction or numerical integration. The following attribute is defined for a prefix P that denotes a subprogram: P'Access P'Access yields an access value that designates the subprogram denoted by P.Vehicle := Cars(2)'Access. If the subprogram denoted by P is declared within a generic unit. Named access types have predefined equality operators. The accessibility level of P shall not be statically deeper than that of S. 85 The predefined operations of an access type also include the assignment operation.3).2 . 88 The Access attribute for subprograms and parameters of an anonymous access-to-subprogram type may together be used to implement “downward closures” — that is.1. -. but has fewer restrictions (see 13. In addition to the places where Legality Rules normally apply (see 12. this rule applies also in the private part of an instance of a generic unit. 86 The object or subprogram designated by an access value can be named with a dereference. Cars : array (1. explicit conversion is allowed between access-to-subprogram types with subtype conformant profiles (see 4. as determined by the expected type.see 3. while the other points to a special prologue that performs an Elaboration_Check and then jumps to the subprogram.Vehicle := Cars(1)'Access.10).6) and the value of X'Access designates that view. Examples 33 34/2 35 36 37/2 38 39 Example of use of the Access attribute: Martha : Person_Name := new Person(F). Martha.. and shall not be Intrinsic. Explicit conversion is allowed between general access types with matching designated subtypes. If this check fails..6). 90 An implementation may consider two access-to-subprogram values to be unequal. a view conversion of X to the designated subtype is evaluated (which might raise Constraint_Error — see 4. to pass a more-nested subprogram as a parameter to a less-nested subprogram. Downward closures can also be implemented using generic formal subprograms (see 12.10. In addition to the places where Legality Rules normally apply (see 12. See 4.2) of aliased Car.6). either an explicit_dereference or an implicit_dereference. 3 — Ada Reference Manual • The accessibility level of the view shall not be statically deeper than that of the access type A. . then the ultimate ancestor of S shall be either a non-formal type declared within the generic unit or an anonymous access type of an access parameter.8). and return an access value that designates it (see 4. A check is made that the accessibility level of X is not deeper than that of the access type A. 28 29 30 31 32/2 NOTES 84 The Unchecked_Access attribute yields the same result as the Access attribute for objects. anonymous access types do not.1 40 41 83 10 November 2006 Operations of Access Types 3.10. and membership tests. Program_Error is raised. There are other predefined operations that yield access values: an allocator can be used to create an object.2. evaluating the literal null yields a null access value that designates no entity at all (see 4. Note that Unchecked_Access is not allowed for subprograms. The profile of P shall be subtype-conformant with the designated profile of S.5. If the nominal subtype of X does not statically match the designated subtype of A. even though they designate the same subprogram.2). This might be because one points directly to the subprogram. George. this rule applies also in the private part of an instance of a generic unit.. See 4.ISO/IEC 8652:2007(E) Ed. and the expression P'Access occurs within the body of that generic unit or within the body of a generic unit declared within the declarative region of the generic unit. 89 Note that using an access-to-class-wide tagged type with a dispatching operation is a potentially more structured alternative to using an access-to-subprogram type.3). but they can use the predefined equality operators for universal_access (see 4.5. qualification.2). 87 A call through the dereference of an access-to-subprogram value is never a dispatching call.

The second part is called the completion of the declaration (and of the entity declared). 3. in the order in which they are given in the declarative_part. and is either another declaration. If two or more tasks are being activated together (see 9. The exception Program_Error is raised if any of these checks fails. Dynamic Semantics 7 The elaboration of a declarative_part consists of the elaboration of the declarative_items. • For a call to a protected operation of a protected type (that has a body — no check is performed if a pragma Import applies to the protected type). An elaborable construct is in the elaborated state after the normal completion of its elaboration. or a pragma. • For the activation of a task. as follows: • For a call to a (non-protected) subprogram that has an explicit body. it is not yet elaborated. This check and the evaluations of any actual parameters of the call are done in an arbitrary order. This check and the evaluation of any explicit_generic_actual_parameters of the instantiation are done in an arbitrary order. a check is made by the activator that the task_body is already elaborated. a check is made that the protected_body is already elaborated. a check is made that the body is already elaborated. Syntax 2 3 declarative_part ::= {declarative_item} declarative_item ::= basic_declarative_item | body basic_declarative_item ::= basic_declaration | aspect_clause | use_clause body ::= proper_body | body_stub proper_body ::= subprogram_body | package_body | task_body | protected_body Static Semantics 4/1 5 6 6.ISO/IEC 8652:2007(E) Ed.1 Completions of Declarations 1/1 Declarations sometimes come in two parts. This check and the evaluations of any actual parameters of the call are done in an arbitrary order.11 Declarative Parts 10 November 2006 84 . • For the instantiation of a generic unit that has a body.4).5.2). For a construct that attempts to use a body. a check (Elaboration_Check) is performed. Prior to that. A declaration that requires a second part is said to require completion. a body. a check is made that this body is already elaborated. this check is done for all of them before activating any of them. 3 — Ada Reference Manual 3.1/2 The list of declarative_items of a declarative_part is called the declaration list of the declarative_part. an entry_body. as the result of the elaboration of a declarative_part or the initialization for the object created by an allocator.11 Declarative Parts 1 A declarative_part contains declarative_items (possibly none). 8 9 10/1 11 12 13 14 3. if any.11. A body is a body. or a renaming-as-body (see 8.

ISO/IEC 8652:2007(E) Ed. and implementations are not required to support pragma Import for every kind of entity.3).11.14 and 7. there shall be a corresponding explicit completion. A type is completely defined at a place that is after its full type definition (if it has one) and after all of its subcomponent types are completely defined. and generic units. protected operations. 3 — Ada Reference Manual Name Resolution Rules A construct that can be a completion is interpreted as the completion of a prior declaration only if: • The declaration and the completion occur immediately within the same declarative region. The Elaboration_Checks of 3. At most one completion is allowed for a given declaration. 6 7 8 9 10 85 10 November 2006 Completions of Declarations 3. for some kinds of declaration. However. A type shall be completely defined before it is frozen (see 13. or is a pragma. The rules of 13. then the completion either has a type-conformant profile. • If the declaration is overloadable. NOTES 91 Completions are in principle allowed for any kind of explicit declaration. “Freezing Rules” prevent. • The defining name or defining_program_unit_name in the completion is the same as in the declaration.1 . premature uses of other entities such as private types and deferred constants.11 prevent such uses at run time for subprograms. 92 There are rules that prevent premature uses of declarations that have a corresponding completion. Additional requirements on completions appear where each kind of completion is defined. the only allowed completion is a pragma Import. Legality Rules 2 3 4 5 An implicit declaration shall not have a completion.14. For any explicit declaration that is specified to require completion. tasks. or in the case of a pragma. at compile time. the pragma applies to the declaration.

.

1 4. Dynamic Semantics 9 10 The evaluation of a name determines the entity denoted by the name. Finally.ISO/IEC 8652:2007(E) Ed. whether declared explicitly or implicitly (see 3. entry families. selected_components. subcomponents and slices of objects and values. The evaluation of a name that has a prefix includes the evaluation of the prefix. then the dereference denotes a view of a subprogram. This evaluation has no other effect for a name that is a direct_name or a character_literal. names can denote attributes of any of the 1 foregoing. The evaluation of a prefix consists of the evaluation of the name or the implicit_dereference. slices. are given in this section. and to their evaluation. protected subprograms.1).1 Names Names can denote declared entities. single entries. If the type of the name in a dereference is some access-to-subprogram type S. the nominal subtype of the view being the designated subtype of T. 3 — Ada Reference Manual Section 4: Names and Expressions The rules applicable to the different forms of name and expression.all implicit_dereference ::= name Certain forms of name (indexed_components. The prefix denotes the entity denoted by the name or the implicit_dereference. 11/2 12 87 10 November 2006 Names and Expressions 4 . Names can also denote objects or subprograms designated by access values. Syntax name ::= direct_name | indexed_component | selected_component | type_conversion | character_literal 2 | explicit_dereference | slice | attribute_reference | function_call 3 4 5 6 7/2 direct_name ::= identifier | operator_symbol prefix ::= name | implicit_dereference explicit_dereference ::= name. the results of type_conversions or function_calls. and entries in families of entries. or an implicit_dereference of an access value that designates some related entity. Static Semantics 8 If the type of the name in a dereference is some access-to-object type T. then the dereference denotes a view of an object. Name Resolution Rules The name in a dereference (either an implicit_dereference or an explicit_dereference) is expected to be of any access type. and attribute_references) include a prefix that is either itself a name that denotes some related entity. the profile of the view being the designated profile of S.

the direct name of a scalar variable -.the direct name of an array variable -.10. 4. expression}) Name Resolution Rules 3 The prefix of an indexed_component with a given number of expressions shall resolve to denote an array (after any implicit dereference) with the corresponding number of index positions.1) 3. Constraint_Error is raised if this check fails. The value of each expression is converted to the corresponding index type. The dereference denotes the object or subprogram designated by the value of the name.the direct name of an exception (see (see (see (see (see (see (see 3.2) 3.Owner 4.1) 3. same as Next_Car.1 Indexed Components 1 An indexed_component denotes either a component of an array or an entry in a family of entries.1) 16 17 Examples of dereferences: Next_Car. Examples 14 15 Examples of direct names: Pi Limit Count Board Matrix Random Error -.1. 3 — Ada Reference Manual 13 The evaluation of a dereference consists of the evaluation of the name and the determination of the object or subprogram that is designated by the value of the name. A check is made that the value of the name is not the null access value.3.1 Names 10 November 2006 88 . Constraint_Error is raised if this check fails. Syntax 2 indexed_component ::= prefix(expression {.the direct name of a function -. A check is made that each index value belongs to the corresponding index range of the array or entry family denoted by the prefix. Dynamic Semantics 6 7 For the evaluation of an indexed_component.the direct name of a type -.ISO/IEC 8652:2007(E) Ed.the direct name of a number -. The expected type for each expression is the corresponding index type. Static Semantics 4 5 When the prefix denotes an array.6) 6.1) 3.1) selected component with implicit dereference.6. The nominal subtype of the indexed_component is the component subtype of the array type.3.Owner ----explicit dereference denoting the object designated by the access variable Next_Car (see 3.1) 11. the indexed_component denotes the component of the array with the specified index value(s). the indexed_component denotes the individual entry of the entry family with the specified index value. When the prefix denotes an entry family.all.3.all Next_Car. the prefix and the expressions are evaluated in an arbitrary order. or shall resolve to denote an entry family of a task or protected object (in which case there shall be only one expression).the direct name of a constant -.

1) (see 3. Constraint_Error is raised if this check fails.10. 3 For a one-dimensional array A. 7 8 9 89 10 November 2006 Indexed Components 4.1) 8 9 NOTES 1 Notes on the examples: Distinct notations are used for components of multidimensional arrays (such as Board) and arrays of arrays (such as Page). 10 4. Thus Page(10)(20) denotes the 20th component of Page(10). Its bounds are those defined by the discrete_range. the slice A(N .2 Slices A slice denotes a one-dimensional array formed by a sequence of consecutive components of a onedimensional array. A slice of a variable is a variable. the prefix and the discrete_range are evaluated in an arbitrary order. 3 — Ada Reference Manual Examples Examples of indexed components: My_Schedule(Sat) Page(10) Board(M. a slice of a value is a value. corresponding to the range of values of the index given by the discrete_range. Dynamic Semantics 5 6 For the evaluation of a slice. Syntax 1 slice ::= prefix(discrete_range) Name Resolution Rules 2 The prefix of a slice shall resolve to denote a one-dimensional array (after any implicit dereference).ISO/IEC 8652:2007(E) Ed. A(N) denotes a component of the array A and has the corresponding component type.1) (see 6.6) (see 3.1 .6) (see 9. NOTES 2 A slice is not permitted as the prefix of an Access attribute_reference. a slice of a constant is a constant. See 3. The expected type for the discrete_range of a slice is the index type of the array type.. In the last example Next_Frame(L) is a function call returning an access value that designates a two-dimensional array.2.1. Static Semantics 3 4 A slice denotes a one-dimensional array formed by the sequence of consecutive components of the array denoted by the prefix. The type of the slice is that of the prefix.1) (see 3.6. its type is the type of A.6. N) ------a component of a one-dimensional array a component of a one-dimensional array a component of a two-dimensional array a component of a component an entry in a family of entries a component of a function call (see 3. then a check is made that the bounds of the discrete_range belong to the index range of the array denoted by the prefix. If the slice is not a null slice (a slice where the discrete_range is a null range).1. even if the components or the array as a whole are aliased. J + 1) Page(10)(20) Request(Medium) Next_Frame(L)(M. The components of an array of arrays are arrays and can therefore be indexed. N) denotes an array that has only one component. On the other hand.

• A single entry. an entry family. or protected subprogram. at least one possible interpretation of its prefix denotes a package or an enclosing named construct (directly. The selector_name shall resolve to denote an entry_declaration or subprogram_declaration occurring (implicitly or explicitly) within the visible part of that type. The first formal parameter of the subprogram shall be of type T.3) (see 3. 15) Page(10 . and the prefix of the selected_component (after any implicit dereference) is called the prefix of the prefixed view. 15)(K) -------a slice of 15 characters a slice of 1 + Size components a slice of the array Page(L) a null slice bounds given by subtype same as Stars(K) provided that K is in 5 . The selector_name shall resolve to denote a discriminant_specification of the type. or a class-wide type that covers T. The designator of the subprogram shall not be the same as that of a component of the tagged type visible at the point of the selected_component. not through a subprogram_renaming_declaration or generic_renaming_declaration).ISO/IEC 8652:2007(E) Ed..3) (see 3.1. selector_name selector_name ::= identifier | character_literal | operator_symbol Name Resolution Rules 4 A selected_component is called an expanded name if. or a protected subprogram: The prefix shall resolve to denote an object or value of some task or protected type (after any implicit dereference). The selected_component denotes the corresponding entry..6. as follows: 4. or an access parameter designating one of these types. 0) My_Schedule(Weekday) Stars(5 . according to the visibility rules. unless the type is a protected type. and protected subprograms. entries. they are also used as expanded names as described below..6) (see 3.6) (see 3. 3 — Ada Reference Manual Examples 10 11 Examples of slices: Stars(1 .5.3) 4.1.2 Slices 10 November 2006 90 5 6 7 8 9 9. An expanded name shall resolve to denote a declaration that occurs immediately within a named declarative region. The selector_name shall resolve to denote a view of a subprogram declared immediately within the declarative region in which an ancestor of the type T is declared. entry family. This view is called a prefixed view of the subprogram.2/2 10 . B) Stars(1 .1/2 9.. The selected_component denotes a view of this subprogram that omits the first formal parameter.6.6.. entry families.6. The selected_component denotes the corresponding component of the object or value. 15 (see 3. A selected_component that is not an expanded name shall resolve to denote one of the following: • A component (including a discriminant): The prefix shall resolve to denote an object or value of some non-array composite type (after any implicit dereference). a component_declaration of the type. • A view of a subprogram whose first formal parameter is of a tagged type or is an access parameter whose designated type is tagged: The prefix (after any implicit dereference) shall resolve to denote an object or value of a specific tagged type T or class-wide type T'Class. 10 + Size) Page(L)(A . Syntax 2 3 selected_component ::= prefix .. or.3 Selected Components 1 Selected_components are used to denote components (including discriminants).1 and 3.1) (see 3.

Further.ISO/IEC 8652:2007(E) Ed.3).Pool Buffer.Owner.1) (see 6. For a selected_component that denotes a component of a variant.1/2 13.Append -.a record component (see 3.Owner -.10. the current instance of a type. or of an anonymous access-to-variable type.Value -.9. the expanded name shall occur within the declarative region of this construct.a record component (see 3.1) Next_Car. the prefix of any prefixed view shall denote a variable. The exception Constraint_Error is raised if this check fails.Month -.1) Min_Cell(H).a record component (a discriminant) (see 3.4) 16 17/2 Examples of expanded names: Key_Manager. independently of the selector_name. or an enclosing named construct.2/2 The evaluation of a selected_component includes the evaluation of the prefix. • The selector_name shall resolve to denote a declaration that occurs immediately within the declarative region of the package or enclosing construct (the declaration shall be visible at the place of the expanded name — see 8. or an accept_statement (in the case of an accept_statement or entry_body. then the expanded name is ambiguous. and it shall resolve to denote a program unit (other than a package).a record component of the result (see 6.Write -.of the function call Min_Cell(H) Cashier. no family index is allowed). 3 — Ada Reference Manual • The prefix shall resolve to denote either a package (including the current instance of a generic package. or a rename of a package).Boolean ------an operator of the visible part of a package a variable declared in a function body a variable declared in a protected unit an entry of a protected unit a variable declared in a block statement the name of a predefined type (see 7. Legality Rules 11 12 13 For a subprogram whose first parameter is an access parameter.3.6) (see A.8) Next_Car.1) -."<" Dot_Product.1) -.3 .Temp Standard.the previous two lines involve implicit dereferences Writer. the prefix of any prefixed view shall denote an aliased view of an object.Age -.a record component (see 3.11) (see 9.10.an entry of a protected object (see 9. The expanded name denotes that declaration.1.1) 18 19 91 10 November 2006 Selected Components 4. For a subprogram whose first parameter is of mode in out or out.4) Control.Read Swap.a prefixed view of a procedure (see 3. Examples 14 15 Examples of selected components: Tomorrow.Unit -. a loop_statement. then it shall be a direct_name or an expanded name.4) Pool(K). if this construct is a callable construct and the prefix denotes more than one such enclosing callable construct.8. Dynamic Semantics 13.Sum Buffer. a check is made that the values of the discriminants are such that the value or object denoted by the prefix has this component.1) (see 9.11) (see 5. a block_statement. • If the prefix does not denote a package.an entry of the task Pool(K) (see 9.Seize -.

and the resolution of the name can use the fact that the type of the object or the profile of the callable 13 14/2 4. if any.. X'Last(N). if the type of the name within the prefix is of an access type. X'Range is equivalent to X'First . the prefix is interpreted as an implicit_dereference. NOTES 4 Attributes are defined throughout this International Standard. Implementation Permissions 12/1 An implementation may provide implementation-defined attributes. if the attribute_designator is for an attribute defined for (at least some) objects of an access type. then the prefix is never interpreted as a parameterless function_call. or some other kind of program entity.1. The expression. an object.1. if any. Syntax 2 3 attribute_reference ::= prefix'attribute_designator attribute_designator ::= identifier[(static_expression)] | Access | Delta | Digits 4 5 range_attribute_reference ::= prefix'range_attribute_designator range_attribute_designator ::= Range[(static_expression)] Name Resolution Rules 6 In an attribute_reference. 5 In general. the expected type for the attribute_reference has to be a single access type. otherwise (and for all range_attribute_references). then the prefix is never interpreted as an implicit_dereference. in an attribute_designator or range_attribute_designator is expected to be of any integer type. However. 3 — Ada Reference Manual 4. otherwise (and for all range_attribute_references). if the attribute_designator is for an attribute defined for (at least some) functions. it is interpreted as a parameterless function_call. Legality Rules 7 8 The expression. and are summarized in Annex K. A range_attribute_reference X'Range(N) is equivalent to the range X'First(N) . except that the prefix is only evaluated once. Similarly. Similarly. in the case of the Access attribute. a subprogram. except that the prefix is only evaluated once.. Static Semantics 9 10 An attribute_reference denotes a value. the identifier for an implementationdefined attribute shall differ from those of the language-defined attributes unless supplied for compatibility with a previous edition of this International Standard. X'Last.4 Attributes 10 November 2006 92 . in an attribute_designator or range_attribute_designator shall be static. if the prefix consists of a name that denotes a function.4 Attributes 1 An attribute is a characteristic of an entity that can be queried via an attribute_reference or a range_attribute_reference.ISO/IEC 8652:2007(E) Ed. the name in a prefix of an attribute_reference (or a range_attribute_reference) has to be resolved without using any context. Dynamic Semantics 11 The evaluation of an attribute_reference (or range_attribute_reference) consists of the evaluation of the prefix.

1) (see 3.ISO/IEC 8652:2007(E) Ed.5. or a string_literal. yields the represented value. 9 10 93 10 November 2006 Attributes 4.1).6.1) 15 16 4.1) (see 3.same as Color'First -.1) (see 9.6.4 . in which case it is interpreted as a parameterless function_call that yields the corresponding value of the character type. Legality Rules 4 A character_literal that is a name shall correspond to a defining_character_literal of the expected type. that is.address of the record variable Message (see 3. The literal null is of type universal_access.number of bits for records of type Date -. the upper bound is the predecessor of the lower bound.upper bound of the second dimension of Board -. This paragraph was deleted. there shall be a corresponding defining_character_literal of the component type of the expected string type. The bounds of this array value are determined according to the rules for positional_array_aggregates (see 4.3.7. Name Resolution Rules 1 This paragraph was deleted. the literal null. as defined in 2. Examples Examples of attributes: Color'First Rainbow'Base'First Real'Digits Board'Last(2) Board'Range(1) Pool(K)'Terminated Date'Size Message'Address -.6.2 Literals A literal represents a value literally.index range of the first dimension of Board -. or the literal null. except that for a null string literal. A literal is either a numeric_literal. In either case.precision of the type Real -. a character_literal. The evaluation of a string_literal that is a primary yields an array value containing the value of each character of the sequence of characters of the string_literal. the character_literal denotes the enumeration_literal_specification. in which case it is interpreted as the name of the corresponding parameterless function declared as part of the character type's definition (see 3.1) (see 3. 3 — Ada Reference Manual entity denoted by the prefix has to match the designated type or be type conformant with the designated profile of the access type.8) (see 3. For each character of a string_literal with a given expected string type. A real literal is of type universal_real. Dynamic Semantics 8/2 The evaluation of a numeric literal. Static Semantics 5 6 7/2 An integer literal is of type universal_integer. The expected type for a primary that is a string_literal shall be a single string type.1.True if task Pool(K) is terminated -.5.5. by means of notation suited to its kind.3).7) (see 3.1) (see 3.5. 2/2 3 For a name that consists of a character_literal. either its expected type shall be a single character type. or of the result type of the expected profile.minimum value of the enumeration type Color -. or its expected profile shall correspond to a parameterless function with a character result type.

or record extension.3. 6 4.3).3 Aggregates 1 An aggregate combines component values into a composite value of an array type. The exception Constraint_Error is raised if either of these checks fails.1. a check is made that the value of each character of the string_literal belongs to the component subtype of T. record_component_association} | null record 4. a check is made that its value belongs to the first subtype of the type. For the evaluation of a null string literal. 3 — Ada Reference Manual 11 For the evaluation of a string_literal of type T. an anonymous object is created and values for the components or ancestor part are obtained (as described in the subsequent subclause for each kind of the aggregate) and assigned into the corresponding components or ancestor part of the anonymous object. Syntax 2 3 record_aggregate ::= (record_component_association_list) record_component_association_list ::= record_component_association {. Legality Rules 4 An aggregate shall not be of a class-wide type. record type. The value of the aggregate is the value of this object.2 Literals 10 November 2006 94 . record type.1 Record Aggregates 1 In a record_aggregate.a character literal "Some Text" -. NOTES 6 Enumeration literals that are identifiers rather than character_literals follow the normal rules for identifiers when used in a name (see 4. a value is specified for each component of the record or record extension value. Syntax 2 aggregate ::= record_aggregate | extension_aggregate | array_aggregate Name Resolution Rules 3/2 The expected type for an aggregate shall be a single array type.ISO/IEC 8652:2007(E) Ed. Obtaining the values and the assignments occur in an arbitrary order.1.1 and 4. or record extension.14159_26536 -. If an aggregate is of a tagged type. Constraint_Error is raised if this check fails. a check is made that its lower bound is greater than the lower bound of the base range of the index type. using either a named or a positional association.a string literal 4. Examples 12 13 14 Examples of literals: 3.3). Character_literals used as selector_names follow the normal rules for expanded names (see 4. Dynamic Semantics 5 For the evaluation of an aggregate.a real literal 1_345 -.an integer literal 'A' -.

only those components not determined by the ancestor expression or subtype are needed (see 4. Any positional component associations shall precede any named component associations. counting only the needed components. it shall be a named association. If a record_component_association with an expression has two or more associated components. 14 15 16/2 17 17.1 . The expected type for the expression of a record_component_association is the type of the associated component(s).ISO/IEC 8652:2007(E) Ed. and each needed component shall be associated with exactly one record_component_association. then it shall be a descendant of a record type. A record_component_association for a discriminant without a default_expression shall have an expression rather than <>.2). Name Resolution Rules 6 7 The expected type for a record_aggregate shall be a single record type or record extension. Each selector_name in a record_component_association shall denote a needed component (including possibly a discriminant). otherwise. the component (including possibly a discriminant) in the corresponding relative position (in the declarative region of the type). it shall come last. all needed components that are not associated with some previous association. In the record_component_association_list for a record_aggregate. the named component(s). If there is a named association with a component_choice_list of others. it is a positional component association. then the value of a discriminant that governs the variant_part shall be given by a static expression. if there is only one association. all components of the composite value defined by the aggregate are needed. • For a named association with the reserved word others. for the association list of an extension_aggregate. through one or more record extensions (and no private extensions). • For a named association with one or more component_selector_names. the associated component(s) are as follows: • For a positional association.1/2 95 10 November 2006 Record Aggregates 4. If the components of a variant_part are needed. all of them shall be of the same type. 3 — Ada Reference Manual record_component_association ::= [component_choice_list =>] expression | component_choice_list => <> component_choice_list ::= component_selector_name {| component_selector_name} 4/2 5 | others A record_component_association is a named component association if it has a component_choice_list. then the reserved words null record shall appear rather than a list of record_component_associations.3. Legality Rules 8/2 9 10 11 12 13 If the type of a record_aggregate is a record extension. For the record_component_association_list of a record_aggregate. If there are no components needed in a given record_component_association_list. Each record_component_association other than an others choice with a <> shall have at least one associated component.3.

Succ|Pred => <>) -. Day => 4. expressions specifying discriminant values appear first since the known_discriminant_part is given first in the declaration of the type. the associated component(s) are initialized by default as for a stand-alone object of the component subtype (see 3.9. For a record_component_association with <>. if the component_declaration has a default_expression. except that the expression for a discriminant is evaluated (and converted) prior to the elaboration of any per-object constraint that depends on it.1/2 20 21 22 23 24 25 26 Example of a record aggregate with positional associations: (4. For the evaluation of a record_component_association_list.1/2 29.1): Expression'(null record) Literal'(Value => 0. the expression defines the value for the associated component(s). Cylinder => 9. 1776) -. Pi/2. any per-object constraints (see 3.see 3.ISO/IEC 8652:2007(E) Ed.see 3.see 3. Succ|Pred => new Cell'(0.10.9 and 3. Paint => Red) 4. which in turn occurs prior to the evaluation and conversion of the expression for the component with the per-object constraint. null)) -. Any constraint elaborations and expression evaluations (and conversions) occur in an arbitrary order.1 Record Aggregates 10 November 2006 96 .1).8) for components specified in the association list are elaborated and any expressions are evaluated and converted to the subtype of the associated component.0. null. that default_expression defines the value for the associated component(s).10.8 Examples of record aggregates with named associations: (Day => 4. Cylinder => 12) -. Examples 19 19.The allocator is evaluated twice: Succ and Pred designate different cells (Value => 0. The expression of a record_component_association is evaluated (and converted) once for each associated component.0) Painted_Point'(0. 3 — Ada Reference Manual Dynamic Semantics 18 The evaluation of a record_aggregate consists of the evaluation of the record_component_association_list. they have to be in the same order as in the known_discriminant_part. Closed.1 (Unit => Disk.Succ and Pred will be set to null -. Month => July.1 -. NOTES 7 For a record_aggregate with positional associations. Track => 1) 27/2 28 29 29. For a record_component_association with an expression.8. Year => 1776) (Disk. July. otherwise.2/2 30 31 Examples of component associations with several choices: (Value => 0. Status => Closed.3. Track => 5.3.see 3.0. Year => 1776) (Month => July.1 Examples of record aggregates for tagged types (see 3.

it shall not be dynamically tagged. plus any inherited discriminants if the ancestor_part is a subtype_mark that denotes an unconstrained subtype. the only components needed are those of the composite value defined by the aggregate that are not inherited from the type of the ancestor_part.3. Constraint_Error is raised if this check fails. Static Semantics 5/2 For the record_component_association_list of an extension_aggregate.6). If the type of the ancestor_part has discriminants that are not inherited by the type of the extension_aggregate.3. it shall denote a specific tagged subtype. Any implicit initializations or evaluations are performed in an arbitrary order. 9 If the ancestor_part is a subtype_mark. if the ancestor_part is a subtype_mark. NOTES 8 If all components of the value of the extension_aggregate are determined by the ancestor_part. through one or more record extensions (and no private extensions). The type of the extension_aggregate shall be derived from the type of the ancestor_part. the components of the value of the aggregate not given by the record_component_association_list are initialized by default as for an object of the ancestor type. it is also evaluated. then its type can be abstract.2 Extension Aggregates An extension_aggregate specifies a value for a type that is a record extension by specifying a value or subtype for an ancestor of the type. except that the expression for a discriminant is evaluated prior to any other evaluation or initialization that depends on it.2 . unless the ancestor_part is a subtype_mark that denotes an unconstrained subtype. 3 — Ada Reference Manual 4. If the ancestor_part is an expression. either in the record_component_association_list. If the ancestor_part is an expression. followed by associations for any components not determined by the ancestor_part. then. If the ancestor_part is an expression. Legality Rules 4/2 If the ancestor_part is a subtype_mark. the record_component_association_list is evaluated. Dynamic Semantics 6 For the evaluation of an extension_aggregate. a check is made that each discriminant of the ancestor has the value specified for a corresponding discriminant. If its type is controlled. the Initialize procedure of the ancestor type is called. or in the derived_type_definition for some ancestor of the type of the extension_aggregate. unless the Initialize procedure is abstract (see 7. Syntax 1 extension_aggregate ::= (ancestor_part with record_component_association_list) ancestor_part ::= expression | subtype_mark Name Resolution Rules 2 3 The expected type for an extension_aggregate shall be a single type that is a record extension. then the record_component_association_list is required to be simply null record. it is expected to be of any tagged type. then as the last step of evaluating the aggregate.ISO/IEC 8652:2007(E) Ed. 7 8 9 10 97 10 November 2006 Extension Aggregates 4.

the corresponding index is the index in position m+1. the components are identified by the values covered by the discrete_choices. Right => 3.4) Addition'(Binop with null record) -.3.ISO/IEC 8652:2007(E) Ed.presuming Binop is of type Binary_Operation 4. expression}.2 Extension Aggregates 10 November 2006 98 10 . a value is specified for each component of an array. For a positional_array_aggregate. representing any remaining components. Syntax 2 array_aggregate ::= positional_array_aggregate | named_array_aggregate positional_array_aggregate ::= (expression. others => <>) named_array_aggregate ::= (array_component_association {. for an (n–m)-dimensional subaggregate within an array_aggregate of an n-dimensional type.1): Painted_Point'(Point with Red) (Point'(P) with Paint => Black) (Expression with Left => 1.3 Array Aggregates 1 In an array_aggregate.9. others => expression) | (expression {. expression {. either positionally or by its index.3. equivalent string_literals). For the multidimensional case (n >= 2) the array_aggregates (or equivalent string_literals) at the n–1 lower levels are called subaggregates of the enclosing n-dimensional array_aggregate. The component type of this array type is the expected type for each array component expression of the array_aggregate. array_component_association}) array_component_association ::= discrete_choice_list => expression | discrete_choice_list => <> 3/2 4 5/2 6 An n-dimensional array_aggregate is one that is written as n levels of nested array_aggregates (or at the bottom level. The expected type for each discrete_choice in any discrete_choice_list of a named_array_aggregate is the type of the corresponding index. with a final others. Name Resolution Rules 7/2 The expected type for an array_aggregate (that is not a subaggregate) shall be a single array type. 3 — Ada Reference Manual Examples 11 12 13 Examples of extension aggregates (for types defined in 3. if any. An others choice is allowed for an array_aggregate only if an applicable index constraint applies to the array_aggregate. expression}. expression}) | (expression {. For a named_array_aggregate. The expressions of the bottom level subaggregates (or of the array_aggregate itself if one-dimensional) are called the array component expressions of the enclosing n-dimensional array_aggregate. An applicable index constraint is a constraint provided by certain contexts where an 4. the components are given in increasing-index order. Legality Rules 8 9 An array_aggregate of an n-dimensional array type shall be written as an n-dimensional array_aggregate. the corresponding index for an array_aggregate that is not a subaggregate is the first index of its type.2.

if the component's nominal subtype is a constrained array subtype. the applicable index constraint is that. or component is a constrained array subtype. each character of such a string_literal shall correspond to a defining_character_literal of the component type.1/2 99 10 November 2006 Array Aggregates 4. Each of the following contexts (and none other) defines an applicable index constraint: • For an explicit_actual_parameter. Each expression in an array_component_association defines the value for the associated component(s). 21 22 23 23.3. • For the operand of a qualified_expression whose subtype_mark denotes a constrained array subtype. no applicable index constraint is defined.ISO/IEC 8652:2007(E) Ed. defined for the expression. no two discrete_choices are allowed to cover the same value (see 3. the applicable index constraint is the constraint of the subtype.1). In a named_array_aggregate with more than one discrete_choice. For an array_component_association with <>. only if it is the single discrete_choice of its discrete_choice_list. 3 — Ada Reference Manual array_aggregate is permitted that can be used to determine the bounds of the array value specified by the aggregate. with each expression being the character_literal for the corresponding character of the string_literal. if there is no others choice. The array component expressions of the aggregate are evaluated in an arbitrary order and their values are converted to the component subtype of the array type. A bottom level subaggregate of a multidimensional array_aggregate of a given array type is allowed to be a string_literal only if the component type of the array type is a character type. the applicable index constraint is the constraint of the subtype. Static Semantics 11/2 12 13 14 15 16 17 18 19 A subaggregate that is a string_literal is equivalent to one that is a positional_array_aggregate of the same length. • For the expression of an assignment_statement where the name denotes an array variable. and converted to the corresponding index type. • For a parenthesized expression. the applicable index constraint is the constraint of the array variable. object.3 . function return object.8. the expression of a return statement. and there is only one array_component_association in the array_aggregate. In the case of an explicit_actual_parameter (or default_expression) for a call on a generic formal subprogram. Dynamic Semantics 20 The evaluation of an array_aggregate of a given array type proceeds in two steps: 1. an explicit_generic_actual_parameter. the applicable index constraint is the constraint of the subtype. when the nominal subtype of the corresponding formal parameter. • For a component expression in an aggregate. generic formal parameter. The discrete_choice_list of an array_component_association is allowed to have a discrete_choice that is a nonstatic expression or that is a discrete_range that defines a nonstatic or null range. Any discrete_choices of this aggregate and of its subaggregates are evaluated in an arbitrary order.3. as well as to any subaggregates thereof. if any. or a default_expression (for a parameter or a component). the initialization expression in an object_declaration. the discrete_choices taken together shall exactly cover a contiguous sequence of values of the corresponding index type. the associated component(s) are initialized by default as for a stand-alone object of the component subtype (see 3. an array component expression is evaluated once for each associated component. 2. The applicable index constraint applies to an array_aggregate that appears in such a context.1).

3). 2 => 2. 9. N) := (M .see 3. 1.C'Last(1)=5.2. 0).N new cells. 2.3) (see 3. For an array_aggregate with an others choice. the upper bound is determined from the lower bound and the number of expressions (or the length of the string_literal). in either case. 5.. For an array_aggregate. 2 => (2. B(10)=1 C : constant Matrix := (1 .6 -.3)) (1 => (1 => 1. 1. or that of the corresponding index subtype....two-dimensional -. if defined. -. others => True) Vector'(1 => 2.. • For a positional_array_aggregate (or equivalent string_literal) without an others choice. Fri => True. The exception Constraint_Error is raised if any of the above checks fail. 9. 5..see 3. F : String(1 . 5 => (1 .6 35 36 37 Examples of array aggregates with named associations: (1 .Three aggregates for the same value of subtype Matrix(1. 1. 2. 2 => 1. the bounds are determined by the smallest and largest index values covered by any discrete_choice_list.a one component aggregate: same as "F" 43 4.2.3). N) := (others => True). others => 0) -. 1. 4.3)) 41 42 Examples of aggregates as initial values: A : Table := (7..0)) (1 . a check is made that the index range defined by its bounds is compatible with the corresponding index subtype.. if not. the bounds are those of the corresponding index range from the applicable index constraint. a check is made that no expression is specified for an index value outside the bounds determined by the applicable index constraint.1. C'Last(2)=8 D : Bit_Vector(M . N => new Cell) -.3. • For a named_array_aggregate without an others choice. such as (1 => X). 6. 2.6 E : Bit_Vector(M . a check is made that all subaggregates that correspond to the same index have the same bounds. A(10)=0 B : Table := (2 | 4 | 10 => 1. 3 => 2. N => True). Examples 25 26 27 28 29 30 31 32/2 33 34 Examples of array aggregates with positional associations: (7. 8. others => 0) Schedule'(Mon .3).1. 5 => (1 . in particular for N = 0 -.1. 3 — Ada Reference Manual 24 The bounds of the index range of an array_aggregate (including a subaggregate) are determined as follows: • For an array_aggregate with an others choice. the lower bound is that of the corresponding index range in the applicable index constraint.B(1)=0. -.. positional notation may only be used with two or more expressions. 4. NOTES 10 In an array_aggregate. 3. (2.1.1.2. 2. 2. 3 => 1. others => 0).3)) (1 => (1.see 3.A(1)=7.2..5) 38 39 40 Examples of two-dimensional array aggregates: -. may be used to specify an array with a single component. 8 => 0.2.1. -.2. For a multidimensional array_aggregate. 1.1.3 Array Aggregates 10 November 2006 100 . 1. 2 => (1 => 2. -. 0) Table'(5. 1) := (1 => 'F').6): ((1.. A named_array_aggregate. 6..0)). 1. a single expression in parentheses is interpreted as a parenthesized expression. 2. 3.single-component vector Table'(2 | 4 | 10 => 1. -.2. others => False) Schedule'(Wed | Sun => False. 8 => 0. 8.ISO/IEC 8652:2007(E) Ed. 8. 4.

see 3.3 . Value => String'('x'. Syntax 1 expression ::= relation {and relation} | relation {and then relation} | relation {or relation} | relation {or else relation} | relation {xor relation} relation ::= simple_expression [relational_operator simple_expression] | simple_expression [not] in range | simple_expression [not] in subtype_mark simple_expression ::= [unary_adding_operator] term {binary_adding_operator term} term ::= factor {multiplying_operator factor} factor ::= primary [** primary] | abs primary | not primary primary ::= numeric_literal | null | string_literal | aggregate | name | qualified_expression | allocator | (expression) Name Resolution Rules 2 3 4 5 6 7 A name used as a primary shall resolve to denote an object or a value. Static Semantics 8 Each expression has a type. In this International Standard.3. the term “expression” refers to a construct of the syntactic category expression or of any of the other five syntactic categories defined below. others => <>)) -. Implementation Permissions 10 For the evaluation of a primary that is a name denoting an object of an unconstrained numeric subtype.ISO/IEC 8652:2007(E) Ed.7 44/2 45/2 4. the implementation may either raise Constraint_Error or return the value of the object. 11 101 10 November 2006 Array Aggregates 4.4 Expressions An expression is a formula that defines the computation or retrieval of a value. Dynamic Semantics 9 The value of a primary that is a name denoting an object is the value of the object. it specifies the computation or retrieval of a value of that type. 3 — Ada Reference Manual Example of an array aggregate with defaulted others choice and with an applicable index constraint provided by an enclosing record aggregate: Buffer'(Size => 50. if the value of the object is outside the base range of its type. Pos => 1.

certain of the above operators are predefined.. Parentheses can be used to impose specific associations.1 through 4. is equivalent to a function_call of the form "op"(Y).relation -.simple expression -. can be used as designators in declarations of functions for user-defined operators. the single parameter is called Right for unary operators. See 6.primary -.simple expression -.expression -. For each such implicit operator declaration.expression (parentheses are required) -.0 -4.4 Expressions 10 November 2006 102 .4. where op is a unary operator.5.relation -. Syntax 2 3 4 5 6 7 logical_operator ::= relational_operator ::= binary_adding_operator ::= unary_adding_operator ::= multiplying_operator ::= highest_precedence_operator ::= and | or | xor = | /= | < | <= | > | >= + |– |& + |– * | / | mod | rem ** | abs | not Static Semantics 8 For a sequence of operators of the same precedence level. An expression of the form X op Y.5 Operators and Expression Evaluation 1 The language defines the following six categories of operators (given in order of increasing precedence).0*A*C R*Sin(θ)*Cos(φ) Password(1 .simple expression -. is equivalent to a function_call of the form "op"(X. and only those.ISO/IEC 8652:2007(E) Ed. where op is a binary operator. they are implicitly declared immediately after the type definition. the operators are associated with their operands in textual order from left to right.6..simple expression -. The corresponding operator_symbols. 9 4. “Overloading of Operators”. An expression of the form op Y. that is. 10 => 0) Sum Integer'Last Sine(X) Color'(Blue) Real(M*N) (Line_Count + 10) ---------real literal named number array aggregate variable attribute function call qualified expression conversion parenthesized expression 14 15/2 Examples of expressions: Volume not Destroyed 2*Line_Count -4.term -. 3 — Ada Reference Manual Examples 12 13 Examples of primaries: 4.factor -. For each form of type definition. 3) = "Bwv" Count in Small_Int Count not in Small_Int Index = 0 or Item_Hit (Cold and Sunny) or Warm A**(B**C) -.0 Pi (1 .expression (parentheses are required) 4.6.5. The predefined operators and their effects are described in subclauses 4.0 + A B**2 .relation -. Y). the parameters are called Left and Right for binary operators.

inclusive disjunction. Right : T) return T function "xor"(Left. for every modular type T. For modular types. Right : T) return T 2 3 For boolean types. are evaluated in an arbitrary order. the predefined operations on real types yield results whose accuracy is defined in Annex G. where zero 4 5 103 10 November 2006 Operators and Expression Evaluation 4. NOTES 11 The two operands of an expression of the form X op Y.ISO/IEC 8652:2007(E) Ed. For implementations that support the Numerics Annex. the predefined logical operators and. as for any function_call (see 6.same as (not Sunny) or Warm -.0) and (Y > 0.5. Implementation Permissions 11 12 For a sequence of predefined operators of the same precedence level (and in the absence of parentheses imposing a specific association).same as (X > 4. respectively. Implementation Requirements 10 The implementation of a predefined operator that delivers a result of an integer or fixed point type may raise Constraint_Error only if the result is outside the base range of the result type. Right : T) return T function "or" (Left. or raise the exception Constraint_Error. the predefined logical operators are defined on a bit-by-bit basis. using the binary representation of the value of the operands to yield a binary representation for the result. the expected type for both relations is that same boolean type. and for every one-dimensional array type T whose component type is a boolean type: function "and"(Left.1 Logical Operators and Short-circuit Control Forms Name Resolution Rules An expression consisting of two relations connected by and then or or else (a short-circuit control form) shall resolve to be of some boolean type. The implementation of a predefined operator that delivers a result of a floating point type may raise Constraint_Error only if the result is outside the safe range of the result type. but ignoring the potential for failure of language-defined checks in either the left-to-right or chosen order of association.4). and xor perform the conventional operations of conjunction. and exclusive disjunction. where op is a binary operator. Static Semantics 1 The following logical operators are predefined for every boolean type T.0 * (A**2)) same as (abs (1 + A)) + B parentheses are necessary same as (A/B)*C evaluate B + C before adding it to A 15 16 17 4.0) -----same as –(4. or. Examples 13 14 Examples of precedence: not Sunny or Warm X > 4. an implementation may impose any association of the operators with operands so long as the result produced is an allowed result for the left-to-right association. 3 — Ada Reference Manual Dynamic Semantics The predefined operations on integer types either yield the mathematically correct result or raise the exception Constraint_Error.0*A**2 abs(1 + A) + B Y**(-3) A / B * C A + (B + C) -.0 -4.5 .0 and Y > 0.

and the right operand is not evaluated if the value of the left operand determines the result. 4. NOTES 12 The conventional meaning of the logical operators is given by the following truth table: A True True False False B True False True False (A and B) True False False False Examples 8 9 10 (A or B) True True True False (A xor B) False True True False 11 12 Examples of logical operators: Sunny or Warm Filter(1 .Owner. a final subtraction by the modulus is performed to bring the result into the base range of the type. The bounds of the resulting array are those of the left operand.Owner /= null and then Next_Car.2).2 Relational Operators and Membership Tests 1 The equality operators = (equals) and /= (not equals) are predefined for nonlimited types.. 6 The logical operators on arrays are performed on a component-by-component basis on matching components (as for equality — see 4. 10) and Filter(15 . For the logical operators on arrays. except that the left operand is always evaluated first. If the tested type is tagged. then the simple_expression shall resolve to be of a type that is convertible (see 4. and >= (greater than or equal).see 3. The other relational_operators are the ordering operators < (less than). using the predefined logical operator for the component type. using in or not in.ISO/IEC 8652:2007(E) Ed. determines whether or not a value belongs to a given subtype or range. Name Resolution Rules 2 3/2 The tested type of a membership test is the type of the range or the type determined by the subtype_mark.10.see 3.Age > 25 N = 0 or else A(N) = Hit_Value -. and vice versa. a check is made that each component of the result belongs to the component subtype. > (greater than).5.6) to the tested type. Also. one-dimensional array types whose components are of a discrete type. a check is made that for each component of the left operand there is a matching component of the right operand. A membership test. or has a tag that identifies a type that is covered by a given type.5. <= (less than or equal). and for discrete array types.. The exception Constraint_Error is raised if either of the above checks fails. The ordering operators are predefined for scalar types. 24) -.5. the expected type for the simple_expression is the tested type. that is. If this result is outside the base range of the type.6. Dynamic Semantics 7 The short-circuit control forms and then and or else deliver the same result as the corresponding predefined and and or operators for boolean types.1 13 14 Examples of short-circuit control forms: Next_Car.1 4. Membership tests are allowed for all types. 3 — Ada Reference Manual represents False and one represents True. if untagged.1 Logical Operators and Short-circuit Control Forms 10 November 2006 104 .

5. or both shall be of access-to-subprogram types. and for every discrete array type T.2/2 The ordering operators are predefined for every specific scalar type T. and not an anonymous access type. and • at least one of its operands is an access parameter with designated type D. where D has a user-defined primitive equality operator such that: • its result type is Boolean.ISO/IEC 8652:2007(E) Ed. 10 11 105 10 November 2006 Relational Operators and Membership Tests 4. Further: • When both are of access-to-object types. with the following specifications: function function function function "<" (Left. if the simple_expression is of a tagged class-wide type. Right : T) return Boolean function "/="(Left.6/2 9. or both shall be of access-to-object types.5/2 9.1/2 7. • When both are of access-to-subprogram types. Legality Rules 9.7/2 For discrete types. For real types. then the designated subtypes shall statically match. with the following specifications: function "=" (Left. Right Right Right Right : : : : T) T) T) T) return return return return Boolean Boolean Boolean Boolean 8 9 Name Resolution Rules At least one of the operands of an equality operator for universal_access shall be of a specific anonymous access type. Right : universal_access) return Boolean function "/="(Left. Unless the predefined equality operator is identified using an expanded name with prefix denoting the package Standard.3/2 9. • it is declared immediately within the same declaration list as D. ">="(Left.4/2 At least one of the operands of the equality operators for universal_access shall be of type universal_access. then the tested type shall be (visibly) tagged. "<="(Left.2 . and if the designated types are elementary or array types. Right : universal_access) return Boolean 7.1/2 9. the designated types shall be the same or one shall cover the other. the designated profiles shall be subtype conformant. Right : T) return Boolean 5 6 7 The following additional equality operators for the universal_access type are declared in package Standard for use with anonymous access types: function "=" (Left. the predefined relational operators are defined in terms of the corresponding mathematical operations on the values of the operands.2/2 9. The equality operators are predefined for every specific type T that is not limited. ">" (Left. Dynamic Semantics 9. Static Semantics 4 The result type of a membership test is the predefined type Boolean. 3 — Ada Reference Manual Legality Rules For a membership test. neither operand shall be of an access-to-object type whose designated type is D or D'Class. the predefined relational operators are defined in terms of corresponding mathematical operations on the position numbers of the values of the operands. subject to the accuracy of the type.

the order in which "=" is called for components is unspecified. the result of the predefined equals operator for composite types (other than for those composite types covered earlier) is defined as follows: • If there are no components. and the successors of matching indices are defined to match. the result is defined to be True. Furthermore. the predefined equality operators (and certain other predefined operations on composite types — see 4. if its full type is tagged. and predefined equality for any other components not inherited from the parent type. the left operand is lexicographically less than the right operand if the first component of the left operand is less than that of the right. predefined equality for the private type is that of its full type.1 and 4. • For two one-dimensional arrays of the same type. or if both are equal to the null value of the access type. defined as follows: • For two composite objects or values of the same non-array type. predefined equality is defined in terms of the primitive equals operator of the full type. • If there are unmatched components.5.2 Relational Operators and Membership Tests 10 November 2006 106 . it is unspecified whether "=" is called on those components. • For two multidimensional arrays of the same type. the predefined ordering operators correspond to lexicographic order using the predefined order relation of the component type: A null array is lexicographically less than any array having at least one component. The analogous definitions apply if the types of the two objects or values are convertible. In the case of nonnull arrays. otherwise the left operand is lexicographically less than the right operand only if their first components are equal and the tail of the left operand is lexicographically less than that of the right (the tail consists of the remaining components beyond the first and can be null). For any composite type. if the result can be determined before calling "=" on some components. matching components are those whose index values match in successive index positions. For a private type. or if both are equal to the null value of the access type. The predefined "/=" operator gives the complementary result to the predefined "=" operator. and the predefined equals for any matching untagged components. • Otherwise. For a type extension.ISO/IEC 8652:2007(E) Ed. Two access-to-subprogram values are unequal if they designate different subprograms. It is unspecified whether two access values that designate the same subprogram but are the result of distinct evaluations of Access attribute_references are equal or unequal. For a discrete array type. the result is defined in terms of the primitive equals operator for any matching tagged components. the result is defined to be False.6) are defined in terms of the corresponding operation on matching components. Two access-to-subprogram values are equal if they are the result of the same evaluation of an Access attribute_reference. 13 14 15 16 17 18 19 20 21 22 23 24 24. Given the above definition of matching components.5. if the full type is untagged. predefined equality is defined in terms of the primitive (possibly user-defined) equals operator of the parent type and of any tagged components of the extension part.1/1 25 26 4. matching components are those that correspond to the same component_declaration or discriminant_specification. rather than being the same. For other composite types. matching components are those (if any) whose index values match in the following sense: the lower bounds of the index ranges are defined to match. 3 — Ada Reference Manual 12 Two access-to-object values are equal if they designate the same object.

5.true if My_Car has been set to null (see 3. the value of the simple_expression is not null.1) -. if the tested type is an access type and the named subtype excludes null. They have the following specifications: function "+"(Left. 32.1) -..subtype membership test (see 3.true if the two cars are identical -. Right : T) return T function "-"(Left. NOTES This paragraph was deleted.2/2 Otherwise the test yields the result False.1) 35 36 37 38 39 4.range membership test -. two values of this type have matching components if and only if their discriminants are equal..3 Binary Adding Operators Static Semantics The binary adding operators + (addition) and – (subtraction) are predefined for every specific numeric type T with their conventional meaning. or the range of the named subtype. Two nonnull arrays have matching components if and only if the length of each dimension is the same for both.range membership test -. the value has a tag that identifies a type covered by the tested type.1/2 30.8.9. or • The tested type is not scalar. A membership test using not in gives the complementary result to the corresponding membership test using in.1/1 33/2 34 13 If a composite type has components that depend on discriminants.ISO/IEC 8652:2007(E) Ed.subtype membership test (see 3.all = Your_Car. and the value of the simple_expression belongs to the given range.2 .all N not in 1 .True -.True -. 10 Today in Mon .5.all in Addition'Class " -. the simple_expression and the range (if any) are evaluated in an arbitrary order. 3 — Ada Reference Manual For the evaluation of a membership test. Right : T) return T 1 2 107 10 November 2006 Relational Operators and Membership Tests 4. A membership test using in yields the result True if: • The tested type is scalar. 30. Implementation Requirements 31 32 For all nonlimited types declared in language-defined packages.10.class membership test (see 3. and the value of the simple_expression satisfies any constraints of the named subtype. Examples Examples of expressions involving relational operators and membership tests: X /= Y "" < "A" and "A" < "Aa" "Aa" < "B" and "A" < "A My_Car = null My_Car = Your_Car My_Car.true if we both share the same car -. and: • • 27 28 29 30/2 if the type of the simple_expression is class-wide.1) -. Fri Today in Weekday Archive in Disk_Unit Tree. the "=" and "/=" operators of the type shall behave as if they were the predefined equality operators for the purposes of the equality of composite types and generic formal types.5.

then the lower bound of the result is that of the index subtype. the result is zero.1 "A" & "BCD" 'A' & "BCD" 'A' & 'A' -. • If the ultimate ancestor of the array type was defined by an unconstrained_array_definition. the result of the concatenation is the right operand. if both operands are of type T. C. using in place of such an operand an array having this operand as its only component (converted to the component subtype) and having the lower bound of the index subtype of the array type as its lower bound. the unary adding operator –.concatenation of two character literals 4. then the lower bound of the result is that of the left operand. If either operand is of the component type C. They have the following specifications: function "+"(Right : T) return T function "-"(Right : T) return T NOTES 15 For modular integer types. T. and whose components comprise the components of the left operand followed by the components of the right operand. the result of the concatenation is a one-dimensional array whose length is the sum of the lengths of its operands.5. the lower bound of the result is determined as follows: • If the ultimate ancestor of the array type was defined by a constrained_array_definition. 2 3 4. If the left operand is a null array. when given a nonzero operand. Otherwise.5. the result of the concatenation is given by the above rules. unless the result is a null array.concatenation of two string literals -. returns the result of subtracting the value of the operand from the modulus. C.3 Binary Adding Operators 10 November 2006 108 . They have the following specifications: function function function function "&"(Left "&"(Left "&"(Left "&"(Left : : : : T. The upper bound is determined by the lower bound and the length.ISO/IEC 8652:2007(E) Ed. for a zero operand. Constraint_Error is raised if this check fails. 3 — Ada Reference Manual 3 The concatenation operators & are predefined for every nonlimited.5). one-dimensional array type T with component type C. the binary adding operators + and – on modular types include a final reduction modulo the modulus if the result is outside the base range of the type. The result of a concatenation is defined in terms of an assignment to an anonymous object.Z has to be of a real type -. NOTES 14 As for all predefined operators on modular types. Examples 6 7 8 9 10 11 12 13 14 Examples of expressions involving binary adding operators: Z + 0. as for any function call (see 6.4 Unary Adding Operators Static Semantics 1 The unary adding operators + (identity) and – (negation) are predefined for every specific numeric type T with their conventional meaning. Right Right Right Right : : : : T) C) T) C) return return return return T T T T 4 Dynamic Semantics 5 For the evaluation of a concatenation with result type T.concatenation of a character literal and a string literal -. A check is made that the upper bound of the result of the concatenation belongs to the range of the index subtype.

Right : universal_fixed) return universal_fixed function "/"(Left. in addition. followed by a reduction modulo the modulus if the result is outside the base range of the type (which is only possible for the "*" operator). as in a number_declaration: function "*"(Left. Right : root_real) return root_real function "/"(Left : root_real.ISO/IEC 8652:2007(E) Ed. Right : universal_fixed) return universal_fixed 18 19 109 10 November 2006 Multiplying Operators 4. Right Right Right Right : : : : T) T) T) T) return return return return T T T T 1 2 Signed integer multiplication has its conventional meaning. for some signed integer value N. this result satisfies the relation: A = B*N + (A mod B) 9 10 The multiplying operators on modular types are defined in terms of the corresponding signed integer operators. Right : Integer) return T 13 14 All of the above multiplying operators are usable with an operand of an appropriate universal numeric type.5. Right : root_integer) return root_real function "*"(Left : root_integer. "/" (Left. Right : T) return T 11 12 The following multiplication and division operators. Right : Integer) return T function "*"(Left : Integer. Right : root_real) return root_real function "/"(Left. Multiplication and division operators are predefined for every specific floating point type T: function "*"(Left. and the result is allowed to be of type root_real.5. and are usable when both operands are of an appropriate universal or root numeric type.5 . The following additional multiplying operators for root_real are predefined. are predefined for every specific fixed point type T: function "*"(Left : T. with an operand of the predefined type Integer. / (division). Right : root_real) return root_real function "*"(Left : root_real.5 Multiplying Operators Static Semantics The multiplying operators * (multiplication). Right : root_integer) return root_real 15 16 17 Multiplication and division between any two fixed point types are provided by the following two predefined operators: function "*"(Left. Signed integer division satisfies the identity: (-A)/B = -(A/B) = A/(-B) 7 8 The signed integer modulus operator is defined such that the result of A mod B has the sign of B and an absolute value less than the absolute value of B. "mod"(Left. Signed integer division and remainder are defined by the relation: A = (A/B)*B + (A rem B) 3 4 5 6 where (A rem B) has the sign of A and an absolute value less than the absolute value of B. "rem"(Left. Right : T) return T function "/"(Left. Right : T) return T function "/"(Left : T. and rem (remainder) are predefined for every specific integer type T: function function function function "*" (Left. mod (modulus). 3 — Ada Reference Manual 4.

for a real type T with T'Machine_Overflows True.2/2 19. if the mathematical result is between two multiples of the small. A/B is the quotient and A rem B is the remainder when A is divided by B. either explicitly or implicitly. 4. and mod if the right operand is zero. Dynamic Semantics 21 The multiplication and division operators for real types have their conventional meaning. for ordinary fixed point types. J : Integer := 2.3/2 19. and • both of its formal parameters are of a fixed-point type. For decimal fixed point types. Unless the predefined universal operator is identified using an expanded name with prefix denoting the package Standard. The exception Constraint_Error is raised by integer division. Similarly. the accuracy of the result is determined by the precision of the result type. the following identity holds: A mod B A 10 11 12 13 14 A 10 11 12 13 14 B 5 5 5 5 5 B -5 -5 -5 -5 -5 = A/B 2 2 2 2 2 A/B -2 -2 -2 -2 -2 (A + K*B) mod B A rem B 0 1 2 3 4 A rem B 0 1 2 3 4 A mod B 0 1 2 3 4 A mod B 0 -4 -3 -2 -1 Examples The relations between signed integer division. the result is truncated toward zero if the mathematical result is between two multiples of the small of the specific result type (possibly determined by context).1/2 The above two fixed-fixed multiplying operators shall not be used in a context where the expected type for the result is itself universal_fixed — the context has to identify some other numeric type to which the result is to be converted. Legality Rules 19. K : Integer := 3. A corresponding requirement applies to the universal fixed-fixed division operator. For floating point types. remainder.ISO/IEC 8652:2007(E) Ed. NOTES 16 For positive A and B. The following relations are satisfied by the rem operator: 22 23 24 25 26 27 28 29 A rem (-B) = A rem B (-A) rem B = -(A rem B) 17 For any signed integer K. it is unspecified which of the two is the result.5. an explicit conversion is required on the result when using the above fixed-fixed multiplication operator if either operand is of a type having a user-defined primitive multiplication operator such that: • it is declared immediately within the same declaration list as the type.5 Multiplying Operators 10 November 2006 110 .4/2 20/2 This paragraph was deleted. division by zero raises Constraint_Error. rem. 3 — Ada Reference Manual Name Resolution Rules 19. and modulus are illustrated by the following table: A -10 -11 -12 -13 -14 A -10 -11 -12 -13 -14 B 5 5 5 5 5 B -5 -5 -5 -5 -5 A/B -2 -2 -2 -2 -2 A/B 2 2 2 2 2 A rem B 0 -1 -2 -3 -4 A rem B 0 -1 -2 -3 -4 A mod B 0 4 3 2 1 A mod B 0 -1 -2 -3 -4 30 31 32 Examples of expressions involving multiplying operators: I : Integer := 1.

Y : Real := 2.5 0. that is. Integer same as K and J. the result is one. this corresponds to a bitwise complement of the binary representation of the value of the operand.X (with N–1 multiplications) except that the multiplications are associated in an arbitrary order.9 33 34 35 4..75*G Fraction(F*G) Real(J)*Y Value 2 1 1 0. F : Fraction := 0. With the value of N negative (only defined for a floating point operand). that is.7 see 3. The highest precedence exponentiation operator ** is predefined for every specific integer type T with the following specification: function "**"(Left : T. the exception Constraint_Error is raised if this check fails. Expression I*J K/J K mod J X/Y F/2 3*F 0.5. with the following specification: function "not"(Right : T) return T 4 5 The result of the operator not for a modular type is defined as the difference between the high bound of the base range of the type and the value of the operand. Fraction universal_fixed. that is. that is. Right : Natural) return T 6 7 8 9 Exponentiation is also predefined for every specific floating point type as well as root_real. with the following specification: function "abs"(Right : T) return T 1 2 3 The highest precedence unary operator not (logical negation) is predefined for every boolean type T. every modular type T.125 0.6 Highest Precedence Operators Static Semantics The highest precedence unary operator abs (absolute value) is predefined for every specific numeric type T. Integer same as K and J.5. The expression X**N with the value of the exponent N positive is equivalent to the expression X*X*.5. the type of both operands after conversion of J --see 3. and for every one-dimensional array type T whose components are of a boolean type. 111 10 November 2006 Multiplying Operators 4.. G : Fraction := 0. Right : Integer'Base) return T 10 11 The right operand of an exponentiation is the exponent.0 Result Type same as I and J. Real same as F. A check is made that each component of the result belongs to the component subtype. the component that has the same index value).75 0. implicitly convertible to any fixed point type Fraction. that is.25. the result is the reciprocal of the result using the absolute value of N as the exponent. Integer same as X and Y.125 4.5.5 . For a binary modulus. as stated by the conversion Real. With N equal to zero. The operator not that applies to a one-dimensional array of boolean components yields a one-dimensional boolean array with the same bounds. each component of the result is obtained by logical negation of the corresponding component of the operand (that is.ISO/IEC 8652:2007(E) Ed.0. 3 — Ada Reference Manual X : Real := 1. Fraction same as F.0.5.375 0. with the following specification (where T is root_real or the floating point type): function "**"(Left : T. that is.

6 Type Conversions 1 Explicit type conversions.5.) NOTES 18 As implied by the specification given above for exponentiation of an integer type. or • The operand type shall be covered by or descended from the target type. or if it appears in a call as an actual parameter of mode out or in out. both value conversions and view conversions. are allowed between closely related types as defined below. 21. the target type shall be convertible (back) to the operand type. or • The operand type shall be a class-wide type that covers the target type. 13 4. even though the final result (after taking the reciprocal) would not be. The operand of a view conversion is interpreted only as a name. Legality Rules 8/2 In a view conversion for an untagged type. Two types are convertible if each is convertible to the other.0. or • The operand and target types shall both be class-wide types and the specific type associated with at least one of them shall be an interface type. other type_conversions are called value conversions.6 Highest Precedence Operators 10 November 2006 112 . or both types are classwide types. Name Resolution Rules 4 5/2 6 7 The operand of a type_conversion is expected to be of any type. the operand of a value conversion is interpreted as an expression. 21/2 If there is a type that is an ancestor of both the target type and the operand type. This clause also defines rules for value and view conversions to a particular subtype of a type.1/2 22 23/2 23.ISO/IEC 8652:2007(E) Ed. Constraint_Error is raised if this check fails.1/2 4. a check is made that the exponent is not negative. Syntax 2 type_conversion ::= subtype_mark(expression) | subtype_mark(name) 3 The target subtype of a type_conversion is the subtype denoted by the subtype_mark. its type is the operand type. The operand of a type_conversion is the expression or name within the parentheses. both explicit ones and those implicit in other constructs. A type_conversion whose operand is the name of an object is called a view conversion if both its target type and operand type are tagged. 3 — Ada Reference Manual Implementation Permissions 12 The implementation of exponentiation for the case of a negative exponent is allowed to raise Constraint_Error if the intermediate result of the repeated multiplications is outside the safe range of the type. then at least one of the following rules shall apply: • The target type shall be untagged. Paragraphs 9 through 20 were reorganized and moved below. One type is convertible to a second type if a type_conversion with the first type as operand type and the second type as target type is legal according to the rules of this clause. (The best machine approximation to the final result in this case would generally be 0.

If the operand type is declared within a generic body. If the target type of a view conversion has aliased components.5/2 24.4/2 24.7/2 24. The accessibility level of the operand type shall not be statically deeper than that of the target type.8/2 24. or the designated type shall be discriminated in its full view and unconstrained in any partial view.13/2 24. Further. or volatile subcomponent. In addition to the places where Legality Rules normally apply (see 12. then the operand type shall be universal_access. private.1/2 24. if the operand type is not universal_access: • • 24.3/2 24. 24. 3 — Ada Reference Manual If there is no type that is the ancestor of both the target type and the operand type. If the component types are anonymous access types. then so shall the operand type. • • • • • • 24/2 24. one of the following rules shall apply: • If the target type is a numeric type. • If the target type is an array type.ISO/IEC 8652:2007(E) Ed. Further.20/2 24. and either: • • 24.9/2 • If the target type is universal_access. then the designated types shall be the same. this rule applies also in the private part of an instance of a generic unit. if the operand type is not universal_access: • If the target type is an access-to-variable type. then the operand designated type shall be convertible to the target designated type. • If the target type is an access-to-subprogram type. then the operand type shall be universal_access or an access-to-object type.15/2 24. In addition to the places where Legality Rules normally apply (see 12. then the operand type shall be an access type.3). Neither the target type nor the operand type shall be limited.6/2 Corresponding index types shall be convertible.12/2 If the target designated type is tagged.17/2 • If the target type is a pool-specific access-to-object type. then the operand type shall be universal_access or an access-to-subprogram type.11/2 24.6 . then the operand type shall be a numeric type. 24. If the target designated type is not tagged. The component subtypes shall statically match.10/2 24.18/2 24. the target type shall be declared within the generic body. then the operand type shall be an access-tovariable type. this rule applies also in the private part of an instance of a generic unit. and one of the designated subtypes shall be unconstrained.3).19/2 The designated profiles shall be subtype-conformant.21/2 A type_conversion that is a value conversion denotes the value that is the result of converting the value of the operand to the target subtype. and they are not both class-wide types.16/2 • The accessibility level of the operand type shall not be statically deeper than that of the target type. then the operand type shall be an array type. Static Semantics 24. 24.14/2 the designated subtypes shall statically match. and The operand type of a view conversion shall not have a tagged. Further: • The types shall have the same dimensionality. • If the target type is a general access-to-object type. then the accessibility level of the operand type shall not be statically deeper than that of the target type. 25 113 10 November 2006 Type Conversions 4. • • 24.2/2 24.

This view is a variable of the target type if the operand denotes a variable.ISO/IEC 8652:2007(E) Ed. If the target subtype is a constrained array subtype. The nominal subtype of a type_conversion is its target subtype.1/2 40 41 • Composite (Non-Array) Type Conversion • • 42 43 • 4. the value of each component of the result is that of the matching component of the operand value (see 4. for implementations that support the Numerics Annex). the result is rounded to the nearest integer (away from zero if exactly halfway between two integers). and only when the operand value is outside the base range of the modular type. The result is the value of the target type with the same position number as that of the operand value. if it 31 32 33 • 34 35 • Enumeration Type Conversion • 36 37 • Array Type Conversion • 38 • 39 • • 39. the operand is evaluated.5. If the target type is an integer type and the operand type is real. if any. then a check is made that the length of each dimension of the value of the operand equals the length of the corresponding dimension of the target subtype. then a check is made that the accessibility level of the operand type is not deeper than that of the target type. Constraint_Error is raised. a check is made that the tag of the operand identifies a (specific) type that is covered by or descended from the target type. then the result is the value of the target type that corresponds to the same mathematical integer as the operand. Dynamic Semantics 27 28 For the evaluation of a type_conversion that is a value conversion.2. its value is that of the corresponding discriminant of the operand value.2). and then the value of the operand is converted to a corresponding value of the target type. The value of each nondiscriminant component of the result is that of the matching component of the operand value. otherwise it is a constant of the target type. Additional rules follow: • Numeric Type Conversion • • • 29 30 If the target and the operand types are both integer types. If the target subtype is an unconstrained array subtype. For each nonnull index range. then the result is within the accuracy of the target type (see G. “Numeric Performance Requirements”. For each discriminant of the target type that corresponds to a discriminant of the operand type. If the target type is a decimal fixed point type. In either array case. The bounds of the result are those of the target subtype. If the target type is some other real type. If there is no value of the target type that corresponds to the operand value. then the result is truncated (toward 0) if the value of the operand is not a multiple of the small of the target type.6 Type Conversions 10 November 2006 114 . 3 — Ada Reference Manual 26 A type_conversion that is a view conversion denotes a view of the object denoted by the operand. then the bounds of the result are obtained by converting each bound of the value of the operand to the corresponding index type of the target type. If the component types of the array types are anonymous access types. The tag of the result is that of the operand. this can only happen on conversion to a modular type. a check is made that the bounds of the range belong to the corresponding index subtype. If the operand type is class-wide.

Any other check associated with a conversion raises Constraint_Error if it fails. if the target subtype is constrained. 44 • 45 • 46 47 48 • Access Type Conversion • • • 49/2 50 After conversion of the value to the target type. the operand name is evaluated. 3 — Ada Reference Manual corresponds to more than one discriminant of the operand type. then a check is made that the value is not null.4. If the operand value is null. If the operand value is not null. Program_Error is raised. the value of the operand object is used to initialize the formal parameter without checking against any constraint of the target subtype (see 6. Conversion to a type is the same as conversion to an unconstrained subtype of the type. 51/2 52 53 54/1 55 56 57 58 115 10 November 2006 Type Conversions 4. some ancestor of the specific type identified by the tag of the operand). a check is made that its value belongs to its subtype. or if the operand type is a descendant of the target type and has discriminants that were not inherited from the target type. checks are performed as above for a value conversion. each nondiscriminant component of the view denotes the matching component of the operand object. If the target subtype excludes null. whose type is the target type. For the evaluation of a view conversion. except if the object is of an access type and the view conversion is passed as an out parameter. a check is made that all these discriminants are equal in the operand value. then an assignment to the view assigns to the corresponding part of the object denoted by the operand. For each discriminant of the operand type that corresponds to a discriminant that is specified by the derived_type_definition for some ancestor of the target type. the bounds or discriminants (if any) of the view are as defined above for a value conversion. in this latter case. its value in the result is that specified by the derived_type_definition. otherwise. a check is performed that the value satisfies this constraint. after converting the assigned value to the subtype of the object (which might raise Constraint_Error). a check is made that the accessibility level of the operand type is not deeper than that of the target type. but viewed as being of the target designated subtype (or profile). The properties of this new view are as follows: • If the target type is composite. an assignment to the view assigns to the object. a check is made that in the operand value it equals the value specified for it.1). then the result designates the same object (or subprogram) as is designated by the operand value.6 . • If the target type is tagged. or if the target subtype is indefinite.ISO/IEC 8652:2007(E) Ed. the subtype of the view is constrained if either the target subtype or the operand object is constrained. If an Accessibility_Check fails. For an access-to-object type. the result of the conversion is the null value of the target type. and a new view of the object denoted by the operand is created. • Reading the value of the view yields the result of converting the value of the operand object to the target subtype (which might raise Constraint_Error). For each discriminant of the result. if the target type is composite. any checks associated with evaluating a conversion to the target designated subtype are performed. • For each discriminant of the target type that corresponds to a discriminant that is specified by the derived_type_definition for some ancestor of the operand type (or if class-wide.

value is 0 65 66 67 68 Example of conversion between derived types: type A_Form is new B_Form.value is 2 -. 42)) -. such an expression enclosed by parentheses is not allowed.bounds are those of Dozen 71 4. Even when the expected and actual types are the same. Examples 63 64 59 60 61/2 62 Examples of numeric type conversion: Real(2*J) Integer(1. a character_literal. -. an integer literal is of the type universal_integer. 100) of Integer. Syntax 2 qualified_expression ::= subtype_mark'(expression) | subtype_mark'aggregate Name Resolution Rules 3 The operand (the expression or aggregate) shall resolve to be of the type determined by the subtype_mark. or to raise Constraint_Error if the (possibly adjusted) value does not satisfy the constraints of the target subtype. and to verify the subtype.the reverse conversion 69 70 Examples of conversions between array types: type Sequence is array (Integer range <>) of Integer. Similarly. subtype Dozen is Sequence(1 .6) Integer(-0. Y := B_Form(X). as is permitted by the type resolution rules (see 8. 12). type conversions are performed implicitly in situations where the expected type and the actual type of a construct differ.. or an attribute_reference for an Access or Unchecked_Access attribute. Similarly. it is recommended that the first subtype be specified as the target to minimize confusion (a similar recommendation applies to renaming and generic formal in out objects). 42)) Dozen(Ledger(31 . 21 The constraint of the target subtype has no effect for a type_conversion of an elementary type passed as an out parameter. For example.7 Qualified Expressions 1 A qualified_expression is used to state explicitly the type. Y : B_Form. Hence.6).6 Type Conversions 10 November 2006 116 . X : A_Form.. of an operand that is either an expression or an aggregate. an aggregate. A qualified_expression (see 4..4) -.value is converted to floating point -. implicit subtype conversions are performed to adjust the array bounds (if any) of an operand to match the desired target subtype.bounds are those of Ledger -.bounds are 31 and 42 -. a string_literal.7) can be used instead of such a type_conversion. 4. 20 A ramification of the overload resolution rules is that the operand of an (explicit) type_conversion cannot be an allocator.. and is implicitly converted when assigned to a target of some specific integer type.ISO/IEC 8652:2007(E) Ed. X := A_Form(Y). Sequence(Ledger) Sequence(Ledger(31 . or a universal type that covers it. Ledger : array(1 . an actual parameter of a specific tagged type is implicitly converted when the corresponding formal parameter is of a class-wide type. 3 — Ada Reference Manual NOTES 19 In addition to explicit type_conversions.

shall not be statically deeper than that of the type of the allocator (see 3.qualification unnecessary for J in Code'(Fix) . Exp. others => 0) -.8 Allocators The evaluation of an allocator creates an object and yields an access value that designates the object. Legality Rules 3/1 An initialized allocator is an allocator with a qualified_expression..10. -. Dec.. type Code is (Fix. In particular. the accessibility level of the type determined by the subtype_indication or qualified_expression shall not be statically deeper than that of the type of the allocator.Dec is of type Code 6 7 8 9 for J in Code'(Fix) .2/2 117 10 November 2006 Qualified Expressions 4. the allocator shall be an initialized allocator. if there is no constraint. Dec. Signif). then the subtype_mark shall denote a definite subtype.. then the accessibility level of the anonymous access type of each access discriminant. -. Code'(Dec) loop . Examples 4 5 Examples of disambiguating expressions using qualification: type Mask is (Fix. -. If the designated subtype of the type of the allocator has one or more unconstrained access discriminants. Print (Code'(Dec)).qualification needed for either Fix or Dec for J in Code range Fix . Syntax 1 allocator ::= new subtype_indication | new qualified_expression Name Resolution Rules 2 The expected type for an allocator shall be a single access-to-object type with designated type D such that either D covers the type determined by the subtype_mark of the subtype_indication or qualified_expression. as determined by the subtype_indication or qualified_expression of the allocator. Dec loop . Sub).. it might be necessary to qualify the operand to resolve its type.Dec is of type Mask -. If the type of the allocator is an access-to-constant type.2). Print (Mask'(Dec)).qualification unnecessary for Dec Dozen'(1 | 3 | 5 | 7 => 2. if an overloaded name or aggregate is passed to an overloaded subprogram.see 4.. The exception Constraint_Error is raised if this check fails. or the expected type is anonymous and the determined type is D'Class.6 10 4. An uninitialized allocator is one with a subtype_indication.7 .. If the designated type of the type of the allocator is class-wide. Cla. Tnz.. NOTES 22 When a given context does not uniquely identify an expected type. 3 — Ada Reference Manual Dynamic Semantics The evaluation of a qualified_expression evaluates the operand (and if of a universal type.ISO/IEC 8652:2007(E) Ed. converts it to the type determined by the subtype_mark) and checks that its value belongs to the subtype denoted by the subtype_mark.. Dec loop .1/2 5. 4 5/2 5. a constraint is permitted only if the subtype_mark denotes an unconstrained composite subtype. In the subtype_indication of an uninitialized allocator.. -. a qualified_expression can be used to do so.

Then: • If the designated type is elementary. If the designated type is composite. 4. Dynamic Semantics 7/2 For the evaluation of an initialized allocator. they are activated (see 9. Program_Error is raised if either such check fails. if any.ISO/IEC 8652:2007(E) Ed. Finally. This object is then initialized by default (see 3. then Program_Error is raised.8 Allocators 10 November 2006 118 .1) has started. If the object to be created by an allocator contains any tasks. • If the designated type is composite. an object of the designated subtype is created and any implicit initial value is assigned. This rule does not apply in the body of a generic unit or within a body declared within the declarative region of a generic unit. If the error is detected. then a check is made that the accessibility level of the type determined by the subtype_indication. otherwise.1/2 10.2). and the finalization of the collection of the type of the allocator (see 7. the elaboration of the subtype_indication is performed first. then the subtype of the created object is the designated subtype when the designated subtype is constrained or there is a partial view of the designated type that is constrained.2/2 10. If the designated subtype of the allocator has one or more unconstrained access discriminants. this rule applies also in the private part of an instance of a generic unit. determined by the subtype_mark of the subtype_indication.6. then the subtype of the created object is the designated subtype. Program_Error is raised.3).3.3). then a check is made that the accessibility level of the anonymous access type of each access discriminant is not deeper than that of the type of the allocator. 3 — Ada Reference Manual 5. Constraint_Error is raised if this check fails.1/2 It is a bounded error if the finalization of the collection of the type (see 7. If the created object contains any tasks. In addition to the places where Legality Rules normally apply (see 12.1) using the subtype_indication to determine its nominal subtype. For the evaluation of an uninitialized allocator. the evaluation of the qualified_expression is performed first. Program_Error is raised. A check is made that the value of the object belongs to the designated subtype. This check and the initialization of the object are performed in an arbitrary order. if the designated type of the type of the allocator is class-wide.6. if the type of the allocator is a descendant of a formal access type declared within the formal part of the generic unit. or by the tag of the value of the qualified_expression.3/2 An allocator shall not be of an access type for which the Storage_Size has been specified by a static expression with value zero or is defined by the language to be zero. Static Semantics 6/2 If the designated type of the type of the allocator is elementary. an object of the designated type is created with tag.3/2 11 11. the allocation proceeds normally. and all of the dependent tasks of the master are terminated (see 9. If the object to be created by an allocator has a controlled or protected part. the created object is constrained by its initial value (even if the designated subtype is unconstrained with defaults).1) of the allocator has started. Bounded (Run-Time) Errors 8 9/2 10/2 10. is not deeper than that of the type of the allocator. and the master of the type of the allocator is completed. Otherwise. an access value that designates the created object is returned. For any allocator. An object of the designated type is created and the value of the qualified_expression is converted to the designated subtype and assigned to the object.

and whose prefix denotes a static scalar subtype.1 new Cell'(Value => 0. Value => (1 . 26 Implementations are permitted. to provide garbage collection (see 13. if any (whether given explicitly or by default). See 3. • a type_conversion whose subtype_mark denotes a static scalar subtype.11. 20) new Matrix'(1 . 80 => 'A')) -.10. and certain scalar and string subtypes are defined to be static subtypes. • a membership test whose simple_expression is a static expression. Pos => 0. • a function_call whose function_name or function_prefix statically denotes a static function. • a static expression enclosed in parentheses. and whose operand is a static expression.1 Expr_Ptr'(new Literal'(Expression with 3.3. 20 => 0. “Storage Management”.9. but not required. the storage for an object allocated by an allocator comes from a storage pool (possibly user defined). certain discrete ranges are defined to be static.initialized explicitly 16 17 18 19 20 new Buffer(100) -. • a qualified_expression whose subtype_mark denotes a static (scalar or string) subtype. Static means determinable at compile time. 24 If any part of the created object is controlled. are all static expressions. null. • an attribute_reference whose prefix statically denotes a statically constrained array object or array subtype. 1 . see 3. • an attribute_reference that denotes a scalar value.initialized explicitly. and whose range is a static range or whose subtype_mark denotes a static (scalar or string) subtype. with an optional dimension. • a name that denotes the declaration of a named number or a static constant. 10 => (1 .initialized explicitly Expr_Ptr'(new Literal) -.. See 7.ISO/IEC 8652:2007(E) Ed. 1 2 3 4 5 6 7 8 9 10 11 12 13 119 10 November 2006 Allocators 4.the bounds only are given -. and whose actual parameters. Instances of Unchecked_Deallocation may be used to explicitly reclaim storage. 10. A static expression is a scalar or string expression that is one of the following: • a numeric_literal.not initialized new Matrix(1 . and whose attribute_designator is First... using the declared properties or values of the program entities. Succ => null. 25 As explained in 13.6. the initialization includes calls on corresponding Initialize or Adjust procedures. Pred => null) -. or Length. The exception Storage_Error is raised by an allocator if there is not enough storage.9 Static Expressions and Static Subtypes Certain expressions of a scalar or string type are defined to be static..allocator for access-to-class-wide type. • a string_literal of a static string subtype. Similarly. • a short-circuit control form both of whose relations are static expressions.9.3). Last.initialized explicitly new Cell -.8 .0)) -.5)) -.the discriminant only is given new Buffer'(Size => 80. and whose operand is a static expression.. null) -. Examples 12 13 14 15 Examples of allocators: new Cell'(0. see 3. 3 — Ada Reference Manual NOTES 23 Allocators cannot create objects of an abstract type.11.initialized explicitly 4.

• a language-defined attribute that is a function. • An index constraint is static if each discrete_range is static.1/2 32 4. A static scalar subtype is an unconstrained scalar subtype whose type is not a descendant of a formal type. • a predefined concatenation operator whose result type is a string type. and the result subtype of a generic formal function. and if the parameter and result types are scalar. • an enumeration literal. unless the type is a descendant of a formal scalar type. In any case. or • It denotes a renaming_declaration with a name that statically denotes the renamed entity. A static function is one of the following: • a predefined operator whose parameter and result types are all scalar types none of which are descendants of formal scalar types. or character_literal. The base range of a scalar type is a static range. • A scalar constraint is static if it has no range_constraint. a generic formal subprogram is not a static function. are not static. 3 — Ada Reference Manual 14 15 A name statically denotes an entity if it denotes the entity and: • It is a direct_name. or a constrained scalar subtype formed by imposing a compatible static constraint on a static scalar subtype. A subtype is statically constrained if it is constrained.ISO/IEC 8652:2007(E) Ed. A static range is a range whose bounds are static expressions. expanded name. and it denotes a declaration other than a renaming_declaration. having a value defined by a static scalar expression or by a static string expression whose value has a length not exceeding the maximum length of a string_literal in the implementation. In any case. The different kinds of static constraint are defined as follows: • A null constraint is always static. if the prefix denotes a static scalar subtype. • A discriminant constraint is static if each expression of the constraint is static. or one with a static range. A static subtype is either a static scalar subtype or a static string subtype. 16 17 18 19 20 21 22 23 24 25 26/2 27 28 29 30 31 31. or a range_attribute_reference that is equivalent to such a range. A static discrete_range is one that is a static range or is a subtype_indication that defines a static scalar subtype. or if it is a static string constant. or a constrained string subtype formed by imposing a compatible static constraint on a static string subtype. or • It is an attribute_reference whose prefix statically denotes some entity. and the subtype of each discriminant is static. A static constant is a constant view declared by a full constant declaration or an object_renaming_declaration with a static nominal subtype. In any case.9 Static Expressions and Static Subtypes 10 November 2006 120 . and each index subtype of the corresponding array type is static. and its constraint is static. the subtype of a generic formal object of mode in out. A static string subtype is an unconstrained string subtype whose index subtype and component subtype are static. the constraint of the first subtype of a scalar formal type is neither static nor null. An object is statically constrained if its nominal subtype is statically constrained.

then its value shall be within the base range of its expected type. if the value is exactly half-way between two machine numbers. Implementation Advice 38/2 For a real static expression that is not part of a larger static expression. 28 A static (or run-time) type_conversion from a real type to an integer type performs rounding. For a static expression that is evaluated: • The expression is illegal if its evaluation fails a language-defined check other than Overflow_Check. Otherwise.9 . and whose expected type is not a descendant of a formal type. NOTES 27 An expression can be static even if it occurs in a context where staticness is not required.3.2 -.14159_26536/2)/90) 44 121 10 November 2006 Static Expressions and Static Subtypes 4. In addition to the places where Legality Rules normally apply (see 12. -.1/2 39 40 Examples of static expressions: 1 + 1 abs(-10)*3 -.1_000_000 Long : constant := Float'Digits*2. the value may be arbitrarily large or small.ISO/IEC 8652:2007(E) Ed. • If the expression is not part of a larger static expression and the expression is expected to be of a single specific type. Implementation Requirements 33 34 35/2 36/2 37/2 For a real static expression that is not part of a larger static expression. If the expected type is a descendant of a formal type. the above restrictions also apply in the private part of an instance of a generic unit.0/Deg_To_Rad. This restriction does not apply if the expected type is a descendant of a formal scalar type (or a corresponding actual type in an instance).2 Deg_To_Rad : constant := Half_Pi/90. the rounding performed is implementationdefined. the rounding should be the same as the default rounding for the target system. Half_Pi : constant := Pi/2. 3 — Ada Reference Manual Legality Rules A static expression is evaluated at compile time except when it is part of the right operand of a static shortcircuit control form whose value is determined by its left operand.30 41 42 43 Kilo : constant := 1000. then no special rounding or truncating is required — normal accuracy rules apply (see Annex G). Rad_To_Deg : constant := 1. Examples 38. Mega : constant := Kilo*Kilo. • If the expression is of type universal_real and its expected type is a decimal fixed point type. the rounding is performed away from zero. -.equivalent to 1. If the operand value is exactly half-way between two integers.3). without performing Overflow_Checks.0/((3. and whose expected type is not a descendant of a formal type. -. This evaluation is performed exactly.see 3. then its value shall be a multiple of the small of the decimal type. the implementation shall round or truncate the value (according to the Machine_Rounds attribute of the expected type) to the nearest machine number of the expected type. or if the static expression appears in the body of an instance of a generic unit and the corresponding expression is nonstatic in the corresponding generic body.

Two anonymous access-to-object subtypes statically match if their designated subtypes statically match.9. A subtype statically matches another subtype of the same type if they have statically matching constraints.3/2 A constraint statically matches another constraint if: • both are null constraints. or if both are static and have equal corresponding bounds. 3 — Ada Reference Manual 4. • both are nonstatic and result from the same elaboration of a constraint of a subtype_indication or the same evaluation of a range of a discrete_subtype_definition.4/2 2/2 3 4 4. for access subtypes. • both are static and have equal corresponding bounds or discriminant values. A constraint is statically compatible with a scalar subtype if it statically matches the constraint of the subtype. and either both or neither are access-to-constant. Two ranges of the same type statically match if both result from the same evaluation of a range. and either both or neither exclude null.2/2 1. 1. Two anonymous access-to-subprogram subtypes statically match if their designated profiles are subtype conformant.1/2 1.1 Statically Matching Constraints and Subtypes 10 November 2006 122 . and.9.1 Statically Matching Constraints and Subtypes Static Semantics 1/2 1. One subtype is statically compatible with a second subtype if the constraint of the first is statically compatible with the second subtype. or • both are nonstatic and come from the same formal_type_declaration.ISO/IEC 8652:2007(E) Ed. or if the subtype is unconstrained. or if both are static and the constraint is compatible with the subtype. and either both or neither exclude null. either both or neither exclude null. A constraint is statically compatible with an access or composite subtype if it statically matches the constraint of the subtype.

requeue_statements. and abort_statements are described in 9. 11 123 10 November 2006 Statements 5 . accept_statements. A simple_statement encloses no other statement. Raise_statements are described in 11. label ::= <<label_statement_identifier>> statement_identifier ::= direct_name 2 3 4/2 | exit_statement | procedure_call_statement | entry_call_statement | delay_statement | raise_statement 5/2 | case_statement | block_statement | select_statement 6 7 8 9 The direct_name of a statement_identifier shall be an identifier (not an operator_symbol). “Exceptions”.Sequences of Statements A statement is either simple or compound. Legality Rules 10 Distinct identifiers shall be used for all statement_identifiers that appear in the same body. Some statements are discussed in later sections: Procedure_call_statements and return statements are described in 6. 3 — Ada Reference Manual Section 5: Statements A statement defines an action to be performed upon its execution. 1 2/2 5. “Tasks and Synchronization”. “Subprograms”.ISO/IEC 8652:2007(E) Ed. delay_statements. select_statements. Syntax 1 sequence_of_statements ::= statement {statement} statement ::= {label} simple_statement | {label} compound_statement simple_statement ::= null_statement | assignment_statement | goto_statement | simple_return_statement | requeue_statement | abort_statement | code_statement compound_statement ::= if_statement | loop_statement | extended_return_statement | accept_statement null_statement ::= null. Entry_call_statements. This section describes the general rules applicable to all statements. The remaining forms of statements are presented in this section. A compound_statement can enclose simple_statements and other compound_statements.1 Simple and Compound Statements . and code_statements in 13. Name Resolution Rules The direct_name of a statement_identifier shall resolve to denote its corresponding implicit declaration (see below). including inner block_statements but excluding inner program units.

Name Resolution Rules 4/2 The variable_name of an assignment_statement is expected to be of any type. the target of an assignment_statement is the variable denoted by the variable_name. If a usage name denotes such an implicit declaration.2 Assignment Statements 1 An assignment_statement replaces the current value of a variable with the result of evaluating an expression. loop_statement.1. As explained in 7. The execution of a sequence_of_statements consists of the execution of the individual statements in succession until the sequence_ is completed. A transfer of control is the run-time action of an exit_statement. there is an implicit declaration (with the specified identifier) at the end of the declarative_part of the innermost block_statement or body that encloses the statement_identifier.Sequences of Statements 10 November 2006 124 . which may trigger finalization. 3 The execution of an assignment_statement includes the evaluation of the expression and the assignment of the value of the expression into the target. or requeue_statement.ISO/IEC 8652:2007(E) Ed. Syntax 2 assignment_statement ::= variable_name := expression. The expected type for the expression is the type of the target. The implicit declarations occur in the same order as the statement_identifiers occur in the source text. raising of an exception. in other words. return statement. Dynamic Semantics 13 14/2 The execution of a null_statement has no effect. 3 — Ada Reference Manual Static Semantics 12 For each statement_identifier. the expanded name for a named statement is not affected by whether the statement occurs inside or outside a named loop or an accept_statement — only nesting within block_statements is relevant to the form of its expanded name. Examples 15 16 17 18 19 Examples of labeled statements: <<Here>> <<Ici>> <<Aqui>> <<Hier>> null. goto_statement. or block_statement with the given statement_identifier. <<After>> X := 1.1 Simple and Compound Statements . the entity it denotes is the label. selection of a terminate_alternative. including object initialization and by-copy parameter passing. 5. a transfer of control can cause the execution of constructs to be completed and then left. which causes the next action performed to be one other than what would normally be expected from the other rules of the language. NOTES 1 A statement_identifier that appears immediately within the declarative region of a named loop_statement or an accept_statement is nevertheless implicitly declared immediately within the declarative region of the innermost enclosing body or block_statement. The target of an assignment operation is the view of the object to which a value is being assigned. An assignment operation (as opposed to an assignment_statement) is performed in other contexts as well. or an abort.6. 5.

a check is made that the tag of the value of the expression is the same as that of the target. which consists of the following two steps: • The value of the target becomes the converted value. the variable_name and the expression are first evaluated in an arbitrary order.. • If any part of the target is controlled. or of type T and tag-indeterminate (see 3.see 6. U := Dot_Product(V.8. B : String(3 .10. J : Integer range 1 . -. and an anonymous object might be used as an intermediate in the assignment. Constraint_Error is raised. If the target is of a tagged class-wide type T'Class.. then the controlling tag value for the expression is the tag of the target..9. .2). an assignment_statement does not change the tag of the target.see 3. The value of the expression is converted to the subtype of the target.2 . The conversion might raise an exception (see 4.1.same number of components 24 25 26 125 10 November 2006 Assignment Statements 5. in particular. then the expression shall either be dynamically tagged. In any case.9. K := J.. 10 := 5.. 20 := 15. Next_Car. the converted value of the expression is then assigned to the target. 3 — Ada Reference Manual Legality Rules The target denoted by the variable_name shall be a variable of a nonlimited type.1 17 18 19 20 Writer := (Status => Open... Dynamic Semantics 5/2 6 For the execution of an assignment_statement. -. Next_Frame(F)(M.will raise Constraint_Error if K > 10 21 22 23 Examples involving array subtype conversions: A : String(1 .see 3. Line_Count => 60). 33). In cases involving controlled types.3 -.1. This paragraph was deleted. Unit => Printer.all := (72074.1 -. 7 8 9 10 11 12 13 14 15 16/2 Examples Examples of assignment statements: Value := Max_Value . if this check fails. -. I := J. as described in 7.2).6). 31). Shade := Blue. -. its value is adjusted as explained in clause 7. the target is finalized. K : Integer range 1 . When the type of the target is class-wide: • If the expression is tag-indeterminate (see 3.see 4. N) := 2.1 Examples involving scalar subtype conversions: I. NOTES 2 The tag of an object never changes. null).5.6. ..compatible ranges -. “Completion and Finalization”.identical ranges -. A := B. J := K.6.ISO/IEC 8652:2007(E) Ed. W). • Otherwise (the expression is dynamically tagged).1.

A(4 . If a condition evaluates to True. because the variable_name and expression are both evaluated before copying the value into the variable. otherwise none of them is executed.... if My_Car. depending on the (truth) value of one or more corresponding conditions. Dynamic Semantics 5 For the execution of an if_statement.. end if. Examples 6 7 Examples of if statements: if Month Month Day Year end if. 8 if Line_Too_Short then raise Layout_Error.see 3. 12) := A(1 .2 Assignment Statements 10 November 2006 126 . -. 9). the condition specified after if. and any conditions specified after elsif.ISO/IEC 8652:2007(E) Ed.Owner.1 9 5. 12) = "tartartartar" would be incorrect. 12) = "tartar sauce" NOTES 3 Notes on the examples: Assignment_statements are allowed even in the case of overlapping slices of the same array. elsif Line_Full then New_Line. 3 condition ::= boolean_expression Name Resolution Rules 4 A condition is expected to be of any boolean type. 9) := "tar sauce". Put(Item). an implementation yielding A(1 .10. := 1. end if.3 If Statements 1 An if_statement selects for execution at most one of the enclosed sequences_of_statements. In the above example. are evaluated in succession (treating a final else as elsif True then). then the corresponding sequence_of_statements is executed. := Year + 1..Vehicle /= My_Car then Report ("Incorrect data"). 28 5. else Put(Item). Syntax 2 if_statement ::= if condition then sequence_of_statements {elsif condition then sequence_of_statements} [else sequence_of_statements] end if. 3 — Ada Reference Manual 27 A(1 .A(1 . until one evaluates to True or all conditions are evaluated and yield False. = December and Day = 31 then := January. -.

Otherwise (the value is not covered by any discrete_choice_list. the chosen alternative is defined by the value of an expression. then the sequence_of_statements of the _alternative is executed.4 . each value of the base range of the type of the expression shall be covered (either explicitly or by others). Two distinct discrete_choices of a case_statement shall not cover the same value. perhaps due to being outside the base range). If the value of the expression is covered by the discrete_choice_list of some case_statement_alternative. 3 — Ada Reference Manual 5. Legality Rules 4 The expressions and discrete_ranges given as discrete_choices of a case_statement shall be static.ISO/IEC 8652:2007(E) Ed. NOTES 4 The execution of a case_statement chooses one and only one alternative. A discrete_choice others. • Otherwise. 11 12 13 14 127 10 November 2006 Case Statements 5.4 Case Statements A case_statement selects for execution one of a number of alternative sequences_of_statements. The expected type for each discrete_choice is the type of the expression. case_statement_alternative ::= when discrete_choice_list => sequence_of_statements Name Resolution Rules 3 The expression is expected to be of any discrete type. then each non-others discrete_choice shall cover only values in that subtype. • If the type of the expression is root_integer. Syntax 1 case_statement ::= case expression is case_statement_alternative {case_statement_alternative} 2 end case. or is a qualified_expression whose subtype_mark denotes a static and constrained scalar subtype. if present. Qualification of the expression of a case_statement by a static subtype can often be used to limit the number of choices that need be given explicitly. or a descendant of a formal scalar type. The possible values of the expression shall be covered as follows: • If the expression is a name (including a type_conversion or a function_call) having a static and constrained nominal subtype. Constraint_Error is raised. then the case_statement shall have an others discrete_choice. and each value of that subtype shall be covered by some discrete_choice (either explicitly or by others). universal_integer. Dynamic Semantics 5 6 7 8 9 10 For the execution of a case_statement the expression is first evaluated. shall appear alone and in the last discrete_choice_list.

Record_Distance (Sensor_Value). otherwise.4 Case Statements 10 November 2006 128 . Static Semantics 6 A loop_parameter_specification declares a loop parameter. if the value of the condition is True. 8 5.. Dynamic Semantics 7 For the execution of a loop_statement. if False. Empty_Bin(2). the sequence_of_statements is executed. Record_Azimuth (Sensor_Value). there shall not be an identifier after the end loop. => => => => Record_Elevation(Sensor_Value). or.. as specified below. when 2 => Update_Bin(2). Generate_Report(Today).5 Loop Statements 1 A loop_statement includes a sequence_of_statements that is to be executed repeatedly. then the identifier shall be repeated after the end loop.ISO/IEC 8652:2007(E) Ed. Thu => when Sat . null. until the loop_statement is complete. when 3 | 4 => Empty_Bin(1). the sequence_of_statements is executed repeatedly. Compute_Closing_Balance. Syntax 2 loop_statement ::= [loop_statement_identifier:] [iteration_scheme] loop sequence_of_statements end loop [loop_identifier]. the execution of the loop_statement is complete. 5. Sun => end case. 3 — Ada Reference Manual Examples 15 16 Examples of case statements: case Sensor is when Elevation when Azimuth when Distance when others end case. zero or more times. 18 case Bin_Number(Count) is when 1 => Update_Bin(1). 17 case Today is when Mon => when Fri => when Tue . which is an object whose subtype is that defined by the discrete_subtype_definition. The loop_statement is complete when a transfer of control occurs that transfers control out of the loop. For the execution of a loop_statement with a while iteration_scheme. Compute_Initial_Balance. null. end case. when others => raise Error. zero or more times. the condition is evaluated before each execution of the sequence_of_statements. in the case of an iteration_scheme. iteration_scheme ::= while condition | for loop_parameter_specification loop_parameter_specification ::= defining_identifier in [reverse] discrete_subtype_definition 3 4 5 If a loop_statement has a loop_statement_identifier.

end loop.. the first has a null range. in which case the values are assigned in decreasing order. the sequence_of_statements is executed once for each value of the discrete subtype defined by the discrete_subtype_definition (or until the loop is left as a consequence of a transfer of control). 14 15 Example of a loop statement with a while iteration scheme: while Bid(N).Price loop Record_Bid(Bid(N). the execution of the loop_statement is complete. 16 17 Example of a loop statement with a for iteration scheme: for J in Buffer'Range loop if Buffer(J) /= Space then Put(Buffer(J)). 1 Examples 13 Example of a loop statement without an iteration scheme: loop Get(Current_Character). 7 The discrete_subtype_definition of a for loop is elaborated just once.5 . Otherwise.Price). since the loop parameter is automatically declared by the loop_parameter_specification.10. -. Prior to each such iteration. 3 — Ada Reference Manual For the execution of a loop_statement with a for iteration_scheme.Value.works even with a null range 18 19 Example of a loop statement with a name: Summation: while Next /= Head loop Sum := Sum + Next. Use of the reserved word reverse does not alter the discrete subtype defined. end loop Summation.see 3. it cannot be updated within the sequence_of_statements of the loop (see 3. -. end loop. 0 for J in 0 .Succ.ISO/IEC 8652:2007(E) Ed. the loop_parameter_specification is first elaborated. 6 An object_declaration should not be given for a loop parameter. end if. and the visibility rules are such that a loop parameter is only visible within the sequence_of_statements of the loop.Price < Cut_Off. N := N + 1. the corresponding value of the discrete subtype is assigned to the loop parameter. exit when Current_Character = '*'. NOTES 5 A loop parameter is a constant. 9 10 11 12 for J in reverse 1 . so that the following iteration_schemes are not equivalent..3).1 20 21 129 10 November 2006 Loop Statements 5. end loop. If the discrete_subtype_definition defines a subtype with a null range. The scope of a loop parameter extends from the loop_parameter_specification to the end of the loop_statement. Next := Next. These values are assigned in increasing order unless the reserved word reverse is present. This elaboration creates the loop parameter and elaborates the discrete_subtype_definition.

An exit_statement with a name is only allowed within the loop_statement denoted by the name. Examples 6 7 Example of a block statement with a local variable: Swap: declare Temp : Integer. begin Temp := V. this is the loop_statement being exited. An exit_statement without a name is only allowed within a loop_statement. Syntax preceded by a 2 block_statement ::= [block_statement_identifier:] [declare declarative_part] begin handled_sequence_of_statements end [block_identifier]. if any. in an exit_statement shall resolve to denote a loop_statement. Legality Rules 4 Each exit_statement applies to a loop_statement. end Swap.6 Block Statements 1 A block_statement encloses a handled_sequence_of_statements optionally declarative_part. the completion is conditional if the exit_statement includes a condition. 3 If a block_statement has a block_statement_identifier. Name Resolution Rules 3 The loop_name. Dynamic Semantics 5 The execution of a block_statement consists of the elaboration of its declarative_part followed by the execution of its handled_sequence_of_statements. U := Temp. 5. and applies to that loop_statement. and applies to the innermost enclosing one. Syntax 2 exit_statement ::= exit [loop_name] [when condition]. V := U. 3 — Ada Reference Manual 5. then the identifier shall be repeated after the end. Static Semantics 4 A block_statement that has no explicit declarative_part has an implicit empty declarative_part.7 Exit Statements 1 An exit_statement is used to complete the execution of an enclosing loop_statement.ISO/IEC 8652:2007(E) Ed.6 Block Statements 10 November 2006 130 . there shall not be an identifier after the end. otherwise. An exit_statement that applies to a given loop_statement shall not 5.

if a goto_statement is enclosed by an accept_statement or a body. Name Resolution Rules 2 The label_name shall resolve to denote a label. end loop. no transfer of control takes place. NOTES 8 Several nested loops can be exited by an exit_statement that names the outer loop. or if there is no condition. Dynamic Semantics For the execution of an exit_statement.. If the value of the condition is False. Merge_Item(New_Item. if_statement. 3 — Ada Reference Manual appear within a body or accept_statement. Storage_File). If the value of the condition is True. completing the execution of any compound_statement that encloses the goto_statement but does not enclose the target.ISO/IEC 8652:2007(E) Ed.8 Goto Statements A goto_statement specifies an explicit transfer of control from this statement to a target statement with a given label. -. the statement with that label is the target statement.7 . if present. the condition. NOTES 9 The above rules allow transfer of control to a statement of an enclosing sequence_of_statements but not the reverse. exit when New_Item = Terminal_Item. Dynamic Semantics 4 The execution of a goto_statement transfers control to the target statement. they prohibit transfers of control such as between alternatives of a case_statement. Furthermore. Main_Cycle: loop -. a transfer of control is done to complete the loop_statement. Syntax 1 goto_statement ::= goto label_name. or from an exception_handler of a handled_sequence_of_statements back to its sequence_of_statements. 7 8 9 5. Legality Rules 3 The innermost sequence_of_statements that encloses the target statement shall also enclose the goto_statement. Similarly. if this construct is itself enclosed by the given loop_statement. Max_Num_Items loop Get_New_Item(New_Item). then the target statement shall not be outside this enclosing construct.initial statements exit Main_Cycle when Found. 5 6 131 10 November 2006 Exit Statements 5. is first evaluated. Examples 5 6 Examples of loops with exit statements: for N in 1 . or select_statement.final statements end loop Main_Cycle. between exception_handlers.

3 — Ada Reference Manual Examples 7 8 Example of a loop containing a goto statement: <<Sort>> for I in 1 . end loop. goto Sort. end if.8 Goto Statements 10 November 2006 132 . 5. A(I+1)).ISO/IEC 8652:2007(E) Ed. N-1 loop if A(I) > A(I+1) then Exchange(A(I)..

The definition of a subprogram can be given in two parts: a subprogram declaration defining its interface.1 Subprogram Declarations A subprogram_declaration declares a procedure or function. A callable entity is invoked by a call.1. 2/2 3/2 4/2 subprogram_specification ::= procedure_specification | function_specification procedure_specification ::= procedure defining_program_unit_name parameter_profile function_specification ::= function defining_designator parameter_and_result_profile designator ::= [parent_unit_name . a delimiter. or accept_statement. ]identifier | operator_symbol defining_designator ::= defining_program_unit_name | defining_operator_symbol defining_program_unit_name ::= [parent_unit_name .ISO/IEC 8652:2007(E) Ed. ]defining_identifier 4. A callable construct is a construct that defines the action of a call upon a callable entity: a subprogram_body. 1 2 6. There are two forms of subprogram: procedures and functions. entry_body. that is. or compound delimiter that corresponds to an operator belonging to one of the six categories of operators defined in clause 4. a subprogram call or entry call. A procedure call is a statement. Operators and enumeration literals are functions.2/2 5 6 7 8 9 10/2 The optional parent_unit_name is only allowed for library units (see 10. 3 — Ada Reference Manual Section 6: Subprograms A subprogram is a program unit or intrinsic operation whose execution is invoked by a subprogram call.1/2 4. This paragraph was deleted.5. Syntax 1 subprogram_declaration ::= [overriding_indicator] subprogram_specification. a function call is an expression and returns a value. parameter_specification}) parameter_specification ::= defining_identifier_list : mode [null_exclusion] subtype_mark [:= default_expression] | defining_identifier_list : access_definition [:= default_expression] mode ::= [in] | in out | out 11 12 13/2 14 15/2 16 133 10 November 2006 Subprograms 6 . A callable entity is a subprogram or entry (see Section 9). operator_symbol ::= string_literal The sequence of characters in an operator_symbol shall form a reserved word. defining_operator_symbol ::= operator_symbol parameter_profile ::= [formal_part] parameter_and_result_profile ::= [formal_part] return [null_exclusion] subtype_mark | [formal_part] return access_definition formal_part ::= (parameter_specification {.1). and a subprogram_body defining its execution.

Mode in is the default.10). the subtypes of the profile of the parameter type. A subprogram_declaration declares a procedure or a function. • For any non-access result. in out. or a pragma Import (see B. • For any access result type of an access-to-subprogram type. • For any access parameters of an access-to-object type. The nominal subtype of a formal parameter is the subtype determined by the optional null_exclusion and the subtype_mark. as indicated by the initial reserved word. 3 — Ada Reference Manual Name Resolution Rules 17 A formal parameter is an object directly visible within a subprogram_body that represents the actual parameter passed to the subprogram in a call. the nominal subtype of the function result. The nominal subtype of a function result is the subtype determined by the optional null_exclusion and the subtype_mark.3) or a null_procedure_declaration (see 6.ISO/IEC 8652:2007(E) Ed. the profile includes information about parameters passed to the callable entity.2/2 29 6. the designated subtype of the result type. Static Semantics 19 20/2 21 22 The profile of (a view of) a callable entity is either a parameter_profile or parameter_and_result_profile.1/2 28/2 28. Legality Rules 18 The parameter mode of a formal parameter conveys the direction of information transfer with the actual parameter: in. the expected type for its default_expression.5). A name that denotes a formal parameter is not allowed within the formal_part in which it is declared. An access parameter is a formal in parameter specified by an access_definition. or out. • For any access parameters of an access-to-subprogram type. Access parameters of an access-to-subprogram type permit calls to subprograms passed as parameters irrespective of their accessibility level. and entries. it is declared by a parameter_specification. For a formal parameter. it embodies information about the interface to that entity — for example. or defined by the access_definition. • For any access result type of an access-to-object type. An access result type is a function result type specified by an access_definition. in the parameter_specification. with name and profile as given by its specification. the subtypes of the profile of the result type. and is the mode of a parameter defined by an access_definition. An access-to-subprogram type has a designated profile. other subprograms. A completion is not allowed for an abstract_subprogram_declaration (see 3. Associated with a profile is a calling convention. A default_expression is only allowed in a parameter_specification for a formal parameter of mode in.1). Access parameters of an access-to-object type allow dispatching calls to be controlled by access values. in the parameter_and_result_profile. An access parameter or result type is of an anonymous access type (see 3. the nominal subtype of the parameter.7). shall have the mode in. nor within the formal_part of a corresponding body or accept_statement. 23/2 24/2 25 26 27/2 27.1/2 28. a renaming_declaration (see 8.9. The formal parameters of a function. is that of the formal parameter. All callable entities have a profile — enumeration literals.1 Subprogram Declarations 10 November 2006 134 . the designated subtype of the parameter type. or defined by the access_definition. The subtypes of a profile are: • For any non-access parameters. if any. The types of a profile are the types of those subtypes. if any. A subprogram_declaration or a generic_subprogram_declaration requires a completion: a body.

10. function Next_Frame(K : Positive) return Frame.see 3. and cannot be used in a nondispatching call (see 3. 38 39 40 41 42 Examples of in parameters with default expressions: procedure Print_Header(Pages : in Natural.see 3. Increment(X : in out Integer).7. a procedure defined by a null_procedure_declaration is a null procedure.ISO/IEC 8652:2007(E) Ed. 2 3 135 10 November 2006 Subprogram Declarations 6.2 Formal Parameter Modes A parameter_specification declares a formal parameter of mode in. An overriding_indicator is used to indicate whether overriding is intended.4 -. See 6. “Abstract Types and Subprograms”. Static Semantics 1 A parameter is passed either by copy or by reference.9. They are not evaluated during the elaboration of the subprogram declaration. 3 The evaluation of default_expressions is caused by certain calls.5.4. the formal parameter denotes (a view of) the object denoted by the actual parameter.6 36 37 function Random return Probability.9. Right : Matrix) return Matrix. or if it is a descendant of a private type whose full type is a by-copy type.1 -. function "*"(Left. Right_Indent(Margin : out Line_Size). as explained in 3.see 3. Right : Vector) return Real.3. To : in out Link).see 3.6 6. Center : in Boolean := True). in out.1 -. A parameter of a by-copy type is passed by copy.see 3.1 .3. 4 Subprograms can be called recursively and can be called concurrently from multiple tasks.see 3.see 3. reads and updates of the formal parameter directly reference the actual parameter object.5..1.3.3. “Overriding Indicators”. 2 Abstract subprograms do not have bodies. -. and any information transfer between the two occurs only before and after executing the subprogram. Similarly.see 3. “Abstract Types and Subprograms”).10 -. Header : in Line := (1 . as described in 6.7 -. function Dot_Product(Left. a procedure declared by a subprogram_declaration is not.1/2 The elaboration of a subprogram_declaration has no effect.10. or out. See 3. the formal parameter denotes a separate object from the actual parameter. Examples 31/2 32 33 34 35 Examples of subprogram declarations: procedure procedure procedure procedure Traverse_Tree.1. a subprogram declared by a subprogram_declaration is not. Line'Last => ' '). 3 — Ada Reference Manual A subprogram declared by an abstract_subprogram_declaration is abstract. When a parameter is passed by reference.6 -. When a parameter is passed by copy. See 8. Switch(From. NOTES 1 A parameter_specification with several identifiers is equivalent to a sequence of single parameter_specifications. function Min_Cell(X : Link) return Cell. “Null Procedures”. -. Dynamic Semantics 30/2 30. A type is a by-copy type if it is an elementary type.

For parameters of other types. If an object is of a type for which the parameter passing mechanism is not specified. • a private type whose full type is a by-reference type.2 Formal Parameter Modes 10 November 2006 136 . NOTES 5 A formal parameter of mode in is a constant view (see 3. A parameter of a by-reference type is passed by reference.ISO/IEC 8652:2007(E) Ed. Each value of a by-reference type has an associated object.3 Subprogram Bodies 1 A subprogram_body specifies the execution of a subprogram. qualified_expression. and then read the value of the object via a distinct access path. The profile of a subprogram_body that completes a declaration shall conform fully to that of the declaration. then it is a bounded error to assign to the object via one access path. For a parenthesized expression. If the body is a completion. it is unspecified whether the parameter is passed by copy or by reference. Legality Rules 4 In contrast to other bodies. 13 6. 3 If a designator appears at the end of a subprogram_body. or some old value of the object is read. or type_conversion. it cannot be updated within the subprogram_body. unless the first access path denotes a part of a formal parameter that no longer exists at the point of the second access (due to leaving the corresponding callable construct). and a second name denotes a part of a distinct formal parameter or an object that is not part of a formal parameter. 6. a subprogram_body need not be the completion of a previous declaration. Syntax 2/2 subprogram_body ::= [overriding_indicator] subprogram_specification is declarative_part begin handled_sequence_of_statements end [designator].3). The possible consequences are that Program_Error is raised. • a nonprivate type with the reserved word limited in its declaration. or the newly assigned value is read. this object is the one associated with the operand. it shall repeat the defining_designator of the subprogram_specification. Bounded (Run-Time) Errors 11 12 If one name denotes a part of a formal parameter. • a task or protected type. then the two names are considered distinct access paths. it shall be the completion of a subprogram_declaration or generic_subprogram_declaration. 3 — Ada Reference Manual 4 5 6 7 8 9 10 A type is a by-reference type if it is a descendant of one of the following: • a tagged type. • a composite type with a subcomponent of a by-reference type. in which case the body declares the subprogram.

Size then raise Stack_Overflow.1. subtype conformance. The execution of a subprogram_body is invoked by a subprogram call. a "/=" operator declared implicitly due to the declaration of "=" (see 6. S : in out Stack) is begin if S. they are required to conform in one of four ways: type conformance. Examples 6 7 Example of procedure body: procedure Push(E : in Element_Type.3 .6).Space(S.Index = S. 10 11 6. return Sum. Dynamic Semantics 5 The elaboration of a non-generic subprogram_body has no other effect than to establish that the subprogram can from then on be called without failing the Elaboration_Check. 5 6 7 137 10 November 2006 Subprogram Bodies 6. For a callable entity or access-to-subprogram type.1). mode conformance. or full conformance. begin Check(Left'First = Right'First and Left'Last = Right'Last).0.Index := S. Static Semantics 1 As explained in B. It can either complete a previous declaration. S. Import. • The Intrinsic calling convention represents subprograms that are “built in” to the compiler. Right : Vector) return Real is Sum : Real := 0. end Dot_Product. and the handled_sequence_of_statements is then executed.Index + 1. or itself be the initial declaration of the subprogram. “Interfacing Pragmas”.1 Conformance Rules When subprogram profiles are given in more than one place. end if. else S.ISO/IEC 8652:2007(E) Ed. For this execution the declarative_part is elaborated. any other implicitly declared subprogram unless it is a dispatching operation of a tagged type. The default calling convention is Intrinsic for the following: • • • 2/1 3 4 an enumeration literal. the convention is called the calling convention. The following conventions are defined by the language: • The default calling convention for any subprogram not listed below is Ada. for J in Left'Range loop Sum := Sum + Left(J)*Right(J). Unless this International Standard states otherwise. A pragma Convention. or Export may be used to override the default calling convention (see B.3. end loop. 3 — Ada Reference Manual Static Semantics A subprogram_body is considered a declaration. 8 9 Example of a function body: function Dot_Product(Left. end Push.Index) := E. a convention can be specified for an entity. the default convention of an entity is Ada.

1/2 11 12 an inherited subprogram of a generic formal tagged type with unknown discriminants. • If not specified above as Intrinsic. and selector_name that is not part of the prefix of an expanded name in one denotes the same declaration as the corresponding direct_name. except that an expanded name may correspond to a direct_name (or character_literal) or to a different expanded name in the other. the calling convention for any inherited or overriding dispatching operation of a tagged type is that of the corresponding subprogram of the parent type. and corresponding parameters have identical modes. and both have a result if either does. Import. or corresponding designated profiles are type conformant. or Export. only Ada and Intrinsic are allowed as a convention_identifier in a pragma Convention. Two expressions are fully conformant if. for access parameters or access results.2/1 14 15/2 16/2 17 18 19 20 21 21. and • each attribute_designator in one must be the same as the corresponding attribute_designator in the other. and corresponding parameters have the same names and have default_expressions that are fully conformant with one another. The Access attribute is not allowed for Intrinsic subprograms.1 Conformance Rules 10 November 2006 138 . Two profiles are subtype conformant if they are mode-conformant. character_literal. and for an access-tosubprogram type with the reserved word protected in its definition. 3 — Ada Reference Manual • • • • 8 9 10/2 10. and corresponding parameter and result types are the same. after replacing each use of an operator with the equivalent function_call: • each constituent construct of one corresponds to an instance of the same syntactic category in the other.3. and • each primary that is a literal in one has the same value as the corresponding literal in the other. The default calling convention for a new dispatching operation of a tagged type is the convention of the type. and the associated calling conventions are the same. or the designated profiles are subtype conformant.1/1 22 6. Two profiles are mode conformant if they are type-conformant. a subprogram declared immediately within a protected_body. Two profiles are type conformant if they have the same number of parameters.1. or. any prefixed view of a subprogram (see 4. • The default calling convention is protected for a protected subprogram. Of these four conventions. and. • The default calling convention is entry for an entry. for access parameters or access result types. the designated subtypes statically match. corresponding subtypes of the profile statically match. character_literal. Two profiles are fully conformant if they are subtype-conformant.1/2 13. The profile of a generic formal subprogram is not subtype-conformant with any other profile. an attribute that is a subprogram. or selector_name in the other. • The calling convention for an anonymous access-to-subprogram parameter or anonymous access-to-subprogram result is protected if the reserved word protected appears in its definition and otherwise is the convention of the subprogram that contains the parameter. corresponding designated types are the same. and • each direct_name.3).ISO/IEC 8652:2007(E) Ed. 13 13.

an implementation is free to follow or to ignore the recommendation expressed by the pragma. is as follows: pragma Inline(name {. and discriminants in the same positions have the same names.5).3. Syntax 1 The form of a pragma Inline.2 Inline Expansion of Subprograms Subprograms may be expanded in line at the call site. and the corresponding simple_expressions of the ranges (if any) fully conform. The prefixed view profile of a subprogram is the profile obtained by omitting the first parameter of that subprogram. 3 — Ada Reference Manual Two known_discriminant_parts are fully conformant if they have the same number of discriminants. statically matching subtypes. Such a pragma applies to all of the denoted entities. An implementation may allow a pragma Inline that has an argument which is a direct_name denoting a subprogram_body of the same declarative_part. the subtype_marks (if any) denote the same subtype. Legality Rules 2 3 The pragma shall apply to one or more callable entities or generic subprograms.1 . name}).3. 6 6. this indicates that inline expansion is desired for all calls to that entity. Implementation Permissions 23 24 24. Two discrete_subtype_definitions are fully conformant if they are both subtype_indications or are both ranges. Static Semantics 4 If a pragma Inline applies to a callable entity. which is a program unit pragma (see 10.1.ISO/IEC 8652:2007(E) Ed. If a pragma Inline applies to a generic subprogram.1/2 7 139 10 November 2006 Conformance Rules 6. Implementation Permissions 5 For each call. For the purposes of defining subtype and mode conformance. and default_expressions that are fully conformant with one another. There is no prefixed view profile for a parameterless subprogram. 25 6. NOTES 6 The name in a pragma Inline can denote more than one entity in the case of overloading.1/2 An implementation may declare an operator declared in a language-defined library unit to be intrinsic. the convention of a prefixed view profile is considered to match that of either an entry or a protected operation. this indicates that inline expansion is desired for all calls to all instances of that generic subprogram.

The name or prefix given in a function_call shall resolve to denote a callable entity that is a function. If a default_expression is used. 10.4 Subprogram Calls 1 A subprogram call is either a procedure_call_statement or a function_call. the name or prefix of the call is evaluated. Name Resolution Rules 8/2 The name or prefix given in a procedure_call_statement shall resolve to denote a callable entity that is a procedure. it invokes the execution of the subprogram_body.1). and each parameter_association is evaluated (see 6. parameter_association}) parameter_association ::= [formal_parameter_selector_name =>] explicit_actual_parameter explicit_actual_parameter ::= expression | variable_name 3 4 5 6 7 A parameter_association is named or positional according to whether or not the formal_parameter_selector_name is specified. The exception Program_Error is raised at the point of a function_call if the function completes normally without executing a return statement.1). Syntax 2 procedure_call_statement ::= procedure_name. | procedure_prefix actual_parameter_part. Each formal parameter without an association shall have a default_expression (in the profile of the view denoted by the name or prefix). The subprogram_body is then executed. Finally.4. the subprogram call is equivalent to a call on the underlying subprogram. if any. or an entry renamed as (viewed as) a procedure.2).ISO/IEC 8652:2007(E) Ed. These evaluations are done in an arbitrary order. Named associations are not allowed if the prefix in a subprogram call is an attribute_reference. and the remaining actual parameters given by the actual_parameter_part. an implicit parameter_association is assumed for this rule.4 Subprogram Calls 10 November 2006 140 . Dynamic Semantics 9 10/2 For the execution of a subprogram call. 3 — Ada Reference Manual 6. The name or prefix shall not resolve to denote an abstract subprogram unless it is also a dispatching subprogram.9. If the name or prefix of a subprogram call denotes a prefixed view (see 4. if any.4. if the subprogram completes normally. function_call ::= function_name | function_prefix actual_parameter_part actual_parameter_part ::= (parameter_association {.1/2 11/2 6.6). A subprogram call shall contain at most one association for each formal parameter. with the first actual parameter being provided by the prefix of the prefixed view (or the Access attribute of this prefix if the first formal parameter is an access parameter). or a call on an entry or protected subprogram is performed (see 3. The call specifies the association of the actual parameters.1. then after it is left. the prefix can be an implicit_dereference of an access-to-subprogram value. any necessary assigning back of formal to actual parameters occurs (see 6. Any positional associations shall precede any named associations. When there is an actual_parameter_part.3). This rule is an overloading rule (see 8. with formal parameters of the subprogram.

procedure Set(Tint : in Color). After => Y).0.3 -.1 -.10 16 17 Examples of procedures with default expressions: procedure Activate(Process After Wait Prior : : : : in in in in Process_Name. procedure Put(X : in String).see 6. V) Clock F. 10. Activate(X.see 9.1 Print_Header(128. Examples 23 24 Examples of overloaded subprograms: procedure Put(X : in Integer).ISO/IEC 8652:2007(E) Ed. Process_Name := No_Process. -. -.5.Set(Red) would be ambiguous since Red may -. To => Next). Examples 12/2 Examples of procedure calls: Traverse_Tree. Title. Set(Color'(Red)).see 3. Pages => 128). 20 21 22 Examples of their calls: Activate(X). NOTES 7 If a default_expression is used for two or more parameters in a multiple parameter_specification. False). True).6 -.all -.1 and 6.0. Hence in the above examples. Duration := 0. -. Pair(Left => new Person.presuming F is of an access-to-subprogram type — see 3.see 6. 3 — Ada Reference Manual A function_call denotes a constant. Put("no possible ambiguity here"). Prior => True). the two calls of Pair are equivalent. Right : in Person_Name := new Person). as defined in 6. Header => Title. Activate(X. Boolean := False). Print_Header(128.denote a value either of type Color or of type Light 28 29 30 31 141 10 November 2006 Subprogram Calls 6. the nominal subtype of the constant is given by the nominal subtype of the function result. -. Pair.see 6.0.1 13 14 15 Switch(From => X. Set(Tint => Red). procedure Set(Signal : in Light). Center => True.4 .10.see 6. -.see 6. 25 26 27 Examples of their calls: Put(28). Right => new Person). Center => True). -.1 Print_Header(Header => Title. Set(Signal => Red). Activate(X. the default_expression is evaluated once for each omitted parameter.1 Examples of function calls: Dot_Product(U. Y.see 6.1 18 19 procedure Pair(Left. Wait => 60.

and: • For an access type. If composite. A formal parameter of mode in out or out with discriminants is constrained if either its nominal subtype or the actual parameter is constrained. if possible. the behavior is as for an in out parameter passed by copy. otherwise. If the mode is in. without a constraint check. Name Resolution Rules 2 The formal_parameter_selector_name of a parameter_association shall resolve to denote a parameter_specification of the view being called.4. • For an in or in out parameter that is passed by copy (see 6. the formal parameter is uninitialized.ISO/IEC 8652:2007(E) Ed. 10 11 12 13 14 15 16 6. the access_definition is elaborated. The type of the actual parameter associated with an access parameter shall be convertible (see 4.1 Parameter Associations 1 A parameter association defines the association between an actual parameter and a formal parameter. which creates the anonymous access type. and the formal parameter denotes that conversion. or the corresponding default_expression if no parameter_association is given for the formal parameter. the actual is interpreted as an expression. the formal parameter object is created. • For a parameter (of any mode) that is passed by reference (see 6. and the value of the actual parameter is converted to the nominal subtype of the formal parameter and assigned to the formal.3. the formal parameter is initialized from the value of the actual. • For an out parameter that is passed by copy. The actual parameter is either the explicit_actual_parameter given in a parameter_association for a given formal parameter.1 Parameter Associations 10 November 2006 142 .2). the actual subtype of the formal is given by its nominal subtype. the formal parameter object is created. a view conversion of the actual parameter to the nominal subtype of the formal parameter is evaluated. and the actual subtype of the formal is that of the view conversion. the actual is interpreted only as a name.6) to its anonymous access type. If elementary. the actual shall be a name that denotes a variable. The expected type for an actual parameter is the type of the corresponding formal parameter.4. • For an access parameter.1). 3 — Ada Reference Manual 6. • For any other type. a view conversion of the actual parameter to the nominal subtype of the formal is evaluated (which might raise Constraint_Error). • For a composite type with discriminants or that has implicit initial values for any subcomponents (see 3.2). Dynamic Semantics 7 8 9 For the evaluation of a parameter_association: • The actual parameter is first evaluated. Legality Rules 3 4 5 6 If the mode is in out or out.

A function body shall contain at least one return statement that applies to the function body. 3 — Ada Reference Manual After normal completion and leaving of a subprogram. A return statement shall not be within a body that is within the construct to which the return statement applies.4/2 143 10 November 2006 Parameter Associations 6. after the reserved word return in the profile of the function. return_subtype_indication ::= subtype_indication | access_definition Name Resolution Rules 2.1 . • If the result subtype of the function is defined by an access_definition. These conversions and assignments occur in an arbitrary order. The accessibility level of this anonymous access subtype is that of the result subtype. The expected type for the expression of an extended_return_statement is that of the return_subtype_indication. of a simple_return_statement is the result type of the corresponding function. For an extended_return_statement that applies to a function body: • If the result subtype of the function is defined by a subtype_mark.3/2 5. If the result subtype of the function is unconstrained. or there shall be an expression. then the subtype defined by the subtype_indication shall be a definite subtype.ISO/IEC 8652:2007(E) Ed. the return_subtype_indication shall be an access_definition. the value of the formal parameter is converted to the subtype of the variable given as the actual parameter and assigned to it. For any return statement that applies to a function body: 4/2 5/2 5. for each in out or out parameter that is passed by copy. Syntax 1/2 simple_return_statement ::= return [expression].2/2 The result subtype of a function is the subtype denoted by the subtype_mark. A simple_return_statement shall include an expression if and only if it applies to a function body. or defined by the access_definition. or accept_statement.1/2 end return].5 Return Statements A simple_return_statement or extended_return_statement (collectively called a return statement) is used to complete the execution of the innermost enclosing subprogram_body.4.2/2 5. then the subtype defined by the subtype_indication shall also be constrained and shall statically match this result subtype. 17 6. The subtype defined by the access_definition shall statically match the result subtype of the function. entry_body. The type of the subtype_indication shall be the result type of the function. If the result subtype of the function is constrained. and it applies to the innermost callable construct or extended_return_statement that contains it. if any.1/2 5. unless the function contains code_statements. Legality Rules 3/2 A return statement shall be within a callable construct. the return_subtype_indication shall be a subtype_indication. The expected type for the expression. An extended_return_statement shall apply to a function body. extended_return_statement ::= return defining_identifier : [aliased] return_subtype_indication [:= expression] [do handled_sequence_of_statements 2/2 2.

it is evaluated and converted to the nominal subtype (which might raise Constraint_Error — see 4. as determined by the expression or the return_subtype_indication of the function.7/2 Within an extended_return_statement. the return object is constrained by its initial value.5 Return Statements 10 November 2006 144 . the return object is created and the converted value is assigned to the return object.5/2 • If the result subtype of the function is limited. the subtype_indication or access_definition is elaborated. and then is assigned to the anonymous return object. a transfer of control is performed which completes the execution of the callable construct. the accessibility level of the anonymous access type of each access discriminant. Upon completion of a return statement that applies to a callable construct. as determined by the expression of the simple_return_statement or the return_subtype_indication. the function_call denotes a constant view of the return object. then the expression of the return statement (if any) shall be an aggregate. Static Semantics 5.2). • If the result subtype of the function is class-wide. If the result subtype has one or more unconstrained access discriminants. If this check fails. Paragraphs 9 through 20 were deleted. and returns to the caller. with the nominal subtype defined by the return_subtype_indication. For the execution of an extended_return_statement. If this check fails. the tag of the return object is that of the value of the expression. 3 — Ada Reference Manual 5.6). the return object is created and initialized by default as for a stand-alone object of its nominal subtype (see 3.6/2 5. If the nominal subtype is indefinite. converted to the result subtype. For the execution of a simple_return_statement. the activation of those tasks does not occur until after the function returns (see 9. or a qualified_expression or parenthesized expression whose operand is one of these. Implementation Permissions 22/2 23/2 24/2 If the result subtype of a function is unconstrained. the accessibility level of the type of the expression of the return statement shall not be statically deeper than that of the master that elaborated the function body.1). Program_Error is raised. This creates the nominal subtype of the return object. is not deeper than that of the master that elaborated the function body.ISO/IEC 8652:2007(E) Ed. shall not be statically deeper than that of the master that elaborated the function body.3. a check is made that the accessibility level of the anonymous access type of each access discriminant. A check is made that the accessibility level of the type identified by the tag of the result is not deeper than that of the master that elaborated the function body. In the case of a function. Within this handled_sequence_of_statements. the expression (if any) is first evaluated. Constraint_Error may be raised at the point of the call (after abandoning the execution of the function body) if. 6/2 7/2 8/2 21/2 If the result subtype of a function has one or more unconstrained access discriminants. and a call on the function is used to provide the initial value of an object with a constrained nominal subtype. Otherwise. the return object is declared with the given defining_identifier. Program_Error is raised. Dynamic Semantics 5. If there is an expression. a function call (or equivalent use of an operator). If the return object has any parts that are tasks. If the result type is class-wide. the tag of the return object is that of the result type. the execution of a simple_return_statement that applies to the extended_return_statement causes a transfer of control that completes the extended_return_statement. If the result type of a function is a specific tagged type.8/2 For the execution of an extended_return_statement. the handled_sequence_of_statements is executed. while elaborating the return_subtype_- 6.

is as follows: pragma No_Return(procedure_local_name{.ISO/IEC 8652:2007(E) Ed.1 for Cell 25 26/2 27 28/2 6. Program_Error is raised at the point of the call. Examples Examples of return statements: return. return Key_Value(Last_Index). it is determined that the value of the result will violate the constraint of the subtype of this object. If a procedure declared within a generic unit is non-returning. Examples 9/2 procedure Fail(Msg : String).Value := Result. Syntax 1/2 The form of a pragma No_Return. Static Semantics 4/2 5/2 6/2 7/2 If a generic procedure is non-returning. the denoted entities are non-returning. -. then so are its instances.raises Fatal_Error exception pragma No_Return(Fail). see 3. entry_body.3). which is a representation pragma (see 13. it may propagate an exception or loop forever. end return. Legality Rules 2/2 3/2 Each procedure_local_name shall denote one or more procedures or generic procedures.accept_statement. then so are the corresponding copies of that procedure in instances. The procedure_local_name shall not denote a null procedure nor an instance of a generic unit. or extended_return_statement -.Succ := Next_Node.1 Pragma No_Return A pragma No_Return indicates that a procedure cannot return normally. -. A procedure shall be non-returning if it overrides a dispatching non-returning procedure. In addition to the places where Legality Rules normally apply (see 12. If a renaming-as-body completes a non-returning procedure declaration. return Node : Cell do Node. A return statement shall not apply to a non-returning procedure or generic procedure.in a function body -. Dynamic Semantics 8/2 If the body of a non-returning procedure completes normally. -.in a function body.1).Inform compiler and reader that procedure never returns normally 10/2 145 10 November 2006 Return Statements 6.5 . Node.in a procedure body. -. procedure_local_name}). this rule applies also in the private part of an instance of a generic unit. then the renamed procedure shall be non-returning. 3 — Ada Reference Manual indication or evaluating the expression of a return statement that applies to the function body.10.5.

6. and C are of the type Vector -. Legality Rules 3 The subprogram_specification of a unary or binary operator shall have one or two parameters. Name Resolution Rules 2 Each use of a unary or binary operator is equivalent to a function_call with function_prefix being the corresponding operator_symbol.ISO/IEC 8652:2007(E) Ed. -. and with (respectively) one or two positional actual parameters being the operand(s) of the operator (in order).assuming that A. C).6 Overloading of Operators 1 An operator is a function whose designator is an operator_symbol. Right : Matrix) return Matrix. may be overloaded. A := "+"(B.the following two statements are equivalent: A := B + C. and hence may be overloaded with both one. Static Semantics 6 A declaration of "=" whose result type is Boolean implicitly declares a declaration of "/=" that gives the complementary result. NOTES 8 The operators "+" and "–" are both unary and binary operators. Default_expressions are not allowed for the parameters of an operator (whether the operator is declared with an explicit subprogram_specification or by a generic_instantiation).6 Overloading of Operators 10 November 2006 146 . Operators. 3 — Ada Reference Manual 6. A generic function instantiation whose designator is an operator_symbol is only allowed if the specification of the generic function has the corresponding number of parameters. 4 5 An explicit declaration of "/=" shall not have a result type of the predefined type Boolean. Examples 7 8 9 Examples of user-defined operators: function "+" (Left. B. like other functions. Right : Vector) return Vector. function "+" (Left.and twoparameter functions. respectively.

By default. the execution of the subprogram_body has no effect. The elaboration of a null_procedure_declaration has no effect. Examples 4/2 5/2 procedure Simplify(Expr : in out Expression) is null. Static Semantics 2/2 A null_procedure_declaration declares a null procedure.9 -. For the execution of a subprogram call on a null procedure. 3 — Ada Reference Manual 6. A completion is not allowed for a null_procedure_declaration.7 Null Procedures A null_procedure_declaration provides a shorthand to declare a procedure with an empty body.ISO/IEC 8652:2007(E) Ed.see 3. Simplify does nothing. but it may be overridden in extensions of Expression 6/2 147 10 November 2006 Null Procedures 6.7 . Syntax 1/2 null_procedure_declaration ::= [overriding_indicator] procedure_specification is null. Dynamic Semantics 3/2 The execution of a null procedure is invoked by a subprogram call. -.

.

1). An entity declared in the private part of a package is visible only within the declarative region of the package itself (including any child units — see 10. while their inner workings remain hidden from outside users.]identifier] If an identifier or parent_unit_name. Each list of basic_declarative_items of a package_specification forms a declaration list of the package. expanded names denoting entities declared in the visible part can be used even outside the package. 1 7. furthermore. which can be called from outside the package. NOTES 1 The visible part of a package contains all the information that another program unit is able to know about the package. but whose completion is not in its package_specification.1. the package has an implicit empty private part. then that body has to occur immediately within the body of the package. then this sequence of lexical elements shall repeat the defining_program_unit_name.identifier appears at the end of a package_specification. 2 If a declaration occurs immediately within the specification of a package. Static Semantics 5/2 The first list of basic_declarative_items of a package_specification of a package other than a generic formal package is called the visible part of the package. Every package has a package_specification.1 Package Specifications and Declarations A package is generally provided in two parts: a package_specification and a package_body. package_specification ::= package defining_program_unit_name is {basic_declarative_item} 2 3 [private {basic_declarative_item}] end [[parent_unit_name.3 and 8. If the reserved word private does not appear. In contrast. direct visibility of such entities can be achieved by means of use_clauses (see 4. Syntax 1 package_declaration ::= package_specification. The optional list of basic_declarative_items after the reserved word private (of any package_specification) is called the private part of the package. Typically.1. a package contains the declaration of a type (often a private type or private extension) along with the declarations of primitive subprograms of the type. Legality Rules 4 A package_declaration or generic_package_declaration requires a completion (a body) if it contains any basic_declarative_item that requires a completion. and the declaration has a corresponding completion that is a body.4). Dynamic Semantics 6/2 7 The elaboration of a package_declaration consists of the elaboration of its basic_declarative_items in the given order. 8 9 10 149 10 November 2006 Packages 7 . but not all packages have a package_body.ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual Section 7: Packages Packages are program units that allow the specification of groups of logically related entities.

identifier appears at the end of a package_body. the entities declared in the package_body are visible only within the package_body itself. 7. the place is partially determined by the elaboration dependences (see Section 10). return return return return Rational.Y : Rational) return Boolean. Static Semantics 5 In any package_body without statements there is an implicit null_statement. function "="(X.Y : Integer) : : : : Rational) Rational) Rational) Rational) return Rational. if there are several such packages.2 Package Bodies 1 In contrast to the entities declared in the visible part of a package. nonlibrary package. this body occurs at the end of the declarative_part of the innermost enclosing program unit or block_statement.Y function "-" (X. 3 — Ada Reference Manual Examples 11 12 13 Example of a package declaration: package Rational_Numbers is type Rational is record Numerator : Integer. then this sequence of lexical elements shall repeat the defining_program_unit_name. For a library package. For any package_declaration without an explicit completion.Y function "/" (X. A library package_declaration or library generic_package_declaration shall not have a body unless it requires a body. Rational.) 7. Syntax 2 package_body ::= package body defining_program_unit_name is declarative_part [begin handled_sequence_of_statements] end [[parent_unit_name. pragma Elaborate_Body can be used to require a library_unit_declaration to have a body (see 10. For a noninstance. (For an instance. 3 If an identifier or parent_unit_name.Y function "*" (X.1) if it would not otherwise require one.1 Package Specifications and Declarations 10 November 2006 150 . end record.to construct a rational number function "+" (X. 14 15 16 17 There are also many examples of package declarations in the predefined language environment (see Annex A).Y end Rational_Numbers. there is an implicit package_body containing a single null_statement. -. Rational.ISO/IEC 8652:2007(E) Ed. Denominator : Positive. As a consequence. Legality Rules 4 A package_body shall be the completion of a previous package_declaration or generic_package_declaration. the implicit package_body occurs at the place of the instantiation (see 12.2.3). Rational. the order of the implicit package_bodies is unspecified. function "/" (X. a package with a package_body can be used for the construction of a group of related subprograms in which the logical operations available to clients are clearly isolated from the internal entities.]identifier].

See 3. end end end end "+". function "/" (X.1 for an overview of type extensions.. Syntax 1 private_type_declaration ::= type defining_identifier [discriminant_part] is [[abstract] tagged] [limited] private. return U. the value of such a variable remains unchanged between calls issued from outside the package to subprograms declared in the visible part.. end Same_Denominator.. Denominator => Y).. .V).Numerator. the logical properties) from other characteristics whose direct use is confined to the package (the details of the definition of the type itself).. "*". and its handled_sequence_of_statements is then executed.2 .. end "=". Denominator => -Y). end if. 15 7.Y (X.Y : Integer) return Rational is begin if Y > 0 then return (Numerator => X.9. Hence a call of such a subprogram by an outside program unit raises the exception Program_Error if the call takes place before the elaboration of the package_body (see 3. function function function function "+" "-" "*" "/" (X.Y : in out Rational) is begin -. NOTES 3 A variable declared in the body of a package is only visible within this body and. In the absence of local tasks. . 2 151 10 November 2006 Package Bodies 7. its declarative_part is first elaborated.. Examples 6 7 8 Example of a package body (see 7.Y : Rational) return Boolean is U : Rational := X..11). "-".Y : : : : Rational) Rational) Rational) Rational) return return return return Rational Rational Rational Rational is is is is . begin Same_Denominator (U. else return (Numerator => -X. 3 — Ada Reference Manual Dynamic Semantics For the elaboration of a nongeneric package_body. 9 10 11 12 13 14 end Rational_Numbers.reduces X and Y to the same denominator: .Y (X...3 Private Types and Private Extensions The declaration (in the visible part of a package) of a type as a private type or private extension serves to separate the characteristics that can be used directly by outside program units (that is.Numerator = V.ISO/IEC 8652:2007(E) Ed. .1): package body Rational_Numbers is procedure Same_Denominator (X. function "="(X. "/". 4 The elaboration of the body of a subprogram explicitly declared in the visible part of a package is caused by the elaboration of the body of the package. consequently.Y (X. its value can only be changed within the package_body. V : Rational := Y. end "/". The properties of such a variable are similar to those of a “static” variable of C.

then the full_type_declaration shall have a fully conforming (explicit) known_discriminant_part (see 6. On the other hand. The view of the type declared by the full_type_declaration is called the full view. and the parent subtype of the full view shall be constrained if and only if the ancestor subtype is constrained. and it requires a completion.9. In addition to the places where Legality Rules normally apply (see 12. In the case where the partial view is untagged and the full view is tagged. A type shall be completely defined before it is frozen (see 3. If a private extension inherits known discriminants from the ancestor subtype.3/2 8 8. The ancestor subtype may be unconstrained. the full view may be limited or nonlimited. If the partial view is nonlimited.3). derivatives of the full view are allowed. then the full view shall be limited. • the partial view shall be a descendant of an interface type (see 3. such a declaration is allowed only as a declarative_item of the visible part of a package. If the declaration of a partial view includes a known_discriminant_part. 3 — Ada Reference Manual private_extension_declaration ::= type defining_identifier [discriminant_part] is 3/2 [abstract] [limited | synchronized] new ancestor_subtype_indication [and interface_list] with private. or if the reserved word limited or synchronized appears in its definition.4) if and only if the full type is a synchronized tagged type. then the full view shall be tagged. The full view of a private extension shall be derived (directly or indirectly) from the ancestor type. A generic formal private type or a generic formal private extension is also a partial view.4) if and only if the full type is a descendant of the interface type. The ancestor subtype of a private_extension_declaration is the subtype defined by the ancestor_subtype_indication. the name of the partial view cannot be used in a generic_instantiation or in a representation item. then the full view may be tagged or untagged. no derivatives of the partial view are allowed within the immediate scope of the partial view. before the full declaration. which shall be a full_type_declaration that occurs as a declarative_item of the private part of the package. then the full view shall be nonlimited.ISO/IEC 8652:2007(E) Ed. Legality Rules 4 A private_type_declaration or private_extension_declaration declares a partial view of the type.1 and 13. If the partial view is tagged. 9 10 7. nor the creation by an allocator of an object of the partial view are allowed before the full declaration of the type. if the partial view is untagged. If a full type has a partial view that is tagged.7). the ancestor type shall be a specific tagged type. a private extension is limited if its ancestor type is a limited type that is not an interface type.14). 5 6/2 7 7. then the full view shall also inherit its discriminants from the ancestor subtype.2/2 7.1/2 If the reserved word limited appears in a private_extension_declaration. the requirement that the ancestor be specific applies also in the private part of an instance of a generic unit.3. A private type is limited if its declaration includes the reserved word limited.9. Thus. the ancestor type shall be a limited interface. If the reserved word synchronized appears in a private_extension_declaration.1/2 7. then: • the partial view shall be a synchronized tagged type (see 3. the parent subtype of the full view is required to be constrained (see 3. if an untagged partial view is limited. On the other hand.11.1.3 Private Types and Private Extensions 10 November 2006 152 . Similarly. neither the declaration of a variable of a partial view of a type. the ancestor type shall be a limited type. “Conformance Rules”). If a tagged partial view is limited.

the formal parameter names and default expressions (if any) come from the corresponding primitive subprogram of the specified ancestor type. If the ancestor type is not an interface type. A declaration of a partial view and the corresponding full_type_declaration define two views of a single type. then the parent subtype of the full view shall impose a statically matching constraint on those discriminants. what attributes and other predefined operations are allowed. In this case. and creates a partial view of a type.2. 7 The ancestor type specified in a private_extension_declaration and the parent type specified in the corresponding declaration of a record extension given in the private part need not be the same. then the full_type_declaration shall define a definite subtype. The full view of the type might or might not be composite.4).1. the full view determines the classes that include the type. then the reserved word limited shall appear in the full_type_declaration if and only if it also appears in the private_extension_declaration.3 . in particular. the declaration of the full view together with the private part define other operations whose direct use is possible only within the declarative region of the package itself. and whether the first subtype is static. for a primitive subprogram that is inherited from the ancestor type and not overridden. 3 — Ada Reference Manual If the full_type_declaration for a private extension is defined by a derived_type_definition. as is its full view. If a partial view has neither known nor unknown discriminants. entries. The progenitor types specified in a private_extension_declaration and the progenitor types specified in the corresponding declaration of a record extension given in the private part need not be the same — the only requirement is that the private extension and the record extension be descended from the same set of interfaces. A private extension is also composite. NOTES 5 The partial view of a type as declared by a private_type_declaration is defined to be a composite view (in 3. the parent type can be any type so long as the full view is a descendant of the ancestor type. and protected subprograms are visible. with or without discriminants. 17 18 19/2 20/2 20. The declaration of a partial view together with the visible part define the operations that are available to outside program units. If the ancestor subtype of a private extension has constrained discriminants. 6 Declaring a private type with an unknown_discriminant_part is a way of preventing clients from creating uninitialized objects of the type.9. A private extension inherits components (including discriminants unless there is a new discriminant_part specified) and user-defined primitive subprograms from its ancestor type and its progenitor types (if any). The elaboration of a private_extension_declaration elaborates the ancestor_subtype_indication. Dynamic Semantics 14 15 16/2 The elaboration of a private_type_declaration creates a partial view of a type.1/2 153 10 November 2006 Private Types and Private Extensions 7. See 3. Static Semantics 10. in the same way that a record extension inherits components and user-defined primitive subprograms from its parent type and its progenitor types (see 3. they are then forced to initialize each object by calling some operation declared in the visible part of the package.2). which components. within its scope. Similarly.ISO/IEC 8652:2007(E) Ed.1/2 11 12 13 A private_type_declaration declares a private type and its first subtype. 8 If the ancestor type specified in a private_extension_declaration is an interface type. the characteristics of the type are determined by the full view. then the full_type_declaration may define a definite or an indefinite subtype. the parent type of the full view can be any descendant of the ancestor type.3. Moreover. within the scope of the declaration of the full view. while the body comes from the corresponding primitive subprogram of the parent type of the full view. a private_extension_declaration declares a private extension and its first subtype. See 7. If a partial view has unknown discriminants.

In such a case. type File_Name is limited private. 3 — Ada Reference Manual Examples 21 22 Examples of private type declarations: type Key is private. In most cases. Such private operations are available only inside the declarative region of the package or generic package. if any. For example. an integer type has a predefined "+" operator. the inherited subprogram is not declared for the private extension. Any additional predefined operators are implicitly declared at that place. the following attribute is defined: 3/1 4/1 5/1 6/1 7 8 7. Inherited subprograms are also implicitly declared immediately after the definition of the type. 7. for every subtype S of an untagged private type whose full view is tagged.Finalization.1 Private Operations 1 For a type declared in the visible part of a package or generic package. the predefined operators of a type are declared immediately after the definition of the type. If later immediately within the declarative region in which the composite type is declared additional characteristics become visible for a component type. At the place where the composite type is declared. an array type whose component type is limited private becomes nonlimited if the full view of the component type is nonlimited and visible at some later place immediately within the declarative region in which the array type is declared. then any corresponding characteristics become visible for the composite type. For a private_extension_declaration. The Class attribute is defined for tagged subtypes in 3. the predefined "=" operator is implicitly declared at that place.9.ISO/IEC 8652:2007(E) Ed. In addition. it is possible to dispatch to it. 23 24 Example of a private extension declaration: type List is new Ada. but for a tagged type. where the corresponding declaration from the parent is visible. the characteristics (see 7.3.Controlled with private. An inherited subprogram that is not declared at all cannot be named in a call and cannot be overridden. Inherited primitive subprograms follow a different rule. but after the type_declaration. Static Semantics 2 The predefined operators that exist for a given type are determined by the classes to which the type belongs.3 Private Types and Private Extensions 10 November 2006 154 . The corresponding rule applies to a type defined by a derived_type_definition. the exceptions are explained below. then the inherited subprogram is not declared at all. though it might be for the full type. Otherwise. each inherited subprogram is declared immediately after the private_extension_declaration if the corresponding declaration from the ancestor is visible at that place. For a derived_type_definition. each inherited primitive subprogram is implicitly declared at the earliest place.3) of the type are determined in part by the characteristics of its component types. the only characteristics of component types used are those characteristics visible at that place. if there is a place immediately within the declarative region in which the type is declared where additional characteristics of its parent type become visible. For example. and assignment is allowed after that place. If there is no such place. except as stated below. For a composite type. certain operations on the type do not become visible until later in the package — either in the private part or the body. immediately within the declarative region in which the type_declaration occurs.

the operations available for objects of type Key include assignment. Examples 10 11 12/2 13 Example of a type with private operations: package Key_Manager is type Key is private. end "<". S'Size is defined (see 13. end Key_Manager. 10 Partial views provide initialization. and Last_Bit attributes are also defined for discriminants and inherited components. First_Bit. since the operator ">=" is not redefined. Y : Key) return Boolean. finalization is still done for controlled components of the full view. The explicitly declared operator "<" hides the predefined operator "<" implicitly declared by the full_type_declaration. function "<" (X. The fact that the full declaration might implement a private type with a type of a particular class (for example. 11 For a subtype S of a partial view. the comparison for equality or inequality. For an object A of a partial view. declared in the package body. The Position.ISO/IEC 8652:2007(E) Ed.) 14 15 16 17 18 19 20 155 10 November 2006 Private Operations 7. they do not include other relational operators such as ">=". until the declaration of the full view.3. procedure Get_Key(K : out Key) is begin Last_Key := Last_Key + 1. (See also the NOTES of 7. Within these outside program units the type is just a private type or private extension. package body Key_Manager is Last_Key : Key := Null_Key. the procedure Get_Key and the operator "<". The value of the variable Last_Key. task dependence rules still apply to components that are task objects. 9 NOTES 9 Because a partial view and a full view are two different views of one and the same type. membership tests. Within the body of the function. remains unchanged between calls of the procedure Get_Key. This attribute is allowed only from the beginning of the private part in which the full view is declared. -.3). private type Key is new Natural.3).4) procedure Get_Key(K : out Key). or arithmetic operators. and explicit conversion. NOTES 12 Notes on the example: Outside of the package Key_Manager. Null_Key : constant Key. an explicit conversion of X and Y to the subtype Natural is necessary to invoke the "<" operator of the parent type. Y : Key) return Boolean is begin return Natural(X) < Natural(Y).1 . outside of the defining package the characteristics of the type are those defined by the visible part. valid everywhere. K := Last_Key. function "<" (X. the attribute Size provides the size of the full view. the attributes A'Size and A'Address are defined (see 13. the Class attribute of the full view can be used. Null_Key : constant Key := Key'First. and any language rule that applies only to another class of types does not apply. 3 — Ada Reference Manual S'Class Denotes the class-wide subtype corresponding to the full view of S. as an array type) is relevant only within the declarative region of the package itself including any child units. however.a deferred constant declaration (see 7.2. For example: any default initialization of components takes place. selected components for the selection of discriminants and inherited components. qualification. Nonlimited partial views also allow use of assignment_statements. end Get_Key. After the full view. end Key_Manager. The consequences of this actual implementation are. Alternatively. the result of the function could be written as not (X >= Y).

3 — Ada Reference Manual 7.1 CPU_Identifier : constant String(1. Legality Rules 2 A deferred constant declaration is an object_declaration with the reserved word constant but no initialization expression. A deferred constant declaration that is completed by a pragma Import need not appear in the visible part of a package_specification. • If the deferred constant declaration includes the reserved word aliased. but with the value of the constant given in the private part. A deferred constant declaration that is completed by a full constant declaration shall occur immediately within the visible part of a package_specification.. Examples 11 12 13 14 Examples of deferred constant declarations: Null_Key : constant Key. or shall have statically matching anonymous access subtypes. CPU_Identifier.1/2 8 9/2 10 The elaboration of a deferred constant declaration elaborates the subtype_indication or (only allowed in the case of an imported constant) the array_type_definition.3. if the subtype of the deferred constant is unconstrained. • The deferred and full constants shall have the same type. like all constants.see 7. and has no full constant declaration.8).4 Deferred Constants 1 Deferred constant declarations may be used to declare constants in the visible part of a package. -.14). then the subtype defined by the subtype_indication in the full declaration shall match it statically. which shall be a full constant declaration (called the full declaration of the deferred constant). On the other hand. The completion of a deferred constant declaration shall occur before the constant is frozen (see 13. then the full declaration shall also. Dynamic Semantics 3 4 5/2 6/2 7/2 7. NOTES 13 The full constant declaration for a deferred constant that is of a given private type or private extension is not allowed before the corresponding full_type_declaration. the subtype of the full declaration shall also exclude null. The constant itself will be constrained. -. A deferred constant declaration requires a completion.ISO/IEC 8652:2007(E) Ed. Link_Name => "CPU_ID").4 Deferred Constants 10 November 2006 156 .14). • If the deferred constant declaration includes a subtype_indication that defines a constrained subtype. The constant declared by a deferred constant declaration is called a deferred constant. or a pragma Import (see Annex B). pragma Import(Assembler. the following additional rules apply to the corresponding full declaration: • The full declaration shall occur immediately within the private part of the same package. then the full declaration is still allowed to impose a constraint.1 7. This is a consequence of the freezing rules for types (see 13. • If the subtype of the deferred constant declaration excludes null.see B. They may also be used to declare constants imported from other languages (see Annex B). For this case.

synchronized.3. For a function_call of a type with a part that is of a task. or explicitly limited record type that is used to initialize an object as allowed above. NOTES 14 While it is allowed to write initializations of limited objects.5) • the default_expression or actual parameter for a formal object of mode in (see 12. 3 — Ada Reference Manual 7. A nonlimited type is a (view of a) type for which copying is allowed. its parent type and any progenitor interfaces shall be limited. the implementation shall not create a separate anonymous object for the aggregate.ISO/IEC 8652:2007(E) Ed. then the reserved word limited shall appear in its record_type_definition.7/2 2.3. Paragraphs 10 through 15 were deleted. Legality Rules 1/2 If a tagged record type has any limited components.3. The aggregate or function_call shall be constructed directly in the new object.1/2 2. task.9/2 A type is limited if it is one of the following: • a type with the reserved word limited.6/2 • the qualified_expression of an initialized allocator (see 4. 8. or protected in its definition.4/2 2. Implementation Requirements 3/2 4/2 5/2 6/2 6.3) 2/2 2.2) • an expression of a positional_array_aggregate array_component_association (see 4. Otherwise. and such aggregates and function_calls must be built directly in the target object. protected. • This paragraph was deleted.2/2 2.1/2 7 8 For an aggregate of a limited type used to initialize an object as allowed above. There are no predefined equality operators for a limited type.3.1/2 9/2 157 10 November 2006 Limited Types 7. • a derived type whose parent is limited and is not an interface. the implementation shall not create a separate return object (see 6.8) • the expression of a return statement (see 6. If the reserved word limited appears in the definition of a derived_type_definition. a function_call.5) for the function_call. The source of such an assignment operation must be an aggregate or function_call. In the following contexts.1) • the default_expression of a component_declaration (see 3.5 .3/2 2. an expression of a limited type is not permitted unless it is an aggregate. the type is nonlimited. such initializations never copy a limited object.8) • the expression of a record_component_association (see 4.4) Static Semantics 2.8/2 2.5/2 or the expression of an 2. • a composite type with a limited component. or a parenthesized expression or qualified_expression whose operand is permitted by this rule: • the initialization expression of an object_declaration (see 3.1) • the expression for an ancestor_part of an extension_aggregate (see 4.5 Limited Types A limited type is (a view of) a type for which copying (such as for an assignment_statement) is not allowed.

21 22 23/2 7. NOTES 16 Notes on the example: In the example above. Item : in Integer).. but a controlled type gives the user additional control over parts of these operations. either explicitly or by default. explicit initialization. an Initialize procedure which is invoked immediately after the normal default initialization of a controlled object. an untagged limited type can become nonlimited under certain circumstances.5). begin . File_Name. after being created (for example. out File_Name). : Integer := 0. 3 — Ada Reference Manual 16 15 As illustrated in 7. 20 package body IO_Package is Limit : constant := 200. In particular. Directory : array (1 . procedure Open (F : in out File_Name) is . by an object_declaration or allocator). Default definitions for these three fundamental operations are provided by the language.. procedure Read (F : in File_Name. a file name obtained from Open acts as a kind of password. They also implement the notion of an encapsulated data type where the only operations on the type are those given in the package specification. Item : out Integer) is . and assignment. An assignment operation is used as part of assignment_statements. end.ISO/IEC 8652:2007(E) Ed. Thus.5 Limited Types 10 November 2006 158 .. a Finalize procedure which is invoked immediately before finalization of any of the components of a controlled object. end IO_Package... clients of the package cannot make copies of objects of type File_Name.3. Most importantly. end. Every object is finalized before being destroyed (for example.. Examples 17 18 19 Example of a package with a limited type: package IO_Package is type File_Name is limited private. end. for a controlled type.. Item : out Integer). Every object is initialized. or by a call to an instance of Unchecked_Deallocation). finalization. and an Adjust procedure which is invoked as the last step of an assignment to a (nonlimited) controlled object. by leaving a subprogram_body containing an object_declaration. Item : in Integer) is . procedure Write(F : in File_Name.. end. the user can define. type File_Descriptor is record . and other operations.2 and 6. procedure Close(F : in out File_Name) is . . Limit) of File_Descriptor.1. an outside subprogram making use of IO_Package may obtain a file name by calling Open and later use it in calls to Read and Write... outside the package.. This example is characteristic of any case where complete control over the operations of a type is desired..6 User-Defined Assignment and Finalization 1 Three kinds of actions are fundamental to the manipulation of objects: initialization. Such packages serve a dual purpose. They prevent a user from making use of the internal structure of the type.. in in in in out File_Name). procedure Open (F : procedure Close(F : procedure Read (F : procedure Write(F : private type File_Name is limited record Internal_Name end record. 2 7. end IO_Package. The fact that the full view of File_Name is explicitly declared limited means that parameter passing will always be by reference and function results will always be built directly in the result object (see 6. its internal properties (such as containing a numeric value) are not known and no other operations (such as addition or comparison of internal names) can be performed on a file name. File_Name... parameter passing. end record.

Finalization. type Controlled is abstract tagged private. except that it is limited and it lacks the primitive subprogram Adjust.. type Limited_Controlled is abstract tagged limited private. 3 4/1 5/2 6/2 7/2 8/2 A controlled type is a descendant of Controlled or Limited_Controlled.1).6 . if any (including both implicit initialization and Initialize calls). procedure Finalize (Object : in out Controlled) is null. The type Limited_Controlled is like Controlled. procedure Initialize (Object : in out Controlled) is null. the Initialize procedure of the ancestor type is called. Initialize is applied to them in order of their component_declarations.. A type is said to need finalization if: • it is a controlled type. a task type or a protected type.5/2 During the elaboration or evaluation of a construct that causes an object to be initialized by default. pragma Preelaborable_Initialization(Limited_Controlled). When a target object with any controlled parts is assigned a value. procedure Adjust (Object : in out Controlled) is null. or • it has a component that needs finalization. Similarly. any task activations follow all calls on Initialize. except as follows. pragma Preelaborable_Initialization(Controlled). as explained in 4. • The value of the target is adjusted.4/2 9. Dynamic Semantics 9/2 9. or • it is one of a number of language-defined types that are explicitly defined to need finalization. either when created or in a subsequent assignment_statement. 3 — Ada Reference Manual Static Semantics The following language-defined library package exists: package Ada. If an object has a component with an access discriminant constrained by a per-object expression. -. private . procedure Finalize (Object : in out Limited_Controlled) is null.2. since this operator is incorporated into the implementation of the predefined equality operator of types derived from Controlled.ISO/IEC 8652:2007(E) Ed. 14 15 159 10 November 2006 User-Defined Assignment and Finalization 7. or • it is a limited type that has an access discriminant whose designated type needs finalization.2/2 9. For an extension_aggregate whose ancestor_part is a subtype_mark denoting a controlled subtype.5.3.3/2 9. Initialize is called on that subcomponent. procedure Initialize (Object : in out Limited_Controlled) is null.1/2 9.not specified by the language end Ada. for every controlled subcomponent of the object that is not assigned an initial value (as defined in 3. Initialize is applied to an object after initialization of its subcomponents. For an object with several components with such a discriminant. the assignment operation proceeds as follows: 10/2 11/2 12 13 • The value of the target becomes the assigned value. Initialize is called on the object. Initialize and other initialization operations are done in an arbitrary order.Finalization is pragma Preelaborate(Finalization). unless that Initialize procedure is abstract. For an allocator. if the object that is initialized by default as a whole is controlled. The predefined "=" operator of type Controlled always returns True. Initialize is applied to this component after any components that do not have such discriminants. pragma Remote_Types(Finalization).

6 User-Defined Assignment and Finalization 10 November 2006 160 19 20 21/2 22/2 23/2 24/2 25/2 26/2 . The aggregate value shall be constructed directly in the target of the assignment operation and Adjust is not called on the target object. • For an aggregate or function call whose value is assigned into a target object. the implementation need not create a separate anonymous object if it can safely create the value of the aggregate or function call directly in the target object. and any conversion (including constraint checking) has been done. an implementation is permitted to omit implicit Initialize. and then. • For an assignment_statement for a noncontrolled type. and • the assignment operations associated with omitted Adjust calls are also omitted. (Assignment includes value adjustment. the implementation may eliminate the intermediate anonymous object. that is. the values of the components of the object are first adjusted in an arbitrary order. an anonymous object is created. Finally. and • any usage of the value of the object after the implicit Initialize or Adjust call and before any subsequent Finalize call on the object does not change the external effect of the program. any execution of the program that executes an Initialize or Adjust call on an object or initializes an object by an aggregate will also later execute a Finalize call on the object and will always do so prior to assigning a new value to the object. and • after the omission of such calls and operations. nor does adjusting the value of a composite object with no controlled parts. the implementation shall not create a separate anonymous object for the aggregate. so this description subsumes the one given in 5. the implementation need not create an anonymous object if the value being assigned is the result of evaluating a name denoting an object (the source object) whose storage cannot overlap with the target. and Finalize calls and associated assignment operations on an object of a nonlimited controlled type provided that: • any omitted Initialize call is not a call on a user-defined Initialize procedure. 7. As explained below. the implementation need not do anything. the implementation may finalize and assign each component of the variable separately (rather than finalizing the entire variable and assigning the entire new value) unless a discriminant of the variable is changed by the assignment. then the implementation can avoid the need for an intermediary anonymous object by exercising one of the above permissions and perform the assignment one component at a time (for an overlapping array assignment). Adjust is called. Furthermore. or not at all (for an assignment where the target and the source of the assignment are the same object). For an assignment_statement. the assignment operation is applied. Implementation Permissions 18 An implementation is allowed to relax the above rules (for nonlimited controlled types) in the following ways: • For an assignment_statement that assigns to an object the value of that same object. Adjust. other than by an assignment_statement. after the name and expression have been evaluated. 3 — Ada Reference Manual 16 To adjust the value of a (nonlimited) composite object.1/2 For an aggregate of a controlled type whose value is assigned.) The target of the assignment_statement is then finalized. “Assignment Statements”. for an assignment_statement. Adjusting the value of an elementary object has no effect.2.ISO/IEC 8652:2007(E) Ed. if the object is controlled. If the source object might overlap with the target object. and the value is assigned into it. The value of the anonymous object is then assigned into the target of the assignment_statement. Similarly. the anonymous object is finalized. Implementation Requirements 17 17.

10. it is left. but before leaving. • If the object is of a controlled type. Completion due to reaching the end of execution. After execution of a construct or entity is complete. they are finalized in the reverse of the order of their component_declarations. A master is the execution of a construct that includes finalization of local objects after it is complete (and after waiting for any local tasks — see 9. When a transfer of control causes completion of an execution. For the finalization of a master. meaning that execution continues with the next action. • If the object is of a protected type. • If the object is of a composite type. For the finalization of an object: • If the object is of an elementary type.3.2).1/2 10 11/2 . dependent tasks are first awaited. from innermost outward. or simple_statement other than a simple_return_statement. each coextension is finalized after the object whose access discriminant designates it. as defined for the execution that is taking place. except in the case of a master: the execution of a body other than a package_body. Leaving an execution happens immediately after its completion. Then each object whose accessibility level is the same as that of the master is finalized if the object was successfully initialized and still exists. Other constructs and entities are left immediately upon completion. except as follows: if the object has a component with an access discriminant constrained by a per-object expression. the actions defined in 9. 27/2 7. 3 — Ada Reference Manual This permission applies to Adjust and Finalize calls even if the implicit calls have additional external effects. or when a transfer of control (see 5.3). • If the object has coextensions (see 3. function_call. the Finalize procedure is called.ISO/IEC 8652:2007(E) Ed. For objects that 161 10 November 2006 User-Defined Assignment and Finalization 7. each included master is finalized in order. The order in which the finalization of a master performs finalization of objects is as follows: Objects created by declarations in the master are finalized in the reverse order of their creation. then after performing the above actions. the object is finalized. or due to the transfer of control of an exit_statement. If an instance of Unchecked_Deallocation is never applied to an object created by an allocator.1) causes it to be abandoned. for an object with several components with such a discriminant. this component is finalized before any components that do not have such discriminants. Dynamic Semantics 1 The execution of a construct or entity is complete when the end of that execution has been reached. or the evaluation of an expression. These actions are performed whether the master is left by reaching the last statement or via a transfer of control.6. range. or requeue_statement or of the selection of a terminate_alternative is normal completion. every component of the object is finalized in an arbitrary order. the execution of a statement.1 Completion and Finalization This subclause defines completion and leaving of the execution of constructs and entities. and it will be finalized then. as explained in 9. goto_statement.6 2/2 3/2 4 5 6 7 8 9/2 9. or range that is not part of an enclosing expression. Immediately before an instance of Unchecked_Deallocation reclaims the storage of an object. if any. function_call. finalization has no effect. the object will still exist when the corresponding master completes. return statement. Completion is abnormal otherwise — when control is transferred out of a construct due to abort or the raising of an exception. and before it is left. A master is finalized after it is complete.4 are performed.

and no later than the point where normal execution would have continued. the finalization of these objects is called the finalization of the collection. Bounded (Run-Time) Errors 13. 3 — Ada Reference Manual were created by allocators for an access type whose ultimate ancestor is declared in the master. • For an Adjust invoked as part of assignment operations other than those invoked as part of an assignment_statement.14) of the ultimate ancestor type. finalization of any (anonymous) objects occurs as the final part of evaluation of the expression. and then Program_Error is raised. • For a Finalize invoked due to reaching the end of the execution of a master. finalization might or might not be applied to objects whose Adjust failed. as do any types and subtypes defined and created within the master. except those already finalized). Program_Error is raised immediately after leaving the master. For an Adjust invoked as part of an assignment_statement. This occurs after waiting for library-level tasks to terminate.ISO/IEC 8652:2007(E) Ed. NOTES 17 The rules of Section 10 imply that immediately prior to partition termination. • For a Finalize invoked by a transfer of control due to an abort or selection of a terminate alternative. After the finalization of a master is complete. return statement. any other finalizations due to be performed are performed. as explained in 7. and then Program_Error is raised. During its propagation. the exception is ignored.1 Completion and Finalization 10 November 2006 162 . The possible consequences depend on what action invoked the Finalize or Adjust operation: • For a Finalize invoked as part of an assignment_statement. the objects finalized as part of its finalization cease to exist. • For a Finalize invoked by the transfer of control of an exit_statement. Any other finalizations due to be performed up to that point are performed before raising Program_Error.2/1 18/2 19 20 21 7. and then Program_Error is raised.10. In the case of an expression that is a master.1/1 17. 15 16/2 17 17. The master of an object is the master enclosing its creation whose accessibility level (see 3. any other finalizations due to be performed for the same master are performed. • For a Finalize invoked by a transfer of control that is due to raising an exception. other adjustments due to be performed might or might not be performed. and then Program_Error is raised. Program_Error is raised no earlier than after the finalization of the master being finalized when the exception occurred. goto_statement. any other finalizations due to be performed are performed. 12/2 13/2 The target of an assignment_statement is finalized before copying in the new value. • For a Finalize invoked as part of the finalization of the anonymous object created by a function call or aggregate. any other finalizations due to be performed are performed. Program_Error is raised at that point. any other adjustments due to be performed are performed. any other finalizations associated with the master are performed.1/2 14/1 It is a bounded error for a call on Finalize or Adjust that occurs as part of object finalization or assignment to propagate an exception. this rule is applied as though each such object that still exists had been created in an arbitrary order at the first freezing point (see 13. • For a Finalize invoked as part of a call on an instance of Unchecked_Deallocation.6. Finalize operations are applied to library-level controlled objects (including those created by allocators of library-level access types.6.2) is equal to that of the object. or requeue_statement. and Program_Error is raised immediately after leaving the master.

even if Finalize was called earlier.ISO/IEC 8652:2007(E) Ed. hence. its Finalize procedure should be designed to have no ill effect if it is applied a second time to the same object.6. or is nonlimited (implying that assignment is allowed). 19 Abort is deferred during certain operations related to controlled types. either explicitly or as part of an assignment.8. 22 23 24 163 10 November 2006 Completion and Finalization 7. as explained in 9. Those rules prevent an abort from causing a controlled object to be left in an ill-defined state. 3 — Ada Reference Manual 18 A constant is only constant between its initialization and finalization. 20 The Finalize procedure is called upon finalization of a controlled object. if a controlled type is visibly controlled (implying that its Finalize primitive is directly callable). Both initialization and finalization are allowed to change the value of a constant.1 .

.

• If a type_declaration is included. as follows: • If a declaration is included. • an exception_handler. The view comprises an identification of the viewed entity. A declaration is local to a declarative region if the declaration occurs immediately within the declarative region. As explained in Section 3. 1 2 8. not counting the declarative region (if any) associated with the declaration itself. Thus. • an accept_statement. 3 — Ada Reference Manual Section 8: Visibility Rules The rules defining the scope of declarations and the rules defining which identifiers. by the previous rule). A declaration occurs immediately within a declarative region if this region is the innermost declarative region that encloses the declaration (the immediately enclosing declarative region). • a block_statement. within which nested declarations can occur: • any declaration. two different usage names might denote two different views of the same entity.ISO/IEC 8652:2007(E) Ed. that is not a completion of a previous declaration. if any. so are the declarations of any child units (and their completions. there is a portion of the program text called its declarative region. then so is a corresponding record_representation_clause. • If the declaration of a library unit (including Standard — see 10. • a loop_statement. in this case they denote the same entity. A usage name denotes a declaration. • If a body_stub is included. The child declarations occur after the declaration.1/2 5 6 7 8 9 10 11 12 13 14 165 10 November 2006 Visibility Rules 8 . It also denotes the view declared by that declaration. and possibly additional properties. The formulation of these rules uses the notion of a declarative region. other than that of an enumeration type. An entity is local to a declarative region if the entity is declared by a declaration that is local to the declarative region. and operator_symbols are visible at (or from) various places in the text of the program are described in this section. and denotes the entity of that view. character_literals. • an extended_return_statement. so is its completion. so is the corresponding subunit. if any.1 Declarative Region Static Semantics For each of the following constructs. The declarative region of a declaration is also called the declarative region of any view or entity declared by the declaration. a declaration declares a view of an entity and associates a defining name with that view.1) is included. 1 2 3 4 4. The declarative region includes the text of the construct together with additional text determined (recursively).1.

The scope of a declaration is also called the scope of any view or entity declared by the declaration. but they are inside its declarative region. other program units. if any. The immediate scope extends to the end of the declarative region.1 Declarative Region 10 November 2006 166 . and that after "use P.Library Units”. The immediate scope starts at the beginning of the declaration. the portion does not contain any text that might appear between the parts of the declarative region. This implies that one can use (for example) "P. the language rules define a certain portion of the program text called the scope of the declaration. An entity is global to a declarative region if the entity is declared by a declaration that is global to the declarative region. task unit. in which case the immediate scope starts just after the place where the profile of the callable entity is determined (which is at the end of the _specification for the callable entity. NOTES 1 The children of a parent library unit are inside the parent's declarative region. the text of the declarative region does not contain any text that might appear between the parts." Q can refer (directly) to that child. 3 4 5 6 7 8 9 8. and 9. 3 — Ada Reference Manual 15 A declaration is global to a declarative region if the declaration occurs immediately within another declarative region that encloses the declarative region. 3 For a declarative region that comes in multiple parts.1. it also includes the profile. Within the scope of an entity. except in the case of an overloadable declaration. or protected unit consists of declarations in the program unit's declaration other than those following the reserved word private. Thus. 2 As explained above and in 10. • The immediate scope of a declaration in the private part of a library unit does not include the visible part of any public descendant of that library unit. all library units are descendants of Standard. and so are contained in the declarative region of Standard. 16 17 18 8. • The visible part of a composite type other than a task or protected type consists of the declarations of all components declared (explicitly or implicitly) within the type_declaration. 9.ISO/IEC 8652:2007(E) Ed. there are places where it is legal to refer to the declared entity. “Compilation Units . The private part of (a view of) an entity that has a visible part contains all declarations within the declaration of (the view of) the entity. see 7. except those in the visible part. and only there. or at the end of the generic_instantiation if an instance). • The visible part of a package. Visible and private parts are defined only for these kinds of entities: callable entities. These places are defined by the rules of visibility and overloading. it also includes the first list of basic_declarative_items of the package_specification. and composite types.1. For a generic subprogram. even though they do not occur inside the parent's declaration or body. • The visible part of a view of a callable entity is its profile.7 for packages.4 for protected units. For a generic package. The visible part of (a view of) an entity is a portion of the text of its declaration containing declarations that are visible from outside. They are not inside the declaration or body of Standard. these are not visible from outside.2 Scope of Declarations 1 For each declaration.1 for task units.1 and 12. • The visible part of a generic unit includes the generic_formal_part. with the following exceptions: • The immediate scope of a library_item includes only its semantic dependents.Q" to refer to a child of P whose defining name is Q. when a portion of a declarative region is said to extend from one place to another in the declarative region. Static Semantics 2 The immediate scope of a declaration is a portion of the declarative region immediately enclosing the declaration.

3 — Ada Reference Manual The scope of a declaration always contains the immediate scope of the declaration. There are two kinds of direct visibility: immediate visibility and use-visibility. parameter_specifications are in the visible part of a subprogram_declaration so that they can be used in named-notation calls appearing outside the called subprogram. given below. or from all visibility. only direct visibility is lost. Both conditions can apply. within certain parts of its scope.1/2 11 12 8.2 . declarations of the visible part of a package can be denoted by expanded names appearing outside the package. A declaration is immediately visible at a place if it is directly visible because the place is within its immediate scope. 10 10. Two or more declarations are overloaded if they all have the same defining name and there is a place where they are all directly visible.3 Visibility The visibility rules. Where hidden from direct visibility. NOTES 4 There are notations for denoting visible declarations that are not directly visible. The scope of an attribute_definition_clause is identical to the scope of a declaration that would occur at the point of the attribute_definition_clause. but not direct visibility. meaning that overloading is allowed for them. Similarly. The visibility rules apply to both explicit and implicit declarations. A declaration is use-visible if it is directly visible because of a use_clause (see 8. and. Two declarations are homographs if they have the same defining name. The syntactic category selector_name is used to indicate contexts where visibility. A declaration can be hidden. determine which declarations are visible and directly visible at each place within a program. An inner declaration hides any outer homograph from direct visibility. that is. The immediate scope of a declaration is also the immediate scope of the entity or view declared by the declaration. The syntactic category direct_name is used to indicate contexts where direct visibility is required. For another example. the scope of a declaration is also the scope of the entity or view declared by the declaration. In addition.4). except that the scope of a library_item includes only its semantic dependents. for a given declaration that occurs immediately within the visible part of an outer declaration. visibility using a selector_name is still possible. it is not visible at all (neither using a direct_name nor a selector_name). their profiles are type conformant. no selected_component notation or special context (such as preceding => in a named association) is necessary to denote the declaration. as well as at other places where some name (such as a selected_component) can denote the declaration. For example. Where hidden from all visibility. or is a public child of an outer declaration. either from direct visibility. the scope of the given declaration extends to the end of the scope of the outer declaration. if both are overloadable. The declarations of callable entities (including enumeration literals) are overloadable.ISO/IEC 8652:2007(E) Ed. is required. Static Semantics 1 A declaration is defined to be directly visible at places where a name consisting of only an identifier or operator_symbol is sufficient to denote the declaration. and can be made directly visible by a use_clause. 2 3 4 5 6 7 8 167 10 November 2006 Scope of Declarations 8. A declaration is defined to be visible wherever it is directly visible.

If more than one such homograph remains that is not thus overridden. the body of a new one can be executed by a call to an old one. a discriminant_specification or parameter_specification is hidden within the scope of a corresponding discriminant_specification or parameter_specification of a corresponding completion.9. abstract subprograms. as follows: • An overridden declaration is hidden from all visibility within the scope of the overriding declaration. or require overriding. • A declaration is hidden from all visibility until the end of the declaration. or subprogram_body. However. For a task declaration or protected declaration. then any null procedure overrides all abstract subprograms and all subprograms that require overriding. or of a corresponding accept_statement. and does not require overriding (see 3. the declaration is hidden from all visibility only until the reserved word is of the declaration. 3 — Ada Reference Manual 9/1 Two homographs are not generally allowed immediately within the same declarative region unless one overrides the other (see Legality Rules below). The limited view of a library package is hidden from all visibility at places that are not within the scope of a limited_with_clause that mentions it. then they are all hidden from all visibility. • The declaration of a library unit (including a library_unit_renaming_declaration) is hidden from all visibility at places outside its declarative region that are not within the scope of a nonlimited_with_clause that mentions it. the first declaration is hidden from all visibility. • 10/1 11 12 12. the declaration is hidden from all visibility only until the reserved word record. if more than one such homograph remains that is not thus overridden. 18/2 18.3).ISO/IEC 8652:2007(E) Ed. 13 • For an implicit declaration of a primitive subprogram in a generic unit. then they override those that are null procedures. • If two or more homographs are implicitly declared at the same place: • If at least one is a subprogram that is neither a null procedure nor an abstract subprogram. except where hidden from all visibility. The copied ones can be called only from within the instance. then within the scope of the completion.3/2 Otherwise (all are null procedures. regardless of which declaration occurs first. in 20/2 8. These new declarations occur immediately after the type declaration. the declaration is hidden from all visibility only until the reserved word with of the declaration if there is one. although for tagged types. • The implicit declaration of an inherited operator overrides that of a predefined operator. Similarly. abstract subprograms. then if they are all fully conformant with one another. A declaration overrides another homograph that occurs immediately within the same declarative region in the following cases: • A declaration that is not overridable overrides one that is overridable. if not. except: • • • 14 15 16 17 For a record type or record extension.1/2 19 • If the completion of a declaration is a declaration. they are all hidden from all visibility. For a package_declaration.2/2 12. or the reserved word is of the declaration if there is no with. or require overriding). The only declarations that are overridable are the implicit declarations for predefined operators and inherited primitive subprograms. a whole new set of primitive subprograms is implicitly declared for each type declared within the visible part of the instance.3 Visibility 10 November 2006 168 . and override the copied ones. • An implicit declaration of an inherited subprogram overrides a previous implicit declaration of an inherited subprogram.1/2 12. generic_package_declaration. one is chosen arbitrarily. there is a copy of this declaration in an instance. the new ones can be called only from outside the instance. A declaration is visible within its scope.

or a pragma that appears at the place of a compilation_unit.3 . 7 Not all contexts where an identifier. so long as the corresponding declarations in the generic were not type conformant. Where the declaration of the limited view of a package is visible. 26/2 27 28 29 169 10 November 2006 Visibility 8.1/2 A direct_name shall resolve to denote a directly visible declaration whose defining name is the same as the direct_name. NOTES 5 Visibility for compilation units follows from the definition of the environment in 10. A selector_name shall resolve to denote a visible declaration whose defining name is the same as the selector_name.4. see the rules in 10. the limited view is hidden from all visibility within the declarative region of the package. These rules on visibility and direct visibility do not apply in a context_clause. “Environment-Level Visibility Rules”. Contexts where visibility is not required are identified by using one of these three syntactic categories directly in a syntax rule.6). Similarly. • For each declaration or renaming of a generic unit as a child of some parent generic package. These rules also apply to dispatching operations declared in the visible part of an instance of a generic unit. • A declaration is also hidden from direct visibility where hidden from all visibility. a parent_unit_name. except that it is necessary to apply a with_clause to obtain visibility to a library_unit_declaration or library_unit_renaming_declaration. However. any name that denotes the package denotes the limited view. as well as within the scope of any nonlimited_with_clause that mentions the package. character_literal. if the homograph occurs within an inner declarative region. and the homograph and the mentioned library unit are both declared immediately within the same declarative region. For those contexts. or operator_symbol are allowed require visibility of a corresponding declaration.1.ISO/IEC 8652:2007(E) Ed. and is not hidden from all visibility by the non-overridable declaration. 6 In addition to the visibility rules given above. A declaration with a defining_identifier or defining_operator_symbol is immediately visible (and hence directly visible) within its immediate scope except where hidden from direct visibility. An attribute_definition_clause is visible everywhere within its scope. and there is a homograph of the library unit that is visible at the place of the compilation unit.1/2 21 22 23 23. the context_clause for a compilation unit is illegal if it mentions (in a with_clause) some library unit. rather than using direct_name or selector_name. Such a nested declaration is hidden from all visibility except at places that are within the scope of a with_clause that mentions the child. Name Resolution Rules 20. Legality Rules 24 25 A non-overridable declaration is illegal if there is a homograph occurring immediately within the same declarative region that is visible at the place of the declaration. such declarations may have type conformant profiles in the instance. the meaning of the occurrence of a direct_name or selector_name at a given place in the text can depend on the overloading rules (see 8. they do not apply to other overloadable declarations in an instance. 3 — Ada Reference Manual addition. In addition. there is a corresponding declaration nested immediately within each instance of the parent.1. a type extension is illegal if somewhere within its immediate scope it has two visible components with the same name.6. including those provided by a package renaming. as follows: • A declaration is hidden from direct visibility within the immediate scope of a homograph of the declaration.

.9. overriding procedure Remove_First(Q : in out Security_Queue. Examples 4/2 5/2 6/2 7/2 8/2 9/2 The use of overriding_indicators allows the detection of errors at compile-time that otherwise might not be detected at all.3. NOTES 8 Rules for overriding_indicators of task and protected entries and of protected subprograms are found in 9. Syntax 2/2 overriding_indicator ::= [not] overriding Legality Rules 3/2 If an abstract_subprogram_declaration. null_procedure_declaration. In addition to the places where Legality Rules normally apply. 10/2 11/2 12/2 13/2 14/2 15/2 16/2 The first four subprogram declarations guarantee that these subprograms will override the four subprograms inherited from the Queue interface. or subprogram_declaration other than a protected subprogram has an overriding_indicator. A misspelling in one of these subprograms will be detected by the implementation.5. we might declare a security queue derived from the Queue interface of 3. Person : in Person_Name). overriding procedure Append(Q : in out Security_Queue. then: • the operation shall be a primitive operation for some type.4 as: type Security_Queue is new Queue with record . not overriding procedure Arrest(Q : in out Security_Queue. then the operation shall override a homograph at the place of the declaration or body. overriding function Cur_Count(Q : in Security_Queue) return Natural.3. Conversely. Person : in Person_Name). overriding function Max_Count(Q : in Security_Queue) return Natural.4..2 and 9. generic_instantiation of a subprogram. For instance. the declaration of Arrest guarantees that this is a new operation.1 Overriding Indicators 10 November 2006 170 . • if the overriding_indicator is not overriding. subprogram_body. these rules also apply in the private part of an instance of a generic unit..ISO/IEC 8652:2007(E) Ed. then the operation shall not override any homograph (at any place). 8. subprogram_body_stub. Person : in Person_Name). subprogram_renaming_declaration.1 Overriding Indicators 1/2 An overriding_indicator is used to declare that an operation is intended to override (or not override) an inherited operation. • if the overriding_indicator is overriding. 3 — Ada Reference Manual 8. respectively.

The scope does not include context_clauses themselves. there is a certain region of text called the scope of the use_clause. the scope is the portion of the declarative region starting just after the use_clause and extending to the end of the declarative region. For a use_clause immediately within a declarative region. A package is named in a use_package_clause if it is denoted by a package_name of that clause. For each type T or T'Class named in a use_type_clause whose scope encloses a place. Dynamic Semantics 6 7 7. each declaration that occurs immediately within the declarative region of the package is potentially use-visible at this place if the declaration is visible at this place.4 Use Clauses A use_package_clause achieves direct visibility of declarations that appear in the visible part of a package. 3 — Ada Reference Manual 8. use_type_clause ::= use type subtype_mark {. the scope is the entire body and any subunits (including multiply nested subunits). Static Semantics 5/2 For each use_clause. For a use_clause within a context_clause of a library_unit_declaration or library_unit_renaming_declaration.4 . the declaration of each primitive operator of type T is potentially use-visible at this place if its declaration is visible at this place. Examples 12 Example of a use clause in a context clause: with Ada. the scope is the entire declarative region of the declaration. • Potentially use-visible declarations that have the same identifier are not use-visible unless each of them is an overloadable declaration. use Ada. A declaration is use-visible if it is potentially use-visible. package_name}. A type is named in a use_type_clause if it is determined by a subtype_mark of that clause.ISO/IEC 8652:2007(E) Ed. Legality Rules 2 3 4 A package_name of a use_package_clause shall denote a nonlimited view of a package. subtype_mark}. However. except in these naming-conflict cases: • A potentially use-visible declaration is not use-visible if the place considered is within the immediate scope of a homograph of the declaration.1/2 8/2 9 10 11 The elaboration of a use_clause has no effect. the scope of a use_clause in the private part of a library unit does not include the visible part of any public descendant of that library unit. a use_type_clause achieves direct visibility of the primitive operators of a type. For each package named in a use_package_clause whose scope encloses a place. Syntax 1 use_clause ::= use_package_clause | use_type_clause use_package_clause ::= use package_name {. For a use_clause within a context_clause of a body. 13 14 171 10 November 2006 Use Clauses 8.Calendar.

package. Alternatively.5 Renaming Declarations 1 A renaming_declaration declares another name for an entity. | defining_identifier : access_definition renames object_name. Syntax 2/2 object_renaming_declaration ::= defining_identifier : [null_exclusion] subtype_mark renames object_name.Rational := 2/3. However. If the anonymous access type is an access-to-object type. a single task or protected object cannot be renamed since the corresponding type is anonymous (meaning it has no nameable subtypes). 10 A task or protected object that is declared by an explicit object_declaration can be renamed as an object. to an anonymous access type.1 Object Renaming Declarations 1 An object_renaming_declaration is used to rename an object. 8. Renaming with a different identifier or operator_symbol does not hide the old name. the new name and the old name need not be visible at the same places. 11 A subtype defined without any additional constraint can be used to achieve the effect of renaming another subtype (including a task or protected subtype) as in 4 5 6 7 subtype Mode is Ada. a subprogram_renaming_declaration can be the completion of a previous subprogram_declaration. Legality Rules 4 The renamed entity shall be an object. 8. -. For similar reasons.4 Use Clauses 10 November 2006 172 . the type of the object_name shall have the same designated type as that of the access_definition. subprogram. If the anonymous access type is an access-to-subprogram type.ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 15 16 Example of a use type clause: use type Rational_Numbers.Text_IO.File_Mode. entry. an object of an anonymous array or access type cannot be renamed.see 7. or in the case where the type is defined by an access_definition.1 Two_Thirds: Rational_Numbers. Syntax 2 renaming_declaration ::= object_renaming_declaration | exception_renaming_declaration | package_renaming_declaration | subprogram_renaming_declaration | generic_renaming_declaration Dynamic Semantics 3 The elaboration of a renaming_declaration evaluates the name that follows the reserved word renames and thereby determines the view and entity denoted by this name (the renamed view and renamed entity). Name Resolution Rules 3/2 The type of the object_name shall resolve to the type determined by the subtype_mark.Rational. NOTES 9 Renaming may be used to resolve name conflicts and to act as a shorthand. exception. A name that denotes the renaming_declaration denotes (a new view of) the renamed entity. the type of the object_name shall have a designated profile that is type conformant with that of the access_definition. such as an object. 8. or generic unit.5.

For an object_renaming_declaration with a null_exclusion or an access_definition that has a null_exclusion: • if the object_name denotes a generic formal object of a generic unit G.1 begin L. its value and whether or not it is a constant are unaffected. • otherwise. the type of the renamed object and the type defined by the access_definition: • shall both be access-to-object types with statically matching designated subtypes and with both or neither being access-to-constant types. these rules apply also in the private part of an instance of a generic unit.4/2 4.ISO/IEC 8652:2007(E) Ed. or the variable is constrained by its initial value.2/2 4. Thus.10.Age + 1.3/2 4. the properties of the renamed object are not affected by the renaming_declaration.1/2 4. or • shall both be access-to-subprogram types with subtype conformant designated profiles.see 3. Static Semantics 4. this rule applies also in the private part of an instance of a generic unit.5. The renamed entity shall not be a subcomponent that depends on discriminants of a variable whose nominal subtype is unconstrained.5/2 4. -. 3 173 10 November 2006 Object Renaming Declarations 8. Syntax 1 exception_renaming_declaration ::= defining_identifier : exception renames exception_name. 3 — Ada Reference Manual In the case where the type is defined by an access_definition. then the declaration of the formal object of G shall have a null_exclusion. In particular. Examples 6/2 Example of renaming an object: declare L : Person renames Leftmost_Person.1 . end. similarly.Age := L. A slice of an array shall not be renamed if this restriction disallows renaming of the array.5. the null exclusion or constraints that apply to an object are not affected by renaming (any constraint implied by the subtype_mark or access_definition of the object_renaming_declaration is ignored). In addition to the places where Legality Rules normally apply (see 12. Legality Rules 2 The renamed entity shall be an exception. and the object_renaming_declaration occurs within the body of G or within the body of a generic unit declared within the declarative region of G.2 Exception Renaming Declarations An exception_renaming_declaration is used to rename an exception.3). 7 8 8. the subtype of the object_name shall exclude null. its type shall not be a descendant of an untagged generic formal derived type. These rules also apply for a renaming that appears in the body of a generic unit. with the additional requirement that even if the nominal subtype of the variable is indefinite. unless this subtype is indefinite. In addition to the places where Legality Rules normally apply.6/2 5/2 An object_renaming_declaration declares a new view of the renamed object whose properties are identical to those of the renamed view.

If the package_name of a package_renaming_declaration denotes a limited view of a package P.5. -.ISO/IEC 8652:2007(E) Ed. 8.2 Exception Renaming Declarations 10 November 2006 174 .5. Syntax 2 package_renaming_declaration ::= package defining_program_unit_name renames package_name. Syntax 2/2 subprogram_renaming_declaration ::= [overriding_indicator] subprogram_specification renames callable_entity_name. Examples 5 6 Example of renaming an exception: EOF : exception renames Ada. Name Resolution Rules 3 The expected profile for the callable_entity_name is the profile given in the subprogram_specification. then a name that denotes the package_renaming_declaration shall occur only within the immediate scope of the renaming or the scope of a with_clause that mentions the package P or. A subprogram_renaming_declaration that is not a completion is called a renaming-as-declaration. and is used to rename a subprogram (possibly an enumeration literal) or an entry.4 Subprogram Renaming Declarations 1 A subprogram_renaming_declaration can serve as the completion of a subprogram_declaration.1/2 The renamed entity shall be a package.13 8. such a renaming_declaration is called a renaming-as-body. Examples 5 6 Example of renaming a package: package TM renames Table_Manager. a name that denotes the package_renaming_declaration denotes a limited view of the package (see 10.1. Static Semantics 4 4.End_Error. At places where the declaration of the limited view of the renamed package is visible.5. 8.see A. Legality Rules 3 3. the innermost library package enclosing P.IO_Exceptions. if P is a nested package.1).1/2 A package_renaming_declaration declares a new view of the renamed package. 3 — Ada Reference Manual Static Semantics 4 An exception_renaming_declaration declares a new view of the renamed exception.3 Package Renaming Declarations 1 A package_renaming_declaration is used to rename a package.

1/1 175 10 November 2006 Subprogram Renaming Declarations 8. In addition to the places where Legality Rules normally apply (see 12. parameter modes. 3 — Ada Reference Manual Legality Rules The profile of a renaming-as-declaration shall be mode-conformant with that of the renamed callable entity.9. while taking the formal parameter names and default_expressions from the profile given in the subprogram_renaming_declaration.3). the inherited or predefined subprogram is called. the profile shall be subtype-conformant with that of the renamed callable entity and the convention of the renamed subprogram shall not be Intrinsic. and the subprogram_renaming_declaration occurs within the body of a generic unit G or within the body of a generic unit declared within the declarative region of the generic unit G. For a parameter or result subtype of the subprogram_specification that has an explicit null_exclusion: • if the callable_entity_name denotes a generic formal subprogram of a generic unit G. then the body executed is that of the overriding declaration. if it is a function. even if the overriding declaration is not visible at the place of the renaming. The callable_entity_name of a renaming shall not denote a subprogram that requires overriding (see 3. this rule applies also in the private part of an instance of a generic unit. then it is a bounded error to call that subprogram. and the renaming renames the subprogram itself. then the corresponding parameter or result subtype of the formal subprogram of G shall have a null_exclusion. If the renaming-as-body completes that declaration before the subprogram it declares is frozen. the profile shall be mode-conformant with that of the renamed callable entity and the subprogram it declares takes its convention from the renamed subprogram. The profile of a renaming-as-body shall conform fully to that of the declaration it completes.1/2 5. or that the call results in infinite recursion. Possible consequences are that Program_Error or Storage_Error is raised.1/2 4. returns the value of the call.1/1 8 If a subprogram directly or indirectly renames itself. through one or more subprogram renaming declarations. never an entry.2/2 6 A renaming-as-declaration declares a new view of the renamed entity. The profile of this new view takes its subtypes. A name that denotes a formal parameter of the subprogram_specification is not allowed within the callable_entity_name. 8. • otherwise. and calling convention from the original profile of the callable entity. For a call on a renaming of a dispatching subprogram that is overridden.3). Static Semantics 4 4.2/2 4. The callable_entity_name of a renaming-as-body shall not denote an abstract subprogram. Bounded (Run-Time) Errors 7. none of whose subprograms has been frozen.5. A renaming-as-body is illegal if the declaration occurs before the subprogram whose declaration it completes is frozen. if the overriding occurred before the renaming. The new view is a function or procedure. the subtype of the corresponding parameter or result type of the renamed callable entity shall exclude null. the execution of the renaming-asbody is equivalent to the execution of a subprogram_body that simply calls the renamed subprogram with its formal parameters as the actual parameters and.ISO/IEC 8652:2007(E) Ed.3/2 5/1 5. Dynamic Semantics 7 For a call to a subprogram whose body is given as a renaming-as-body. otherwise. otherwise.4 .

-.1 17 18 19 20 21 Example of a subprogram renaming declaration with new parameter names: function "*" (X. -.1 Example of a subprogram renaming declaration with a new default expression: function Minimum(L : Link := Head) return Cell renames Min_Cell.ISO/IEC 8652:2007(E) Ed. 15 The primitiveness of a renaming-as-declaration is determined by its profile.5. as for any declaration of (a view of) a subprogram. nor in an asynchronous_select. | generic procedure defining_program_unit_name renames generic_procedure_name.6 for operator declarations. function Int_Plus (Left.see 4. An entry of a family can be renamed. primitiveness is not determined by the renamed view. | generic function defining_program_unit_name renames generic_function_name.Y : Vector) return Real renames Dot_Product. so the corresponding specifications cannot be written. -. function Next(X : Color) return Color renames Color'Succ. 14 Calls with the new name of a renamed entry are procedure_call_statements and are not allowed at places where the syntax requires an entry_call_statement in conditional_ and timed_entry_calls. function Rouge return Color renames Red. the new name is only allowed to appear in contexts that allow a procedure name. similarly. Right : Real ) return Real renames "+". the Count attribute is not available for the new name. Examples 13 14 15 16 9 10 11 12 Examples of subprogram renaming declarations: procedure My_Write(C : in Character) renames Pool(K). Static Semantics 4 A generic_renaming_declaration declares a new view of the renamed generic unit.5. and by where it occurs. 13 The operators of the root numeric types cannot be renamed because the types in the profile are anonymous.5 Generic Renaming Declarations 1 A generic_renaming_declaration is used to rename a generic unit. -.see 3.4 Subprogram Renaming Declarations 10 November 2006 176 . Right : Integer) return Integer renames "+".5. A function whose defining_designator is either an identifier or an operator_symbol can be renamed with either an identifier or an operator_symbol. but an entry family cannot be renamed as a whole. not a non-primitive renaming of a primitive subprogram. In order to perform a dispatching call.see 3. the subprogram name has to denote a primitive subprogram.1 function Rot return Color renames Red. the same holds for certain attributes. 8. such as Pos. function Rosso return Color renames Rouge. Legality Rules 3 The renamed entity shall be a generic unit of the corresponding kind. attribute_references that denote functions (such as references to Succ and Pred) can be renamed as functions. similarly.3 function Real_Plus(Left. Enumeration literals can be renamed as functions. for renaming as an operator.1 8. -.see 6.5. Syntax 2 generic_renaming_declaration ::= generic package defining_program_unit_name renames generic_package_name.Write. 3 — Ada Reference Manual NOTES 12 A procedure can only be renamed as a procedure. An entry can only be renamed as a procedure.see 6. the subprogram specification given in the renaming_declaration is subject to the rules given in 6.1.

Text_IO. • The expression of a case_statement. If a possible interpretation violates an overloading rule.3 determine the possible interpretations. and • for each usage name.10.6 The Context of Overload Resolution Because declarations can be overloaded. to which syntactic categories it belongs.5 4 5 6 7 8 9 10 11 12 13 14 . • A pragma_argument_association. and • for a complete context that is a declarative_item. • A declarative_item or declaration. there usually has to be exactly one acceptable interpretation of a construct that is a “complete context”. To be legal. An (overall) interpretation of a complete context embodies its meaning. Various rules for the matching of formal and actual parameters are overloading rules.see A. in most cases. those rules that specify an expected type or expected profile. Most type checking rules (rules that require a particular type. not counting inner complete contexts. Each of the following constructs is a complete context: • A context_item. • A statement.5. violations of non-overloading rules do not affect which interpretation is chosen. This clause describes how the possible interpretations resolve to the actual interpretation. whether or not it is a completion of a declaration. that is. Examples 5 Example of renaming a generic unit: generic package Enum_IO renames Ada. the place where the generic_renaming_declaration occurs may affect the legality of subsequent renamings and instantiations that denote the generic_renaming_declaration. it is assumed not to be the intended interpretation. or a particular class of types. and by which syntax rules. An acceptable interpretation is a possible interpretation that obeys the overloading rules. not including constituents of inner complete contexts: • for each constituent of the complete context. which view and which entity it denotes). or specify how a construct shall resolve or be interpreted. Certain rules of the language (the Name Resolution Rules) are considered “overloading rules”. in particular if the renamed generic unit is a library unit (see 10. The syntax rules of the language and the visibility rules given in 8. and includes the following information about the constituents of the complete context. Name Resolution Rules 1 2 3 Overload resolution is applied separately to each complete context.ISO/IEC 8652:2007(E) Ed. for example) are overloading rules. it is possible for an occurrence of a usage name to have more than one possible interpretation. not counting any nested complete contexts. instead. A possible interpretation is one that obeys the syntax rules and the visibility rules. On the other hand. and (if so) which declaration it completes. they cause the construct to be illegal.1). -. therefore.Enumeration_IO.1. some other possible interpretation is assumed to be the actual interpretation. 177 10 November 2006 Generic Renaming Declarations 8. 3 — Ada Reference Manual NOTES 16 Although the properties of the new view are the same as those of the renamed view. which declaration it denotes (and. ambiguity is disallowed.10 6 7 8.

then the type of the construct shall resolve to a type in that class or to a universal type that covers the class. universal literals. if there is exactly one. 25. then that one is chosen. or of the universal or class-wide type for a class. or when T is an anonymous access-to-subprogram type (see 3. but using the requirement that it be in the given class. then it denotes the current instance of the type (rather than the type itself).” means that the construct's interpretation says that it belongs to the syntactic category function_call. the current instance of a type is the object or value of the type that is associated with the execution that evaluates the usage name. in such cases. Legality Rules 27/2 When a construct is one that requires that its expected type be a single type in a given class. then it denotes the current instance of the generic unit (rather than the generic unit itself). the types considered for the construct during overload resolution. to an access-to-subprogram type whose designated profile is type-conformant with that of T. for example. • If a usage name appears within the declarative region of a generic_declaration (but not within its generic_formal_part) and it denotes that same generic_declaration. according to the type resolution rules given below. Each occurrence of a usage name denotes the declaration determined by its interpretation. 3 — Ada Reference Manual 15 The interpretation of a constituent of a complete context is determined from the overall interpretation of the complete context as a whole. Thus. the name shall resolve to the name of a callable entity whose profile is type conformant with the expected profile. excluding the construct itself. name.10) with designated type D. and anonymous access types: • If a construct is expected to be of any type in a class of types. dispatching operations. or: • • • • 16 17/2 18 19 20/2 21 22 23 24 25/2 to T'Class. In particular. The type resolution rules provide support for class-wide programming.ISO/IEC 8652:2007(E) Ed. the construct shall not be the operand of a type_conversion. A usage name that denotes a view also denotes the entity of that view. Furthermore. to an access-to-object type whose designated type is D'Class or is covered by D. • If the expected type for a construct is a specific type T. “interpreted as a function_call. such as in a subprogram_renaming_declaration. The expected type for a given expression. the Name Resolution Rules define an expected profile for a given name.3. or to a universal type that covers T. the context shall not be one that expects any type in some class that contains types of the given class.10). then the type of the construct shall resolve either to T.1/2 26 In certain contexts.6 The Context of Overload Resolution 10 November 2006 178 . A complete context shall have at least one acceptable interpretation. See also 12. This rule does not apply if the usage name appears within the subtype_mark of an access_definition for an access-to-object type. or within the subtype of a parameter or result of an access-to-subprogram type. except in the following cases: • If a usage name appears within the declarative region of a type_declaration and denotes that same type_declaration. if two acceptable interpretations of a constituent of a complete context differ only 28 29 8. in particular. or other construct determines. or when T is a specific anonymous access-to-object type (see 3. the type of the construct shall be determinable solely from the context in which the construct appears. It also denotes the view declared by its denoted declaration. There is a preference for the primitive operators (and ranges) of the root numeric types root_integer and root_real.

for example.6 . then that one overall acceptable interpretation is chosen. this does not mean that the usage name is necessarily legal since other requirements exist which are not considered for overload resolution. freezing rules. Similarly. whether an object is constant. For a complete context. but only if every acceptable interpretation of the pragma argument is as a name that statically denotes a callable entity. 3 — Ada Reference Manual in that one is for a primitive operator (or range) of the type root_integer or root_real. However. the interpretation using the primitive operator (or range) of the root numeric type is preferred. subtypes are not considered for overload resolution (the violation of a constraint does not make a program illegal but raises an exception during program execution). and so on.ISO/IEC 8652:2007(E) Ed. order of elaboration. NOTES 17 If a usage name has only one acceptable interpretation. and the other is not. A complete context other than a pragma_argument_association shall not be ambiguous. 30 31 32 33 34 179 10 November 2006 The Context of Overload Resolution 8. the fact that an expression is static. if there is exactly one overall acceptable interpretation where each constituent's interpretation is the same as or preferred (in the above sense) over those in all other overall acceptable interpretations. and all of the views declared by these declarations. Otherwise. A complete context that is a pragma_argument_association is allowed to be ambiguous (unless otherwise specified for the particular pragma). Such a name denotes all of the declarations determined by its interpretations. then it denotes the corresponding entity. mode and subtype conformance rules. the complete context is ambiguous.

.

which has a corresponding task_body. A task declaration may be a task_type_declaration. or a timed asynchronous select statement (see next item). • an abort statement. 10 11 9. in which case it declares a named task type. Static Semantics 1 2 3 4 5 6 7 8 The properties of a task are defined by a corresponding task declaration and task_body. a timed entry call or accept. 2/2 181 10 November 2006 Tasks and Synchronization 9 .ISO/IEC 8652:2007(E) Ed. NOTES 1 Concurrent task execution may be implemented on multicomputers. as well as declaring a named task object of that type. While ready. tasks proceed through various states. • a call on a protected subprogram of a protected object. The various forms of task interaction are described in this section. whenever an implementation can determine that the required semantic effects can be achieved when parts of the execution of a given task are performed by different physical processors acting in parallel. it may choose to perform them in this way. Each task represents a separate thread of control that proceeds independently and concurrently between the points where it interacts with other tasks. A task is initially inactive. providing exclusive read-write access. allowing for asynchronous communication with one or more other tasks using that same protected object. where a task stops what it is doing and begins execution at a different point in response to the completion of an entry call or the expiration of a delay. On the other hand. allowing for synchronous communication with that task. either of another task. or with interleaved execution on a single physical processor. alternatively. which together define a program unit called a task unit. upon activation. a task competes for the available execution resources that it requires to run. or concurrent read-only access to shared data. or of a protected object. it may be a single_task_declaration. presuming the access is properly synchronized through some other kind of task interaction. 3 — Ada Reference Manual Section 9: Tasks and Synchronization The execution of an Ada program consists of the execution of one or more tasks. • a timed operation. • an asynchronous transfer of control as part of an asynchronous select statement. and prior to its termination it is either blocked (as part of some task interaction) or ready to run. including a simple delay statement. multiprocessors. in which case it defines an anonymous task type. Syntax 1 task_type_declaration ::= task type defining_identifier [known_discriminant_part] [is [new interface_list with] task_definition]. Dynamic Semantics 9 Over time. • a call on an entry. allowing one task to cause the termination of another task.1 Task Units and Task Objects A task unit is declared by a task declaration. and include: • the activation and termination of a task. tasks can communicate indirectly by reading and updating (unprotected) shared variables. In addition.

together with the known_discriminant_part. which shall be a task_body. Static Semantics 9 A task_definition defines a task type and its first subtype.6/2 9.1 Task Units and Task Objects 10 November 2006 182 . 7 If a task_identifier appears at the end of a task_definition or task_body.4). Legality Rules 9. the task type inherits user-defined primitive subprograms from each progenitor type (see 3. If the first parameter of a primitive inherited subprogram is of the task type or an access parameter designating the task type.ISO/IEC 8652:2007(E) Ed. Legality Rules 8/2 This paragraph was deleted. if the first parameter of the subprogram is of the task type or is an access parameter designating the task type. whose profile is type conformant with the prefixed view profile of the inherited subprogram. For a task declaration with an interface_list. 3 — Ada Reference Manual single_task_declaration ::= task defining_identifier [is [new interface_list with] task_definition].4). it shall repeat the defining_identifier. and every task_body shall be the completion of some task declaration. task_definition ::= {task_item} 3/2 4 [ private {task_item}] end [task_identifier] 5/1 6 task_item ::= entry_declaration | aspect_clause task_body ::= task body defining_identifier is declarative_part begin handled_sequence_of_statements end [task_identifier].4/2 9.2/2 9. The optional list of task_items after the reserved word private is called the private part of the task unit. in the same way that a derived type inherits user-defined primitive subprograms from its progenitor types (see 3. the inherited subprogram is said to be implemented by the conforming task entry.9. and there is an entry_declaration for a single entry with the same identifier within the task declaration. if any. For a task declaration without a task_definition. Each interface_subtype_mark of an interface_list appearing within a task declaration shall denote a limited interface type that is not a protected interface. The first list of task_items of a task_definition.1/1 9. For each primitive subprogram inherited by the type declared by a task declaration.5/2 9.3/2 A task declaration requires a completion. is called the visible part of the task unit. a task_definition without task_items is assumed. The prefixed view profile of an explicitly declared primitive subprogram of a tagged task type shall not be type conformant with any entry of the task type. at most one of the following shall apply: 9.

or • the inherited subprogram is implemented by a single entry of the task type.4 entry Read (C : out Character). NOTES 2 Other than in an access_definition. end Server. If an application needs to store and exchange task identities. • An entry queue for each entry of the task object. end Keyboard_Driver.7/2 9. 3 — Ada Reference Manual • the inherited subprogram is overridden with a primitive subprogram of the task type. Assignment is available for such an access type as for any access type. if any. The execution of a task_body is invoked by the activation of a task of the corresponding type (see 9. any aspect_clauses and any per-object constraints associated with entry_declarations of the corresponding task_definition are elaborated in the given order. As part of the initialization of a task object. in which case its prefixed view profile shall be subtype conformant with that of the task entry. The elaboration of a task_body has no effect other than to establish that tasks of the type can from then on be activated without failing the Elaboration_Check.1. if the implementation supports the Systems Programming Annex. The elaboration of a task_definition creates the task type and its first subtype. Within a task unit.6). The content of a task object of a given task type includes: • The values of the discriminants of the task object. • A representation of the state of the associated task. Examples 10 11 12/1 13 14 15 16 17 18 19/2 20 21/2 Examples of declarations of task types: task type Server is entry Next_Work_Item(WI : in Work_Item).9. entry Write(C : in Character). 3 The notation of a selected_component can be used to denote a discriminant of a task (see 4. entry Shut_Down. The elaboration of a single_task_declaration also creates an object of an (anonymous) task type. the Identity attribute can be used for task identification (see C.1 . If neither applies. Dynamic Semantics 9. the name of a discriminant of the task type denotes the corresponding discriminant of the current instance of the unit.3).3). 22 23 24/2 183 10 November 2006 Task Units and Task Objects 9. task type Keyboard_Driver(ID : Keyboard_ID := New_ID) is new Serial_Device with -. these rules also apply in the private part of an instance of a generic unit. In addition to the places where Legality Rules normally apply (see 12.7. in which case the overriding subprogram shall be subtype conformant with the inherited subprogram and not abstract. it also includes the elaboration of the entry_declarations in the given order. Alternatively.2).9/2 The elaboration of a task declaration elaborates the task_definition.see 3. the inherited subprogram shall be a null procedure. rather than the first subtype of the corresponding task type (and thus the name cannot be used as a subtype_mark). 4 A task type is a limited type (see 7. and hence precludes use of assignment_statements and predefined equality operators.8/2 9. the name of a task unit within the declaration or body of the task unit denotes the current instance of the unit (see 8. it can do so by defining an access type designating the corresponding task objects and by using access values for identification purposes.5).1).ISO/IEC 8652:2007(E) Ed.

just prior to executing the statements of the handled_sequence_of_statements. Pool : array(1 . the activations are initiated within the context of the handled_sequence_of_statements (and its associated exception_handlers if any — see 11. 9. task User. prior to returning the new access value. it consists of the elaboration of the declarative_part of the task_body. Teletype : Keyboard_Driver(TTY_ID). for tasks that are part or coextensions of the object created by the evaluation of an allocator. The initial part of this execution is called the activation of the task. 2/2 All tasks that are part or coextensions of a single object that is not a stand-alone object are activated together. 3 — Ada Reference Manual 25 26 Examples of declarations of single tasks: task Controller is entry Request(Level)(D : Item). The task that created the new tasks and initiated their activations (the activator) is blocked until all of these activations complete (successfully or not). end. In particular. Once all of these activations are complete.2 Task Execution . entry Next_Action(A : out Parser_Action). if the activation of any of the tasks has failed (due to the propagation of an exception). Terminal : Keyboard := new Keyboard_Driver(Term_ID). For tasks that are part or coextensions of a single object that is not a stand-alone object.. 10) of Keyboard_Driver. prior to performing any other operation on the outermost object.ISO/IEC 8652:2007(E) Ed. or a coextension of one of these. For tasks that are part or coextensions of an object that is the result of a function call. A task object (which represents one task) can be a part of a stand-alone object.a family of entries 27 task Parser is entry Next_Lexeme(L : in Lexical_Element).2).1 Task Units and Task Objects 10 November 2006 184 4/2 5 . of an object created by an allocator. Should an exception be propagated by the elaboration of its declarative_part. 3/2 For the tasks of a given declarative region.Task Activation Dynamic Semantics 1 The execution of a task of a given task type consists of the execution of the corresponding task_body. -.2. Otherwise. the activation of the task is defined to have failed. 31 32 Example of access type designating task objects: type Keyboard is access Keyboard_Driver. as defined in 7. For a package without an explicit body or an explicit handled_sequence_of_statements. the activations are not initiated until after the function returns. Tasking_Error is raised in the activator. or of an anonymous object of a limited type. the activator proceeds with its 9. -. the activations are initiated as the last step of evaluating the allocator. end Controller.has no entries 28 29 30 Examples of task objects: Agent : Server. All tasks that are part or coextensions of any of the stand-alone objects created by the elaboration of object_declarations (or generic_associations of formal objects of mode in) of a single declarative region are activated together. and it becomes a completed task. an implicit body or an implicit null_statement is assumed. at the place at which it initiated the activations. activations are initiated after completing any initialization of the outermost object enclosing these tasks.

as follows: • If the task is created by the evaluation of an allocator for a given access type. C are activated together before the first statement . the task depends on the master of the outermost object of which it is a part (as determined by the accessibility level of that object — see 3.6. and (recursively) on any master of that task. NOTES 5 An entry of a task can be called before the task has been activated.8).1).6. 7 A task can become completed during its activation either because of an exception or because it is aborted (see 9. it depends on each master that includes this elaboration.10.1). end. The first step of finalizing a master (including a task_body) is to wait for the termination of any tasks dependent on the master.3 Task Dependence .ISO/IEC 8652:2007(E) Ed. the execution of any of these tasks need not await the end of the activation of the other tasks. -.Task Activation 9. the newly created tasks become terminated and are never activated. it is defined to depend on the task that executes the master.2 and 7.1/2 4 5 6/1 7/2 185 10 November 2006 Task Execution . A task is said to be terminated when any finalization of the task_body has been performed (see 7. as well as on any master whose execution includes that of the master of the outermost object. B.Termination of Tasks Dynamic Semantics Each task (other than an environment task — see 10.1). • If the task is created by the elaboration of an object_declaration. if a task depends on a given master. the open terminate_alternative is selected if and only if the following conditions are satisfied: • The task depends on some completed master. Furthermore. Completion of a task (and the corresponding task_body) can occur when the task is blocked at a select_statement with an open terminate_alternative (see 9. The task executing the master is blocked until all the dependents have terminated. Any tasks that are aborted prior to completing their activation are ignored when determining whether to raise Tasking_Error.2 .1). it depends on each master that includes the elaboration of the declaration of the ultimate ancestor of the given access type. B C : Server. 10 11 9.the tasks A. Any remaining finalization is then performed and the master is left. and 1 2 3 3. Should the task that created the new tasks never reach the point where it would initiate the activations (due to an abort or the raising of an exception).7. B : Server. A task is said to be completed when the execution of its corresponding task_body is completed. 3 — Ada Reference Manual execution normally. 6 If several tasks are activated together. Examples 6 7 8 9 Example of task activation: procedure P is A..elaborate the task objects A. • Otherwise.elaborate the task object C begin -.6.. -.2) depends on one or more masters (see 7.

the task considered becomes completed. -.ISO/IEC 8652:2007(E) Ed.all L : Local := new Server. -. end.3 Task Dependence .all (but not X.see 9. G : Global. -. 11 If two or more tasks are blocked on select_statements with open terminate_alternatives. B : Server. 10 The rules given for the collective completion of a group of tasks all blocked on select_statements with open terminate_alternatives ensure that the collective completion can occur only when there are no remaining active tasks that could call one of the tasks being collectively completed. 3 — Ada Reference Manual 8 • Each task that depends on the master considered is either already terminated or similarly blocked at a select_statement with an open terminate_alternative. 9 An object_renaming_declaration defines a new view of an existing entity and hence creates no further dependence. begin -.all C : Server. -.. B. 12 The completion of a task can occur due to any of the following: • • • • the raising of an exception during the elaboration of the declarative_part of the corresponding task_body.. their finalization actions proceed concurrently. and G. or can have subcomponents of a task type.activation of C G := X.activation of A and B declare type Local is access Server. -. the selection of an open terminate_alternative of a select_statement in the corresponding task_body. end. -. Creation of an object of such a type creates dependences according to the full type.all 9.Termination of Tasks 10 November 2006 186 .activation of X. and become completed collectively. together with all tasks that depend on the master considered that are not yet completed.1 A.all) .await termination of C and L. the abort of the task.. begin -. the completion of the handled_sequence_of_statements of the corresponding task_body. Examples 9 10 11 12 13 14 15 16 17 18 19 20 Example of task dependence: declare type Global is access Server.. NOTES 8 The full view of a limited private type can be a task type.await termination of A.both G and X designate the same task object . X : Global := new Server.activation of L. When both conditions are satisfied.

protected_definition ::= { protected_operation_declaration } 2/2 3/2 4 [ private { protected_element_declaration } ] end [protected_identifier] protected_operation_declaration ::= subprogram_declaration | entry_declaration | aspect_clause protected_element_declaration ::= protected_operation_declaration | component_declaration protected_body ::= protected body defining_identifier is { protected_operation_item } end [protected_identifier]. in which case it declares a named protected type. it may be a single_protected_declaration. together with the known_discriminant_part. which has a corresponding protected_body. The optional list of protected_element_declarations after the reserved word private is called the private part of the protected unit. if any. The list of protected_operation_declarations of a protected_definition. 3 — Ada Reference Manual 9. through calls on its visible protected operations. alternatively. is called the visible part of the protected unit. in which case it defines an anonymous protected type. 11/2 187 10 November 2006 Protected Units and Protected Objects 9. A protected unit is declared by a protected declaration. Static Semantics 10/2 A protected_definition defines a protected type and its first subtype. single_protected_declaration ::= protected defining_identifier is [new interface_list with] protected_definition. which can be protected subprograms or protected entries. as well as declaring a named protected object of that type. Legality Rules 9 This paragraph was deleted.4 . A protected declaration may be a protected_type_declaration.ISO/IEC 8652:2007(E) Ed. protected_operation_item ::= subprogram_declaration | subprogram_body | entry_body | aspect_clause 5/1 6 7 8/1 If a protected_identifier appears at the end of a protected_definition or protected_body. Syntax 1 protected_type_declaration ::= protected type defining_identifier [known_discriminant_part] is [new interface_list with] protected_definition. it shall repeat the defining_identifier.4 Protected Units and Protected Objects A protected object provides coordinated access to shared data.

If the first parameter of a primitive inherited subprogram is of the protected type or an access parameter designating the protected type.3/2 11.13/2 12 The elaboration of a protected declaration elaborates the protected_definition. Dynamic Semantics 11. the inherited subprogram is said to be implemented by the conforming protected subprogram or entry.4/2 11.8/2 11.4 Protected Units and Protected Objects 10 November 2006 188 .3). if the first parameter of the subprogram is of the protected type or is an access parameter designating the protected type. these rules also apply in the private part of an instance of a generic unit. and every protected_body shall be the completion of some protected declaration.10/2 11. the protected type inherits user-defined primitive subprograms from each progenitor type (see 3. The elaboration of a single_protected_declaration also creates an object of an (anonymous) protected type.2/2 A protected declaration requires a completion. in the same way that a derived type inherits userdefined primitive subprograms from its progenitor types (see 3. 3 — Ada Reference Manual 11. then the subprogram shall not implement any inherited subprogram. Legality Rules 11. then at the point of the declaration: • if the overriding_indicator is overriding. The prefixed view profile of an explicitly declared primitive subprogram of a tagged protected type shall not be type conformant with any protected operation of the protected type. the inherited subprogram shall be a null procedure. or • the inherited subprogram is implemented by a protected subprogram or single entry of the protected type.6/2 11. then the first parameter of the inherited subprogram shall be of mode out or in out.3).12/2 11.11/2 11. in which case its prefixed view profile shall be subtype conformant with that of the protected subprogram or entry.7/2 11.1/2 For a protected declaration with an interface_list. Each interface_subtype_mark of an interface_list appearing within a protected declaration shall denote a limited interface type that is not a task interface. If a protected subprogram declaration has an overriding_indicator.5/2 11.9/2 11. 13 9.4). • if the overriding_indicator is not overriding.4). In addition to the places where Legality Rules normally apply (see 12. then the subprogram shall implement an inherited subprogram. In addition to the places where Legality Rules normally apply (see 12. If an inherited subprogram is implemented by a protected procedure or an entry. If neither applies. these rules also apply in the private part of an instance of a generic unit.9. which shall be a protected_body. and there is a protected_operation_declaration for a protected subprogram or single entry with the same identifier within the protected declaration. whose profile is type conformant with the prefixed view profile of the inherited subprogram.ISO/IEC 8652:2007(E) Ed. The elaboration of a protected_definition creates the protected type and its first subtype. it also includes the elaboration of the component_declarations and protected_operation_declarations in the given order. at most one of the following shall apply: • the inherited subprogram is overridden with a primitive subprogram of the protected type. or an access-to-variable parameter. in which case the overriding subprogram shall be subtype conformant with the inherited subprogram and not abstract. For each primitive subprogram inherited by the type declared by a protected declaration.

rather than the first subtype of the corresponding protected type (and thus the name cannot be used as a subtype_mark). Otherwise. Program_Error is raised. 17 The declarations in the private part are only visible within the private part and the body of the protected unit. each call remaining on any entry queue of the object is removed from its queue and Program_Error is raised at the place of the corresponding entry_call_statement.4 . it can be acquired (as part of a protected action — see 9. or for exclusive read-write access.3). including (implicitly) an entry queue for each entry declared for the protected object. the call proceeds normally. The execution resource associated with a protected object has to be acquired to read or update any components of the protected object. protected body Resource is entry Seize when not Busy is begin Busy := True. which may leave a task queued forever.1/2 21/2 22 23/2 24 25 Example of declaration of protected type and corresponding body: protected type Resource is entry Seize. 16 The bodies of the protected operations given in the protected_body define the actions that take place upon calls to the protected operations.8) are elaborated. end Resource. the name of a discriminant of the protected type denotes the corresponding discriminant of the current instance of the unit. The content of an object of a given protected type includes: • The values of the components of the protected object. the name of the protected unit denotes the current instance of the unit (see 8. 26 27 28 29 189 10 November 2006 Protected Units and Protected Objects 9.6). end Resource. end Seize. 3 — Ada Reference Manual As part of the initialization of a protected object.1) either for concurrent read-only access. any per-object constraints (see 3. As the first step of the finalization of a protected object.1. procedure Release is begin Busy := False. Bounded (Run-Time) Errors 14 15 16 17 18 19 20 It is a bounded error to call an entry or subprogram of a protected object after that object is finalized.5). • A representation of the state of the execution resource associated with the protected object (one such resource is associated with each protected object). NOTES 13 Within the declaration or body of a protected unit other than in an access_definition. end Release.ISO/IEC 8652:2007(E) Ed. 15 A protected type is a limited type (see 7. procedure Release. The elaboration of a protected_body has no other effect than to establish that protected operations of the type can from then on be called without failing the Elaboration_Check.5. Examples 20. If the error is detected. Within a protected unit. private Busy : Boolean := False. and hence precludes use of assignment_statements and predefined equality operators. 14 A selected_component can be used to denote a discriminant of a protected object (see 4.

end Set_Component. and is determined by the operation name (or prefix) used in the call on the operation.4). end Shared_Array. procedure Set_Component(N : in Index. Calls on protected subprograms allow coordinated access to shared data objects. • If it is a selected_component that is not an expanded name. 9. • If the name or prefix is a dereference (implicit or explicit) of an access-to-protected-subprogram value. E : in Item).ISO/IEC 8652:2007(E) Ed. as follows: • If it is a direct_name or expanded name that denotes the declaration (or body) of the operation. Static Semantics 2 Any call on an entry or on a protected subprogram identifies a target object for the operation. then the target object is implicitly specified to be the current instance of the task or protected unit immediately enclosing the operation. such a call is defined to be an external call. 3 — Ada Reference Manual 30 31 Example of a single protected declaration and corresponding body: protected Shared_Array is -. Entry calls allow for blocking the caller until a given condition is satisfied (namely. 100) of Resource. 3 4 5 6 7 9. such a call is defined to be an internal call. • If the name or prefix denotes a subprogram_renaming_declaration. with a corresponding distinction between an internal requeue and an external requeue. and Item_Array are global types function Component (N : in Index) return Item. then the target object is determined by the prefix of the Access attribute_reference that produced the access value originally. 32 33 34 35 Examples of protected objects: Control Flags : Resource. and then communicating data or control information directly with another task or indirectly via a shared protected object. The target object is considered an implicit parameter to the operation. A corresponding definition of target object applies to a requeue_statement (see 9. then the target object is explicitly specified to be the task or protected object denoted by the prefix of the name. and the call is defined to be an external call. which is either a task (for an entry call) or a protected object (for an entry call or a protected subprogram call).4 Protected Units and Protected Objects 10 November 2006 190 .5 Intertask Communication 1 The primary means for intertask communication is provided by calls on entries and protected subprograms. then the target object is as determined by the name of the renamed entity.5. end Shared_Array. end Component. Item.3). procedure Set_Component(N : in Index.. E : in Item) is begin Table(N) := E.Index. private Table : Item_Array(Index) := (others => Null_Item). protected body Shared_Array is function Component(N : in Index) return Item is begin return Table(N). that the corresponding entry is open — see 9.5. : array(1 .

The following are defined to be potentially blocking operations: • a select_statement.1/2 Within the body of a protected operation. it is a bounded error to invoke an operation that is potentially blocking. Protected procedures provide exclusive read-write access to the data of a protected object.5. If the call is an external call. the evaluation of the name or prefix and of the parameter associations. Any call on a protected procedure or entry of a target protected object is defined to be an update to the object. and within an entry_body. the current instance is defined to be a variable (updating is permitted).5 . Dynamic Semantics 7. Within the body of a protected procedure (or a procedure declared immediately within a protected_body). or for exclusive read-write access otherwise.3). unless both actions are the result of a call on a protected function. This rule is expressible in terms of the execution resource associated with the protected object: • Starting a protected action on a protected object corresponds to acquiring the execution resource associated with the protected object. proceeds as for a normal subprogram call (see 6. 8 9 191 10 November 2006 Intertask Communication 9. A new protected action is not started on a protected object while another protected action on the same protected object is underway. its subcomponents may be read but not updated). If the call is an internal call (see 9. 8 9 9.4).5. Bounded (Run-Time) Errors 3 4 5 6 7 During a protected action.5).ISO/IEC 8652:2007(E) Ed. the entry queues (if any) of the protected object are serviced (see 9. A protected action can also be started by an entry call (see 9. the protected action completes after the body of the subprogram is executed.5.6) of the immediately enclosing protected unit is determined by the target object specified (implicitly or explicitly) in the call (or requeue) on the protected operation.3).1 Protected Subprograms and Protected Actions A protected subprogram is a subprogram declared immediately within a protected_definition. either for concurrent read-only access if the protected action is for a call on a protected function. then the body of the subprogram is executed as part of a new protected action on the target protected object. as is a requeue on such an entry. protected functions provide concurrent read-only access to the data. but prior to completing the associated protected action. Dynamic Semantics 2 For the execution of a call on a protected subprogram. • Completing the protected action corresponds to releasing the associated execution resource. the current instance (see 8. 3 — Ada Reference Manual Legality Rules The view of the target protected object associated with a call of a protected procedure or entry shall be a variable. and any assigning back of in out or out parameters. After performing an operation on a protected object other than a call on a protected function. the body of the subprogram is executed as for a normal subprogram call. the current instance of the enclosing protected unit is defined to be a constant (that is. Static Semantics 1 Within the body of a protected function (or a function declared immediately within a protected_body).

• an entry_call_statement. with the corresponding entry_bodies or accept_statements. an internal call on a protected subprogram. a language-defined subprogram is nonblocking. E). If the bounded error is detected. 19 The body of a protected unit may contain declarations and bodies for local subprograms. the body of a protected procedure can contain internal calls on both protected functions and procedures.1 Protected Subprograms and Protected Actions 10 November 2006 192 .Component(M). On the other hand. 22 The pragma Detect_Blocking may be used to ensure that all executions of potentially blocking operations during a protected action raise Program_Error. Other potentially blocking subprograms are identified where they are defined. • a delay_statement. 9.Release. Program_Error is raised. If not detected. • an external call on a protected subprogram (or an external requeue) with the same target object as that of the protected action.1/2 23 24 Examples of protected subprogram calls (see 9.ISO/IEC 8652:2007(E) Ed. and at most one is calling a protected function. Control. E := Shared_Array. • an abort_statement. 20 The body of a protected function can contain internal calls on other protected functions. There is no language-defined ordering or queuing presumed for tasks competing to start a protected action — on a multiprocessor such tasks might use busy-waiting. the subprograms of the language-defined input-output packages that manipulate files (implicitly or explicitly) are potentially blocking. 9. 21 From within a protected action. 3 — Ada Reference Manual 10 11 12 13 14 15 • an accept_statement. and it might be consuming processing resources while it awaits its turn. are used to define potentially queued operations on tasks and protected objects. then only one of the tasks can proceed.Set_Component(N. When not specified as potentially blocking.4): Shared_Array. In particular.3.5. but not protected procedures. or an external call on a protected subprogram with a different target object is not considered a potentially blocking operation.2 Entries and Accept Statements 1 Entry_declarations.5. • a call on a subprogram whose body contains a potentially blocking operation. Syntax 2/2 entry_declaration ::= [overriding_indicator] entry defining_identifier [(discrete_subtype_definition)] parameter_profile. NOTES 18 If two tasks both try to start a protected action on a protected object. Although the other task cannot proceed. because the current instance is a constant. see D. These are not visible outside the protected unit. Examples 16 17 18 19 20 21 22 22. it is not considered blocked.5. Certain language-defined subprograms are potentially blocking. for monoprocessor considerations. the bounded error might result in deadlock or a (nested) protected action on the same target object. “Priority Ceiling Locking”. • task creation or activation. See H.

4/2 14 193 10 November 2006 Entries and Accept Statements 9.3). If an entry_declaration has an overriding_indicator.2/2 13.1. and the selected_component is interpreted as an expanded name (see 4. If an entry_identifier appears at the end of an entry_body. entry_body_formal_part ::= [(entry_index_specification)] parameter_profile entry_barrier ::= when condition entry_index_specification ::= for defining_identifier in discrete_subtype_definition 6 7 8 9 If an entry_identifier appears at the end of an accept_statement.2 . Name Resolution Rules 10 10.10).1/2 In an accept_statement. For an accept_statement. then the entry shall not implement any inherited subprogram. An entry_declaration is allowed only in a protected or task declaration. 3 — Ada Reference Manual accept_statement ::= accept entry_direct_name [(entry_index)] parameter_profile [do handled_sequence_of_statements end [entry_identifier]]. • if the overriding_indicator is not overriding. it shall repeat the defining_identifier. entry_index ::= expression entry_body ::= entry defining_identifier entry_body_formal_part entry_barrier is declarative_part 3 4 5 begin handled_sequence_of_statements end [entry_identifier]. the expected profile for the entry_direct_name is that of the entry_declaration. Within the handled_sequence_of_statements of an accept_statement. the expected type for an entry_index is that of the subtype defined by the discrete_subtype_definition of the corresponding entry_declaration.ISO/IEC 8652:2007(E) Ed. An overriding_indicator is not allowed in an entry_declaration that includes a discrete_subtype_definition. then the entry shall implement an inherited subprogram. if a selected_component has a prefix that denotes the corresponding entry_declaration.3/2 13. and the entry_direct_name shall denote an entry_declaration in the corresponding task declaration. the innermost enclosing body shall be a task_body. then at the point of the declaration: • if the overriding_indicator is overriding. then the entity denoted by the prefix is the accept_statement. it shall repeat the entry_direct_name. the profile of the accept_statement shall conform fully to that of the corresponding entry_declaration.1/2 13.3). the selector_name of the selected_component has to be the identifier for some formal parameter of the accept_statement. these rules also apply in the private part of an instance of a generic unit. An accept_statement shall 13 13. Legality Rules 11 12 An entry_declaration in a task declaration shall not contain a specification for an access parameter (see 3.5. In addition to the places where Legality Rules normally apply (see 12.

After a rendezvous.5. the entry_index_specification declares a named constant whose subtype is the entry index subtype defined by the corresponding entry_declaration. Further execution of the accept_statement is then blocked until a caller of the corresponding entry is selected (see 9. is first evaluated and converted to the entry index subtype. Static Semantics 16 17 18 19 The parameter modes defined for parameters in the parameter_profile of an entry_declaration are the same as for a subprogram_declaration and have the same meaning (see 6. When an exception is propagated from the handled_sequence_of_statements of an accept_statement. In this case.3). The actions to be performed when an entry is called are specified by the corresponding accept_statements (if any) for an entry of a task unit. with one such entry for each value of the entry index subtype defined by the discrete_subtype_definition. Dynamic Semantics 20 21 22/1 The elaboration of an entry_declaration for an entry family consists of the elaboration of the discrete_subtype_definition.5. 15 An accept_statement shall not be within another accept_statement that corresponds to the same entry_declaration. A name that denotes a formal parameter of an entry_body is not allowed within the entry_barrier of the entry_body. In the entry_body for an entry family. 3 — Ada Reference Manual have a parenthesized entry_index if and only if the corresponding entry_declaration has a discrete_subtype_definition.2). 23 24 25 9. which shall be an entry_body. An entry_declaration of a protected unit requires a completion. The elaboration of an entry_declaration for a single entry has no effect. An entry_declaration with a discrete_subtype_definition (see 3. as described in 3. the discrete_subtype_definitions of the entry_declaration and the entry_index_specification shall fully conform to one another (see 6.1). the accept_statement completes and is left. The profile of the entry_body shall conform fully to that of the corresponding declaration. nor within an asynchronous_select inner to the enclosing task_body. A name for an entry of a family takes the form of an indexed_component. For the execution of an accept_statement. and the index value identifies the entry within the family. the same exception is also raised by the execution of the corresponding entry_call_statement. if any. The term single entry is used to refer to any entry other than an entry of an entry family. the entry_index. Upon completion of the handled_sequence_of_statements. this index value identifies which entry of the family is to be accepted.6) declares a family of distinct entries having the same profile.2 Entries and Accept Statements 10 November 2006 194 . and by the corresponding entry_body for an entry of a protected unit. with the formal parameters associated with the corresponding actual parameters of the selected entry call. An entry_body_formal_part shall have an entry_index_specification if and only if the corresponding entry_declaration has a discrete_subtype_definition. of the accept_statement is executed. whereupon the handled_sequence_of_statements. and every entry_body shall be the completion of an entry_declaration of a protected unit. where the prefix denotes the entry_declaration for the family. The above interaction between a calling task and an accepting task is called a rendezvous.3.8. if any. the value of the named entry index identifies which entry of the family was called. the two tasks continue their execution independently.ISO/IEC 8652:2007(E) Ed.

4). the declarative_part of the entry_body is elaborated. The value of the named entry index. A simple entry call is a standalone statement that represents an unconditional call on an entry of a target task or a protected object. and data global to the protected unit. -. the components (including discriminants) of the protected object.5. or entry of the corresponding entry family. NOTES 23 A task entry has corresponding accept_statements (zero or more). Entry calls can also appear as part of select_statements (see 9.4 and 6. Syntax 1 entry_call_statement ::= entry_name [actual_parameter_part].7). if any. 34 35 36 37 9. accept Request(Low)(D : Item) do . entry Request(Level)(D : Item).4. and the handled_sequence_of_statements of the body is executed.5..3 Entry Calls An entry_call_statement (an entry call) can appear in various contexts. 3 — Ada Reference Manual An entry_body is executed when the condition of the entry_barrier evaluates to True and a caller of the corresponding single entry. Name Resolution Rules 2 The entry_name given in an entry_call_statement shall resolve to denote an entry. Examples 26 27 28 29/2 30 31 Examples of entry declarations: entry Read(V : out Item). This includes the entry index (if any). whereas a protected entry has a corresponding entry_body (exactly one). the entry_barrier can be “when True” and the caller can be requeued (on some private entry) when its parameters indicate that it cannot be handled immediately.3).4) may be used to complete the execution of an accept_statement or an entry_body. 26 The condition in the entry_barrier may reference anything visible except the formal parameters of the entry.5) or a requeue_statement (see 9. end Read. For the execution of the entry_body. 3 195 10 November 2006 Entries and Accept Statements 9.5. entry Seize..1). The restriction against referencing the formal parameters within an entry_barrier ensures that all calls of the same entry see the same barrier value. 25 A return statement (see 6. is determined by the value of the entry index specified in the entry_name of the selected entry call (or intermediate requeue_statement — see 9. 24 A consequence of the rule regarding the allowed placements of accept_statements is that a task can execute accept_statements only for its own entries. The rules for parameter associations are the same as for subprogram calls (see 6. the Count attribute of an entry of that protected object. end Request.5.2 . has been selected (see 9.a family of entries 32 33 Examples of accept statements: accept Shut_Down. accept Read(V : out Item) do V := Local_Item.5.ISO/IEC 8652:2007(E) Ed. If it is necessary to look at the parameters of an entry call before deciding whether to handle it. as for the execution of a subprogram_body.

1) with an open accept_alternative that corresponds to the entry.3 Entry Calls 10 November 2006 196 .1). • An entry of a protected object is open if the condition of the entry_barrier of the corresponding entry_body evaluates to True. otherwise it is closed. The default entry queuing policy is to select calls on a given entry queue in order of arrival. any necessary assigning back of formal to actual parameters occurs. then one such call is selected according to the entry queuing policy in effect (see below).5). the exception Program_Error is propagated to all current callers of all entries of the protected object. If there is at least one call on a queue corresponding to an open entry. the accepting task becomes ready and continues the execution of the corresponding accept_statement (see 9. 6 7 8 9 10 11 12 13 14 15 16 17 9.ISO/IEC 8652:2007(E) Ed. If calls from two or more queues are simultaneously eligible for selection. and the execution of the call proceeds as follows: • For a call on an open entry of a task. If the evaluation of the condition propagates an exception. an entry of a task or protected object is checked to see whether it is open or closed: • An entry of a task is open if the task is blocked on an accept_statement that corresponds to the entry (see 9. the default entry queuing policy does not specify which queue is serviced first. The named entry is checked to see if it is open. otherwise it is closed. 3 — Ada Reference Manual Static Semantics 4 The entry_name of an entry_call_statement specifies (explicitly or implicitly) the target object of the call. for a call on a protected entry).2). and the corresponding accept_statement or entry_body is executed as above for an entry call that is selected immediately. an operation on the object other than a call on a protected function.4).5. The entry queuing policy controls selection among queued calls both for task and protected entry queues. • If after performing.5. as for a subprogram call (see 6. if open. the entry is checked and found to be open. as part of a protected action on the associated protected object. Dynamic Semantics 5 Under certain circumstances (detailed below). there is a separate (logical) entry queue for each entry of a given task or protected object (including each entry of an entry family). If the accept_statement or entry_body completes other than by a requeue (see 9. Other entry queuing policies can be specified by pragmas (see D.5. • For a call on an open entry of a protected object. evaluation of the name and of the parameter associations is as for a subprogram call (see 6.5. the entry call is added to an entry queue (as part of the protected action.2) as part of the protected action. For the execution of an entry_call_statement. or on a selective_accept (see 9. Selecting a queued call from a particular entry queue is called servicing the entry queue.1). return is made to the caller (after servicing the entry queues — see below). When a queued call is selected. if any (see 9.5. it is removed from its entry queue.4). a new protected action is started on the object (see 9. and the call remains queued until it is selected or cancelled. The entry call is then issued: For a call on an entry of a protected object. or a selective_accept with a corresponding open accept_alternative. If the named entry is closed.2).4). the entry or entry family.7. the entry call is said to be selected immediately. such assignments take place outside of any protected action. and the entry index. An entry with queued calls can be serviced under the following circumstances: • When the associated task reaches a corresponding accept_statement. the corresponding entry_body is executed (see 9.5.4.

similarly. it need not be that of the task that started the protected action. 29 In addition to simple entry calls.8). The cancellation of a call on an entry of a protected object is a protected action.7.7.4). an implementation need not reevaluate the condition if nothing it references was updated by an intervening protected action on the protected object. 3 — Ada Reference Manual For a protected object. even if this might allow the entry call to be selected in the interim. it may use the thread of control of the caller itself to attempt the cancellation. it includes servicing of the entry queues (in case some entry barrier depends on a Count attribute). 30 The condition of an entry_barrier is allowed to be evaluated by an implementation more often than strictly necessary. 22 23 24 25 26 27 28 29 197 10 November 2006 Entry Calls 9. the calling task is blocked during a rendezvous. 9. the implementation need not reevaluate the condition of the corresponding entry_barrier if no variable or attribute referenced by the condition (directly or indirectly) has been altered by the execution (or cancellation) of a protected procedure or entry call on the object since the condition was last evaluated. then the corresponding calling task may be made ready without waiting for the entire protected action to complete. the entry is checked to see if it is open prior to queuing the call. A call on an entry of a task that has already completed its execution raises the exception Tasking_Error at the point of the call. or the call is selected and a corresponding accept_statement or entry_body completes without requeuing.7. 9.3. the implementation need not make the attempt using the thread of control of the task (or interrupt) that initiated the cancellation.8) and as part of certain forms of select_statement (see 9.7.4). An attempt can be made to cancel an entry call upon an abort (see 9. and 9. in particular. If an entry_body completes without requeuing.4).7.2. it is propagated to the corresponding caller (see 11. An implementation may evaluate the conditions of all entry_barriers of a given protected object any time any entry of the object is checked to see if it is open. the above servicing of entry queues continues until there are no open entries with queued calls. Implementation Permissions 18 19 20 21 An implementation may perform the sequence of steps of a protected action using any thread of control. and see 9.3 . Like any protected action.4). 28 For a call on a protected entry. This applies equally to a simple entry call and to an entry call as part of a select_statement. conditional. When an attempt is made to cancel an entry call.9) is referenced in some entry barrier. at which point the protected action completes. When the entry of a protected object is checked to see whether it is open. On the other hand.3. even if the evaluation might have side effects.5. and that is not the triggering_statement of an asynchronous_select (see 9. and asynchronous entry calls (see 9.2.5. even if the condition references some global variable that might have been updated by an action performed from outside of a protected action.7. and again thereafter if its Count attribute (see 9. the calling task is blocked until the call is cancelled. NOTES 27 If an exception is raised during the execution of an entry_body. In addition. and not protected from cancellation as part of a requeue (see 9. at such a point.7. this exception is raised at the point of the call if the called task completes its execution or becomes abnormal before accepting the call or completing the rendezvous (see 9. For an entry call that is added to a queue. and as such cannot take place while any other protected action is occurring on the protected object. The cancellation does not take place until a point (if any) when the call is on some entry queue. the language permits timed. the call is removed from the entry queue and the call completes due to the cancellation.4).ISO/IEC 8652:2007(E) Ed.

and this construct shall be the innermost enclosing body or callable construct. In a requeue_statement of an accept_statement of some task unit. The entry_body or accept_statement enclosing the requeue_statement is then completed.4 Requeue Statements 1 A requeue_statement can be used to complete an accept_statement or entry_body. either the target object shall be a part of a formal parameter of the accept_statement. the named entry is checked to see if it is open and the requeued call is either selected immediately or queued.1) with the profile of the innermost enclosing entry_body or accept_statement. after leaving the enclosing callable construct: • if the requeue is an internal requeue (that is. then its profile shall be subtype conformant with the profile of the innermost enclosing callable construct. finalized.5.Request(Low)(Some_Item).5). If the target entry has parameters. after leaving the enclosing callable construct. the requeue is back on an entry of the same protected object — see 9. including the prefix identifying the target task or protected object and the expression identifying the entry within an entry family. For the execution of a requeue on an entry of a target protected object. the call is added to the queue of the named entry and the ongoing protected action continues (see 9. while redirecting the corresponding entry call to a new (or the same) entry queue. For the execution of a requeue on an entry of a target task. Flags(3). Controller. and left (see 7. or that has a profile that is type conformant (see 6.5.1 see 9.3). Legality Rules 4 A requeue_statement shall be within a callable construct that is either an entry_body or an accept_statement. In a requeue_statement of an entry_body of some protected unit. Pool(5).6.Shut_Down. -----see 9. Dynamic Semantics 5 6 7 The execution of a requeue_statement proceeds by first evaluating the entry_name. due to an abort or the expiration of a delay. Syntax 2 requeue_statement ::= requeue entry_name [with abort].5.1).Read(Next_Char). either the target object shall be a part of a formal parameter of the entry_body.5.1 see 9. 3 — Ada Reference Manual Examples 30 31 Examples of entry calls: Agent.4 9.Seize. or the accessibility level of the target object shall not be statically deeper than that of the entry_declaration. 8 9 10 9. if any. Name Resolution Rules 3 The entry_name of a requeue_statement shall resolve to denote an entry (the target entry) that either has no parameters.1). Parser. or the accessibility level of the target object shall not be equal to or statically deeper than any enclosing accept_statement of the task unit.1 see 9.1 see 9.ISO/IEC 8652:2007(E) Ed. as for a normal entry call (see 9. Such a requeue can be performed with or without allowing an intermediate cancellation of the call.3.3 Entry Calls 10 November 2006 198 .Next_Lexeme(E).

In any case. 3 — Ada Reference Manual • if the requeue is an external requeue (that is.6 Delay Statements. -. -. then: • if the original entry call has been aborted (see 9.ISO/IEC 8652:2007(E) Ed.4 . or in seconds from the current time (in a delay_relative_statement). The expiration time can be specified either as a particular point in time (in a delay_until_statement).5. if any.Seize. any parameter passing is implicit. Legality Rules 5 There can be multiple time bases. plays no part in the subtype conformance check between the profiles of the two entries. Syntax 1 delay_statement ::= delay_until_statement | delay_relative_statement delay_until_statement ::= delay until delay_expression. and Time A delay_statement is used to block further execution until a specified expiration time is reached.1 requeue Flags(I). and the call is cancelled and no requeue is performed. the formal parameters denote the same objects as did the corresponding formal parameters of the callable construct completed by the requeue. then the original expiration time is the expiration time for the requeued call.3).5. see 9. If the reserved words with abort do not appear. NOTES 31 A requeue is permitted from a single entry to an entry of an entry family. The language-defined package Calendar provides definitions for a type Time and associated operations. the target protected object is not implicitly the same as the current object — see 9. an entry index is part of the entry_name for an entry of a family. If the requeue_statement includes the reserved words with abort (it is a requeue-with-abort). and a corresponding time type. a protected action is started on the target object and proceeds as for a normal entry call (see 9.5). The entry index. The type of the delay_expression in a delay_until_statement shall be a time type — either the type Time 6 199 10 November 2006 Requeue Statements 9.requeue on a member of an entry family of the current task.8). or vice-versa. • if the original entry call was timed (or conditional). delay_relative_statement ::= delay delay_expression. then during the execution of the accept_statement or entry_body corresponding to the new entry. no parameters are specified in a requeue_statement. including a function Clock that returns the current time.4 18 19 20 9. see 9. Examples 11 12 13 14 15 16 17 Examples of requeue statements: requeue Request(Medium) with abort. each with a corresponding clock. The delay_expression in a delay_until_statement is expected to be of any nonlimited type. then the requeue acts as an abort completion point for the call.requeue on an entry of an array component. Name Resolution Rules 2 3 4 The expected type for the delay_expression in a delay_relative_statement is the predefined type Duration. If the new entry named in the requeue_statement has formal parameters. Duration. then the call remains protected against cancellation while queued as the result of the requeue_statement.

“Delay Accuracy” or is implementation defined. and then rounded up to the next clock tick. in the time base associated with relative delays. "<="(Left. -. Month_Number. function function function function function function function function "+" "+" "-" "-" (Left (Left (Left (Left : : : : in Time. ">" (Left. or of some other implementation-defined time type. : Time) return Time. Boolean. the expiration time for the delay is the value of the delay_expression.0) Duration) return Time.not specified by the language end Ada. ">="(Left.Calendar is type Time is private. For a delay_relative_statement. 9. the expiration time is defined as the current time. Year_Number.8). 31. 15 16 Time. return return return return 18 19 Time_Error : exception. The time base associated with relative delays is as defined in D. Static Semantics 7 There is a predefined fixed point type named Duration.. and Time 10 November 2006 200 . represents a time as reported by a corresponding clock. : Day_Duration := 0. in the time base associated with the type of the expression.. Day_Duration. 3 — Ada Reference Manual defined in the language-defined package Calendar (see below). The type Duration is not specific to a particular time base.6 Delay Statements.. the delay_expression is first evaluated. Right : Duration. expressed in seconds. Day_Number. plus the value of the delay_expression converted to the type Duration. Right : Time. 86_400.Calendar. Duration) return Time. 12 13 function Clock return Time. For a delay_until_statement. : out Month_Number. 12. Duration.0 Time) Time) Time) Time) return return return return . private . a value of type Duration is used to represent the length of an interval of time. 8 9 10 11/2 subtype subtype subtype subtype function function function function Year_Number Month_Number Day_Number Day_Duration Year (Date Month (Date Day (Date Seconds(Date is is is is : : : : Integer range 1901 Integer range 1 .. Boolean. A value of the type Time in package Calendar. : out Day_Duration). Time) return Duration. Right Time. Boolean.9.ISO/IEC 8652:2007(E) Ed. The following language-defined library package exists: package Ada. 2399.0. : out Day_Number. : out Year_Number. or some other implementation-defined time type (see D. but can be used with any time base. Year_Number. Duration range 0. Boolean. Dynamic Semantics 20 For the execution of a delay_statement. Right : Right Right Right Right : : : : Time) Time) Time) Time) 17 "<" (Left. declared in the visible part of package Standard. 14 procedure Split (Date : Year Month Day Seconds function Time_Of(Year : Month Day Seconds return Time.. Integer range 1 . : Day_Number. .. : Month_Number.

and the relational operators for times.4 and 9. a month number. and a duration. Duration'Small shall not be greater than twenty milliseconds.ISO/IEC 8652:2007(E) Ed.6 . Implementation Permissions 27 An implementation may define additional time types (see D. a day number.8). at which point it becomes ready again. Implementation Requirements 21 22 23 24/2 25 26/1 The implementation of the type Duration shall allow representation of time intervals (both positive and negative) up to at least 86400 seconds (one day). The functions Year. The function Clock of package Calendar returns a value representing the current time for this time base.0. the task is not blocked. The time base associated with the type Time of package Calendar is implementation defined. The value returned by the function Seconds or through the Seconds parameter of the procedure Split is always less than 86_400. thereby completing the delay_statement.Clock. The operators "+" and "–" for addition and subtraction of times and durations. if any. into a value of type Time.Clock remains constant. the _statement is cancelled if the expiration time has not yet passed. Implementation Advice 28 29 Whenever possible in an implementation. have the conventional meaning. it may allow representation of other dates as well (both earlier and later). NOTES 32 A delay_relative_statement with a negative value of the delay_expression is equivalent to one with a zero value. The time base for delay_relative_statements should be monotonic. the value of Duration'Small should be no greater than 100 microseconds. The exception Time_Error is raised by the function Time_Of if the actual parameters do not form a proper date. The actual limit. The implementation-defined value of the named number System. it need not be the same time base as used for Calendar. and Seconds and the procedure Split if the year number of the given date is outside of the range of the subtype Year_Number.0. Month. 3 — Ada Reference Manual The task executing a delay_statement is blocked until the expiration time is reached. Month. the procedure Split returns all four corresponding values.0. the value returned is equal to the value of Time_Of for the next day with a seconds value of 0. Day. This exception is also raised by the operators "+" and "–" if the result is not representable in the type Time or Duration.8). and Seconds return the corresponding values for a given value of the type Time. If an attempt is made to cancel the delay_statement (as part of an asynchronous_select or abort — see 9. An implementation may raise Time_Error if the value of a delay_expression in a delay_until_statement of a select_statement represents a time more than 90 days past the current time. and Time 9. as appropriate to an implementation-defined time zone. The implementation of the type Time shall allow representation of all dates with year numbers in the range of Year_Number. If the expiration time has already passed. Duration.7. as appropriate. 30 31 32 201 10 November 2006 Delay Statements. is implementation-defined.7) is an approximation of the length of the real-time interval during which the value of Calendar.Tick (see 13. This exception is also raised by the functions Year. the function Time_Of combines a year number. Day. Conversely. If Time_Of is called with a seconds value of 86_400.

“Delay Accuracy”. Time Zones. . end loop. consequently delay_statements may be executed as part of the elaboration of a library_item or the execution of the main subprogram. 34 A delay_statement is an abort completion point and a potentially blocking operation.Time zone manipulation: type Time_Offset is range -28*60 . and Time 10 November 2006 202 . end. even if the task is not actually blocked. 36 Additional requirements associated with delay_statements are given in D. function function function function "+" "+" "-" "-" (Left : Time.Time_Zones is -. 35 There is no necessary relationship between System. end Ada. 28*60.Calendar. Right : Time) return Day_Count.Year_Number'First). Examples 34 35 36 37 38 39 40 Example of a relative delay statement: delay 3.Arithmetic on days: type Day_Count is range -366*(1+Year_Number'Last .0 seconds Example of a periodic task: declare use Ada.. procedure Difference (Left.Calendar. Right : Day_Count) return Time.Period is a global constant of type Duration begin loop -. Right : in Time. 9.Calendar. 11/2 12/2 13/2 9.6 Delay Statements...perform some actions Next_Time := Next_Time + Period. (Left. Duration. 366*(1+Year_Number'Last .Arithmetic is 9/2 10/2 -. Right : Day_Count) return Time. Days : out Day_Count.delay 3. Right : Time) return Time. 3 — Ada Reference Manual 33 33 A delay_statement may be executed by the environment task.Tick (the resolution of the clock of package Calendar) and Duration'Small (the small of type Duration). (Left : Time. -.Time_Zones. Next_Time : Time := Clock + Period. 2047.1 Formatting.2). and other operations for Time Static Semantics 1/2 2/2 3/2 4/2 5/2 6/2 7/2 8/2 The following language-defined library packages exist: package Ada. -. package Ada. subtype Leap_Seconds_Count is Integer range -2047 . function UTC_Time_Offset (Date : Time := Clock) return Time_Offset. Seconds : out Duration.6.Year_Number'First) . Leap_Seconds : out Leap_Seconds_Count).repeated every Period seconds delay until Next_Time. -.0.9. Unknown_Zone_Error : exception.Calendar. Such statements delay the environment task (see 10.ISO/IEC 8652:2007(E) Ed. (Left : Day_Count...

function Day_of_Week (Date : Time) return Day_Name. 29/2 function Time_Of (Year : Year_Number.0 . Natural range 0 . package Ada. procedure Split (Seconds Hour Minute Second Sub_Second : : : : : in Day_Duration. 59. out Second_Number.. out Minute_Number. (Date : Time) return Second_Number. Time_Zone : Time_Zones.Calendar. 59.Time_Offset := 0) return Hour_Number. (Date : Time. with Ada. (Date : Time.0. Hour : Hour_Number. Day : Day_Number. Thursday. Minute : Minute_Number. function Seconds_Of (Hour : Hour_Number. Tuesday. Sunday). Minute : Minute_Number. 1.Calendar.Time_Offset := 0) return Day_Number. Day : Day_Number.Time_Offset := 0) return Month_Number...Formatting is -. Second : Second_Number. Saturday. Month : Month_Number. Second : Second_Number := 0.6. 21/2 function Month 22/2 function Day 23/2 function Hour 24/2 function Minute 25/2 function Second 26/2 27/2 28/2 function Sub_Second (Date : Time) return Second_Duration. function Time_Of (Year : Year_Number. Seconds : Day_Duration := 0. Sub_Second : Second_Duration := 0. Friday.Calendar.Arithmetic. 16/2 17/2 18/2 19/2 20/2 14/2 15/2 function Year (Date : Time. Sub_Second : Second_Duration := 0. Time_Zone : Time_Zones.Time_Offset := 0) return Year_Number.Time_Offset := 0) return Minute_Number. Day_Duration range 23.Hours:Minutes:Seconds access: subtype subtype subtype subtype Hour_Number Minute_Number Second_Number Second_Duration is is is is Natural range 0 .0. out Hour_Number. 30/2 31/2 203 10 November 2006 Formatting. Time_Zone : Time_Zones. Wednesday. Time_Zone : Time_Zones. Natural range 0 .Time_Offset := 0) return Time.0) return Day_Duration. Time_Zone : Time_Zones.Day of the week: type Day_Name is (Monday. Time_Zone : Time_Zones.ISO/IEC 8652:2007(E) Ed. 0. (Date : Time.Time_Zones. and other operations for Time 9. 3 — Ada Reference Manual end Ada. Time Zones.1 . out Second_Duration). (Date : Time.0. Leap_Second: Boolean := False. Month : Month_Number. Time_Zone : Time_Zones.Time_Offset := 0) return Time. Leap_Second: Boolean := False. -..

out Year_Number. Seconds is the remainder seconds of difference excluding leap seconds.Time_Offset := 0). out Minute_Number.Time_Offset := 0). Days is the number of days of difference. 9. out Second_Duration. Days : out Day_Count. in Time_Zones. at the time Date. 41/2 42/2 Returns. in Time_Zones. Time_Zone : Time_Zones. out Month_Number. out Month_Number. function UTC_Time_Offset (Date : Time := Clock) return Time_Offset. then Seconds <= 0.Formatting. function Image (Elapsed_Time : Duration. 33/2 procedure Split (Date : Year : Month : Day : Hour : Minute : Second : Sub_Second : Leap_Second: Time_Zone : procedure Split (Date : Year : Month : Day : Seconds : Leap_Second: Time_Zone : 34/2 35/2 -. out Day_Number. out Day_Number. Time Zones. Otherwise. out Month_Number. Leap_Seconds : out Leap_Seconds_Count).ISO/IEC 8652:2007(E) Ed. and Leap_Seconds is the number of leap seconds.6. all values are nonnegative. as a number of minutes. out Day_Number. procedure Difference (Left.0.Time_Offset := 0) return Time. out Second_Number.0. function Value (Elapsed_Time : String) return Duration. then Seconds + Duration(Leap_Seconds) = Calendar. and other operations for Time 10 November 2006 204 . out Hour_Number. out Year_Number. out Year_Number. If the time zone of the Calendar implementation is unknown. Seconds : out Duration. Include_Time_Fraction : Boolean := False.Calendar. out Day_Duration. in Time.Simple image and value: function Image (Date : Time. out Second_Duration."–" (Left. Include_Time_Fraction : Boolean := False) return String. Right). Right : in Time. the difference between the implementation-defined time zone of Calendar.Time_Offset := 0) return String. out Second_Number. in Time_Zones. 3 — Ada Reference Manual 32/2 procedure Split (Date Year Month Day Hour Minute Second Sub_Second Time_Zone : : : : : : : : : in Time. out Boolean. Days <= 0. For the returned values. in Time. then Unknown_Zone_Error is raised. Time_Zone : Time_Zones. out Minute_Number.Time_Offset := 0). 43/2 44/2 Returns the difference between Left and Right. and UTC time. end Ada. function Value (Date : String. 36/2 37/2 38/2 39/2 40/2 Type Time_Offset represents the number of minutes difference between the implementation-defined time zone used by Calendar and another time zone. out Boolean. If Left < Right. The absolute value of Seconds is always less than 86_400. out Hour_Number. and Leap_Seconds <= 0.1 Formatting. if Days = 0.

66/2 205 10 November 2006 Formatting. Right : Time) return Time. function Day_of_Week (Date : Time) return Day_Name. 3 — Ada Reference Manual function "+" (Left : Time. Time_Zone : Time_Zones. Time_Zone : Time_Zones. and returns the number of days between them. Time Zones. function Day (Date : Time. as appropriate for the specified time zone offset. 49/2 50/2 Subtracts two time values.Time_Offset := 0) return Hour_Number. as appropriate for the specified time zone offset. function "+" (Left : Day_Count. function "-" (Left : Time.Time_Offset := 0) return Day_Number. Right : Day_Count) return Time. as appropriate for the specified time zone offset.ISO/IEC 8652:2007(E) Ed. Time_Zone : Time_Zones. Right : Time) return Day_Count. 60/2 61/2 Returns the minute within the hour for Date. 56/2 57/2 Returns the day number for Date. This is the same value that Difference would return in Days. 51/2 52/2 Returns the day of the week for Time. as appropriate for the specified time zone offset. function Hour (Date : Time. function Minute (Date : Time. Time_Error is raised if the result is not representable as a value of type Time.6. The value returned is always less than 1. This is based on the Year. Month. 64/2 65/2 Returns the fraction of second for Date (this has the same accuracy as Day_Duration). 62/2 63/2 Returns the second within the hour and minute for Date. Time_Zone : Time_Zones. and other operations for Time 9. Right : Day_Count) return Time. Time_Zone : Time_Zones.0. as appropriate for the specified time zone offset. function Sub_Second (Date : Time) return Second_Duration. 53/2 Returns the year for Date. and Day values of Time. Time_Error is raised if the result is not representable as a value of type Time. function Year (Date : Time. 46/2 47/2 48/2 Subtracts a number of days from a time value. 58/2 59/2 Returns the hour for Date. function "-" (Left.Time_Offset := 0) return Minute_Number. 54/2 55/2 Returns the month for Date.Time_Offset := 0) return Year_Number.1 . function Second (Date : Time) return Second_Number.Time_Offset := 0) return Month_Number. 45/2 Adds a number of days to a time value. function Month (Date : Time.

If Time_Of is called with a Seconds value of 86_400. and Sub_Second. Seconds : Day_Duration := 0. Hour : Hour_Number. Day : Day_Number.0.Time_Offset := 0) return Time.0. Month : Month_Number. the value returned is equal to the value of Seconds_Of for the next second with a Sub_Second value of 0. If Time_Of is called with a Sub_Second value of 1. If Leap_Second is True.0. Minute : Minute_Number. 68/2 Returns a Day_Duration value for the combination of the given Hour.0.0. out Second_Duration). Time Zones. function Time_Of (Year : Year_Number. returns a Time built from the date and time values. 73/2 74/2 If Leap_Second is False. Second : Second_Number := 0. If Seconds_Of is called with a Sub_Second value of 1.Time_Of as well as the argument to Calendar."–". Month : Month_Number. The value returned in the Sub_Second parameter is always less than 1.6. 9. returns the Time that represents the time within the leap second that is one second later than the time specified by the other parameters. Minute. Minute. out Hour_Number.Time_Offset := 0) return Time. out Minute_Number. the value returned is equal to the value of Time_Of for the next second with a Sub_Second value of 0. Time_Error is raised if the parameters do not form a proper date or time. Sub_Second : Second_Duration := 0. relative to the specified time zone offset. Leap_Second: Boolean := False.0) return Day_Duration. returns the Time that represents the time within the leap second that is one second later than the time specified by the other parameters. Second : Second_Number.0. procedure Split (Seconds Hour Minute Second Sub_Second : : : : : in Day_Duration. Time_Zone : Time_Zones.0. Day : Day_Number.1 Formatting. This value can be used in Calendar. the value returned is equal to the value of Time_Of for the next day with a Seconds value of 0.0. relative to the specified time zone offset. Minute : Minute_Number. Sub_Second : Second_Duration := 0. Time_Zone : Time_Zones.0. Time_Error is raised if the parameters do not form a proper date or time. Second. 69/2 70/2 Splits Seconds into Hour. and other operations for Time 10 November 2006 206 . Leap_Second: Boolean := False. If Leap_Second is True."+" and Calendar. 71/2 72/2 If Leap_Second is False. 3 — Ada Reference Manual 67/2 function Seconds_Of (Hour : Hour_Number. out Second_Number. returns a Time built from the date and time values. Second and Sub_Second in such a way that the resulting values all belong to their respective subtypes.ISO/IEC 8652:2007(E) Ed. function Time_Of (Year : Year_Number.

Time_Offset := 0). If Include_Time_Fraction is True. out Year_Number. and sets Leap_Seconds to True. out Day_Number. Hour. splits Date into its constituent parts (Year. and sets Leap_Second to False. Second. relative to the specified time zone offset. the integer part of Sub_Seconds*100 is suffixed to the string as a point followed by a 2-digit value. in Time_Zones. Month.Time_Offset := 0). out Boolean. procedure Split (Date : Year : Month : Day : Seconds : Leap_Second: Time_Zone : in Time. 76/2 77/2 Splits Date into its constituent parts (Year. out Boolean. 3 — Ada Reference Manual procedure Split (Date : Year : Month : Day : Hour : Minute : Second : Sub_Second : Leap_Second: Time_Zone : in Time. and sets Leap_Second to False. and all others are 2-digit values. in Time_Zones. function Image (Date : Time. 80/2 81/2 Returns a string form of the Date relative to the given Time_Zone. Minute. Month. out Month_Number. 78/2 79/2 If Date does not represent a time within a leap second. Time_Zone : Time_Zones. The format is "Year-MonthDay Hour:Minute:Second". The value returned in the Sub_Second parameter is always less than 1. out Month_Number. Seconds). The value returned in the Seconds parameter is always less than 86_400. procedure Split (Date Year Month Day Hour Minute Second Sub_Second Time_Zone : : : : : : : : : in Time. and other operations for Time 9. Second. If Date represents a time within a leap second. Day. Day. Include_Time_Fraction : Boolean := False.Time_Offset := 0). The separators between the values are a minus. The value returned in the Sub_Second parameter is always less than 1. relative to the specified time zone offset.0. out Hour_Number. out Minute_Number. out Day_Duration.1 . out Minute_Number. of the functions defined in Calendar and Calendar.0.Formatting. out Year_Number. out Year_Number. If Date represents a time within a leap second. Time Zones. out Hour_Number. Day. a colon. set the constituent parts to values corresponding to a time one second earlier than that given by Date. out Day_Number. 82/2 207 10 November 2006 Formatting.ISO/IEC 8652:2007(E) Ed. relative to the specified time zone offset. in Time_Zones. out Second_Number. Sub_Second). if needed. out Month_Number. Sub_Second). out Second_Duration. and sets Leap_Seconds to True. Month. out Second_Duration. out Day_Number. another minus. Hour. relative to the specified time zone offset. relative to the specified time zone offset.6. out Second_Number. splits Date into its constituent parts (Year.0. Minute. and a single space between the Day and Hour.Time_Offset := 0) return String. where the Year is a 4-digit value. including a leading zero. set the constituent parts to values corresponding to a time one second earlier than that given by Date. 75/2 If Date does not represent a time within a leap second.

minutes. UTC_Time_Offset always returns the difference relative to the implementation-defined time zone of package Calendar. Include_Time_Fraction) prefixed with a minus sign. If Elapsed_Time < 0. function Image (Elapsed_Time : Duration. UTC time can be safely calculated (within the accuracy of the underlying time-base). 85/2 86/2 Returns a string form of the Elapsed_Time. Include_Time_Fraction : Boolean := False) return String. The separators between the values are colons. Implementation Advice 89/2 An implementation should support leap seconds if the target system supports them. If Include_Time_Fraction is True.Time_Offset := 0) return Time. 38 Calling Split on the results of subtracting Duration(UTC_Time_Offset*60) from Clock provides the components (hours. Time_Zone : Time_Zones. Constraint_Error is raised if the string is not formatted as described for Image. Constraint_Error is raised if the string is not formatted as described for Image. function Value (Elapsed_Time : String) return Duration.1 Formatting. the result is Image (abs Elapsed_Time.6. 87/2 88/2 Returns a Duration value for the image given as Elapsed_Time. 84/2 Returns a Time value for the image given as Date.0. If leap seconds are not supported. Difference should return zero for Leap_Seconds. and so on) of the UTC time. and other operations for Time 10 November 2006 208 . the integer part of Sub_Seconds*100 is suffixed to the string as a point followed by a 2-digit value. If UTC_Time_Offset does not raise Unknown_Zone_Error. the result is implementation-defined. The fourth provides asynchronous transfer of control. and Time_Of should raise Time_Error if Leap_Second is True. Time Zones. but need not. The format is "Hour:Minute:Second".7 Select Statements 1 There are four forms of the select_statement. or the function cannot interpret the given string as a Duration value. 3 — Ada Reference Manual 83/2 function Value (Date : String. be the local time zone. if needed. or the function cannot interpret the given string as a Time value. In the United States. including a leading zero. for example.ISO/IEC 8652:2007(E) Ed. UTC_Time_Offset will generally be negative. Two provide timed and conditional entry calls. If abs Elapsed_Time represents 100 hours or more. 90/2 91/2 9. One form provides a selective wait for one or more select_alternatives. Split should return False for Leap_Second. relative to the given time zone. Syntax 2 select_statement ::= selective_accept | timed_entry_call | conditional_entry_call | asynchronous_select 9. NOTES 37 The implementation-defined time zone of package Calendar may. where all values are 2-digit values.

These three possibilities are mutually exclusive. end select. Stop_The_Train. In addition. it can contain: • a terminate_alternative (only one).7.7 14 . or • an else part (the reserved word else followed by a sequence_of_statements). 3 — Ada Reference Manual Examples Example of a select statement: select accept Driver_Awake_Signal. The selection may depend on conditions associated with each alternative of the selective_accept. 3 4 5 6 7 8 9 10 11 12 A selective_accept shall contain at least one accept_alternative. Syntax 1 selective_accept ::= 2 select [guard] select_alternative { or [guard] select_alternative } [ else sequence_of_statements ] end select. 3 4 9. or delay 30.ISO/IEC 8652:2007(E) Ed. or if the condition of its guard evaluates to True. or all shall be delay_until_statements for the same time type. then all shall be delay_relative_statements. It is said to be closed otherwise.0*Seconds. Legality Rules If a selective_accept contains more than one delay_alternative. or • one or more delay_alternatives.1 Selective Accept This form of the select_statement allows a combination of waiting for. guard ::= when condition => select_alternative ::= accept_alternative | delay_alternative | terminate_alternative accept_alternative ::= accept_statement [sequence_of_statements] delay_alternative ::= delay_statement [sequence_of_statements] terminate_alternative ::= terminate. Dynamic Semantics 13 A select_alternative is said to be open if it is not immediately preceded by a guard. and selecting from. 209 10 November 2006 Select Statements 9. one or more alternatives.

Premature shut down requested or terminate. if any.Normal shutdown at end of scope end select. If several delay_alternatives have this same expiration time. These evaluations are performed in an arbitrary order.7. exit. For an open delay_alternative. When such an alternative is selected.1 Selective Accept 10 November 2006 210 .5. end Server. -. the delay_expression is also evaluated. • The else part is selected and its sequence_of_statements is executed if no accept_alternative can immediately be selected. end loop.3 and D. any guard conditions are evaluated. open alternatives are thus determined. then completes the execution of the selective_accept. end. Open accept_alternatives are first considered. begin loop select accept Next_Work_Item(WI : in Work_Item) do Current_Work_Item := WI. if all alternatives are closed. If no selection is immediately possible (in the above sense) and there is no else part. the default queuing policy chooses arbitrarily among the delay_alternatives whose expiration time has passed. 9. one of them is selected according to the queuing policy in effect (see D. -. Selection of one such alternative takes place immediately if the corresponding entry already has queued calls.ISO/IEC 8652:2007(E) Ed.4). A selective_accept is allowed to have several open accept_alternatives for the same entry. in particular. Similarly. NOTES 39 A selective_accept is allowed to have several open delay_alternatives. or accept Shut_Down. or of the else part. • An open terminate_alternative is selected if the conditions stated at the end of clause 9.3 are satisfied. except that a delay_expression or entry_index is not evaluated until after evaluating the corresponding condition.4). Selection and execution of one open alternative. the selected call is removed from its entry queue and the handled_sequence_of_statements (if any) of the corresponding accept_statement is executed. Selection of the other forms of alternative or of an else part is performed as follows: • An open delay_alternative is selected when its expiration time is reached if no accept_alternative or other delay_alternative can be selected prior to the expiration time. The exception Program_Error is raised if all alternatives are closed and there is no else part. 3 — Ada Reference Manual 15 For the execution of a selective_accept. one of them is selected according to the entry queuing policy in effect (see 9. after the rendezvous completes any subsequent sequence_of_statements of the alternative is executed. Process_Work_Item(Current_Work_Item). for an open accept_alternative for an entry of a family. the rules for this selection are described below. the task blocks until an open alternative can be selected. the entry_index is also evaluated. Examples 16 17 18 19 20 21 22 23 24 Example of a task body with a selective accept: task body Server is Current_Work_Item : Work_Item. If several alternatives can thus be selected.

4). The expiration time (see 9. the optional sequence_of_statements of the entry_call_alternative is executed. entry_call_alternative ::= procedure_or_entry_call [sequence_of_statements] procedure_or_entry_call ::= procedure_call_statement | entry_call_statement Legality Rules 3/2 3. Syntax 1/2 timed_entry_call ::= 2 select entry_call_alternative or delay_alternative end select. determine the target object of the call and the entry to be called.1/2 If a procedure_call_statement is used for a procedure_or_entry_call.2 . then the procedure_name.3) or procedure call (see 6. the entry_name. If the call is queued (including due to a requeue-with-abort).2 Timed Entry Calls A timed_entry_call issues an entry call that is cancelled if the call (or a requeue-with-abort of the call) is not selected before the expiration time is reached. the optional sequence_of_statements of the delay_alternative is executed.6) for the call is determined by evaluating the delay_expression of the delay_alternative. A procedure call may appear rather than an entry call for cases where the procedure might be implemented by an entry. the sequence_of_statements of the delay_alternative is ignored. Dynamic Semantics 3. or procedure_prefix. Otherwise.5.7. If the call is an entry call or a call on a procedure implemented by an entry.4 for a procedure call. 3 — Ada Reference Manual 9. 4/2 5 211 10 November 2006 Timed Entry Calls 9. and the procedure is implemented by an entry. as for a simple entry call (see 9.2/2 If a procedure_call_statement is used for a procedure_or_entry_call. and not selected before the expiration time is reached. the call proceeds as described in 6. if the entry call completes normally.7. If the call completes due to the cancellation. the entry call is then issued. followed by the sequence_of_statements of the entry_call_alternative. and any actual parameters are evaluated.2). an attempt to cancel the call is made.ISO/IEC 8652:2007(E) Ed.3/2 For the execution of a timed_entry_call. procedure_name. the procedure_name or procedure_prefix of the procedure_call_statement shall statically denote an entry renamed as a procedure or (a view of) a primitive subprogram of a limited interface whose first parameter is a controlling parameter (see 3.9. Static Semantics 3. or procedure_prefix and possibly the first parameter of the procedure_call_statement.

else null. NOTES 40 A conditional_entry_call may briefly increase the Count attribute of the entry. Examples 4 5 6 Example of a conditional entry call: procedure Spin(R : in Resource) is begin loop select R. 9.0.busy waiting end select. return. even if the conditional call is not selected. or delay 45.3 Conditional Entry Calls 1/2 A conditional_entry_call issues an entry call that is then cancelled if it is not selected immediately (or if a requeue-with-abort of the call is not selected immediately). 3 — Ada Reference Manual Examples 6 7 Example of a timed entry call: select Controller.7. Syntax 2 conditional_entry_call ::= select entry_call_alternative else sequence_of_statements end select. end. -.Seize.ISO/IEC 8652:2007(E) Ed.Request(Medium)(Some_Item). -. end loop.7. 9. Dynamic Semantics 3 The execution of a conditional_entry_call is defined to be equivalent to the execution of a timed_entry_call with a delay_alternative specifying an immediate expiration time and the same sequence_of_statements as given after the reserved word else.controller too busy. A procedure call may appear rather than an entry call for cases where the procedure might be implemented by an entry.2 Timed Entry Calls 10 November 2006 212 . try something else end select.

ISO/IEC 8652:2007(E) Ed. Examples 6/2 7 8 9 Example of a main command loop for a command interpreter: loop select Terminal. Syntax 1 asynchronous_select ::= 2 select triggering_alternative then abort abortable_part end select. the entry call is issued. If the abortable_part completes and is left prior to completion of the triggering_statement. then the abortable_part is executed. triggering_alternative ::= triggering_statement [sequence_of_statements] triggering_statement ::= procedure_or_entry_call | delay_statement abortable_part ::= sequence_of_statements Dynamic Semantics 3 4/2 5 For the execution of an asynchronous_select whose triggering_statement is a procedure_or_entry_call. 10 11 213 10 November 2006 Asynchronous Transfer of Control 9. Get_Line(Command.4 .3) or procedure call (see 6. If the triggering_statement completes normally. an attempt to cancel the triggering_statement is made. For the execution of an asynchronous_select whose triggering_statement is a delay_statement. If the entry call is selected immediately. If the call is an entry call or a call on a procedure implemented by an entry. the abortable_part is executed. then the abortable_part is never started. procedure_name. If the expiration time has not already passed.3 and 9.Last)). the call proceeds as described in 6. Put_Line("Interrupted"). If the call is on a procedure that is not implemented by an entry. If the triggering_statement completes other than due to cancellation. end select. If the attempt to cancel succeeds (see 9. end loop.. the optional sequence_of_statements of the triggering_alternative is executed after the abortable_part is left. as for a normal delay_statement. or procedure_prefix. and never requeued-with-abort. followed by the sequence_of_statements of the triggering_alternative. Last). the abortable_part is aborted (if started but not yet completed — see 9.Wait_For_Interrupt.4. and actual parameters are evaluated as for a simple entry call (see 9. If the entry call is queued (or requeued-with-abort).7. the delay_expression is evaluated and the expiration time is determined.7. Process_Command(Command(1. the asynchronous_select is complete.6). 3 — Ada Reference Manual 9.8).4 Asynchronous Transfer of Control An asynchronous select_statement provides asynchronous transfer of control upon completion of an entry call or the expiration of a delay. the abortable_part is never started. then abort -.5.5.4). the entry_name.This will be abandoned upon terminal interrupt Put_Line("-> ").

Horribly_Complicated_Recursive_Function(X. which consists of making the task abnormal and aborting the execution of the corresponding task_body. The completion of the triggering_statement of an asynchronous_select causes a sequence_of_statements to be aborted. end select. The order in which tasks become abnormal as the result of an abort_statement or the abort of a sequence_of_statements is not specified by the language. • the execution of a Finalize procedure as part of the finalization of a controlled object. • an assignment operation to an object with a controlled part. an immediate attempt is made to cancel the entry call (see 9. except for executions included within the execution of an abort-deferred operation. the following are the abort-deferred operations: 5 6 7 • a protected action.7. Name Resolution Rules 3 Each task_name is expected to be of any task type. it is assumed to diverge. task_name}. the given task_names are evaluated in an arbitrary order. the execution of every construct included within the aborted execution is also aborted.This calculation should finish in 5. at a point that is outside the execution of an abort-deferred operation.8 Abort of a Task . then the execution of the 9. If the execution of a construct is aborted at a time when the execution is blocked. 8 9 10 11 12 13 14 15 If the execution of an entry call is aborted.6. Syntax 2 abort_statement ::= abort task_name {. When a master is aborted. they need not all be of the same task type. • the execution of an Initialize procedure as the last step of the default initialization of a controlled object. 9.0 seconds.ISO/IEC 8652:2007(E) Ed. Each named task is then aborted. The last three of these are discussed further in 7. unless it is already completed. other than for an entry call. • waiting for an entry call to complete (after having initiated the attempt to cancel it — see below). When the execution of a construct is aborted (including that of a task_body or of a sequence_of_statements). Dynamic Semantics 4 For the execution of an abort_statement. then abort -.4 Asynchronous Transfer of Control 10 November 2006 214 . Y).5.Abort of a Sequence of Statements 1 An abort_statement causes one or more tasks to become abnormal. all tasks that depend on that master are aborted.if not.3). -. 3 — Ada Reference Manual 12 13 Example of a time-limited calculation: select delay 5. • waiting for the termination of dependent tasks.0. the execution of an abortdeferred operation continues to completion without being affected by the abort. Put_Line("Calculation does not converge"). thus preventing any further interaction with such tasks.

but excluding.8 . In both cases. the following attributes are defined: T'Callable Yields the value True when the task denoted by T is callable. The value of this attribute is of the type universal_integer. 3 4 5 215 10 November 2006 Abort of a Task . For a prefix E that denotes an entry of a task or protected unit. within any program unit that is. these immediate effects occur before the execution of the abort_statement completes. 1 2 T'Terminated Yields the value True if the task denoted by T is terminated. For an abort due to an abort_statement. • the end of the activation of a task. an attempt to create a task that depends on a master that is included entirely within the execution of an abort-deferred operation is a bounded error. the target of the assignment or its parts can become abnormal.9. in the case of an entry of a task unit. except that an abort of the abortable_part or the created task might or might not have an effect. inner to the body of the task unit.1.9 Task and Entry Attributes Dynamic Semantics For a prefix T that is of a task type (after any implicit dereference). the execution of the aborted construct completes no later than its next abort completion point (if any) that occurs outside of an abort-deferred operation. The value of this attribute is of the predefined type Boolean. Other than for these immediate cases. the following are abort completion points for an execution: • the point where the execution initiates the activation of another task. or abort_statement. accept_statement. 3 — Ada Reference Manual construct completes immediately. E'Count Yields the number of calls presently queued on the entry E of the current instance of the unit. including itself. 43 Additional requirements associated with abort are given in D. However. as explained in 13. 42 A task is allowed to abort any task it can name. The value of this attribute is of the predefined type Boolean. and False otherwise. and certain subsequent uses of the object can be erroneous. itself.Abort of a Sequence of Statements 9. Similarly.ISO/IEC 8652:2007(E) Ed.6. otherwise the operations proceed as they would outside an abort-deferred operation. a task is callable unless it is completed or abnormal. Erroneous Execution 20 If an assignment operation completes prematurely due to an abort. the assignment is said to be disrupted. NOTES 41 An abort_statement should be used only in situations requiring unconditional termination. “Preemptive Abort”. 21 22 23 24 9. or of the sequence_of_statements of an exception_handler. Bounded (Run-Time) Errors 16 17 18 19 An attempt to execute an asynchronous_select as part of the execution of an abort-deferred operation is a bounded error. Program_Error is raised if the error is detected by the implementation. the following attribute is defined. and False otherwise. • the start of the execution of a select_statement. • the start or end of the execution of an entry call. This attribute is only allowed within the body of the task or protected unit. delay_statement. the execution of a construct that is aborted does not necessarily complete before the abort_statement completes.

even if the conditional call is not accepted. 46 Within protected units. any two nonoverlapping objects are independently addressable. 3 4 5 6 6. and A2 is the action of returning from the corresponding entry call. • If A1 is part of the execution of a protected procedure body or entry_body for a given protected object. or Component_Size is specified for a given composite object. task interactions can be used to synchronize the actions of two or more tasks to allow. and A2 is either the evaluation of the expression T'Terminated or a call to Ada. 3 — Ada Reference Manual NOTES 44 For the Count attribute. a conditional_entry_call may briefly increase this value.7. and A2 is part of a later execution of an entry_body for the same protected object. 45 Within task units. and A2 is part of the corresponding execution of the appropriate entry_body or accept_statement. the entry can be either a single entry or an entry of a family.1). • If A1 is part of the execution of a task.Is_Terminated with an actual parameter that identifies T (see C. • If A1 is part of the activation of a task. then it is implementation defined whether or not two nonoverlapping parts of that composite object are independently addressable. Normally.1/1 7 8 9 10 9.Task_Identification. and its decrease. including nonoverlapping parts of the same object.9 Task and Entry Attributes 10 November 2006 216 . for example. and A2 is the action of waiting for the termination of the task. The actions of two different tasks are synchronized in this sense when an action of one task signals an action of the other task. algorithms interrogating the attribute E'Count should take precautions to allow for the increase of the value of this attribute for incoming entry calls. if packing. and the language rules require A1 to be performed before A2. The name of the entry or entry family can be either a direct_name or an expanded name. • If A1 is the action of an activator that initiates the activation of a task. meaningful communication by the direct updating and reading of variables shared between the tasks. and A2 is the action of waiting for completion of the activation. an action A1 is defined to signal an action A2 under the following circumstances: • If A1 and A2 are part of the execution of the same task. However. • If A1 is part of the execution of an accept_statement or entry_body. 6 7 8 9. for example with timed_entry_calls. and A2 is part of the execution of the task that is activated. Also.10 Shared Variables Static Semantics 1 If two different objects.ISO/IEC 8652:2007(E) Ed. algorithms interrogating the attribute E'Count in the entry_barrier for the entry E should take precautions to allow for the evaluation of the condition of the barrier both before and after queuing a given caller. • If A1 is the termination of a task T. However. Dynamic Semantics 2 Separate tasks normally proceed independently and concurrently with one another. • If A1 is the action of issuing an entry call. record layout. • If A1 signals some action that in turn signals A2. they can be manipulated concurrently by two different tasks without synchronization. are independently addressable.

the producing task might have the following structure: task Producer. . 4 5 6/2 The buffer object contains an internal array of person names managed in a round-robin fashion.simulate arrival of the next customer Buffer. the Buffer can be passed to the Transfer class-wide operation defined for objects of a type covered by Queue'Class. For instance.1 begin loop . The Buffer is defined as an extension of the Synchronized_Queue interface (see 3.10. end Producer. -.9. and as such promises to implement the abstraction defined by that interface.10 . an In_Index denoting the index for the next input person name and an Out_Index denoting the index for the next output person name.Append_Wait(Person).11 Example of Tasking and Synchronization Examples The following example defines a buffer protected object to smooth variations between the speed of output of a producing task and the speed of input of some consuming task. task body Producer is Person : Person_Name. 1 2 3/2 and the consuming task might have the following structure: task Consumer.4).ISO/IEC 8652:2007(E) Ed. end loop. and an action of reading or updating a part of the same object (or of a neighboring object if the two are not independently addressable). -.6.Remove_First_Wait(Person). begin loop Buffer. -.. 3 — Ada Reference Manual Erroneous Execution Given an action of assigning to an object.. task body Consumer is Person : Person_Name. exit when Person = null.simulate serving a customer end loop. 11 12 13 14 15 9. The array has two indices. and at most one of the actions is part of a call on a protected function of the protected object. • Both actions occur as part of the execution of the same task.1/2 217 10 November 2006 Shared Variables 9. By doing so. • Both actions occur as part of protected actions on the same protected object.see 3. Two actions are sequential if one of the following is true: • One action signals the other. then the execution of the actions is erroneous unless the actions are sequential.. 7/2 7. A pragma Atomic or Atomic_Components may also be used to ensure that certain reads and updates are sequential — see C. exit when Person = null. end Consumer..

end Buffer. procedure Remove_First(Person : out Person_Name) is begin if Count = 0 then raise Queue_Error with "Buffer Empty". Person := Pool(Out_Index). function Max_Count return Natural is begin return Pool'Length. end Append.see 11. Count : Natural := 0.4 entry Append_Wait(Person : in Person_Name). protected body Buffer is entry Append_Wait(Person : in Person_Name) when Count < Pool'Length is begin Append(Person). procedure Append(Person : in Person_Name) is begin if Count = Pool'Length then raise Queue_Error with "Buffer Full". -. end Remove_First. Pool(In_Index) := Person.3 end if.see 11. Out_Index : Positive := 1. function Max_Count return Natural. end Append_Wait. function Cur_Count return Natural. 9/2 9.11 Example of Tasking and Synchronization 10 November 2006 218 . end Cur_Count. Out_Index := (Out_Index mod Pool'Length) + 1. In_Index. 100).ISO/IEC 8652:2007(E) Ed. function Cur_Count return Natural is begin return Buffer. private Pool : Person_Name_Array(1 . end Remove_First_Wait.3 end if. end Buffer. end Max_Count.9. Count := Count .1/2 10/2 11/2 12/2 13/2 9. -. 3 — Ada Reference Manual 8/2 protected Buffer is new Synchronized_Queue with -.see 3. In_Index := (In_Index mod Pool'Length) + 1. entry Remove_First_Wait(Person : out Person_Name). entry Remove_First_Wait(Person : out Person_Name) when Count > 0 is begin Remove_First(Person). procedure Remove_First(Person : out Person_Name). procedure Append(Person : in Person_Name). Count := Count + 1.Count.1..

each of which may execute in a separate address space. As explained below. A library unit is a separately compiled program unit. or generic unit. which contains library_items and their subunits. and may have other program units physically nested within them. and is always a package. 4 10. A library unit is a child of its parent unit. subprogram. the body. Library units may be organized into a hierarchy of children. The representation for a compilation is implementation-defined. or an explicitly declared subprogram other than an enumeration literal.ISO/IEC 8652:2007(E) Ed. body. grandchildren. Implementation Permissions 1 2 3 An implementation may impose implementation-defined restrictions on compilations that contain multiple compilation_units. 10. possibly on a separate computer. Alternatively.1 Separate Compilation A program unit is either a package. A root library unit. together with its children and grandchildren and so on. The text of a program can be submitted to the compiler in one or more compilations. Certain kinds of program units can be separately compiled. a partition is constructed from library units. The root library units are the children of the predefined library package Standard. 3 — Ada Reference Manual Section 10: Program Structure and Compilation Issues The overall structure of programs and the facilities for separate compilation are described in this section. and so on. A program is a set of partitions. as is the body of a library unit. “Program Execution” discusses issues related to what is traditionally known as “link time” and “run time” — building and executing partitions.2. Each compilation is a succession of compilation_units.Library Units A library_item is a compilation unit that is the declaration. the declaration of a library unit is a library_item. they can appear physically nested within other program units. or renaming of a library unit.1. This section has two clauses: 10. a generic unit. An implementation may support a concept of a program library (or simply. A compilation_unit contains either the declaration.1. Syntax 1 compilation ::= {compilation_unit} compilation_unit ::= context_clause library_item | context_clause subunit library_item ::= [private] library_unit_declaration | library_unit_body | [private] library_unit_renaming_declaration 2 3 4 219 10 November 2006 Program Structure and Compilation Issues 10 . a protected entry. form a subsystem. which is a library package or generic library package. 1 2 3 10. a “library”). a task unit. Library units may have other (logically nested) library units as children. Each library unit (except Standard) has a parent unit. a protected unit. “Separate Compilation” discusses compile-time issues related to separate compilation.1 Compilation Units . Syntactically. or a renaming of a program unit.

The public descendants of a library unit are the library unit itself. The limited view of a package contains: • For each nested package_declaration. generic_instantiation. The parent declaration of a library_item (and of the library unit) is the declaration denoted by the parent_unit_name.Library Units 10 November 2006 220 . When a program unit is a library unit.5/2 12. a declaration of the limited view of that package. The limited view of a library package_declaration is private if that library package_declaration is immediately preceded by the reserved word private. as well as to its declaration and body. the library_item is a root library_item. and the library unit (renaming) is a root library unit (renaming). if any. it is otherwise public. 9 10 11 12 12. A library unit is a program unit that is declared by a library_item. its parent.4/2 12. • For each type_declaration in the visible part. For each library package_declaration in the environment.1.ISO/IEC 8652:2007(E) Ed. A library unit is private or public according to its declaration. When the meaning is clear from context. The children of a library unit occur immediately within the declarative region of the declaration of the library unit. nonetheless. The implicit declaration of a limited view of a library package is not the declaration of a library unit (the library package_declaration is). as in “library procedure”. or subprogram_renaming_declaration that declares a library unit. its parent's parent. A library package_declaration is the completion of the declaration of its limited view. then the view is a tagged incomplete view.1/2 An overriding_indicator is not allowed in a subprogram_declaration. Its other descendants are private descendants.) The descendant relation is the inverse of the ancestor relation. (Standard is an ancestor of every library unit. of the defining_program_unit_name of the library_item. the parent declaration is the declaration of Standard. with the same defining_program_unit_name. the compilation_unit without the context_clause and the separate (parent_unit_name)). The implicit declaration of the limited view of a library package forms an (implicit) compilation unit whose context_clause is empty. and so on. if the type_declaration is tagged. A library_unit_declaration or a library_unit_renaming_declaration is private if the declaration is immediately preceded by the reserved word private. The term compilation unit is used to refer to a compilation_unit.6/2 10. The ancestors of a library unit are itself.1/2 12. There is no syntax for declaring limited views of packages. The parent unit of a library_item or library unit is the library unit declared by its parent declaration.2/2 12. “library package_body”. there is an implicit declaration of a limited view of that library package. and the public descendants of its public children. the term is also used to refer to the library_item of a compilation_unit or to the proper_body of a subunit (that is. because they are always implicit. the prefix “library” is used to refer to it (or “generic library” if generic). it is a library_item.3/2 12. an incomplete view of the type. or “generic library package”. If there is no parent_unit_name. The declaration and body of Standard itself have no parent declaration.1 Compilation Units . 3 — Ada Reference Manual library_unit_declaration ::= subprogram_declaration | generic_declaration 5 | package_declaration | generic_instantiation 6 library_unit_renaming_declaration ::= package_renaming_declaration | generic_renaming_declaration | subprogram_renaming_declaration library_unit_body ::= subprogram_body | package_body parent_unit_name ::= name 7 8 8.

if any.1 . The renaming of a child of a generic package shall occur only within the declarative region of the generic package. The defining name of a function that is a compilation unit shall not be an operator_symbol. the (old) name shall denote a library_item. A library_unit_body depends semantically upon the corresponding library_unit_declaration. For the purposes of this rule. each corresponding declaration for C has a corresponding child D. then every child of the library package shall either be itself an instance or be a renaming of a library unit. 22 23 24 25 26/2 221 10 November 2006 Compilation Units . There are two kinds of dependences among compilation units: • The semantic dependences (see below) are the ones needed to check the compile-time rules across compilation unit boundaries. On the other hand. not a renaming-as-body. The semantic dependence relationship is transitive. A library_item depends semantically upon its parent declaration. A library subprogram shall not override a primitive subprogram. if a child C itself has a child D. • The elaboration dependences (see 10. Static Semantics 13 14 15/2 16 17 18 19/2 20 21 A subprogram_renaming_declaration that is a library_unit_renaming_declaration is a renaming-asdeclaration. then the given declaration or body shall be a library_item. If a library package is an instance of a generic package. For each child C of some parent generic package P.1. A compilation unit depends semantically upon each library_item mentioned in a with_clause of the compilation unit. The visibility rules are based on the semantic dependences. The corresponding declaration for a child within an instance is visible only within the scope of a with_clause that mentions the (original) child generic unit. The body of a program unit shall be a library_item if and only if the declaration of the program unit is a library_item. A parent_unit_name (which can be used within a defining_program_unit_name of a library_item and in the separate clause of a subunit). shall not denote a renaming_declaration. a compilation unit depends semantically on the other compilation units needed to determine its legality. If a defining_program_unit_name of a given declaration or body has a parent_unit_name. The declaration of the limited view of a library package depends semantically upon the declaration of the limited view of its parent. there is a corresponding declaration C nested immediately within each instance of P.ISO/IEC 8652:2007(E) Ed. then the given compilation unit depends semantically upon the other compilation unit. 3 — Ada Reference Manual Legality Rules The parent unit of a library_item shall be a library package or generic library package.2) determine the order of elaboration of library_items. In a library_unit_renaming_declaration. if a given compilation unit contains an attribute_reference of a type defined in another compilation unit. In addition. The declaration of a library package depends semantically upon the declaration of its limited view. A child of a parent generic package shall be instantiated or renamed only within the declarative region of the parent generic. A subunit depends semantically upon its parent body. A child of a generic library package shall either be itself a generic unit or be a renaming of some other child of the same generic unit. and each of its prefixes. a name that denotes a library_unit_renaming_declaration is allowed in a nonlimited_with_clause and other places where the name of a library unit is allowed.Library Units 10.

1.1 Ada. see 7. IO. library_unit_name}.Put("The answer is: "). and a locally declared subprogram is allowed to overload a library subprogram. renaming_declarations are allowed to define overloaded names for such subprograms. -. 10. The expanded name Standard.Text_IO.. nonlimited_with_clause ::= [private] with library_unit_name {.see A. library_unit_name}. but a nonlibrary renaming_declaration is allowed to rename a library function as an operator. procedure Get(R : out Rational). -.Library Units 10 November 2006 222 .Text_IO. with Rational_Numbers..IO. Ada. -.With Clauses 1 A context_clause is used to specify the library_items whose names are needed within a compilation unit.1 Compilation Units . A compilation need not have any compilation units.10 procedure Main is -.construct a rational number.L can be used to denote a root library unit L (unless the declaration of Standard is hidden) since root library unit declarations occur immediately within the declarative region of package Standard.New_Line. end Rational_Numbers. Syntax 2 3 4/2 4.IO.1/2 4.Put(R). 3 — Ada Reference Manual Dynamic Semantics 26. Within a partition. package Rational_IO renames Rational_Numbers.a root library procedure R : Rational.Text_io. with Rational_Numbers. Examples 27 28 29 30 Examples of library units: package Rational_Numbers. use Rational_Numbers. However.IO is -. private procedure Rational_Numbers. with Ada.IO.2/2 context_clause ::= {context_item} context_item ::= with_clause | use_clause with_clause ::= limited_with_clause | nonlimited_with_clause limited_with_clause ::= limited [private] with library_unit_name {. its text can consist of pragmas. -. end Main.Reduce.a library unit renaming declaration 31 32 33 34 35 Each of the above library_items can be submitted to the compiler separately.public child of Rational_Numbers.IO.private child of Rational_Numbers with Rational_Numbers. 10. -.2 Context Clauses . begin R := 5/3.1/2 The elaboration of the declaration of the limited view of a package has no effect. 2 The designator of a library function cannot be an operator_symbol.1 procedure Put(R : in Rational). see 7. two library subprograms are required to have distinct names and hence cannot overload each other.refer to a private child package body Rational_Numbers is . for example.ISO/IEC 8652:2007(E) Ed.Reduce(R : in out Rational). NOTES 1 A simple program may consist of a single compilation unit. end Rational_Numbers.1.

in which case the with_clause shall include the reserved word private. then the corresponding declaration nested within each visible instance is visible within the 8/2 9/2 10/2 11/2 12/2 13/2 14/2 15/2 16/2 17/2 18/2 19/2 20/2 21/2 22/2 23/2 223 10 November 2006 Context Clauses . and instances of a generic library unit can be declared. A limited_with_clause shall not appear on a library_unit_body. Thus. or within the scope of. but not a subprogram body acting as a subprogram declaration (see 10. or • in the same context_clause as. or • the declaration of a public descendant of that library unit. the name of a library package can be given in use_clauses and can be used to form expanded names.With Clauses 10. If a child of a parent generic package is mentioned in a nonlimited_with_clause. the declaration or renaming of a library unit can be visible only within the scope of a with_clause that mentions it. which includes all subunits. or library_unit_renaming_declaration.1. a library subprogram can be called. NOTES 3 A library_item mentioned in a nonlimited_with_clause of a compilation unit is visible within the compilation unit and hence acts just like an ordinary declaration. generic instance. 3 — Ada Reference Manual Name Resolution Rules The scope of a with_clause that appears on a library_unit_declaration or library_unit_renaming_declaration consists of the entire declarative region of the declaration. • in the same context_clause as. Legality Rules 5 6/2 7 If a with_clause of a given compilation_unit mentions a private child of some library unit. but not within the subprogram_specification of a library subprogram body. which includes all children and subunits. A library_item mentioned in a limited_with_clause shall be the implicit declaration of the limited view of a library package. • a private descendant of the unit on which one of these with_clauses appear. a use_clause that names an entity declared within the declarative region of the library package.1. within a compilation unit that mentions its declaration. or within the scope of. Outside its own declarative region. body. The scope of a with_clause that appears on a body consists of the body. A limited_with_clause that names a library package shall not appear: • in the context_clause for the explicit declaration of the named library package. • a body. A library_item (and the corresponding library unit) is named in a with_clause if it is denoted by a library_unit_name in the with_clause.ISO/IEC 8652:2007(E) Ed. generic unit. A name denoting a library item that is visible only due to being mentioned in one or more with_clauses that include the reserved word private shall appear only within: • a private part. subunit.4). or a renaming. The visibility of the declaration or renaming of a library unit otherwise follows from its placement in the environment. • the body or subunit of a public descendant of that library unit. a nonlimited_with_clause that mentions the same library package. then the given compilation_unit shall be one of: • the declaration. not the declaration of a subprogram. or subunit of a private descendant of that library unit. A library_item (and the corresponding library unit) is mentioned in a with_clause if it is named in the with_clause or if it is denoted by a prefix in the with_clause. or • a pragma within a context clause.2 .

limited with Office.3 Subunits of Compilation Units 1 Subunits are like child units. procedure Assign_Manager(Dept : in out Department. Loc : Locations. function Manager_Of(Dept : Department) return access Employees.Departments. declarations appearing in the parent's body can be visible within the subunits.2 Context Clauses .Employees. a library_item mentioned in a limited_with_clause of a compilation unit is visible within the compilation unit and thus can be used to form expanded names. 28/2 29/2 30/2 31/2 The limited_with_clause may be used to support mutually dependent abstractions that are split across multiple packages.Locations is type Location is new Ada.1. Examples 24/2 25/2 package Office is end Office. Dept : access Departments. 3/2 4 10. The compiler checks that no use is made of the second unit in the visible part of the first unit. package Office. -.Unbounded.Locations. 3 — Ada Reference Manual compilation unit. end Office..Employees is Employee is private.Unbounded. Mgr : access Employees. end Office. private type Employee is record Dept : access Departments.Employee).Department). an employee is assigned to a department.Departments is type Department is private. with these (important) differences: subunits support the separate compilation of bodies only (not declarations).types are incomplete -. end record.Location.With Clauses 10 November 2006 224 .Employee. but restricts that visibility to the private part and body of the first unit...Department. Syntax 2 body_stub ::= subprogram_body_stub | package_body_stub | task_body_stub | protected_body_stub subprogram_body_stub ::= [overriding_indicator] subprogram_specification is separate. In this case.Unbounded_String. and a department has a manager who is an employee.Departments. package Office. If a with_clause with the reserved word private appears on one library unit and mentions a second library unit..Strings. end Office.Locations. procedure Assign_Dept(Emp : in out Employee.Strings. Similarly. limited private package type with Office.Employees. .only visible in private part 26/2 27/2 function Dept_Of(Emp : Employee) return access Departments. with Office. package_body_stub ::= package body defining_identifier is separate.1. it provides visibility to the second library unit.. the parent contains a body_stub to indicate the existence and place of each of its subunits.. with Ada. .ISO/IEC 8652:2007(E) Ed. Office. 10.Department. .

subunit ::= separate (parent_unit_name) proper_body Legality Rules 5 6 7 The parent body of a subunit is the body of the program unit denoted by its parent_unit_name. A body_stub shall appear immediately within the declarative_part of a compilation unit body. NOTES 4 The rules in 10. If the _stub is a completion. as well as any subunit that names such a subunit as its parent (recursively). The effect of the elaboration of a body_stub is to elaborate the subunit. The term subunit is used to refer to a subunit and also to the proper_body of a subunit. and shall contain a corresponding body_stub with the same defining_identifier as the subunit. package body Parent is Variable : String := "Hello. end Inner. A subunit that corresponds to a body_stub shall be of the same kind (package_.1. a protected_body_stub shall be the completion of a protected declaration. The profile of a subprogram_body_stub that completes a declaration shall conform fully to that of the declaration.Put_Line(Variable). subprogram_. there. task_.Text_IO. a subprogram_body_stub need not be the completion of a previous declaration. with Ada. The subunits of a program unit include any subunit that names that program unit as its parent. A package_body_stub shall be the completion of a package_declaration or generic_package_declaration.Text_IO.3 . a task_body_stub shall be the completion of a task declaration. procedure Inner is begin Ada. This implies: • • Visibility within a subunit is the visibility that would be obtained at the place of the corresponding body_stub (within the parent body) if the context_clause of the subunit were appended to that of the parent body. or protected_) as the body_stub. 3 — Ada Reference Manual task_body_stub ::= task body defining_identifier is separate. Post-Compilation Rules 8/2 9 10/2 11 12 13 14 For each body_stub. The profile of a subprogram_body subunit shall be fully conformant to that of the corresponding body_stub.4. it shall be the completion of a subprogram_declaration or generic_subprogram_declaration. end Parent. The defining_identifiers of all body_stubs that appear immediately within a particular declarative_part shall be distinct.ISO/IEC 8652:2007(E) Ed. there shall be a subunit containing the corresponding proper_body. in which case the _stub declares the subprogram. protected_body_stub ::= protected body defining_identifier is separate.1. The parent body of a subunit shall be present in the current environment. 19 20 21 225 10 November 2006 Subunits of Compilation Units 10. Examples 15 16 17 18 The package Parent is first written without subunits: package Parent is procedure Inner. “The Compilation Process” say that a body_stub is equivalent to the corresponding proper_body.". end Parent. This rule does not apply within an instance of a generic unit. In contrast.

which is a conceptual declarative_part that forms the outermost declarative region of the context of any compilation. it is interpreted only as a completion if a library_unit_declaration with the same defining_program_unit_name already exists in the environment for a subprogram other than an instance of a generic subprogram or for a generic subprogram (even if the profile of the body is not type conformant with that of the declaration). an environment). an environment forms the declarative_part of the body of the environment task of a partition (see 10. the implementation may remove from the environment any preexisting version of the same compilation unit.Text_IO. end Parent.". the set of these compilation units shall be consistent in the sense that the new compilation unit shall not semantically depend (directly or indirectly) on two different versions of the same compilation unit. procedure Inner is separate. otherwise the subprogram_body is interpreted as both the declaration and body of a library subprogram.2.2). all compilation units upon which it depends semantically shall already exist in the environment. At run time.3 Subunits of Compilation Units 10 November 2006 226 .ISO/IEC 8652:2007(E) Ed. nor on an earlier version of itself. The visibility rules apply as if the environment were the outermost declarative region. “Program Execution”). Legality Rules 5 When a compilation unit is compiled. Each included subunit occurs in place of the corresponding stub. When a compilation unit that contains a body_stub is added to the environment. Implementation Permissions 6/2 The implementation may require that a compilation unit be legal before it can be mentioned in a limited_with_clause or it can be inserted into the environment.1.4 The Compilation Process 1 Each compilation unit submitted to the compiler is compiled in the context of an environment declarative_part (or simply. end Inner. the implementation may remove any preexisting library_item or subunit with the same full expanded name as 7/2 10. The mechanisms for adding a compilation unit mentioned in a limited_with_clause to an environment are implementation defined. except that with_clauses are needed to make declarations of library units visible (see 10.Text_IO. The mechanisms for creating an environment and for adding and replacing compilation units within an environment are implementation defined.Put_Line(Variable).1. there. The declarative_items of the environment are library_items appearing in an order such that there are no forward semantic dependences. separate(Parent) procedure Inner is begin Ada.1. the implementation may remove from the environment any preexisting library_item or subunit with the same full expanded name. When a compilation unit that is a subunit or the body of a library unit is added to the environment. with Ada. When a compilation unit that declares or renames a library unit is added to the environment. 3 — Ada Reference Manual 22 23 The body of procedure Inner may be turned into a subunit by rewriting the package body as follows (with the declaration of Parent remaining the same): package body Parent is Variable : String := "Hello. 24 10. Name Resolution Rules 2 3/2 4/1 If a library_unit_body that is a subprogram_body is submitted to the compiler.

which shall be a direct_name that denotes one or more of the following (and nothing else): a subprogram_declaration.1. Legality Rules 2 A program unit pragma shall appear in one of these places: • At the place of a compilation_unit. generic_subprogram_declaration.ISO/IEC 8652:2007(E) Ed. just as they are enforced within a single compilation unit. in which case the pragma shall immediately follow in the same compilation (except for other pragmas) a library_unit_declaration that is a subprogram_declaration.1. or generic_instantiation. if any. 8 9 10 10. and compilations.4 . • At the place of a declaration other than the first. of the same declarative_part or program unit declaration. 3 — Ada Reference Manual the body_stub. When a given compilation unit is removed from the environment. Static Semantics 3 4 5/1 6 7 A library unit pragma that applies to a generic unit does not apply to its instances.5 Pragmas and Program Units This subclause discusses pragmas related to program units. • Immediately within the visible part of a program unit and before any nested declaration (but not within a generic formal part).1/1 227 10 November 2006 The Compilation Process 10. of a declarative_part or program unit declaration. in a library unit pragma shall denote the declaration of a library unit. If the given compilation unit contains the body of a subprogram to which a pragma Inline applies. or it shall resolve to denote the declaration of the immediately enclosing program unit (if any). If multiple libraries are supported. the pragma applies to the immediately enclosing program unit. and the pragma shall have an argument that is a name denoting that declaration. unless a specific rule for the pragma specifies the contrary. Therefore. 6 An implementation may support a concept of a library. Naming conflicts between different libraries might be resolved by treating each library as the root of a hierarchy of child library units. Name Resolution Rules 1 Certain pragmas are defined to be program unit pragmas. a generic_subprogram_declaration. if any. in which case the argument. 7 A compilation unit containing an instantiation of a separately compiled generic unit does not semantically depend on the body of the generic unit. The name. Certain program unit pragmas are defined to be library unit pragmas. A name given as the argument of a program unit pragma shall resolve to denote the declarations or renamings of one or more program units that occur immediately within the declarative region or compilation in which the pragma immediately occurs. or a generic_instantiation. replacing the generic body in the environment does not result in the removal of the compilation unit containing the instantiation. in which case the pragma shall have an argument. the implementation may also remove any compilation unit containing a call to that subprogram. the implementation has to define how a single environment is constructed when a compilation unit is submitted to the compiler. If there are no names given as arguments. library units. the implementation may also remove any compilation unit that depends semantically upon the given one. the pragma applies to the denoted program unit(s). 7. which contains library_items. NOTES 5 The rules of the language are enforced across compilation and compilation unit boundaries. shall be a direct_name that denotes the immediately enclosing program unit declaration.

The pragma applies to all compilation_units appearing in the compilation. a program unit pragma that is not a library unit pragma should apply to each instance of the generic unit for which there is not an overriding pragma applied directly to the instance.1. and each root library_item so mentioned is directly visible. 10.ISO/IEC 8652:2007(E) Ed. in which case it applies to all future compilation_units compiled into the same environment. and the only declarations that are directly visible are those that are explicit root library_items of the environment. the implementation shall still accept configuration pragmas in individual compilations that confirm the initially selected partition-wide or system-wide options. Notwithstanding the rules of 4. or a pragma that appears at the place of a compilation unit may consist of a prefix that denotes a generic package and a selector_name that denotes a child of that generic package.3. In this case. the declaration corresponding to each body_stub in the environment is also visible.1.1. if a given declaration is visible or directly visible.5 Pragmas and Program Units 10 November 2006 228 . within such a use_clause.1. Implementation Permissions 9/2 An implementation may require that configuration pragmas that select partition-wide or system-wide options be compiled when the environment contains no library_items other than those of the predefined environment. The ancestor root library_item is directly visible. the only declarations that are visible are those that are the implicit declaration of the limited view of a library package of the environment. The special visibility rules for those contexts are given here. Within the parent_unit_name of a subunit. nor within a pragma that appears at the place of a compilation unit. see 10.1. They are generally used to select a partition-wide or system-wide option. 3 — Ada Reference Manual Post-Compilation Rules 8 Certain pragmas are defined to be configuration pragmas. and within a nonlimited_with_clause.6 Environment-Level Visibility Rules 1 The normal visibility rules do not apply within a parent_unit_name or a context_clause. they shall appear before the first compilation_unit of a compilation. Within a use_clause or pragma that is within a context_clause. the immediately preceding library_item and each of its ancestors is visible. In addition. the only declarations that are visible are those that are explicit library_items of the environment. an expanded name in a with_clause. in addition. Within a limited_with_clause. each library_item mentioned in a previous with_clause of the same context_clause is visible.) 3 4 5 6/2 10. Static Semantics 2/2 Within the parent_unit_name at the beginning of an explicit library_item. Implementation Advice 10/1 When applied to a generic unit. each declaration that occurs immediately within the given declaration's visible part is also visible. library_items are visible as they are in the parent_unit_name of a library_item. Within a pragma that appears at the place of a compilation unit. and the only declarations that are directly visible are those that are the implicit declaration of the limited view of a root library package. a pragma in a context_clause. unless there are none. (The child is necessarily a generic unit. No other declarations are visible or directly visible.

For example. then there is an elaboration dependence of the given library_item upon the body of the other library unit. In addition.2 Program Execution An Ada program consists of a set of partitions. then so is the explicit declaration of the library package.1/2 7 8 9 10 11 12/2 The environment declarative_part at (1) is a sequence of declarative_items consisting of copies of the library_items included in the partition. • If a compilation unit with stubs is needed. and then calls the main subprogram. then so is any corresponding library_unit_body. The order of elaboration of library_items is the order in which they appear in the environment declarative_part: • The order of all included library_items is such that there are no forward elaboration dependences. • If a library_unit_declaration is needed. if specified. 13 14 229 10 November 2006 Program Execution 10.2 .. if a given library_item or any of its subunits has a pragma Elaborate or Elaborate_All that names another library unit. shall be a subprogram. for Elaborate_All only. 3 — Ada Reference Manual 10. The compilation units needed by a given compilation unit are determined as follows (unless specified otherwise via an implementation-defined pragma. There is an elaboration dependence of a given library_item upon another if the given library_item or any of its subunits depends semantically on the other library_item.. and possibly on a separate computer. Each partition has an anonymous environment task. (2) -. A main subprogram. (1) -. The order of elaboration of library units is determined primarily by the elaboration dependences. and. The compilation units included in a partition are those of the explicitly assigned library units. as well as other compilation units needed by those library units.ISO/IEC 8652:2007(E) Ed. upon each library_item needed by the declaration of the other library unit. 2 3 4 5 6/2 6. • If a compilation unit is needed. The assignment is done in an implementation-defined manner. or by some other implementation-defined means): • A compilation unit needs itself. then so are any compilation units upon which it depends semantically. Post-Compilation Rules 1 A partition is a program or part of a program that can be invoked from outside the Ada implementation. a partition might be an executable file generated by the system linker. which can execute in parallel with one another. A partition's execution is that of its tasks.. if there is one.(that is. begin . the sequence of library_items) goes here. on many systems.The environment declarative_part -. The user can explicitly assign library units to a partition. which is an implicit outermost task whose execution elaborates the library_items of the environment declarative_part. if there is one. possibly in a separate address space. then so are any corresponding subunits. The environment task for a partition has the following structure: task Environment_Task.Call the main subprogram. • If the (implicit) declaration of the limited view of a library package is needed. task body Environment_Task is .. end Environment_Task. The user can optionally designate (in an implementation-defined manner) one subprogram as the main subprogram for the partition.

where the actuals come from is implementation defined. • All library_items declared pure occur before any that are not declared pure. or: • A null_statement. What happens to the result of a main function is also implementation defined. Implementation Requirements 27 The implementation shall ensure that all compilation units included in a partition are consistent with one another. The order is otherwise implementation defined.ISO/IEC 8652:2007(E) Ed. • All preelaborated library_items occur before any that are not preelaborated. in dynamic linking. as. with implementation-defined semantics. If such a task is activated. If the environment task completes abnormally. 3 — Ada Reference Manual 15 • Any included library_unit_declaration to which a pragma Elaborate_Body applies is immediately followed by its library_unit_body. An implementation may restrict the kinds of subprograms it supports as main subprograms. if included. and are legal according to the rules of the language. Standard pragmas for distribution and methods for specifying inter-partition communication are defined in Annex E.2 Program Execution 10 November 2006 230 . and may result in the raising of Program_Error either upon creation or activation of the task. the implementation may abort any dependent tasks. it waits for the termination of all such tasks. any further attempt to create a task (during finalization) is a bounded error. and then finalizes any remaining objects of the partition. for example. an implementation is required to support all main subprograms that are public parameterless library procedures. ends when the environment task terminates. or “load-and-go” systems. The mechanisms for building and running partitions are implementation defined. The full expanded names of the library units and subunits included in a given partition shall be distinct. Dynamic Semantics 16 17 18 19 20 21 22 23 24 25 The execution of a program consists of the execution of a set of partitions. it is not specified whether the task is awaited prior to termination of the environment task. These might be combined into one operation. 29 30 31 10. if the partition has one. if there is no main subprogram. The sequence_of_statements of the environment task (see (2) above) consists of either: • A call to the main subprogram. If the main subprogram has parameters. However. There shall be a total order of the library_items that obeys the above rules. Implementation Permissions 28 The kind of partition described in this clause is known as an active partition. they are passed. NOTES 8 An implementation may provide inter-partition communication mechanism(s) via special packages and pragmas. The execution of the (implicit) task_body of the environment task acts as a master for all other tasks created as part of the execution of the partition. The execution of a partition starts with the execution of its environment task. Further details are implementation defined. and includes the executions of all tasks of the partition. When the environment task completes (normally or abnormally). Bounded (Run-Time) Errors 26 Once the environment task has awaited the termination of all other tasks of the partition. An implementation is allowed to support other kinds of partitions.

Passive partitions. or statically denotes a discriminant of an enclosing type. If a pragma Preelaborate (or pragma Pure — see below) applies to a library unit.) 11 A partition (active or otherwise) need not have a main subprogram. 32 33 34 10. and all subunits that are elaborated as part of elaborating the library unit. and behaves as a program in and of itself.3/2 10. “Distributed Systems”. an implementation might support dynamic linking via the partition concept. 9 Partitions are not required to run in separate address spaces. • The evaluation of a primary that is a name of an object. then its declaration.2/2 10. which cannot have main subprograms. • A call to a subprogram other than a static function. 3 — Ada Reference Manual “Distributed Systems”.1/2 4. are elaborated prior to all non-preelaborated library_items of the partition. and • the actual for each formal subprogram is a user-defined subprogram. 10 An order of elaboration of library_items that is consistent with the partial ordering defined above does not always ensure that each library_unit_body is elaborated before any other compilation unit whose elaboration necessitates that the library_unit_body be already elaborated. • the actual for each formal type is nonstatic. then it is preelaborated.1 Elaboration Control This subclause defines pragmas that help control the elaboration order of library_items. A pragma Preelaborate is a library unit pragma.1/2 10. Similarly. all the work done by the partition would be done by elaboration of various library_items. if any.2 . Legality Rules 2 3 4 4. presuming that: • the actual for each formal private type (or extension) declared within the formal part of the generic unit is a private type (or extension) that does not have preelaborable initialization. • The creation of an object (including a component) of a type that does not have preelaborable initialization. In such a case.4/2 11/1 231 10 November 2006 Program Execution 10. then each partition is isolated from all others. (In particular. If no such mechanisms are provided. Syntax 1 The form of a pragma Preelaborate is as follows: pragma Preelaborate[(library_unit_name)]. the evaluation of an extension_aggregate with an ancestor subtype_mark denoting a subtype of such a type. and body. unless the pragmas in subclause 10. are defined in Annex E.ISO/IEC 8652:2007(E) Ed. there is no requirement that the body of a library unit be elaborated as soon as possible after the library_unit_declaration is elaborated. unless the name is a static expression.3). shall be preelaborable. and by tasks created by that elaboration. If a library unit is preelaborated.1 are used. if any.2/2 An elaborable construct is preelaborable unless its elaboration performs any of the following actions: • The execution of a statement other than a null_statement. this rule applies also in the private 5 6 7 8 9/2 10/2 10. A generic body is preelaborable only if elaboration of a corresponding instance body would not perform any such actions. The declaration and body of a preelaborated library unit. The form of a pragma Preelaborable_Initialization is as follows: pragma Preelaborable_Initialization(direct_name).2. For example. In addition to the places where Legality Rules normally apply (see 12. • the actual for each formal object is nonstatic.2.

then the direct_name shall denote the first subtype of a private type. • A view of a type has preelaborable initialization if it is an elementary type.2/2 The following rules specify which entities have preelaborable initialization: • The partial view of a private type or private extension. However. a type declared in a preelaborated package should have the same representation in every elaboration of a given version of the package. all compilation units of a preelaborated library unit shall depend semantically only on compilation units of other preelaborated library units. then the direct_name shall denote a generic formal private type or a generic formal derived type declared in the same generic_formal_part as the pragma.7/2 11. or if its declaration does not include a default expression and its type has preelaborable initialization.3/2 11. a user-defined controlled type with an overriding Initialize procedure does not have preelaborable initialization. have preelaborable initialization if and only if the pragma Preelaborable_Initialization has been applied to them.8/2 12 In an implementation.1/2 A pure library_item is a preelaborable library_item whose elaboration does not perform any of the following actions: • the elaboration of a variable declaration. each component of the protected type shall have preelaborable initialization. In addition. and the type shall be declared immediately within the same package as the pragma. If the pragma is applied to a private type or a private extension.2/2 . This pragma shall appear in the visible part of a package or generic package.6/2 11. In addition to the places where Legality Rules normally apply.5/2 11. or protected type that is not an interface type and is without entry_declarations. a protected type without entry_declarations. 10. private extension.4/2 11. A protected type with entry_declarations or a task type never has preelaborable initialization. whether the elaborations occur in distinct executions of the same program.2. 11. A pragma Pure is a library unit pragma. • A component (including a discriminant) of a record or protected type has preelaborable initialization if its declaration includes a default_expression whose execution does not perform any actions prohibited in preelaborable constructs as described above. Implementation Advice 11. the full view of the type shall have preelaborable initialization. or a generic formal derived type. these rules apply also in the private part of an instance of a generic unit. a generic formal private type. Syntax 13 14 15 The form of a pragma Pure is as follows: pragma Pure[(library_unit_name)]. • A derived type has preelaborable initialization if its parent type has preelaborable initialization and (in the case of a derived record extension) if the non-inherited components all have preelaborable initialization. If the pragma appears in a generic_formal_part. If the pragma appears in the first list of basic_declarative_items of a package_specification. Static Semantics 15. or an interface type. a record type whose components all have preelaborable initialization. an array type whose component type has preelaborable initialization.1 Elaboration Control 10 November 2006 232 15. If the pragma is applied to a protected type. A pragma Preelaborable_Initialization specifies that a type has preelaborable initialization. 3 — Ada Reference Manual part of an instance of a generic unit. or in executions of distinct programs or partitions that include the given version. In a generic_instantiation the corresponding actual type shall have preelaborable initialization.ISO/IEC 8652:2007(E) Ed.1/2 11.

pragma Elaborate_Body[(library_unit_name)].4/2 15. library_unit_name}). • the elaboration of the declaration of a named access-to-constant type for which the Storage_Size has been specified by an expression other than a static expression with value zero. A pragma Elaborate_All specifies that each library_item that is needed by the named library 26 233 10 November 2006 Elaboration Control 10.1/2 A pragma Elaborate specifies that the body of the named library unit is elaborated before the current library_item. Syntax 18/2 The form of a pragma Elaborate.ISO/IEC 8652:2007(E) Ed. then its compilation units shall be pure. • the elaboration of the declaration of a named access-to-variable type unless the Storage_Size of the type has been specified by a static expression with value zero or is defined by the language to be zero. Furthermore. A pragma Elaborate or Elaborate_All is only allowed within a context_clause. the values of all by-copy-in actual parameters. the implementation may omit a call on such a subprogram and simply reuse the results produced by an earlier call on the same subprogram. The library_unit_name of a pragma Elaborate or Elaborate_All shall denote a nonlimited view of a library unit. In addition. for the purposes of this rule. then the declaration requires a completion (a body). the full view of any partial view declared in the visible part of the library unit that has any available stream attributes shall support external streaming (see 13. then the implementation is permitted to omit a call on a library-level subprogram of the library unit if the results are not needed after the call.2). and the values of all objects accessible via access values from the parameters. Legality Rules 15. Static Semantics 25 25. the partial view of a type is presumed to have non-visible components whose default initialization evaluates such an allocator.13. and the addresses and values of all by-reference actual parameters. library_unit_name}). This permission applies even if the subprogram produces other side effects when called.5/2 15. Legality Rules 19 20 21 22 23 24 If a pragma Elaborate_Body applies to a declaration. If a pragma Pure applies to a library unit.6/2 This paragraph was deleted. are the same as they were at the earlier call. The Storage_Size for an anonymous access-to-variable type declared at library level in a library unit that is declared pure is defined to be zero.1 . pragma Elaborate_All(library_unit_name{. Implementation Permissions If a library unit is declared pure.2. and they shall depend semantically only on compilation units of other library units that are declared pure.3/2 15. provided that none of the parameters nor any object accessible via access values from the parameters are of a limited type. Elaborate_All. 3 — Ada Reference Manual • the evaluation of an allocator of an access-to-variable type. A pragma Elaborate_Body is a library unit pragma. 16/2 17/2 A pragma Pure is used to declare that a library unit is pure. or Elaborate_Body is as follows: pragma Elaborate(library_unit_name{.

3 — Ada Reference Manual unit declaration is elaborated before the current library_item. 13 A library unit that is declared pure is allowed to have impure children. 10.2.1 Elaboration Control 10 November 2006 234 . 27 28 NOTES 12 A preelaborated library unit is allowed to have non-preelaborable children.ISO/IEC 8652:2007(E) Ed. A pragma Elaborate_Body specifies that the body of the library unit is elaborated immediately after its declaration.

one of them is raised when a language-defined check fails. Performing some actions in response to the arising of an exception is called handling the exception. an occurrence of such a situation (at run time) is called an exception occurrence. When an exception arises. or it can be propagated to a dynamically enclosing execution. Syntax 1 exception_declaration ::= defining_identifier_list : exception. 1 2 11. 1 235 10 November 2006 Exceptions 11 . An exception represents a kind of exceptional situation. Examples 5 6 Examples of user-defined exception declarations: Singular : exception. Underflow : exception. An exception is raised initially either by a raise_statement or by the failure of a language-defined check. Overflow.2 Exception Handlers The response to one or more exceptions is specified by an exception_handler. 3 — Ada Reference Manual Section 11: Exceptions This section defines the facilities for dealing with errors or other exceptional situations that arise during program execution. If a generic unit includes an exception_declaration. The particular exception denoted by an exception name is determined at compilation time and is the same regardless of how many times the exception_declaration is elaborated.1 Exception Declarations An exception_declaration declares a name for an exception. The execution of any construct raises Storage_Error if there is insufficient storage for that execution. The amount of storage needed for the execution of constructs is unspecified.ISO/IEC 8652:2007(E) Ed. 7 8 11. the exception_declarations implicitly generated by different instantiations of the generic unit refer to distinct exceptions (but all have the same defining_identifier). Program_Error. control can be transferred to a user-provided exception_handler at the end of a handled_sequence_of_statements. Dynamic Semantics 3 4 The elaboration of an exception_declaration has no effect. The predefined exceptions are the ones declared in the declaration of package Standard: Constraint_Error. Static Semantics 2 Each single exception_declaration declares a name for a different exception. Error : exception. To raise an exception is to abandon normal program execution so as to draw attention to the fact that the corresponding situation has arisen. and Tasking_Error. An exception_declaration declares a name for an exception. Storage_Error.

-. Two choices in different exception_handlers of the same handled_sequence_of_statements shall not cover the same exception. Examples 11 12 Example of an exception handler: begin Open(File. During the handling of an exception occurrence.4. An exception_name of a choice shall not denote an exception declared in a generic formal package. 11. 3 — Ada Reference Manual Syntax 2 handled_sequence_of_statements ::= sequence_of_statements [exception exception_handler {exception_handler}] 3 exception_handler ::= when [choice_parameter_specification:] exception_choice {| exception_choice} => sequence_of_statements choice_parameter_specification ::= defining_identifier exception_choice ::= exception_name | others Legality Rules 4 5 6 A choice with an exception_name covers the named exception. The optional handlers are used to handle any exceptions that are propagated by the sequence_of_statements. Static Semantics 7 8 9 A choice_parameter_specification declares a choice parameter. A choice with others covers all exceptions not named by previous choices of the same handled_sequence_of_statements. if any.1). | raise exception_name [with string_expression]. Put_Line(Exception_Message(E)).2 Exception Handlers 10 November 2006 236 . the choice parameter.ISO/IEC 8652:2007(E) Ed. of the handler represents the exception occurrence that is being handled.see A.1 raise. In_File.8.4. -. Syntax 2/2 raise_statement ::= raise. Dynamic Semantics 10 The execution of a handled_sequence_of_statements consists of the execution of the sequence_of_statements. which is a constant object of type Exception_Occurrence (see 11.see 11. end.txt"). "input. A choice with others is allowed only for the last handler of a handled_sequence_of_statements and as the only choice of that handler.2 exception when E : Name_Error => Put("Cannot open input file : "). 11.3 Raise Statements 1 A raise_statement raises an exception.

which creates the choice parameter and initializes it to the occurrence. the occurrence is handled by that handler.1/2 To raise an exception is to raise a new occurrence of that exception. the execution of a is said to dynamically enclose the execution of b.11 raise. Then. the named exception is raised. is first elaborated. Name Resolution Rules 3 The expression. When an occurrence is handled by a given handler. the expression is evaluated and its value is associated with the exception occurrence.1.3 . if any.6. the rest of the execution of that construct is abandoned. that is. -.Name_Error. this execution replaces the abandoned portion of the execution of the sequence_of_statements. and then left. if any. which means that the occurrence is raised again in that context. Examples 4/2 Examples of raise statements: raise Ada. The construct is first completed. 3 — Ada Reference Manual Legality Rules The name. To handle an exception occurrence is to respond to the exceptional event.13 raise Queue_Error with "Buffer Full".re-raise the current exception 5 6/2 7 11.see 9. the sequence_of_statements of the handler is executed.4 Exception Handling When an exception occurrence is raised. For the execution of a re-raise statement. • If the construct is the sequence_of_statements of a handled_sequence_of_statements that has a handler with a choice covering the exception. the choice_parameter_specification. Then: • If the construct is a task_body. Dynamic Semantics 1 Within a given task. as explained in 11. in a raise_statement.IO_Exceptions.ISO/IEC 8652:2007(E) Ed. then while b is executing. is expected to be of type String. the occurrence is propagated to the innermost dynamically enclosing execution. if any. To propagate an exception occurrence is to raise it again in another context. the exception does not propagate further. but not within a body enclosed by that handler. When an exception occurrence is raised by the execution of a given construct. if any.see A. For the execution of a raise_statement with an exception_name. a re-raise statement) shall be within a handler. normal program execution is abandoned and control is transferred to an applicable exception_handler. • Otherwise. -.4. A raise_statement with no exception_name (that is. any portions of the execution that have not yet taken place are not performed. if the execution of construct a is defined by this International Standard to consist (in part) of the execution of construct b. -. Dynamic Semantics 3. as explained in 7. The innermost dynamically enclosing execution of a given execution is the dynamically enclosing execution that started most recently. 2 3 4 5 6 7 237 10 November 2006 Raise Statements 11. the exception occurrence that caused transfer of control to the innermost enclosing handler is raised again. that is. If a string_expression is present. in a raise_statement shall denote an exception. to fail to respond to the exceptional event in the present context.

and is the default initial value of type Exception_Occurrence. procedure Save_Occurrence(Target : out Exception_Occurrence. 8 11.1 The Package Exceptions Static Semantics 1 2/2 The following language-defined library package exists: with Ada. Null_Id does not represent any exception. Item : out Exception_Occurrence).Streams. function Wide_Wide_Exception_Name(X : Exception_Occurrence) return Wide_Wide_String.2/2 6. function Wide_Exception_Name(Id : Exception_Id) return Wide_String.Exceptions.Streams. function Exception_Information(X : Exception_Occurrence) return String. procedure Raise_Exception(E : in Exception_Id. function Save_Occurrence(Source : Exception_Occurrence) return Exception_Occurrence_Access. for Exception_Occurrence'Read use Read_Exception_Occurrence. Message : in String := ""). Null_Occurrence does not represent any exception occurrence.Streams. function Wide_Wide_Exception_Name(Id : Exception_Id) return Wide_Wide_String.Root_Stream_Type'Class. -.ISO/IEC 8652:2007(E) Ed. and is the default initial value of type Exception_Id. -. Item : in Exception_Occurrence). function Exception_Name(X : Exception_Occurrence) return String. private .not specified by the language end Ada. pragma No_Return(Raise_Exception). Source : in Exception_Occurrence).4 Exception Handling 10 November 2006 238 . for Exception_Occurrence'Write use Write_Exception_Occurrence.3/2 7 Each distinct exception is represented by a distinct value of type Exception_Id.Same as Exception_Name(Exception_Identity(X)).Exceptions is pragma Preelaborate(Exceptions). package Ada. pragma Preelaborable_Initialization(Exception_Id). function Exception_Name(Id : Exception_Id) return String.. type Exception_Id is private. 3 — Ada Reference Manual NOTES 1 Note that exceptions raised in a declarative_part of a body are not handled by the handlers of the handled_sequence_of_statements of that body.1/2 6.Same as Wide_Wide_Exception_Name(Exception_Identity(X)). function Wide_Exception_Name(X : Exception_Occurrence) return Wide_String.Root_Stream_Type'Class. -. Each occurrence of an exception is represented by a value of type Exception_Occurrence. 11.4.Same as Wide_Exception_Name(Exception_Identity(X)). type Exception_Occurrence_Access is access all Exception_Occurrence. procedure Write_Exception_Occurrence (Stream : not null access Ada. pragma Preelaborable_Initialization(Exception_Occurrence).. Null_Occurrence : constant Exception_Occurrence. function Exception_Identity(X : Exception_Occurrence) return Exception_Id. 3/2 4/2 5/2 6/2 6. procedure Read_Exception_Occurrence (Stream : not null access Ada. function Exception_Message(X : Exception_Occurrence) return String. procedure Reraise_Occurrence(X : in Exception_Occurrence). Null_Id : constant Exception_Id. type Exception_Occurrence is limited private. -.

The type of this attribute is Exception_Id. starting with a root library unit. The Save_Occurrence procedure copies the Source to the Target. 3 — Ada Reference Manual For a prefix E that denotes an exception. 8/1 9 Raise_Exception raises a new occurrence of the identified exception. the following attribute is defined: E'Identity E'Identity returns the unique identity of the exception. Exception_Message returns a string with lower bound 1. and Wide_Wide_Exception_Name functions has lower bound 1.2/2 11 12/2 12. The Save_Occurrence function uses an allocator of type Exception_Occurrence_Access to create a new object. The returned string has lower bound 1. Raise_Exception and Exception_Name raise Constraint_Error for a Null_Id. In all cases. For the occurrence raised by a raise_statement with an exception_name and a string_expression. the message is the string_expression. For an occurrence raised by a call to Raise_Exception. Wide_Exception_Name. and returns an access value designating this new object. Exception_Information returns implementation-defined information about the exception occurrence. Read_Exception_Occurrence reconstructs an exception occurrence from a stream (including one written in a different partition).4. Exception_Message returns the message associated with the given Exception_Occurrence. otherwise.1/2 This paragraph was deleted. and Exception_Information raise Constraint_Error for a Null_Occurrence. Exception_Message.2/2 13/2 14/2 15 object.1 . The result is implementation defined if the exception is declared within an unnamed block_statement. Exception_Identity returns the identity of the exception of the occurrence. Wide_Exception_Name) return the same sequence of graphic characters as that defined for Wide_Wide_Exception_Name. the sequence of characters is implementation defined. the message is the Message parameter passed to Raise_Exception. Reraise_Occurrence has no effect in the case of Null_Occurrence. in upper case. the result may be deallocated using an instance of Unchecked_Deallocation. The Exception_Name functions (respectively. Exception_Name. Wide_Character). the message is a string giving implementationdefined information about the exception occurrence. Reraise_Occurrence reraises the specified exception occurrence. Implementation Requirements 15.1/2 12. but no shorter than that returned by Wide_Wide_Exception_Name for the same value of the argument.1/2 10. The Wide_Wide_Exception_Name functions return the full expanded name of the exception. For an exception declared immediately within package Standard. Exception_Identity applied to Null_Occurrence returns Null_Id. The string returned by the Exception_Name. For the occurrence raised by a raise_statement with an exception_name but without a string_expression. 16/2 239 10 November 2006 The Package Exceptions 11. copies the Source to this new 10/2 10. Write_Exception_Occurrence writes a representation of an exception occurrence to a stream.ISO/IEC 8652:2007(E) Ed. if all the graphic characters are defined in Character (respectively. the defining_identifier is returned.

1 The Package Exceptions 10 November 2006 240 . Exception_Message should not include the Exception_Name. Pragma Assertion_Policy is used to control whether such assertions are to be ignored by the implementation. Assertion_Error : exception. end Ada. 11/2 12/2 13/2 14/2 15/2 11. 11. or handled in some implementation-defined manner. The form of a pragma Assertion_Policy is as follows: pragma Assertion_Policy(policy_identifier). and the re-raise statement.ISO/IEC 8652:2007(E) Ed. Ignore. A pragma Assert is allowed at the place where a declarative_item or a statement is allowed. A pragma Assertion_Policy is a configuration pragma. the Reraise_Occurrence procedure. 3 — Ada Reference Manual Implementation Permissions 17 An implementation of Exception_Name in a space-constrained environment may return the defining_identifier instead of the full expanded name. Implementation Advice 18 19 Exception_Message (by default) and Exception_Information should produce information useful for debugging. Static Semantics 10/2 A pragma Assertion_Policy is a configuration pragma that specifies the assertion policy in effect for the compilation units to which it applies. whereas Exception_Information can be long. Different policies may apply to different compilation units within the same partition.Assertions.4. procedure Assert(Check : in Boolean. Message : in String).Assertions is pragma Pure(Assertions). Exception_Information should include both the Exception_Name and the Exception_Message.4. The string returned by Exception_Message may be truncated (to no less than 200 characters) by the Save_Occurrence procedure (not the function). or an implementationdefined identifier. Exception_Message should be short (about one line). The expected type for the string_expression of a pragma Assert is type String. The following language-defined library package exists: package Ada. The default assertion policy is implementation-defined. Legality Rules 9/2 The policy_identifier of a pragma Assertion_Policy shall be either Check. checked at run-time. [Message =>] string_expression]). Syntax 2/2 3/2 4/2 5/2 6/2 7/2 The form of a pragma Assert is as follows: pragma Assert([Check =>] boolean_expression[. Name Resolution Rules 8/2 The expected type for the boolean_expression of a pragma Assert is any boolean type. procedure Assert(Check : in Boolean).2 Pragmas Assert and Assertion_Policy 1/2 Pragma Assert is used to assert the truth of a Boolean expression at any point within a sequence of declarations or statements.

procedure Read(F : in out File_Handle. 24/2 25/2 26/2 11. Implementation Permissions 23/2 Assertion_Error may be declared by renaming an implementation-defined exception from another package. 3 — Ada Reference Manual A compilation unit containing a pragma Assert has a semantic dependence on the Assertions library unit. procedure Open(F : in out File_Handle.Assertion_Error. end if. 18/2 19/2 20/2 Calling the procedure Assertions. If the assertion policy is Check at the point of a pragma Assert.Assert without a Message parameter is equivalent to: if Check = False then raise Ada. Dynamic Semantics 16/2 17/2 An assertion policy specifies how a pragma Assert is interpreted by the implementation. the elaboration of the pragma consists of evaluating the boolean expression.Assertion_Error with Message. end if. Calling the procedure Assertions. If the assertion policy is Ignore at the point of a pragma Assert. with a message if the Message argument is provided. so that the particular assertion policy in effect will not affect normal operation of the program.Assertions.Assertion_Error. -.raises File_Not_Found if named file does not exist End_Of_File : exception.4. evaluating the Message argument. end File_System. 1 2/2 3 4 5 241 10 November 2006 Pragmas Assert and Assertion_Policy 11. Data : out Data_Type). Name : String). the boolean expression in a pragma Assert should not call functions that have significant side-effects when the result of the expression is True.raises End_Of_File if the file is not open . -. if any. the pragma is ignored.2 . 21/2 22/2 The procedures Assertions. NOTES 2 Normally. The assertion policy that applies to a generic unit also applies to all its instances..Assertions..Assert with a Message parameter is equivalent to: if Check = False then raise Ada. and if the result is False.Assert have these effects independently of the assertion policy in effect. File_Not_Found : exception.3 Example of Exception Handling Examples Exception handling may be used to separate the detection of an error from the response to that error: package File_System is type File_Handle is limited private. and raising the exception Assertions.4.ISO/IEC 8652:2007(E) Ed. Implementations may define their own assertion policies.

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual
6/2

package body File_System is procedure Open(F : in out File_Handle; Name : String) is begin if File_Exists(Name) then ... else raise File_Not_Found with "File not found: " & Name & "."; end if; end Open; procedure Read(F : in out File_Handle; Data : out Data_Type) is begin if F.Current_Position <= F.Last_Position then ... else raise End_Of_File; end if; end Read; ... end File_System; with Ada.Text_IO; with Ada.Exceptions; with File_System; use File_System; use Ada; procedure Main is begin ... -- call operations in File_System exception when End_Of_File => Close(Some_File); when Not_Found_Error : File_Not_Found => Text_IO.Put_Line(Exceptions.Exception_Message(Not_Found_Error)); when The_Error : others => Text_IO.Put_Line("Unknown error:"); if Verbosity_Desired then Text_IO.Put_Line(Exceptions.Exception_Information(The_Error)); else Text_IO.Put_Line(Exceptions.Exception_Name(The_Error)); Text_IO.Put_Line(Exceptions.Exception_Message(The_Error)); end if; raise; end Main;

7

8 9 10

11

In the above example, the File_System package contains information about detecting certain exceptional situations, but it does not specify how to handle those situations. Procedure Main specifies how to handle them; other clients of File_System might have different handlers, even though the exceptional situations arise from the same basic causes.

11.5 Suppressing Checks
1/2

Checking pragmas give instructions to an implementation on handling language-defined checks. A pragma Suppress gives permission to an implementation to omit certain language-defined checks, while a pragma Unsuppress revokes the permission to omit checks.. A language-defined check (or simply, a “check”) is one of the situations defined by this International Standard that requires a check to be made at run time to determine whether some condition is true. A check fails when the condition being checked is false, causing an exception to be raised.

2

11.4.3 Example of Exception Handling

10 November 2006

242

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual
Syntax

The forms of checking pragmas are as follows: pragma Suppress(identifier); pragma Unsuppress(identifier); A checking pragma is allowed only immediately within a declarative_part, immediately within a package_specification, or as a configuration pragma.
Legality Rules

3/2 4/2 4.1/2 5/2

The identifier shall be the name of a check.
This paragraph was deleted.
Static Semantics

6/2 7/2

A checking pragma applies to the named check in a specific region, and applies to all entities in that region. A checking pragma given in a declarative_part or immediately within a package_specification applies from the place of the pragma to the end of the innermost enclosing declarative region. The region for a checking pragma given as a configuration pragma is the declarative region for the entire compilation unit (or units) to which it applies. If a checking pragma applies to a generic instantiation, then the checking pragma also applies to the instance. If a checking pragma applies to a call to a subprogram that has a pragma Inline applied to it, then the checking pragma also applies to the inlined subprogram body. A pragma Suppress gives permission to an implementation to omit the named check (or every check in the case of All_Checks) for any entities to which it applies. If permission has been given to suppress a given check, the check is said to be suppressed. A pragma Unsuppress revokes the permission to omit the named check (or every check in the case of All_Checks) given by any pragma Suppress that applies at the point of the pragma Unsuppress. The permission is revoked for the region to which the pragma Unsuppress applies. If there is no such permission at the point of a pragma Unsuppress, then the pragma has no effect. A later pragma Suppress can renew the permission. The following are the language-defined checks: • The following checks correspond to situations in which the exception Constraint_Error is raised upon failure. Access_Check When evaluating a dereference (explicit or implicit), check that the value of the name is not null. When converting to a subtype that excludes null, check that the converted value is not null. Discriminant_Check Check that the discriminants of a composite value have the values imposed by a discriminant constraint. Also, when accessing a record component, check that it exists for the current discriminant values. Division_Check Check that the second operand is not zero for the operations /, rem and mod. Index_Check Check that the bounds of an array value are equal to the corresponding bounds of an index constraint. Also, when accessing a component of an array object, check for each dimension that the given index value belongs to the range defined by the bounds of the

7.1/2

7.2/2

8/2

8.1/2

9 10

11/2

12

13/2

14

243

10 November 2006

Suppressing Checks 11.5

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

array object. Also, when accessing a slice of an array object, check that the given discrete range is compatible with the range defined by the bounds of the array object.
15

Length_Check Check that two arrays have matching components, in the case of array subtype conversions, and logical operators for arrays of boolean components. Overflow_Check Check that a scalar value is within the base range of its type, in cases where the implementation chooses to raise an exception instead of returning the correct mathematical result. Range_Check Check that a scalar value satisfies a range constraint. Also, for the elaboration of a subtype_indication, check that the constraint (if present) is compatible with the subtype denoted by the subtype_mark. Also, for an aggregate, check that an index or discriminant value belongs to the corresponding subtype. Also, check that when the result of an operation yields an array, the value of each component belongs to the component subtype. Tag_Check Check that operand tags in a dispatching call are all equal. Check for the correct tag on tagged type conversions, for an assignment_statement, and when returning a tagged limited object from a function. • The following checks correspond to situations in which the exception Program_Error is raised upon failure. Accessibility_Check Check the accessibility level of an entity or view. Allocation_Check For an allocator, check that the master of any tasks to be created by the allocator is not yet completed or some dependents have not yet terminated, and that the finalization of the collection has not started. Elaboration_Check When a subprogram or protected entry is called, a task activation is accomplished, or a generic instantiation is elaborated, check that the body of the corresponding unit has already been elaborated.
This paragraph was deleted.

16

17

18

19

19.1/2

19.2/2

20

21/2 22

23

• The following check corresponds to situations in which the exception Storage_Error is raised upon failure. Storage_Check Check that evaluation of an allocator does not require more space than is available for a storage pool. Check that the space available for a task or subprogram has not been exceeded. • The following check corresponds to all situations in which any predefined exception is raised. All_Checks Represents the union of all checks; suppressing All_Checks suppresses all checks.
Erroneous Execution

24 25

26

If a given check has been suppressed, and the corresponding error situation occurs, the execution of the program is erroneous.

11.5 Suppressing Checks

10 November 2006

244

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual
Implementation Permissions

An implementation is allowed to place restrictions on checking pragmas, subject only to the requirement that pragma Unsuppress shall allow any check names supported by pragma Suppress. An implementation is allowed to add additional check names, with implementation-defined semantics. When Overflow_Check has been suppressed, an implementation may also suppress an unspecified subset of the Range_Checks. An implementation may support an additional parameter on pragma Unsuppress similar to the one allowed for pragma Suppress (see J.10). The meaning of such a parameter is implementation-defined.
Implementation Advice

27/2

27.1/2

The implementation should minimize the code executed for checks that have been suppressed.
NOTES 3 There is no guarantee that a suppressed check is actually removed; hence a pragma Suppress should be used only for efficiency reasons. 4 It is possible to give both a pragma Suppress and Unsuppress for the same check immediately within the same declarative_part. In that case, the last pragma given determines whether or not the check is suppressed. Similarly, it is possible to resuppress a check which has been unsuppressed by giving a pragma Suppress in an inner declarative region.
Examples

28

29

29.1/2

Examples of suppressing and unsuppressing checks:
pragma Suppress(Index_Check); pragma Unsuppress(Overflow_Check);

30/2 31/2

11.6 Exceptions and Optimization
This clause gives permission to the implementation to perform certain “optimizations” that do not necessarily preserve the canonical semantics.
Dynamic Semantics
1

The rest of this International Standard (outside this clause) defines the canonical semantics of the language. The canonical semantics of a given (legal) program determines a set of possible external effects that can result from the execution of the program with given inputs. As explained in 1.1.3, “Conformity of an Implementation with the Standard”, the external effect of a program is defined in terms of its interactions with its external environment. Hence, the implementation can perform any internal actions whatsoever, in any order or in parallel, so long as the external effect of the execution of the program is one that is allowed by the canonical semantics, or by the rules of this clause.
Implementation Permissions

2

3

The following additional permissions are granted to the implementation: • An implementation need not always raise an exception when a language-defined check fails. Instead, the operation that failed the check can simply yield an undefined result. The exception need be raised by the implementation only if, in the absence of raising it, the value of this undefined result would have some effect on the external interactions of the program. In determining this, the implementation shall not presume that an undefined result has a value that belongs to its subtype, nor even to the base range of its type, if scalar. Having removed the raise of the exception, the canonical semantics will in general allow the implementation to omit the code for the check, and some or all of the operation itself.

4 5

245

10 November 2006

Suppressing Checks 11.5

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

6

• If an exception is raised due to the failure of a language-defined check, then upon reaching the corresponding exception_handler (or the termination of the task, if none), the external interactions that have occurred need reflect only that the exception was raised somewhere within the execution of the sequence_of_statements with the handler (or the task_body), possibly earlier (or later if the interactions are independent of the result of the checked operation) than that defined by the canonical semantics, but not within the execution of some abort-deferred operation or independent subprogram that does not dynamically enclose the execution of the construct whose check failed. An independent subprogram is one that is defined outside the library unit containing the construct whose check failed, and has no Inline pragma applied to it. Any assignment that occurred outside of such abort-deferred operations or independent subprograms can be disrupted by the raising of the exception, causing the object or its parts to become abnormal, and certain subsequent uses of the object to be erroneous, as explained in 13.9.1.
NOTES 5 The permissions granted by this clause can have an effect on the semantics of a program only if the program fails a language-defined check.

7

11.6 Exceptions and Optimization

10 November 2006

246

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

Section 12: Generic Units
A generic unit is a program unit that is either a generic subprogram or a generic package. A generic unit is a template, which can be parameterized, and from which corresponding (nongeneric) subprograms or packages can be obtained. The resulting program units are said to be instances of the original generic unit. A generic unit is declared by a generic_declaration. This form of declaration has a generic_formal_part declaring any generic formal parameters. An instance of a generic unit is obtained as the result of a generic_instantiation with appropriate generic actual parameters for the generic formal parameters. An instance of a generic subprogram is a subprogram. An instance of a generic package is a package. Generic units are templates. As templates they do not have the properties that are specific to their nongeneric counterparts. For example, a generic subprogram can be instantiated but it cannot be called. In contrast, an instance of a generic subprogram is a (nongeneric) subprogram; hence, this instance can be called but it cannot be used to produce further instances.
1

2

3

12.1 Generic Declarations
A generic_declaration declares a generic unit, which is either a generic subprogram or a generic package. A generic_declaration includes a generic_formal_part declaring any generic formal parameters. A generic formal parameter can be an object; alternatively (unlike a parameter of a subprogram), it can be a type, a subprogram, or a package.
Syntax
1

generic_declaration ::= generic_subprogram_declaration | generic_package_declaration generic_subprogram_declaration ::= generic_formal_part subprogram_specification; generic_package_declaration ::= generic_formal_part package_specification; generic_formal_part ::= generic {generic_formal_parameter_declaration | use_clause} generic_formal_parameter_declaration ::= formal_object_declaration | formal_type_declaration | formal_subprogram_declaration | formal_package_declaration

2 3

4

5 6

The only form of subtype_indication allowed within a generic_formal_part is a subtype_mark (that is, the subtype_indication shall not include an explicit constraint). The defining name of a generic subprogram shall be an identifier (not an operator_symbol).
Static Semantics

7

A generic_declaration declares a generic unit — a generic package, generic procedure, or generic function, as appropriate. An entity is a generic formal entity if it is declared by a generic_formal_parameter_declaration. “Generic formal,” or simply “formal,” is used as a prefix in referring to objects, subtypes (and types), functions, procedures and packages, that are generic formal entities, as well as to their respective declarations. Examples: “generic formal procedure” or a “formal integer type declaration.”

8/2

9

247

10 November 2006

Generic Units 12

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual
Dynamic Semantics
10

The elaboration of a generic_declaration has no effect.
NOTES 1 Outside a generic unit a name that denotes the generic_declaration denotes the generic unit. In contrast, within the declarative region of the generic unit, a name that denotes the generic_declaration denotes the current instance. 2 Within a generic subprogram_body, the name of this program unit acts as the name of a subprogram. Hence this name can be overloaded, and it can appear in a recursive call of the current instance. For the same reason, this name cannot appear after the reserved word new in a (recursive) generic_instantiation. 3 A default_expression or default_name appearing in a generic_formal_part is not evaluated during elaboration of the generic_formal_part; instead, it is evaluated when used. (The usual visibility rules apply to any name used in a default: the denoted declaration therefore has to be visible at the place of the expression.)
Examples

11

12

13

14 15 16 17 18 19

Examples of generic formal parts:
generic -- parameterless -- formal object -- formal object with a default expression generic Size : Natural;

generic Length : Integer := 200; Area generic type type type with

: Integer := Length*Length; -- formal object with a default expression Item is Index is Row is function private; -- formal type (<>); -- formal type array(Index range <>) of Item; -- formal type "<"(X, Y : Item) return Boolean; -- formal subprogram

20 21

Examples of generic declarations declaring generic subprograms Exchange and Squaring:
generic type Elem is private; procedure Exchange(U, V : in out Elem); generic type Item is private; with function "*"(U, V : Item) return Item is <>; function Squaring(X : Item) return Item;

22

23 24

Example of a generic declaration declaring a generic package:
generic type Item is private; type Vector is array (Positive range <>) of Item; with function Sum(X, Y : Item) return Item; package On_Vectors is function Sum (A, B : Vector) return Vector; function Sigma(A : Vector) return Item; Length_Error : exception; end On_Vectors;

12.1 Generic Declarations

10 November 2006

248

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

12.2 Generic Bodies
The body of a generic unit (a generic body) is a template for the instance bodies. The syntax of a generic body is identical to that of a nongeneric body.
Dynamic Semantics
1

The elaboration of a generic body has no other effect than to establish that the generic unit can from then on be instantiated without failing the Elaboration_Check. If the generic body is a child of a generic package, then its elaboration establishes that each corresponding declaration nested in an instance of the parent (see 10.1.1) can from then on be instantiated without failing the Elaboration_Check.
NOTES 4 The syntax of generic subprograms implies that a generic subprogram body is always the completion of a declaration.
Examples

2

3

Example of a generic procedure body:
procedure Exchange(U, V : in out Elem) is T : Elem; -- the generic formal type begin T := U; U := V; V := T; end Exchange; -- see 12.1

4 5

Example of a generic function body:
function Squaring(X : Item) return Item is begin return X*X; -- the formal operator "*" end Squaring; -- see 12.1

6 7

Example of a generic package body:
package body On_Vectors is -- see 12.1 function Sum(A, B : Vector) return Vector is Result : Vector(A'Range); -- the formal type Vector Bias : constant Integer := B'First - A'First; begin if A'Length /= B'Length then raise Length_Error; end if; for N in A'Range loop Result(N) := Sum(A(N), B(N + Bias)); -- the formal function Sum end loop; return Result; end Sum; function Sigma(A : Vector) return Item is Total : Item := A(A'First); -- the formal type Item begin for N in A'First + 1 .. A'Last loop Total := Sum(Total, A(N)); -- the formal function Sum end loop; return Total; end Sigma; end On_Vectors;

8 9 10

11

12

249

10 November 2006

Generic Bodies 12.2

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

12.3 Generic Instantiation
1

An instance of a generic unit is declared by a generic_instantiation.
Syntax

2/2

generic_instantiation ::= package defining_program_unit_name is new generic_package_name [generic_actual_part]; | [overriding_indicator] procedure defining_program_unit_name is new generic_procedure_name [generic_actual_part]; | [overriding_indicator] function defining_designator is new generic_function_name [generic_actual_part]; generic_actual_part ::= (generic_association {, generic_association}) generic_association ::=

3

4

[generic_formal_parameter_selector_name =>] explicit_generic_actual_parameter
5

explicit_generic_actual_parameter ::= expression | variable_name | subprogram_name | entry_name | subtype_mark | package_instance_name

6

A generic_association is named or positional according to whether or not the generic_formal_parameter_selector_name is specified. Any positional associations shall precede any named associations. The generic actual parameter is either the explicit_generic_actual_parameter given in a generic_association for each formal, or the corresponding default_expression or default_name if no generic_association is given for the formal. When the meaning is clear from context, the term “generic actual,” or simply “actual,” is used as a synonym for “generic actual parameter” and also for the view denoted by one, or the value of one.
Legality Rules

7/2

8

In a generic_instantiation for a particular kind of program unit (package, procedure, or function), the name shall denote a generic unit of the corresponding kind (generic package, generic procedure, or generic function, respectively). The generic_formal_parameter_selector_name of a generic_association shall denote a generic_formal_parameter_declaration of the generic unit being instantiated. If two or more formal subprograms have the same defining name, then named associations are not allowed for the corresponding actuals.

9

10

A generic_instantiation shall contain at most one generic_association for each formal. Each formal without an association shall have a default_expression or subprogram_default. In a generic unit Legality Rules are enforced at compile time of the generic_declaration and generic body, given the properties of the formals. In the visible part and formal part of an instance, Legality Rules are enforced at compile time of the generic_instantiation, given the properties of the actuals. In other parts of an instance, Legality Rules are not enforced; this rule does not apply when a given rule explicitly specifies otherwise.

11

12.3 Generic Instantiation

10 November 2006

250

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual
Static Semantics

A generic_instantiation declares an instance; it is equivalent to the instance declaration (a package_declaration or subprogram_declaration) immediately followed by the instance body, both at the place of the instantiation. The instance is a copy of the text of the template. Each use of a formal parameter becomes (in the copy) a use of the actual, as explained below. An instance of a generic package is a package, that of a generic procedure is a procedure, and that of a generic function is a function. The interpretation of each construct within a generic declaration or body is determined using the overloading rules when that generic declaration or body is compiled. In an instance, the interpretation of each (copied) construct is the same, except in the case of a name that denotes the generic_declaration or some declaration within the generic unit; the corresponding name in the instance then denotes the corresponding copy of the denoted declaration. The overloading rules do not apply in the instance. In an instance, a generic_formal_parameter_declaration declares a view whose properties are identical to those of the actual, except as specified in 12.4, “Formal Objects” and 12.6, “Formal Subprograms”. Similarly, for a declaration within a generic_formal_parameter_declaration, the corresponding declaration in an instance declares a view whose properties are identical to the corresponding declaration within the declaration of the actual. Implicit declarations are also copied, and a name that denotes an implicit declaration in the generic denotes the corresponding copy in the instance. However, for a type declared within the visible part of the generic, a whole new set of primitive subprograms is implicitly declared for use outside the instance, and may differ from the copied set if the properties of the type in some way depend on the properties of some actual type specified in the instantiation. For example, if the type in the generic is derived from a formal private type, then in the instance the type will inherit subprograms from the corresponding actual type. These new implicit declarations occur immediately after the type declaration in the instance, and override the copied ones. The copied ones can be called only from within the instance; the new ones can be called only from outside the instance, although for tagged types, the body of a new one can be executed by a call to an old one. In the visible part of an instance, an explicit declaration overrides an implicit declaration if they are homographs, as described in 8.3. On the other hand, an explicit declaration in the private part of an instance overrides an implicit declaration in the instance, only if the corresponding explicit declaration in the generic overrides a corresponding implicit declaration in the generic. Corresponding rules apply to the other kinds of overriding described in 8.3.
Post-Compilation Rules

12

13

14

15

16

17

18

Recursive generic instantiation is not allowed in the following sense: if a given generic unit includes an instantiation of a second generic unit, then the instance generated by this instantiation shall not include an instance of the first generic unit (whether this instance is generated directly, or indirectly by intermediate instantiations).
Dynamic Semantics

19

For the elaboration of a generic_instantiation, each generic_association is first evaluated. If a default is used, an implicit generic_association is assumed for this rule. These evaluations are done in an arbitrary order, except that the evaluation for a default actual takes place after the evaluation for another actual if the default includes a name that denotes the other one. Finally, the instance declaration and body are elaborated.

20

251

10 November 2006

Generic Instantiation 12.3

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

21

For the evaluation of a generic_association the generic actual parameter is evaluated. Additional actions are performed in the case of a formal object of mode in (see 12.4).
NOTES 5 If a formal type is not tagged, then the type is treated as an untagged type within the generic body. Deriving from such a type in a generic body is permitted; the new type does not get a new tag value, even if the actual is tagged. Overriding operations for such a derived type cannot be dispatched to from outside the instance.
Examples

22

23 24

Examples of generic instantiations (see 12.1):
procedure Swap is new Exchange(Elem => Integer); procedure Swap is new Exchange(Character); -- Swap is overloaded function Square is new Squaring(Integer); -- "*" of Integer used by default function Square is new Squaring(Item => Matrix, "*" => Matrix_Product); function Square is new Squaring(Matrix, Matrix_Product); -- same as previous package Int_Vectors is new On_Vectors(Integer, Table, "+");

25 26 27 28

Examples of uses of instantiated units:
Swap(A, B); A := Square(A); T : Table(1 .. 5) := (10, 20, 30, 40, 50); N : Integer := Int_Vectors.Sigma(T); -- 150 (see 12.2, “Generic Bodies” for the body of Sigma) use Int_Vectors; M : Integer := Sigma(T); -- 150

29

12.4 Formal Objects
1

A generic formal object can be used to pass a value or variable to a generic unit.
Syntax

2/2

formal_object_declaration ::= defining_identifier_list : mode [null_exclusion] subtype_mark [:= default_expression]; defining_identifier_list : mode access_definition [:= default_expression];
Name Resolution Rules

3 4 5/2

The expected type for the default_expression, if any, of a formal object is the type of the formal object. For a generic formal object of mode in, the expected type for the actual is the type of the formal. For a generic formal object of mode in out, the type of the actual shall resolve to the type determined by the subtype_mark, or for a formal_object_declaration with an access_definition, to a specific anonymous access type. If the anonymous access type is an access-to-object type, the type of the actual shall have the same designated type as that of the access_definition. If the anonymous access type is an access-tosubprogram type, the type of the actual shall have a designated profile which is type conformant with that of the access_definition. .
Legality Rules

6

If a generic formal object has a default_expression, then the mode shall be in (either explicitly or by default); otherwise, its mode shall be either in or in out. For a generic formal object of mode in, the actual shall be an expression. For a generic formal object of mode in out, the actual shall be a name that denotes a variable for which renaming is allowed (see 8.5.1).

7

12.3 Generic Instantiation

10 November 2006

252

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

In the case where the type of the formal is defined by an access_definition, the type of the actual and the type of the formal: • shall both be access-to-object types with statically matching designated subtypes and with both or neither being access-to-constant types; or • shall both be access-to-subprogram types with subtype conformant designated profiles. For a formal_object_declaration with a null_exclusion or an access_definition that has a null_exclusion: • if the actual matching the formal_object_declaration denotes the generic formal object of another generic unit G, and the instantiation containing the actual occurs within the body of G or within the body of a generic unit declared within the declarative region of G, then the declaration of the formal object of G shall have a null_exclusion; • otherwise, the subtype of the actual matching the formal_object_declaration shall exclude null. In addition to the places where Legality Rules normally apply (see 12.3), this rule applies also in the private part of an instance of a generic unit.
Static Semantics

8/2

8.1/2

8.2/2 8.3/2 8.4/2

8.5/2

A formal_object_declaration declares a generic formal object. The default mode is in. For a formal object of mode in, the nominal subtype is the one denoted by the subtype_mark or access_definition in the declaration of the formal. For a formal object of mode in out, its type is determined by the subtype_mark or access_definition in the declaration; its nominal subtype is nonstatic, even if the subtype_mark denotes a static subtype; for a composite type, its nominal subtype is unconstrained if the first subtype of the type is unconstrained, even if the subtype_mark denotes a constrained subtype. In an instance, a formal_object_declaration of mode in is a full constant declaration and declares a new stand-alone constant object whose initialization expression is the actual, whereas a formal_object_declaration of mode in out declares a view whose properties are identical to those of the actual.
Dynamic Semantics

9/2

10/2

For the evaluation of a generic_association for a formal object of mode in, a constant object is created, the value of the actual parameter is converted to the nominal subtype of the formal object, and assigned to the object, including any value adjustment — see 7.6.
NOTES 6 The constraints that apply to a generic formal object of mode in out are those of the corresponding generic actual parameter (not those implied by the subtype_mark that appears in the formal_object_declaration). Therefore, to avoid confusion, it is recommended that the name of a first subtype be used for the declaration of such a formal object.

11

12

253

10 November 2006

Formal Objects 12.4

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

12.5 Formal Types
1/2

A generic formal subtype can be used to pass to a generic unit a subtype whose type is in a certain category of types.
Syntax

2

formal_type_declaration ::= type defining_identifier[discriminant_part] is formal_type_definition; formal_type_definition ::= formal_private_type_definition | formal_derived_type_definition | formal_discrete_type_definition | formal_signed_integer_type_definition | formal_modular_type_definition | formal_floating_point_definition | formal_ordinary_fixed_point_definition | formal_decimal_fixed_point_definition | formal_array_type_definition | formal_access_type_definition | formal_interface_type_definition
Legality Rules

3/2

4

For a generic formal subtype, the actual shall be a subtype_mark; it denotes the (generic) actual subtype.
Static Semantics

5

A formal_type_declaration declares a (generic) formal type, and its first subtype, the (generic) formal subtype. The form of a formal_type_definition determines a category (of types) to which the formal type belongs. For a formal_private_type_definition the reserved words tagged and limited indicate the category of types (see 12.5.1). For a formal_derived_type_definition the category of types is the derivation class rooted at the ancestor type. For other formal types, the name of the syntactic category indicates the category of types; a formal_discrete_type_definition defines a discrete type, and so on.
Legality Rules

6/2

7/2

The actual type shall be in the category determined for the formal.
Static Semantics

8/2

The formal type also belongs to each category that contains the determined category. The primitive subprograms of the type are as for any type in the determined category. For a formal type other than a formal derived type, these are the predefined operators of the type. For an elementary formal type, the predefined operators are implicitly declared immediately after the declaration of the formal type. For a composite formal type, the predefined operators are implicitly declared either immediately after the declaration of the formal type, or later immediately within the declarative region in which the type is declared according to the rules of 7.3.1. In an instance, the copy of such an implicit declaration declares a view of the predefined operator of the actual type, even if this operator has been overridden for the actual type. The rules specific to formal derived types are given in 12.5.1.

12.5 Formal Types

10 November 2006

254

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual
NOTES 7 Generic formal types, like all types, are not named. Instead, a name can denote a generic formal subtype. Within a generic unit, a generic formal type is considered as being distinct from all other (formal or nonformal) types. 8 A discriminant_part is allowed only for certain kinds of types, and therefore only for certain kinds of generic formal types. See 3.7.
Examples

9

10

Examples of generic formal types:
type Item is private; type Buffer(Length : Natural) is limited private; type type type type Enum Int Angle Mass is is is is (<>); range <>; delta <>; digits <>;

11 12 13

type Table is array (Enum) of Item;

14 15 16

Example of a generic formal part declaring a formal integer type:
generic type Rank is range <>; First : Rank := Rank'First; Second : Rank := First + 1; -- the operator "+" of the type Rank

12.5.1 Formal Private and Derived Types
In its most general form, the category determined for a formal private type is all types, but it can be restricted to only nonlimited types or to only tagged types. The category determined for a formal derived type is the derivation class rooted at the ancestor type.
Syntax
1/2

formal_private_type_definition ::= [[abstract] tagged] [limited] private formal_derived_type_definition ::=

2 3/2

[abstract] [limited | synchronized] new subtype_mark [[and interface_list]with private]
Legality Rules

If a generic formal type declaration has a known_discriminant_part, then it shall not include a default_expression for a discriminant. The ancestor subtype of a formal derived type is the subtype denoted by the subtype_mark of the formal_derived_type_definition. For a formal derived type declaration, the reserved words with private shall appear if and only if the ancestor type is a tagged type; in this case the formal derived type is a private extension of the ancestor type and the ancestor shall not be a class-wide type. Similarly, an interface_list or the optional reserved words abstract or synchronized shall appear only if the ancestor type is a tagged type. The reserved word limited or synchronized shall appear only if the ancestor type and any progenitor types are limited types. The reserved word synchronized shall appear (rather than limited) if the ancestor type or any of the progenitor types are synchronized interfaces. The actual type for a formal derived type shall be a descendant of the ancestor type and every progenitor of the formal type. If the reserved word synchronized appears in the declaration of the formal derived type, the actual type shall be a synchronized tagged type. If the formal subtype is definite, then the actual subtype shall also be definite. For a generic formal derived type with no discriminant_part:
255 10 November 2006 Formal Types 12.5

4

5/2

5.1/2

6 7

ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual

8

• If the ancestor subtype is constrained, the actual subtype shall be constrained, and shall be statically compatible with the ancestor; • If the ancestor subtype is an unconstrained access or composite subtype, the actual subtype shall be unconstrained. • If the ancestor subtype is an unconstrained discriminated subtype, then the actual shall have the same number of discriminants, and each discriminant of the actual shall correspond to a discriminant of the ancestor, in the sense of 3.7. • If the ancestor subtype is an access subtype, the actual subtype shall exclude null if and only if the ancestor subtype excludes null. The declaration of a formal derived type shall not have a known_discriminant_part. For a generic formal private type with a known_discriminant_part: • The actual type shall be a type with the same number of discriminants. • The actual subtype shall be unconstrained. • The subtype of each discriminant of the actual type shall statically match the subtype of the corresponding discriminant of the formal type. For a generic formal type with an unknown_discriminant_part, the actual may, but need not, have discriminants, and may be definite or indefinite.
Static Semantics

9

10

10.1/2

11

12 13 14

15

16/2 17/2

The category determined for a formal private type is as follows: Type Definition limited private private tagged limited private tagged private Determined Category the category of all types the category of all nonlimited types the category of all tagged types the category of all nonlimited tagged types

18 19

The presence of the reserved word abstract determines whether the actual type may be abstract. A formal private or derived type is a private or derived type, respectively. A formal derived tagged type is a private extension. A formal private or derived type is abstract if the reserved word abstract appears in its declaration. If the ancestor type is a composite type that is not an array type, the formal type inherits components from the ancestor type (including discriminants if a new discriminant_part is not specified), as for a derived type defined by a derived_type_definition (see 3.4 and 7.3.1). For a formal derived type, the predefined operators and inherited user-defined subprograms are determined by the ancestor type and any progenitor types, and are implicitly declared at the earliest place, if any, immediately within the declarative region in which the formal type is declared, where the corresponding primitive subprogram of the ancestor or progenitor is visible (see 7.3.1). In an instance, the copy of such an implicit declaration declares a view of the corresponding primitive subprogram of the ancestor or progenitor of the formal derived type, even if this primitive has been overridden for the actual type. When the ancestor or progenitor of the formal derived type is itself a formal type, the copy of the implicit declaration declares a view of the corresponding copied operation of the ancestor or progenitor. In the case of a formal private extension, however, the tag of the formal type is that of the actual type, so if the tag in a call is statically determined to be that of the formal type, the body executed will be that corresponding to the actual type.

20/2

21/2

12.5.1 Formal Private and Derived Types

10 November 2006

256

The value of this attribute is of the predefined type Boolean.3. NOTES 12 The actual type shall be in the class of types implied by the syntactic category of the formal type definition (see 12.5. If such a function is renamed. 3 — Ada Reference Manual For a prefix S that denotes a formal indefinite subtype. according to the rules for tag-indeterminate calls (see 3. For a formal derived type. If it is a function. the actual shall be in the class rooted at the ancestor subtype. the following attribute is defined: S'Definite S'Definite yields True if the actual subtype corresponding to S is definite.3/2 24/2 25 26 27 28 10 The actual type can be abstract only if the formal type is abstract (see 3. 8 9 257 10 November 2006 Formal Private and Derived Types 12. then the controlling tag value is determined by the context of the call. Otherwise. • If the corresponding operation of T has no controlling formal parameters. otherwise it yields False.2/2 23.1) whose body consists of a dispatching call upon the corresponding operation of T. 12.9. “Formal Types”).3). then so shall be the actual. the call raises Program_Error. For example.ISO/IEC 8652:2007(E) Ed.9.5. with its formal parameters as the actual parameters. “Formal Types”): • • If the formal type is nonlimited. each of the primitive operations of the actual type is considered to be a subprogram (with an intrinsic calling convention — see 6. 23.5.1 .2). floating point. Syntax 1/2 formal_discrete_type_definition ::= (<>) formal_signed_integer_type_definition ::= range <> formal_modular_type_definition ::= mod <> formal_floating_point_definition ::= digits <> formal_ordinary_fixed_point_definition ::= delta <> formal_decimal_fixed_point_definition ::= delta <> digits <> Legality Rules 2 3 4 5 6 7 The actual type for a formal scalar type shall not be a nonstandard numeric type. In the case where the tag would be statically determined to be that of the formal type.5. signed integer. the actual can be either definite or indefinite.2 Formal Scalar Types A formal scalar type is one defined by any of the formal_type_definitions in this subclause. The category determined for a formal scalar type is the category of all discrete. and the actual type is a class-wide type T'Class: • For the purposes of defining the primitive operations of the formal type. the result of the dispatching call is returned. modular. NOTES 9 In accordance with the general rule that the actual type shall belong to the category determined for the formal (see 12. or decimal types. ordinary fixed point. any call on the renaming raises Program_Error. Dynamic Semantics 22/1 23 In the case where a formal type is tagged with unknown discriminants. 11 If the formal has a discriminant_part.2 and 5. the actual has to be definite.1/2 23. the actual for a formal_modular_type_definition shall be a modular type.

the formal subtype and the actual subtype shall be either both constrained or both unconstrained.5.. • The component subtypes of the formal and actual array types shall statically match.5. • For each index position.3 Formal Array Types 10 November 2006 258 .. Vector => Mix.and the types type Mix is array (Color range <>) of Boolean. 3 — Ada Reference Manual 12. -. Index => Color. and the index subtypes (if unconstrained). or the index ranges (if constrained).given the generic package generic type type type type package . (<>).Note that Mix cannot match Table and Option cannot match Vector 12.then Mix can match Vector and Option can match Table package R is new P(Item => Boolean. type Option is array (Color) of Boolean. end P.3 Formal Array Types 1/2 The category determined for a formal array type is the category of all array types. array (Index range <>) of Item. the actual subtype shall satisfy the following conditions: • The formal array type and the actual array type shall have the same dimensionality. • If the formal type has aliased components. 12 13 14 15 16 -. the index types shall be the same. Table => Option).9. then so shall the actual. -. For a formal array subtype. array (Index) of Item. shall statically match (see 4.ISO/IEC 8652:2007(E) Ed. Examples 4 5 6 7 8 9 10 11 Example of formal array types: -. Syntax 2 formal_array_type_definition ::= array_type_definition Legality Rules 3 The only form of discrete_subtype_definition that is allowed within the declaration of a generic formal (constrained) array subtype is a subtype_mark.1). Item Index Vector Table P is is is is is private.

Number : License_Number.4 .the formal types of the generic package generic type Node is private. end record. end P. package P is . If and only if the general_access_modifier constant applies to the formal. then the actual shall be a general access-to-variable type (see 3. type Car_Name is access Car.5 Formal Interface Types The category determined for a formal interface type is the category of all interface types. -. Examples 3 4/2 5 Example of formal access types: -. If and only if the formal subtype excludes null.5. Owner : Person. For a formal access-to-subprogram subtype.in the following generic instantiation package R is new P(Node => Car.10). Syntax 1/2 formal_interface_type_definition ::= interface_type_definition Legality Rules 2/2 The actual type shall be a descendant of every progenitor of the formal type. type Car is record Pred.4 Formal Access Types The category determined for a formal access type is the category of all access types. Link => Car_Name). 6 7 8 9 10 11 12 13 12. -.. 3/2 259 10 November 2006 Formal Access Types 12. Syntax 1/2 formal_access_type_definition ::= access_type_definition Legality Rules 2 For a formal access-to-object type. If the general_access_modifier all applies to the formal..5. type Link is access Node. the designated profiles of the formal and the actual shall be mode-conformant. the actual shall be an accessto-constant type.ISO/IEC 8652:2007(E) Ed.can be matched by the actual types type Car. the designated subtypes of the formal and actual types shall statically match. Succ : Car_Name. and the calling convention of the actual shall be protected if and only if that of the formal is protected.5. 3 — Ada Reference Manual 12. the actual subtype shall exclude null.

ISO/IEC 8652:2007(E) Ed.3/2 12. 7/2 This generic allows an application to establish a standard interface that all tasks need to implement so they can be managed appropriately by an application-specific scheduler. is that of the formal subprogram. generic type Managed_Task is task interface. the expected profile for the actual is that of the formal subprogram. protected. or synchronized interface if and only if the formal type is also. • otherwise.1/2 8. subprogram_default ::= default_name | <> | null default_name ::= name 2. Legality Rules 7 8 8. For a parameter or result subtype of a formal_subprogram_declaration that has an explicit null_exclusion: • if the actual matching the formal_subprogram_declaration denotes a generic formal object of another generic unit G. end Server_Manager. The profiles of the formal and actual shall be mode-conformant. In addition to the places where Legality 8. or synchronized interface. Syntax 2/2 formal_subprogram_declaration ::= formal_concrete_subprogram_declaration | formal_abstract_subprogram_declaration formal_concrete_subprogram_declaration ::= with subprogram_specification [is subprogram_default]. a limited.1/2 A subprogram_default of null shall not be specified for a formal function or for a formal_abstract_subprogram_declaration.5 Formal Interface Types 10 November 2006 260 . 3 — Ada Reference Manual 4/2 The actual type shall be a limited. task.2/2 The profiles of the formal and any named default shall be mode-conformant. formal_abstract_subprogram_declaration ::= with subprogram_specification is abstract [subprogram_default]. Examples 5/2 6/2 type Root_Work_Item is tagged private. then the corresponding parameter or result type of the formal subprogram of G shall have a null_exclusion. task. protected. end Server.1/2 2. package Server_Manager is task type Server is new Managed_Task with entry Start(Data : in out Work_Item). respectively. and the instantiation containing the actual that occurs within the body of a generic unit G or within the body of a generic unit declared within the declarative region of the generic unit G. if any. the subtype of the corresponding parameter or result type of the actual matching the formal_subprogram_declaration shall exclude null.2/2 3/2 4 4. 12. type Work_Item(<>) is new Root_Work_Item with private. For a generic formal subprogram.6 Formal Subprograms 1 Formal subprograms can be used to pass callable entities to a generic unit. Name Resolution Rules 5 6 The expected profile for the default_name.5.

if the result of a formal_abstract_subprogram_declaration for a function is of a specific tagged type T or of an anonymous access type designating a specific tagged type T. A formal_abstract_subprogram_declaration shall have exactly one controlling type. default_expressions need not correspond. however.3). then it is equivalent to an explicit actual parameter that is a usage name identical to the defining name of the formal. The actual subprogram for a formal_abstract_subprogram_declaration shall be a dispatching operation of the controlling type or of the actual type corresponding to the controlling type. NOTES 13 The matching rules for formal subprograms state requirements that are similar to those applying to subprogram_renaming_declarations (see 8. while taking the formal parameter names and default_expressions from the profile given in the formal_subprogram_declaration. to avoid confusion. of the formal subprogram are those determined by the subtype_marks given in the formal_subprogram_declaration. T is called a controlling type of the formal_abstract_subprogram_declaration. In particular. then it is equivalent to an explicit actual parameter that is a null procedure having the profile given in the formal_subprogram_declaration. 18 The actual subprogram cannot be abstract unless the formal subprogram is a formal_abstract_subprogram_declaration (see 3. 17 A default_name denotes an entity that is visible or directly visible at the place of the generic_declaration. 15 The subtype specified for a formal parameter of a generic formal subprogram can be any visible subtype. it is recommended that the name of a first subtype be used in any declaration of a formal subprogram. In an instance.9.2/2 11 12 13 14 15 16/2 261 10 November 2006 Formal Subprograms 12. the nominal subtypes of the formal parameters and result. 3 — Ada Reference Manual Rules normally apply (see 12.3). are defined to be nonstatic. and the corresponding actual parameter is omitted. T is called a controlling type of the formal_abstract_subprogram_declaration. a box used as a default is equivalent to a name that denotes an entity that is directly visible at the place of the _instantiation. Similarly. The profile of this view takes its subtypes and calling convention from the original profile of the actual entity.4). 14 The constraints that apply to a parameter of a formal subprogram are those of the corresponding formal parameter of the matching actual subprogram (not those implied by the corresponding subtype_mark in the _specification of the formal subprogram). if any. 16 A formal subprogram is matched by an attribute of a type if the attribute is a function with a matching specification.5. Therefore.ISO/IEC 8652:2007(E) Ed. 9 10 10. this rule applies also in the private part of an instance of a generic unit.5/2 A formal_subprogram_declaration declares a generic formal subprogram.4/2 8. a formal_subprogram_declaration declares a view of the actual. and unconstrained if of an array type (no applicable index constraint is provided in a call on a formal subprogram). independent of the particular subtypes that are denoted by the subtype_marks. similarly. the name of a parameter of the formal subprogram need not be the same as that of the corresponding parameter of the actual subprogram. The types of the formal parameters and result. An enumeration literal of a given type matches a parameterless formal function whose result type is the given type. including a generic formal subtype of the same generic_formal_part. A similar remark applies to the result of a function. and the corresponding actual parameter is omitted. If a generic unit has a subprogram_default specified by the reserved word null. The view is a function or procedure. if any. never an entry. If a generic unit has a subprogram_default specified by a box. for these parameters. If a formal parameter of a formal_abstract_subprogram_declaration is of a specific tagged type T or of an anonymous access type designating a specific tagged type T.1/2 10. The subprogram declared by a formal_abstract_subprogram_declaration with a controlling type T is a dispatching operation of type T.6 . Static Semantics 8.

formal_package_actual_part ::= 3/2 ([others =>] <>) | [generic_actual_part] | (formal_package_association {. with with with with with 19 20 21 22 23 24 12. formal_package_association} [. 3 — Ada Reference Manual 16.13. Examples 16. A formal_package_actual_part shall contain at most one formal_package_association for each formal parameter. Syntax 2 formal_package_declaration ::= with package defining_identifier is new generic_package_name formal_package_actual_part.and the procedure procedure Put_Item(X : in Item). The formal_package_declaration declares that the formal package is an instance of a given generic package.3. Y : Item) return Item is <>.2/2 Any positional formal_package_associations shall precede any named formal_package_associations. 4. function Image(X : Enum) return String is Enum'Image. procedure Iterate(Seq : in Item_Sequence). Upon instantiation. the actual package has to be an instance of that generic package. All calls on a subprogram declared by a formal_abstract_subprogram_declaration must be dispatching calls.1/2 formal_package_association ::= generic_association | generic_formal_parameter_selector_name => <> 3. 20 A null procedure as a subprogram default has convention Intrinsic (see 6. others => <>]) 3. the formal package is an instance of the template.3. -.2/2 17 18/2 Examples of generic formal subprograms: function "+"(X. -.1/2 19 The subprogram declared by a formal_abstract_subprogram_declaration is an abstract subprogram.ISO/IEC 8652:2007(E) Ed.1/2 12.defaults to no action procedure Write(S : not null access Root_Stream_Type'Class.2 -. See 3.Dispatching operation on Descriptor with default -. -. procedure Pre_Action(X : in Item) is null. Desc : Descriptor) is abstract Descriptor'Write.7 Formal Packages 1 Formal packages can be used to pass packages to a generic unit. If the formal_package_actual_part does not include “others => <>”.see 13.1). each formal parameter without an association shall have a default_expression or subprogram_default.given the generic procedure declaration generic with procedure Action (X : in Item). -. procedure Update is Default_Update.9.6 Formal Subprograms 10 November 2006 262 . Legality Rules 4 The generic_package_name shall denote a generic package (the template for the formal package).the following instantiation is possible procedure Put_List is new Iterate(Action => Put_Item).

Provide a "join" between two mappings subtype Key_Type is Mapping_1.18. any actual parameter that is the name of a formal object of mode in is replaced by the formal object's actual expression (recursively).Containers. If the formal_package_actual_part is (<>) or (others => <>).Element_Type. a copy of the declaration of the corresponding formal parameter of the template is included in the visible part of the formal package. with package Mapping_2 is new Ada. for each actual parameter that is not required to match. copies of the implicit declarations of the primitive subprograms of the formal type are also included in the visible part of the formal package. The rules for matching of actual parameters between the actual instance and the formal package are as follows: • For a formal object of mode in. the actuals match if they denote statically matching subtypes. . others => <>).Element_Type.1/1 A formal_package_declaration declares a generic formal package. subtype Element_Type is Mapping_2. plus. the actuals match if they are static expressions with the same value. determined as follows: • If the formal_package_actual_part includes generic_associations as well as associations with <>. For the purposes of matching. For the purposes of matching. the copies of the formal parameters of the template included in the visible part of A.see A. Examples 9 10/2 11/2 Example of a generic package with formal package parameters: with Ada.Ordered_Maps (Key_Type => Mapping_1. • Otherwise. then only the actual parameters specified explicitly with generic_associations are required to match.1/2 5. all actual parameters shall match..Containers.3/2 6/2 7 8 8. or if they are both the literal null. • For other kinds of formals. end Ordered_Join. if the actual instance A is itself a formal package. the actuals match if they statically denote the same entity. or if they statically denote the same constant. Static Semantics 5/2 5. otherwise. • For a formal subtype.Ordered_Maps(<>). package Ordered_Join is -. function Lookup(Key : Key_Type) return Element_Type. whether any actual parameter is given explicitly or by default. then the actual parameters of A are those specified explicitly or implicitly in the formal_package_actual_part for A.ISO/IEC 8652:2007(E) Ed. certain of the actual parameters of the actual instance shall match the corresponding actual parameters of the formal package. If the copied declaration is for a formal type. then the actual may be any instance of the template.2/2 5. for those not specified.Key_Type..7 . In addition. 12/2 13/2 14/2 15/2 16/2 263 10 November 2006 Formal Packages 12.6 generic with package Mapping_1 is new Ada. -.Containers. 3 — Ada Reference Manual The actual shall be an instance of the template. The visible part of a formal package includes the first list of basic_declarative_items of the package_specification.Ordered_Maps.

Size). generic Size : Positive. Space : Table(1 . procedure Pop (E : out Item). end Stack.Containers. Element_Type => String_Id). Apple_Info : constant Symbol_Info := String_Info. Overflow. Mapping_2 => Symbol_Table). Index : Natural := 0. end if. Space(Index) := E.. Underflow : exception. 22/2 23/2 24/2 25/2 12. Examples 2/1 3 This paragraph was deleted.Ordered_Maps (Key_Type => String. end Symbol_Package. 3 — Ada Reference Manual 17/2 18/2 19/2 20/2 21/2 Example of an instantiation of a package with formal packages: with Ada. Index := Index + 1. package body Stack is type Table is array (Positive range <>) of Item.Lookup("Apple"). package String_Info is new Ordered_Join(Mapping_1 => String_Table. Index := Index . package Stack is procedure Push(E : in Item). type Symbol_Info is ..Ordered_Maps. 4 5 6 7 8 12. package String_Table is new Ada.7 Formal Packages 10 November 2006 264 . package Symbol_Package is type String_Id is .Containers. package Symbol_Table is new Ada. type Item is private. end Push..8 Example of a Generic Package 1 The following example provides a possible formulation of stacks by means of a generic package.ISO/IEC 8652:2007(E) Ed.Containers. procedure Pop(E : out Item) is begin if Index = 0 then raise Underflow. end Stack.1. E := Space(Index)..Ordered_Maps (Key_Type => String_Id. Element_Type => Symbol_Info).. procedure Push(E : in Item) is begin if Index >= Size then raise Overflow. The size of each stack and the type of the stack elements are provided as generic formal parameters. end if. end Pop.

package On_Stacks is type Stack(Size : Positive) is limited private. S : Stack(100). Push(S. Item => Integer).8 . 3 — Ada Reference Manual Instances of this generic package can be obtained as follows: package Stack_Int is new Stack(Size => 200. begin . an instance has to be created and thereafter stacks of the corresponding type can be declared: declare package Stack_Real is new On_Stacks(Real). package Stack_Bool is new Stack(100. procedure Push(S : in out Stack.. end record.. 2. Size).ISO/IEC 8652:2007(E) Ed. Index : Natural := 0. procedure Pop (S : in out Stack. Underflow : exception. Overflow. a generic formulation of the type Stack can be given as follows (package body omitted): generic type Item is private. type Stack(Size : Positive) is record Space : Table(1 .Push(True).54). the procedures of the instantiated packages can be called as follows: Stack_Int. E : in Item). end On_Stacks. 9 10 Thereafter. Stack_Bool.Push(N).. E : out Item). 13 14 In order to use such a package.. end. 11 12 Alternatively. 15 16 265 10 November 2006 Example of a Generic Package 12. private type Table is array (Positive range <>) of Item.. . Boolean). use Stack_Real.

.

There are six kinds of representation items: attribute_definition_clauses for representation attributes. 3 — Ada Reference Manual Section 13: Representation Issues This section describes features for querying and controlling certain aspects of entities and for interfacing to hardware. record_representation_clauses. if the local_name is a direct_name. task_definition. peripheral hardware). which denotes an entity declared local to the current declarative region.2/1 aspect_clause ::= attribute_definition_clause | enumeration_representation_clause | record_representation_clause | at_clause local_name ::= direct_name | direct_name'attribute_designator | library_unit_name 2/1 3 A representation pragma is allowed only at places where an aspect_clause or compilation_unit is allowed. or within the same declarative_part.ISO/IEC 8652:2007(E) Ed. 1/1 13.1/1 1. They can be provided to give more efficient representation or to interface with features that are outside the domain of the language (for example. protected_definition. and representation pragmas. at_clauses. If a local_name denotes a local callable entity. Two kinds of aspects of entities can be specified: aspects of representation and operational aspects. Representation items specify how the types and other entities of the language are to be mapped onto the underlying machine. or record_definition as the representation or operational item. one or more entities) declared immediately preceding it in a compilation. then it shall resolve to denote an implementation-defined component (see 13. Legality Rules 5/1 The local_name of an aspect_clause or representation pragma shall statically denote an entity (or. in the case of a pragma. in the case of a pragma. then it shall resolve to denote a declaration (or. An operational item is an attribute_definition_clause for an operational attribute.5. enumeration_representation_clauses.1 Operational and Representation Items Representation and operational items can be used to specify aspects of entities. An operational item or a representation item applies to an entity identified by a local_name. it may do so 6/1 267 10 November 2006 Representation Issues 13 .1/1 1/1 1. package_specification. or a library unit declared immediately preceding a representation pragma in a compilation. Name Resolution Rules 4/1 In an operational item or representation item.1) or a class-wide type implicitly declared immediately within the same declarative region as the item. Operational items specify other properties of entities. A local_name that is a library_unit_name (only permitted in a representation pragma) shall resolve to denote the library_item that immediately precedes (except for other pragmas) the representation pragma. Syntax 0. one or more declarations) that occurs immediately within the same declarative region as the item. If the local_name has an attribute_designator. component_clauses.

The local_name of an operational item shall denote a first subtype. Operational and representation aspects of a generic formal parameter are the same as those of the actual.1/1 10 11/2 12 13/1 13. and before the subtype or type is frozen (see 13.1). A representation item that specifies the Size for a given subtype. whose local_name shall denote a first subtype.1 Operational and Representation Items 10 November 2006 268 . For a composite object. storing. For an untagged derived type. For an elementary object. these are the bits reserved for this object. An operational item that names a subtype is type-related. A derived type inherits each type-related aspect of representation of its parent type that was directly specified before the declaration of the derived type. A representation item that names a subtype is either subtype-specific (Size and Alignment clauses) or type-related (all others).14). otherwise. A representation or operational item that is not supported by the implementation is illegal. If the size of an object is greater than that of its subtype. A representation item directly specifies an aspect of representation of the entity denoted by the local_name. For an object of a composite type. If a representation item is given that directly specifies an aspect of an entity. and which directly specifies an aspect of the subtype's type.1/2 14 15/1 If two subtypes statically match. except in the case of a type-related representation item. A derived subtype inherits each subtype-specific 13. If an operational item is given that directly specifies an aspect of a type. An operational item that directly specifies an aspect of a type shall appear before the type is frozen (see 13. or has any user-defined primitive subprograms. or the size or storage place for an object (including a component) of a given subtype. or (in the case where the parent is derived) that was inherited by the parent type from the grandparent type. no type-related representation items are allowed if the parent type is a byreference type. padding bits might not be read or updated in any given composite operation. A type_declaration is illegal if it has one or more progenitors. and this representation item conflicts with the representation of some other ancestor. For an object of an elementary type. or operating-on the value of the object. Static Semantics 8 8.ISO/IEC 8652:2007(E) Ed. then it is illegal to give another representation item that directly specifies the same aspect of the entity. A representation item that directly specifies an aspect of a subtype or type shall appear after the type is completely defined (see 3. and a representation item applies to an ancestor. these padding bits are normally read and updated along with the others.14). depending on the implementation. A type-related representation item is not allowed for a descendant of a generic formal untagged type. the additional bits are padding bits. An operational item directly specifies an operational aspect of the type of the subtype denoted by the local_name. shall allow for enough storage space to accommodate any value of the subtype. The cases that cause conflicts are implementation defined. these are the bits that are normally read or updated by the machine code when loading. the local_name shall not denote a renaming_declaration. Operational and representation aspects are the same for all views of a type. then their subtype-specific aspects (Size and Alignment) are the same. then it is illegal to give another operational item that directly specifies the same aspect of the type. 3 — Ada Reference Manual through a local subprogram_renaming_declaration (as a way to resolve ambiguity in the presence of overloading).1/1 9 9.11. 7/2 The representation of an object consists of a certain number of bits (the size of the object). and include bits occupied by subcomponents of the object. or raises an exception at run time. Subtypespecific aspects may differ for different subtypes of the same type.

nor the size or storage place for an object (including a component) of a given composite subtype.1/1 18. then that aspect of the entity is as specified.1/2 15. • An implementation need not support a specification for the Size for a given composite subtype. Each aspect of representation of an entity is as follows: • If the aspect is specified for the entity. A representation item that specifies an aspect of representation that would have been chosen in the absence of the representation item is said to be confirming. or (in the case where the parent is derived) that was inherited by the parent subtype from the grandparent subtype. Otherwise. it is chosen by default in an unspecified manner.2/2 16 17 18 18. An inherited operational aspect is overridden by a subsequent operational item that specifies the same aspect of the type.2/2 For the elaboration of an aspect_clause. An implementation may place implementation-defined restrictions on representation items. In contrast. • If an aspect of representation of an entity is not specified. except in the case of Storage_Size. meaning that it is either directly specified or inherited. 21 21. An inherited aspect of representation is overridden by a subsequent representation item that specifies the same aspect of the type or subtype. Dynamic Semantics 15. which specifies a minimum. the derived type inherits the aspect in the same way that a derived type inherits a user-defined primitive subprogram from its parent (see 3. then that aspect of the entity is as specified. any evaluable constructs within it are evaluated. except that an implementation should support a representation item for a given entity if each nonstatic expression in the representation item is a name that statically denotes a constant declared before the entity. whether operational aspects are inherited by an untagged derived type depends on each specific aspect. Operational aspects are never inherited for a tagged type. “Required Representation Support”). A recommended level of support is specified for representation items and related features in each subclause. the aspect of the entity has the default value for that aspect.ISO/IEC 8652:2007(E) Ed. When an aspect that is a subprogram is inherited. aspects that were directly specified by operational items that are visible at the point of the derived type declaration.4). 3 — Ada Reference Manual aspect of representation of its parent subtype that was directly specified before the declaration of the derived type. • An implementation need not support representation items containing nonstatic expressions.2. or (in the case where the parent is derived) that were inherited by the parent type from the grandparent type are inherited.1 .1/2 22 23 269 10 November 2006 Operational and Representation Items 13. Implementation Permissions 19/1 An implementation may interpret aspects of representation in an implementation-defined manner. When operational aspects are inherited by an untagged derived type. These recommendations are changed to requirements for implementations that support the Systems Programming Annex (see C. If an operational aspect is specified for an entity (meaning that it is either directly specified or inherited). but only if the parent subtype statically matches the first subtype of the parent type. Implementation Advice 20 The recommended level of support for all representation items is qualified as follows: • A confirming representation item should be supported.

not on any available information about how the type is used. then the implementation should try to minimize storage allocated to objects of the type. For purposes of these rules. and a pragma Pack causes packing only of the extension part. the components should be packed as tightly as possible subject to the Sizes of the component subtypes. at an address that is not an integral multiple of that alignment.1/2 7 8 13. The recommended level of support for pragma Pack is: • For a packed record type. Legality Rules 4 The first_subtype_local_name of a pragma Pack shall denote a composite subtype. it presumes that minimally aligned objects of this type might be declared at some point. subject to reasonable complexity in addressing calculations. when the alignment attribute of the subtype of such an object is nonzero. or an object whose type is by-reference. • An implementation need not support a nonconfirming subtype-specific representation item specifying an aspect of representation of an indefinite or abstract subtype. If a packed type has a component that is not of a by-reference type and has no aliased part. the type (or the extension part) is said to be packed. to have a size smaller than that which would have been chosen by default. • An implementation need not support a nonconfirming representation item if it could cause an aliased object of an elementary type to have a size other than that which would have been chosen by default. Implementation Advice 6 If a type is packed. 3 — Ada Reference Manual unless the constraints on the subtype and its composite subcomponents (if any) are all static constraints.ISO/IEC 8652:2007(E) Ed. In particular. Static Semantics 5 A pragma Pack specifies the packing aspect of representation. Syntax 2 3 The form of a pragma Pack is as follows: pragma Pack(first_subtype_local_name).2 Pragma Pack 1 A pragma Pack specifies that storage minimization should be the main criterion when selecting the representation of a composite type. then such a component need not be aligned according to the Alignment of its subtype. in particular it need not be allocated on a storage element boundary. • An implementation need not support a nonconfirming representation item if it could cause an aliased object of a composite type. possibly at the expense of speed of accessing components. and subject to any record_representation_clause that applies 6.1 Operational and Representation Items 10 November 2006 270 . 25/2 26/2 27/2 28/2 13. 24/2 • An implementation need not support a nonconfirming representation item if it could cause an aliased object or an object of a by-reference type to be allocated at a nonaddressable location or. the determination of whether a representation item applied to a type could cause an object to have some property is based solely on the properties of the type itself. For a type extension. the parent part is packed as for the parent type.

A component whose Size is greater than the word size may be allocated an integral number of words. A storage element is an addressable element of storage in the machine. the name shall resolve to denote an entity of the appropriate kind. reorder components or cross aligned word boundaries to improve the packing.1/2 271 10 November 2006 Pragma Pack 13. 3 — Ada Reference Manual to the type. but must include at least the storage element and the word. Otherwise. or operated upon by the hardware. Some of these attributes are specifiable via an attribute_definition_clause. Legality Rules 3 4 An attribute_designator is allowed in an attribute_definition_clause only if this International Standard explicitly allows it. A word consists of an integral number of storage elements. Additional requirements are defined for particular attributes. or for an implementation-defined attribute if the implementation allows it. and Component_Size is not specified for the type. 7/2 8 8. • For a packed array type.ISO/IEC 8652:2007(E) Ed. For an attribute_definition_clause that specifies an attribute that denotes a value or an object. Each specifiable attribute constitutes an operational aspect or aspect of representation.2 . Name Resolution Rules 2 For an attribute_definition_clause that specifies an attribute that denotes a value. Machine scalars are used to interpret component_clauses when the nondefault bit ordering applies. Static Semantics 5/1 6 A Size clause is an attribute_definition_clause whose attribute_designator is Size. rounded up to the nearest factor of the word size. Similar definitions apply to the other specifiable attributes. the form with an expression shall be used. if the component subtype's Size is less than or equal to the word size. stored. the expected profile for the name is the profile required for the attribute. Syntax 1/1 attribute_definition_clause ::= for local_name'attribute_designator use expression. | for local_name'attribute_designator use name. the form with a name shall be used. Component_Size should be less than or equal to the Size of the component subtype. For an attribute_definition_clause that specifies an attribute that denotes a subprogram. For an attribute_definition_clause that specifies an attribute that denotes a subprogram. For an attribute_definition_clause that specifies an attribute that denotes some other kind of entity. 9 13. A machine scalar is an amount of storage that can be conveniently and efficiently loaded. The set of machine scalars is implementation defined. given the implementation's run-time model. Machine scalars consist of an integral number of storage elements. A word is the largest amount of storage that can be conveniently and efficiently manipulated by the hardware. the profile shall be mode conformant with the one required for the attribute. and the convention shall be Ada.3 Operational and Representation Attributes The values of certain implementation-dependent characteristics can be obtained by interrogating appropriate operational or representation attributes. the implementation may. the expected type for the expression or name is that of the attribute. but need not.

program unit.4/2 . and nonnegative. Implementation Advice 14 15 16 For an array X. and its value nonnegative.3/2 For every subtype S: S'Alignment The value of this attribute is of type universal_integer. this value refers to the machine code associated with the corresponding body or statement. then X is aligned on a storage unit boundary and X'Address is an integral multiple of X'Alignment (that is. • This paragraph was deleted. • If the Address of an object is specified. For a prefix X that denotes an object. Size. program execution is erroneous.1) for a subprogram or object is an alternative to explicit specification of its link-time address. and only the bits of X. X'Address should point at the first component of the array. and nonnegative. 13.1/2 26. and Component_Size. Address may be specified for stand-alone objects and for program units via an attribute_definition_clause. the expression of such a clause shall be static. then X'Address points at a storage element containing all of the bits of X. Storage_Size. otherwise. then X'Alignment is a nonzero integral multiple of S'Alignment unless specified otherwise by a representation item. For a program unit or label.Address. • An implementation should support Address clauses for imported subprograms. allowing a link-time directive to place the subprogram or object within memory. or is an entity whose Address has been specified. This paragraph was deleted. and its value nonnegative. 24/2 25/2 Alignment may be specified for stand-alone objects via an attribute_definition_clause. The value of this attribute is of type System. then the implementation should not perform optimizations based on assumptions of no aliases. it is the programmer's responsibility to ensure that the address is valid. 3 — Ada Reference Manual 9/1 The following representation attributes are defined: Address.3 Operational and Representation Attributes 10 November 2006 272 26. and not at the array bounds. or label: X'Address Denotes the address of the first of the storage elements allocated to X. the Address modulo the Alignment is zero). the expression of such a clause shall be static. NOTES 1 The specification of a link name in a pragma Export (see B. If X'Alignment is not zero. or it is imported or exported. 26/2 26. zero means that the object is not necessarily aligned on a storage element boundary.ISO/IEC 8652:2007(E) Ed. that if X'Size = Storage_Unit. This paragraph was deleted. Alignment may be specified for first subtypes via an attribute_definition_clause. if S'Alignment is not zero. Static Semantics 17 18/2 19 20 21 22/2 23/2 For a prefix X that denotes an object: X'Alignment The value of this attribute is of type universal_integer. for an aliased object X. 2 The rules for the Size attribute imply. For an object X of subtype S. Alignment. Erroneous Execution 10/1 11 12 13 If an Address is specified. The recommended level of support for the Address attribute is: • X'Address should produce a useful result if X is an object that is aliased or of a by-reference type.2/2 26.

The recommended level of support for the Alignment attribute for objects is: • This paragraph was deleted. enumeration types.3 . • An implementation need not support an Alignment specified for a derived tagged type which is not a multiple of the Alignment of the parent type. The value of this attribute is of the type universal_integer. fixed point type. For example. page alignment is likely to be supported for such objects. record type.1/2 273 10 November 2006 Operational and Representation Attributes 13. or array type. 29 30/2 31/2 32/2 32. an implementation should at least support the alignments supported for their subtype.1/2 33 34/2 35 35. record types. Component_Size clause. execution is erroneous if the object is not aligned according to its Alignment. Static Semantics For a prefix X that denotes an object: X'Size Denotes the size in bits of the representation of the object. • For other objects. • For stand-alone library-level objects of statically constrained subtypes. fixed point types. 41. Implementation Advice 39/1 40 41 The size of an array object should not include its bounds. but not for subtypes. the expression of such a clause shall be static and its value nonnegative. An implementation need not support a nonconfirming Alignment specified for a derived untagged by-reference type. specifying an Alignment value that is zero or a power of two.2/2 36 37/2 38 4 A component_clause. 3 — Ada Reference Manual Erroneous Execution Program execution is erroneous if an Address clause is given that conflicts with the Alignment.ISO/IEC 8652:2007(E) Ed. and array types. This paragraph was deleted. Implementation Advice 27 28/2 The recommended level of support for the Alignment attribute for subtypes is: • An implementation should support an Alignment clause for a discrete type. NOTES 3 Alignment is a subtype-specific attribute.1/2 35. Size may be specified for stand-alone objects via an attribute_definition_clause. A corresponding limitation may be imposed for modular integer types. • An implementation need not support a nonconfirming Alignment clause which could enable the creation of an object of an elementary type which cannot be easily loaded and stored by available machine instructions. subject to the following: • An implementation need not support an Alignment clause for a signed integer type specifying an Alignment greater than the largest Alignment value that is ever chosen by default by the implementation for any signed integer type. the implementation should support all Alignments supported by the target linker. or a pragma Pack can override a specified Alignment. For an object that is not allocated under control of the implementation. subject to the following: • An implementation need not support Alignments specified for objects of a by-reference type or for objects of types containing aliased subcomponents if the specified Alignment is not a multiple of the Alignment of the subtype of the object.

ISO/IEC 8652:2007(E) Ed. when the size is chosen by default). but not the size of what they point at. denotes the size (in bits) that the implementation would choose for the following objects of subtype S: • A record component of subtype S when the record type is packed. unless the Size of the component is determined by a component_clause or Component_Size clause.3 Operational and Representation Attributes 10 November 2006 274 . If such a subtype is a first subtype. Implementation Advice 50/2 If the Size of a subtype allows for efficient independent addressability (see 9. a component_clause. • An implementation should support a Size clause for a discrete type. A nonconfirming size clause for the first subtype of a derived untagged by-reference type need not be supported. The recommended level of support for the Size attribute of subtypes is: • The Size (if not specified) of a static discrete or fixed point subtype should be the number of bits needed to represent each value belonging to the subtype using an unbiased representation. Boolean'Size shall be 1. The value of this attribute is of the type universal_integer. A corresponding limitation may be imposed for modular integer types. record type. except that only a confirming Size clause need be supported for an aliased elementary object.2/2 An implementation need not support a Size clause for a signed integer type specifying a Size greater than that of the largest signed integer type supported by the implementation in the absence of a size clause (that is. • Unaliased components. • For a subtype implemented with levels of indirection. enumeration types. then an implementation should support a specified Size for it that reflects this representation. record types. the meaning is implementation defined. subject to the following: • 51 52 53 54 55 56 56. Size may be specified for first subtypes via an attribute_definition_clause. Implementation Requirements 46 47 48 49 In an implementation. then the Size of the following objects of the subtype should equal the Size of the subtype: • Aliased objects (including components). leaving space for a sign bit only if the subtype contains negative values. fixed point type. • This paragraph was deleted.3/2 • 13. and array types. • The formal parameter of an instance of Unchecked_Conversion that converts from subtype S to some other subtype. the expression of such a clause shall be static and its value nonnegative. or a Component_Size clause. or array type. Static Semantics 43/2 44 45 For every subtype S: S'Size If S is definite. 56. 3 — Ada Reference Manual 42/2 The recommended level of support for the Size attribute of objects is the same as for subtypes (see below). A Size clause on a composite subtype should not affect the internal layout of components. fixed point types.1/2 56. The Size of an object is at least as large as that of its subtype. the Size should include the size of the pointers. If S is indefinite. unless the object's Size is determined by a Size clause.10) on the target architecture.

the Storage_Size attribute of the newly created task object is at least the value of the expression. 71 72 73 275 10 November 2006 Operational and Representation Attributes 13. if any. 3 — Ada Reference Manual NOTES 5 Size is a subtype-specific attribute. the array should contain no gaps between components when packing is also specified. A pragma Storage_Size is allowed only immediately within a task_definition. The Storage_Size includes the size of the task's stack. Static Semantics 57 58 For a prefix T that denotes a task object (after any implicit dereference): T'Storage_Size Denotes the number of storage elements reserved for the task. and its value nonnegative. 6 A component_clause or Component_Size clause can override a specified Size. the implementation should forbid this combination in cases where it cannot support a no-gaps representation. the expression is evaluated. Static Semantics 66 67 For a prefix X that denotes an array subtype or array object (after any implicit dereference): X'Component_Size Denotes the size in bits of components of the type of X. Dynamic Semantics 65 A pragma Storage_Size is elaborated when an object of the type defined by the immediately enclosing task_definition is created. Implementation Advice 68/1 69 70 The recommended level of support for the Component_Size attribute is: • An implementation need not support specified Component_Sizes that are less than the Size of the component subtype. A pragma Pack cannot.ISO/IEC 8652:2007(E) Ed. the value of the Storage_Size attribute is at least the value specified in the pragma. For other Component_Sizes (if supported). Syntax 59/1 60 61 The form of a pragma Storage_Size is as follows: pragma Storage_Size(expression). • An implementation should support specified Component_Sizes that are factors and multiples of the word size. Storage_Error is raised if there is insufficient free storage to accommodate the requested Storage_Size. Name Resolution Rules 62 63 64 The expression of a pragma Storage_Size is expected to be of any integer type. the array should contain no gaps between components. For such Component_Sizes. The language does not specify whether or not it includes other storage associated with the task (such as the “task control block” used by some implementations. The value of this attribute is of the type universal_integer. The value of this attribute is of type universal_integer. the expression of such a clause shall be static. For the elaboration of a pragma Storage_Size. Component_Size may be specified for array types via an attribute_definition_clause. A pragma Storage_Size specifies the amount of storage to be reserved for the execution of a task. At the point of task object creation.3 . or upon task activation.) If a pragma Storage_Size is given.

Output. it is of the predefined type String.Root_Stream_Type'Class) return T. and Write. and all compilation units on which it semantically depends. 8 It follows from the general rules in 13. are the same in two different partitions. 65_000. the expression of such a clause shall be static. for Device_Register'Size use Medium'Size.0. fifteen bits is the minimum necessary. At a minimum. Read. 100.. type Medium is range 0 . since the type definition requires Short'Small <= 2**(–7). at least for some of the kinds of entities to which they apply: Address. for Medium'Alignment use 2.To_Address(16#FFFF_0020#). for Medium'Size use 2*Byte. 3 — Ada Reference Manual Static Semantics 73. 82 83 84/2 85 13. Storage_Pool.Streams. Bit_Order. External_Tag may be specified for a specific tagged type via an attribute_definition_clause. The default external tag representation is implementation defined.ISO/IEC 8652:2007(E) Ed. NOTES 7 The following language-defined attributes are specifiable.approximately 2000 cars function My_Input(Stream : not null access Ada. See 3.13.2 NOTES 9 Notes on the examples: In the Size clause for Short. The value of External_Tag is never inherited. Small.” then the X'Size attribute_reference will return Y (assuming the implementation allows the Size clause). the default value is always used unless a new value is directly specified for a type. For every subtype S of a tagged type T (specific or class-wide): S'External_Tag S'External_Tag denotes an external string representation for S'Tag. Page : constant := 2**12. -. The same is true for all of the specifiable attributes except Storage_Size.9. -.01 range -100. Machine_Radix. Input.1/1 74/1 75/1 The following operational attribute is defined: External_Tag. for Device_Register'Address use System. Alignment. if the compilation unit is not recompiled between building the two different partitions that include it. External_Tag.3 Operational and Representation Attributes 10 November 2006 276 . Implementation Requirements 76 In an implementation.2. Stream_Size. Examples 77/2 78 79 80 81 Examples of attribute definition clauses: Byte : constant := 8. the default external tag for each specific tagged type declared in a partition shall be distinct. What it means for a compilation unit to be the same in two different partitions is implementation defined. Size. Storage_Size.Storage_Elements. then the external tag for the type shall be the same in the two partitions. so long as the type is declared outside an instance of a generic body. for Short'Size use 15. the compilation unit is considered the same in the two partitions.0 . for Car_Name'Storage_Size use -. If the compilation unit in which a given tagged type is declared.2 and 13. for T'Input use My_Input. Component_Size. Device_Register : Medium.13.specify access type's storage pool size 2000*((Car'Size/System..see 13.Storage_Unit) +1).1 that if one writes “for X'Size use Y. type Short is delta 0.

for Mix_Code use (ADD => 1.System. Pos always returns the position number. An implementation need not support enumeration_representation_clauses for boolean types. The coding consists of the internal code for each enumeration literal. then for each value of the type. and each component expression is expected to be of any integer type.4 Enumeration Representation Clauses An enumeration_representation_clause specifies the internal codes for enumeration literals. enumeration_aggregate ::= array_aggregate Name Resolution Rules 2 3 The enumeration_aggregate shall be written as a one-dimensional array_aggregate. not the internal integer code that might have been specified in an enumeration_representation_clause}.Max_Int. STA. Syntax 1 enumeration_representation_clause ::= for first_subtype_local_name use enumeration_aggregate. the associated integer codes shall satisfy the predefined ordering relation of the type. for which the index subtype is the unconstrained subtype of the enumeration type. Static Semantics 5 6/2 An enumeration_representation_clause specifies the coding aspect of representation. Legality Rules 4 The first_subtype_local_name of an enumeration_representation_clause shall denote an enumeration subtype. 12 13 14 277 10 November 2006 Enumeration Representation Clauses 13. STZ =>33). LDA. STA => 24. that is. The attributes of the type.. NOTES 10 Unchecked_Conversion may be used to query the internal codes used for an enumeration type. STZ). MUL. Pred. The expressions given in the array_aggregate shall be static.ISO/IEC 8652:2007(E) Ed. if the coding is not specified for the type. and shall specify distinct integer codes for each value of the enumeration type. such as Succ. SUB => 2. LDA => 8. the internal code shall be equal to its position number. and Pos. Examples 9 10 11/1 Example of an enumeration representation clause: type Mix_Code is (ADD. Each component of the array_aggregate shall be given by an expression rather than a <>. 3 — Ada Reference Manual 13. Implementation Advice 8 The recommended level of support for enumeration_representation_clauses is: • An implementation should support at least the internal codes in the range System. are unaffected by the enumeration_representation_clause.Min_Int. MUL => 3. Implementation Requirements 7 For nonboolean enumeration types. the integral value used internally to represent each literal. For example. SUB.4 .

including for each discriminant (component_clauses may be given for some. 9 10 10. then either: • the value of last_bit shall be less than the size of the largest machine scalar. first_bit.5 Record Layout 10 November 2006 278 .5. and last_bit shall be static expressions. the component shall not be inherited. all.2/2 10. that is. The position. storage place attributes of the components.Storage_Unit. position. Legality Rules 8/2 The first_subtype_local_name of a record_representation_clause shall denote a specific record or record extension subtype.. or • the value of first_bit shall be zero and the value of last_bit + 1 shall be a multiple of System. last_bit. For a record extension.5 Record Layout 1 The (record) layout aspect of representation consists of the storage places for some or all components.ISO/IEC 8652:2007(E) Ed. and size of components (including discriminants. and shall not be a discriminant that corresponds to a discriminant of the parent type. If the component_local_name has an attribute_designator. the order. if any). 3 component_clause ::= component_local_name at position range first_bit . Storage places within a component_list shall not overlap. or none of the components). If the component_local_name is a direct_name. and the attribute_designator shall denote an implementation-defined implicit component of the type. The value of position and first_bit shall be nonnegative.3/2 11 13. 3 — Ada Reference Manual 13. At most one component_clause is allowed for each component of the type.1 Record Representation Clauses 1 A record_representation_clause specifies the storage representation of records and record extensions. The value of last_bit shall be no less than first_bit – 1. position ::= static_expression first_bit ::= static_simple_expression last_bit ::= static_simple_expression Name Resolution Rules 4 5 6 7 Each position. that is.1/2 10. 13. unless they are for components in distinct variants of the same variant_part. the direct_name of the local_name shall denote either the declaration of the type or a component of the type. If the nondefault bit ordering applies to the type. The layout can be specified with a record_representation_clause. and last_bit is expected to be of any integer type. first_bit. the local_name shall denote a component of the type. Syntax 2 record_representation_clause ::= for first_subtype_local_name use record [mod_clause] {component_clause} end record.

given the available machine instructions and run-time model. all of the components having the same value of position are considered to be part of a single machine scalar. the first_bit and last_bit of each component_clause are then interpreted as bit offsets in this machine scalar. the position. and address formats supported by the machine.1 . whether or not those storage places had been specified. 17 17. 3 — Ada Reference Manual A name that denotes a component of a type is not allowed within a record_representation_clause for the type. • An implementation should support storage places that can be extracted with a load. and disallow other components from overlapping that place. • for other component_clauses. An implementation may allow such implementation-defined names to be used in record_representation_clauses. one containing the offset of another component).4/2 14 An implementation may generate implementation-defined components (for example. any storage place that does not cross an aligned word boundary should be supported. first_bit. An implementation may generate names that denote such implementationdefined components. mask. located at that position. shift. except as the component_local_name of a component_clause. this machine scalar has a size which is the smallest machine scalar size larger than the largest last_bit for all component_clauses at that position.1/2 13.1/2 18 19 20/2 21 22 279 10 November 2006 Record Representation Clauses 13. shift sequence of machine code. such names shall be implementation-defined attribute_references. • For a component with a subtype whose Size is less than the word size. If the nondefault bit ordering applies to the type then the layout is determined as follows: • the component_clauses for which the value of last_bit is greater than or equal to the size of the largest machine scalar directly specify the position and size of the corresponding component. If the default bit ordering applies to the type. • An implementation need not support a component_clause for a component of an extension part if the storage place is not after the storage places of all components of the parent type. and set with a load. An implementation can restrict such component_clauses in any manner it sees fit. Static Semantics 12 A record_representation_clause (without the mod_clause) specifies the layout.3/2 13. • An implementation may reserve a storage place for the tag field of a tagged type. A record_representation_clause for a record extension does not override the layout of the parent part. floating point. and it starts and ends on a boundary that obeys the Alignment of the component subtype. if the layout was specified for the parent type. • A storage place should be supported if its size is equal to the Size of the component subtype. If a record_representation_clause is given for an untagged derived type.ISO/IEC 8652:2007(E) Ed. and last_bit of each component_clause directly specify the position and size of the corresponding component. store sequence.5.2/2 13. the storage place attributes for all of the components of the derived type may differ from those of the corresponding components of the parent type. even for components whose storage place is not specified explicitly in the record_representation_clause. Implementation Advice 15 16 The recommended level of support for record_representation_clauses is: • An implementation should support machine scalars that correspond to all of the integer. Implementation Permissions 13/2 13. mask. it is inherited by the record extension.

Exp. R. . 31.7) of Boolean. is array (State) of Boolean. imported. Integer range 0 . 28 type Program_Status_Word record System_Mask Protection_Key Machine_State Interrupt_Cause Ilc Cc Program_Mask Inst_Address end record. 3. Dec. . This offset is measured in bits. for Program_Status_Word'Alignment use 8. is array (Mode) of Boolean. 3. 11... is array (0.. 29 for Program_Status_Word use record System_Mask at 0*Word Protection_Key at 0*Word Machine_State at 0*Word Interrupt_Cause at 0*Word Ilc at 1*Word Cc at 1*Word Program_Mask at 1*Word Inst_Address at 1*Word end record.. 30 for Program_Status_Word'Size use 8*System. If component_clauses are given for all components. from the start of the first of the storage elements occupied by C. is (Fix. The Size clause guarantees that (at least) eight storage elements are used for objects of the type. Integer range 0 . the record_representation_clause completely specifies the representation of the type and will be obeyed exactly by the implementation. Examples 24 25 26 27 23 Example of specifying the layout of a record type: Word : constant := 4. 31. Address. is : : : : : : : : Byte_Mask.M.. . type State type Mode type Byte_Mask type State_Mask type Mode_Mask -. 7. -.. non-array object R.9 unused 15.bits 8. the storage place attributes are defined: R.2 Storage Place Attributes Static Semantics 1 2/2 For a component C of a composite. The Alignment clause guarantees that aliased.Storage_Unit. 7. otherwise.W. -.ISO/IEC 8652:2007(E) Ed. .5.. denotes the offset. 4 bytes per word is (A.5.P). Integer range 0 .storage element is byte. denotes the value given for the first_bit of the component_clause. Signif). State_Mask. or exported objects of the type will have addresses divisible by eight. . .. NOTES 12 Note on the example: The record_representation_clause defines the record layout.. of the first bit occupied by C. denotes the value given for the position of the component_clause. The value of this attribute is of the type universal_integer. 1. denotes the same value as R. otherwise. and if a component_clause specifies the placement of C.1 Record Representation Clauses 10 November 2006 280 .. range range range range range range range range 0 10 12 16 0 2 4 8 . and if a component_clause specifies the placement of C. Mode_Mask..C'Position If the nondefault bit ordering applies to the composite type. 3.. . 31 13. Interruption_Code. then the choice of the storage place for the component is left to the implementation.second word 3. 3 — Ada Reference Manual NOTES 11 If no component_clause is given for a component.C'First_Bit If the nondefault bit ordering applies to the composite type.C'Address – R'Address. The 3/2 13.

the expression of such a clause shall be static. If Word_Size > Storage_Unit. They do not guarantee transparent exchange of data between such machines. The value of this attribute is of the type universal_integer. the default bit ordering is implementation defined. This offset is measured in bits. Bit_Order may be specified for specific record types via an attribute_definition_clause. If a component is allocated discontiguously from the rest of the object.3 Bit Ordering The Bit_Order attribute specifies the interpretation of the storage place attributes. NOTES 13 Bit_Order clauses make it possible to write record_representation_clauses that can be ported between machines having different bit ordering. 7 8/2 9/2 281 10 November 2006 Storage Place Attributes 13. Low_Order_First (known in the vernacular as “little endian”) means the opposite: the first bit is the least significant. Implementation Advice 5 6 The recommended level of support for the nondefault bit ordering is: • The implementation should support the nondefault bit ordering in addition to the default bit ordering. and this data is contiguous with the rest of the object. The value of this attribute is of the type universal_integer. the default bit ordering is the same as the ordering of storage elements in a word.5. The storage place attributes of a component of a type are interpreted according to the bit ordering of the type. 2 3 4 If Word_Size = Storage_Unit. 3 — Ada Reference Manual first bit of a storage element is numbered zero. Implementation Advice 4/2 If a component is represented using some form of pointer (such as an offset) to the actual data of the component. The value of this attribute is of type System.Bit_Order. otherwise. then the storage place attributes should reflect the place of the actual data.5. from the start of the first of the storage elements occupied by C. then a warning should be generated upon reference to one of its storage place attributes. the following attribute is defined: S'Bit_Order Denotes the bit ordering for the type of S. not the pointer. denotes the offset. of the last bit occupied by C. R. 5 13. High_Order_First (known in the vernacular as “big endian”) means that the first bit of a storage element (bit 0) is the most significant bit (interpreting the sequence of bits that represent a component as an unsigned integer value).ISO/IEC 8652:2007(E) Ed. Static Semantics 1 A bit ordering is a method of interpreting the meaning of the storage place attributes.C'Last_Bit If the nondefault bit ordering applies to the composite type. when interpreted as an integer. denotes the value given for the last_bit of the component_clause. For every specific record subtype S.2 . and if a component_clause specifies the placement of C.

-. Examples 2 3 4 Example of change of representation: -. If one type has packing specified and the other does not.ISO/IEC 8652:2007(E) Ed. D := Descriptor(P). apart from their -.component clauses for some or for all components end record. To convert a record from one representation to another. Distinct representations can then be specified for the record types. and explicit conversion between the types can be used to effect a change in representation. P := Packed_Descriptor(D).Change of representation can now be accomplished by explicit type conversions: D : Descriptor.representation type Descriptor is record -.unpack P 5 6 7 8 9 10 13.with identical characteristics. To convert an array from one representation to another. two record types with a common ancestor type need to be declared.6 Change of Representation 1 A type_conversion (see 4. 3 — Ada Reference Manual 13. two array types need to be declared with matching component subtypes. P : Packed_Descriptor.6 Change of Representation 10 November 2006 282 .Packed_Descriptor and Descriptor are two different types -.components of a descriptor end record. with no inherited subprograms. -.6) can be used to convert between two different representations of the same array or record. then explicit conversion can be used to pack or unpack an array. for Packed_Descriptor use record -. type Packed_Descriptor is new Descriptor.pack D -. and convertible index types.

3 — Ada Reference Manual 13. Null_Address : constant Address.Storage-related Declarations: type Address is implementation-defined. . Right : Address) return Boolean. Right : Address) return Boolean. Right : Address) return Boolean. 19 283 10 November 2006 The Package System 13.not specified by the language end System. Any_Priority'Last. -. : constant := implementation-defined. : constant := implementation-defined. Right : Address) return Boolean.1): subtype Any_Priority is Integer range implementation-defined. Right : Address) return Boolean. Default_Bit_Order : constant Bit_Order := implementation-defined. Default_Priority : constant Priority := (Priority'First + Priority'Last)/2.. 14 15/2 16 17 18 Name is an enumeration subtype. Max_Nonbinary_Modulus : constant := implementation-defined. type Name is implementation-defined-enumeration-type. function ">="(Left. System_Name : constant Name := implementation-defined. : constant := implementation-defined. Values of type Name are the names of alternative machine configurations handled by the implementation. Word_Size : constant := implementation-defined * Storage_Unit."/=" is implicitly defined pragma Convention(Intrinsic.function "/=" (Left. -.. "<"). -. private . implementation-defined.Other System-Dependent Declarations: type Bit_Order is (High_Order_First.ISO/IEC 8652:2007(E) Ed.7 . : constant := root_integer'Last.System-Dependent Named Numbers: Min_Int Max_Int : constant := root_integer'First. -. Static Semantics 1 The following language-defined library package exists: package System is pragma Pure(System). Right : Address) return Boolean. System_Name represents the current machine configuration.Address Comparison: function "<" (Left..Priority-related declarations (see D.7 The Package System For each implementation there is a library package called System which includes the definitions of certain configuration-dependent characteristics. subtype Interrupt_Priority is Any_Priority range Priority'Last+1 .. -. function "<="(Left. -. Max_Base_Digits Max_Digits Max_Mantissa Fine_Delta Tick : constant := root_real'Digits. Storage_Unit : constant := implementation-defined. function "=" (Left.and so on for all language-defined subprograms in this package -. function ">" (Left. Memory_Size : constant := implementation-defined. Low_Order_First). -. subtype Priority is Any_Priority range Any_Priority'First . 2 3/2 4 5 6 7 8 9 10 11 12 13 Max_Binary_Modulus : constant := implementation-defined... -. : constant := implementation-defined.

Implementation Permissions 34/2 35/2 36/2 An implementation may add additional implementation-defined declarations to package System and its children. The meanings of the named numbers are: Min_Int Max_Int The smallest (most negative) value allowed for the expressions of a signed_integer_type_definition. See 13. 3 — Ada Reference Manual 20 The named numbers Fine_Delta and Tick are of the type universal_real. Memory_Size An implementation-defined value that is intended to reflect the memory size of the configuration in storage elements.5.ISO/IEC 8652:2007(E) Ed. Implementation Advice 37 Address should be a private type. 24 Max_Binary_Modulus A power of two such that it. Max_Nonbinary_Modulus A value such that it.3 for an explanation of Bit_Order and Default_Bit_Order.0. it is usually better for the implementation to provide additional functionality via implementation-defined children of System.Clock remains constant.0 .) 25 26 27 28 Max_Mantissa 29 Fine_Delta Tick Storage_Unit The smallest delta allowed in an ordinary_fixed_point_definition that has the real_range_specification range –1. Max_Digits The largest value allowed for the requested decimal precision in a floating_point_definition that has no real_range_specification. 1. The number of bits per storage element. 21 22 23 The largest (most positive) value allowed for the expressions of a signed_integer_type_definition.. Address is a definite.7 The Package System 10 November 2006 284 . Max_Base_Digits The largest value allowed for the requested decimal precision in a floating_point_definition. However. The largest possible number of binary digits in the mantissa of machine numbers of a userdefined ordinary fixed point type. and all lesser positive powers of two. 31 32 33 Word_Size The number of bits per word. Address represents machine addresses capable of addressing individual storage elements. nonlimited type with preelaborable initialization (see 10. Max_Digits is less than or equal to Max_Base_Digits. Null_Address is an address that is distinct from the address of any object or program unit.2. and all lesser positive integers. (The mantissa is defined in Annex G. 13. are allowed as the modulus of a modular_type_definition.1). are allowed as the modulus of a modular_type_definition. the others are of the type universal_integer. 30 A period in seconds approximating the real time interval during which the value of Calendar. Default_Bit_Order shall be a static constant.

For example.. type Storage_Element is mod implementation-defined. 38 13.. pragma Convention(Intrinsic. for Storage_Array'Component_Size use Storage_Unit. To_Address and To_Integer convert back and forth between this type and Address. end System. Storage_Count represents a number of storage elements. type Storage_Array is array (Storage_Offset range <>) of aliased Storage_Element.Conversion to/from integers: type Integer_Address is implementation-defined. 1 2/2 3 4 5 6 7 function "mod"(Left : Address. -.Storage_Offset'Last.7 . Right : Address) Storage_Offset. Storage_Array represents a contiguous sequence of storage elements.ISO/IEC 8652:2007(E) Ed. Integer_Address is a (signed or modular) integer subtype.1 The Package System.and so on for all language-defined subprograms declared in this package.” Operations that do not make sense should raise Program_Error. "-"(Left : Address. Implementation Advice 15/2 Operations in System and its children should reflect the target environment semantics as closely as is reasonable. Right : Storage_Offset) Address.Storage_Elements. 3 — Ada Reference Manual NOTES 14 There are also some language-defined child packages of System defined elsewhere. -. on most machines.Storage_Elements is pragma Pure(Storage_Elements). type Storage_Offset is range implementation-defined. Storage_Offset represents an offset in storage elements. Storage_Offset'First shall be <= (–Storage_Offset'Last). Implementation Permissions 14 This paragraph was deleted. Right : Storage_Offset) return Storage_Offset.. Right : Storage_Offset) Address. Right : Address) Address. Implementation Requirements 12 13 Storage_Offset'Last shall be greater than or equal to Integer'Last or the largest possible storage offset.Storage_Elements Static Semantics The following language-defined library package exists: package System. 16 285 10 November 2006 The Package System 13. "-"(Left.7. 8 9 10 11 Storage_Element represents a storage element. whichever is smaller.Address Arithmetic: function return function return function return function return "+"(Left : Address. "+"). "+"(Left : Storage_Offset. it makes sense for address arithmetic to “wrap around. subtype Storage_Count is Storage_Offset range 0.. for Storage_Element'Size use Storage_Unit. function To_Address(Value : Integer_Address) return Address. function To_Integer(Value : Address) return Integer_Address. -.

Implementation Permissions 6 An implementation may place restrictions on instantiations of Address_To_Access_Conversions. pragma Convention(Intrinsic. To_Address(null) returns Null_Address.2 The Package System.Address_To_Access_Conversions Static Semantics 1 2 The following language-defined generic library package exists: generic type Object(<>) is limited private. 3 4 5/2 The To_Pointer and To_Address subprograms convert back and forth between values of types Object_Pointer and Address.Machine_Code. 13. If a subprogram_body contains any code_statements. package System.all'Address. type Object_Pointer is access all Object. pragma Convention(Intrinsic. The meaning of code_statements is implementation defined. Name Resolution Rules 4 The qualified_expression is expected to be of any type. and no exception_handler is allowed (comments and pragmas are allowed as usual). To_Pointer(X'Address) is equal to X'Unchecked_Access for any X that allows Unchecked_Access. the only allowed declarative_items are use_clauses.7.Address_To_Access_Conversions is pragma Preelaborate(Address_To_Access_Conversions).2 The Package System. Syntax 2 3 code_statement ::= qualified_expression. end System.Machine_Code.8 Machine Code Insertions 1 A machine code insertion can be achieved by a call to a subprogram whose sequence_of_statements contains code_statements. To_Pointer). function To_Pointer(Value : Address) return Object_Pointer. For other addresses. To_Pointer(Null_Address) returns null. returns Y. where Y /= null. Legality Rules 5 6 The qualified_expression shall be of a type declared in package System. Static Semantics 7 The contents of the library package System. then within this subprogram_body the only allowed form of statement is a code_statement (labeled or not). the behavior is unspecified. each qualified_expression represents a machine instruction or assembly directive.Address_To_Access_Conversions 10 November 2006 286 . 3 — Ada Reference Manual 13.Machine_Code (if provided) are implementation defined. function To_Address(Value : Object_Pointer) return Address. Typically. 13.ISO/IEC 8652:2007(E) Ed.7. A code_statement is only allowed in the handled_sequence_of_statements of a subprogram_body. A code_statement shall appear only within the scope of a with_clause that mentions package System. To_Address).Address_To_Access_Conversions. To_Address(Y).

pragma Pure(Ada. NOTES 15 An implementation may provide implementation-defined pragmas specifying register conventions and calling conventions. pragma Inline(Set_Mask). • S and the target subtype both have a contiguous representation. function Ada. B => M'Base_Reg. Ada.1. This is the actual subtype passed to Source. 3 — Ada Reference Manual Implementation Permissions An implementation may place restrictions on code_statements. procedure Set_Mask.Machine_Code.ISO/IEC 8652:2007(E) Ed.Unchecked_Conversion).9 Unchecked Type Conversions An unchecked type conversion can be achieved by a call to an instance of the generic function Unchecked_Conversion. “Interface to Other Languages”. Static Semantics 1 The following language-defined generic library function exists: generic type Source(<>) is limited private. the effect of an unchecked conversion is to return the value of an object of the target subtype whose representation is the same as that of the source object S: • S'Size = Target'Size. procedure Set_Mask is use System.8 . In fact. 12 13 14 13. type Target(<>) is limited private.Unchecked_Conversion).” appears somewhere above begin SI_Format'(Code => SSM. -. Dynamic Semantics 2 3 The size of the formal parameter S in an instance of Unchecked_Conversion is that of its subtype. Interface to assembly language can be achieved using the features in Annex B. return statements are forbidden. • The target subtype is not an unconstrained composite subtype. Examples 8 9 10/2 11 Example of a code statement: M : Mask. “Conformance Rules”) can also be used to achieve machine code insertions.3. except when the actual is an unconstrained composite subtype.Machine_Code. • The representation of S is a representation of an object of the target subtype. since only code_statements are allowed.assume “with System.Unchecked_Conversion(S : Source) return Target. 17 Intrinsic subprograms (see 6. 16 Machine code functions are exempt from the rule that a return statement is required. 4 5 6 7 8 9 10 287 10 November 2006 Machine Code Insertions 13. in which case the subtype is constrained by the bounds or discriminants of the value of the actual expression passed to S. • S'Alignment = Target'Alignment.Machine_Code. If all of the following are true. An implementation is not required to provide package System. D => M'Disp). pragma Convention(Intrinsic.Base_Reg and Disp are implementation-defined attributes end Set_Mask. -.

9. the bounds should not be part of the converted data. if after 5 6/2 6. It should take advantage of the permission to return by reference when possible. If the result type is nonscalar.9 Unchecked Type Conversions 10 November 2006 288 . 3 — Ada Reference Manual 11/2 Otherwise. To enable meaningful use of unchecked conversion. and can have an invalid representation (see 13. for statically constrained array subtypes whose component subtype is one of the subtypes described in this paragraph. the effect is implementation defined. the result can be abnormal (see 13. However. In this case. • The object is the return object of a function call of a nonscalar type. Implementation Permissions 12 An implementation may return the result of an unchecked conversion by reference. Abnormal objects and invalid representations are explained in this subclause.9. the result of the unchecked conversion represents simply a different (readonly) view of the operand of the conversion. and any explicit or default initializations have been performed. or the stream attribute T'Read. a contiguous representation should be used for elementary subtypes.1/2 13. The recommended level of support for unchecked conversions is: • Unchecked conversions should be supported and should be reversible in the cases where this clause defines the result. Restrictions on unchecked conversions should be avoided unless required by the target environment. • The object is not scalar. if the Source type is not a by-copy type. Subsequent uses of abnormal objects can be erroneous.ISO/IEC 8652:2007(E) Ed. and for record subtypes without discriminants whose component subtypes are described in this paragraph. and is passed to an in out or out parameter of an imported procedure. or the stream attribute T'Input. Subsequent operations generally leave them normal. An implementation may place restrictions on Unchecked_Conversion. which means that the object's representation does not represent any value of the object's subtype. Implementation Advice 13 14/2 Since the Size of an array object generally does not include its bounds. The implementation should not generate unnecessary run-time checks to ensure that the representation of S is a representation of the target type. The primary cause of invalid representations is uninitialized variables. an object or part of an object can become abnormal in the following ways: • An assignment to the object is disrupted due to an abort (see 9.1 Data Validity 1 Certain actions that can potentially lead to erroneous execution are not directly erroneous.8) or due to the failure of a language-defined check (see 11. and the function is an imported function. the result of the function is implementation defined.1). if after return from the procedure the representation of the parameter does not represent a value of the parameter's subtype.6). 15 16 17 13. Direct_IO. A scalar object can have an invalid representation. an instance of Unchecked_Conversion. if the result type is scalar. the object and all of its parts are in the normal state. Dynamic Semantics 2 3 4 When an object is first created.1). the Read procedure of an instance of Sequential_IO. in particular. but instead can cause objects to become abnormal.9. or Storage_IO.

Bounded (Run-Time) Errors 8 If the representation of a scalar object does not represent a value of the object's subtype (perhaps because the object was not initialized). Static Semantics 1 For a prefix X that denotes a scalar object (after any implicit dereference).9. and the result is used other than as the expression of an assignment_statement or an object_declaration. or to evaluate a prefix that denotes an abnormal object. the value of the type is used. the object is said to have an invalid representation. input. An abnormal object becomes normal again upon successful completion of an assignment to the object as a whole. if it designates a nonexistent object. interface to foreign languages. or as the prefix of a Valid attribute. for example. execution continues using the invalid representation. the following attribute is defined: 2 289 10 November 2006 Data Validity 13. and the assigned value is an invalid representation for the target of the assignment.9. If the error is detected. because of Unchecked_Deallocation. 3 — Ada Reference Manual return from the function the representation of the return object does not represent a value of the function's subtype. Unchecked_Access. NOTES 18 Objects can become abnormal due to other kinds of actions that directly update the object's representation. Whether or not an object actually becomes abnormal in these cases is not specified. Otherwise. • If the representation of the object does not represent a value of the object's type. or if it is an access-tovariable value that designates a constant object. The semantics of operations on invalid representations are as follows: • If the representation of the object represents a value of the object's type.2/2 7 It is erroneous to evaluate a primary that is a name denoting an abnormal object. the semantics of operations on such representations is implementation-defined. The dereference of an access value is erroneous if it does not designate an object of an appropriate type or a subprogram with an appropriate profile. 12/2 13 14 13. but does not by itself lead to erroneous or unpredictable execution. however. or Unchecked_Conversion. or to other objects becoming abnormal. Erroneous Execution 9 10 11 A call to an imported function or an instance of Unchecked_Conversion is erroneous if the result is scalar.1 . For an imported object. then any use of the target object prior to a further assignment to the target object. such actions are generally considered directly erroneous. If such a result object is used as the source of an assignment. it is the programmer's responsibility to ensure that the object remains in a normal state. and the like. Erroneous Execution 6. either Constraint_Error or Program_Error is raised. Such an access value can exist. is erroneous. The rules of the language outside this subclause assume that all objects have valid representations.ISO/IEC 8652:2007(E) Ed. It is a bounded error to evaluate the value of such an object. the result object has an invalid representation.2 The Valid Attribute The Valid attribute can be used to check the validity of data produced by unchecked conversion. other than as the prefix of a Valid attribute reference.

21 The Valid attribute may be used to check the result of calling an instance of Unchecked_Conversion (or any other operation that can return invalid values). By default. 23 There is no Unchecked_Access attribute for subprograms.9.” Static Semantics 2 3 The following attribute is defined for a prefix X that denotes an aliased view of an object: X'Unchecked_Access All rules and semantics that apply to X'Access (see 3. 4 5 6 7 8 9 10 11 12 13/2 NOTES 19 Invalid data can be created in the following cases (not counting erroneous or unpredictable execution): • • • • • • • an uninitialized scalar object.2. NOTES 22 This attribute is provided to support the situation where a local object is to be inserted into a global linked data structure.10. The Access attribute would be illegal in this case (see 3. 13. “Operations of Access Types”).2) apply also to X'Unchecked_Access. Several access types can share the same pool. instances of Unchecked_Deallocation return storage to the pool. 13. hence. The user may define new pool types. A storage pool is a variable of a type in the class rooted at Root_Storage_Pool.ISO/IEC 8652:2007(E) Ed. for the purposes of accessibility rules and checks. it is not an error to check the validity of invalid data. input. which is an abstract limited controlled type. and may override the choice of pool for an access-to-object type by specifying Storage_Pool for the type.10 Unchecked Access Value Creation 1 The attribute Unchecked_Access is used to create access values in an unsafe manner — the programmer is responsible for preventing “dangling references.2 The Valid Attribute 10 November 2006 290 . 20 X'Valid is not considered to be a read of X. The value of this attribute is of the predefined type Boolean. aborting an assignment. Storage_Size shall not be specified for it. and use of an object whose Address has been specified.10. an exception handler should also be provided because implementations are permitted to raise Constraint_Error or Program_Error if they detect the use of an invalid representation (see 13. interface to another language (including machine code). 4 5 13. except that. it is as if X were declared immediately within a library package. 3 — Ada Reference Manual 3 X'Valid Yields True if and only if the object denoted by X is normal and has a valid representation.1). when the programmer knows that it will always be removed from the data structure prior to exiting the object's scope. the result of an unchecked conversion.9. Legality Rules 2/2 3 If Storage_Pool is specified for a given access type.6).11 Storage Management 1 Each access-to-object type has an associated storage pool. the implementation chooses a standard storage pool for each access-to-object type. disrupting an assignment due to the failure of a language-defined check (see 11. However. The storage allocated by an allocator comes from the pool.

Alignment : in Storage_Elements. function Storage_Size(Pool : Root_Storage_Pool) return Storage_Elements.not specified by the language end System. Storage_Address : in Address. The Alignment parameter is D'Alignment. S'Storage_Size Yields the result of calling Storage_Size(S'Storage_Pool).Limited_Controlled with private. The result returned in the Storage_Address parameter is used by the allocator as the address of the allocated storage.Storage_Pools). and is no more than D'Max_Size_In_Storage_Elements.Storage_Count) is abstract. 3 — Ada Reference Manual Static Semantics The following language-defined library package exists: with Ada. For every access-to-object subtype S. with System.Finalization. Alignment : in Storage_Elements. The type of this attribute is universal_integer. the name in a Storage_Pool clause shall denote a variable. The Size_In_Storage_Elements parameter indicates the number of storage elements to be allocated.Storage_Pools is pragma Preelaborate(System. private . Any exception propagated by Allocate is propagated by the allocator. pragma Preelaborable_Initialization(Root_Storage_Pool). Size_In_Storage_Elements : in Storage_Elements. Size_In_Storage_Elements : in Storage_Elements. If Storage_Pool is not specified for a type defined by an access_to_object_definition. The elements of a storage pool are the objects allocated in the pool by allocators..11 .Storage_Count) is abstract. procedure Allocate( Pool : in out Root_Storage_Pool. type Root_Storage_Pool is abstract new Ada. It is implementation defined whether or not the implementation provides user-accessible names for the standard pool type(s). then the Storage_Size of this pool is at least that requested.Storage_Pools. the following representation attributes are defined: S'Storage_Pool Denotes the storage pool of the type of S. The type of this attribute is Root_Storage_Pool'Class. passing T'Storage_Pool as the Pool parameter. package System. then the storage is allocated by calling Allocate. In this case. where D is the designated subtype. Storage_Address : out Address. and the storage for the pool is reclaimed when the master containing the declaration of the access type is 11 12/2 13 14 15 16 17 18 291 10 November 2006 Storage Management 13. which is a contiguous block of memory of Size_In_Storage_Elements storage elements..Storage_Elements. -.Finalization. the exception Storage_Error is raised by an allocator if there is not enough storage. If the storage pool is a user-defined object. An allocator of type T allocates storage from T's storage pool.Storage_Count. Storage_Size or Storage_Pool may be specified for a non-derived access-to-object type via an attribute_definition_clause. 4 5 6/2 7 8 9 10 A storage pool type (or pool type) is a descendant of Root_Storage_Pool.ISO/IEC 8652:2007(E) Ed. procedure Deallocate( Pool : in out Root_Storage_Pool.Storage_Count. If Storage_Size is specified for an access type. then the implementation chooses a standard storage pool for it in an implementation-defined manner.Storage_Count is abstract. which is intended to be a measure of the number of storage elements reserved for the pool.

The user can override Initialize and Finalize if there is any need for non-trivial initialization and finalization for a user-defined pool type.ISO/IEC 8652:2007(E) Ed. then the program execution is erroneous. NOTES 24 A user-defined storage pool type can be obtained by extending the Root_Storage_Pool type. If the implementation cannot satisfy the request. and be reclaimed when the allocated object becomes inaccessible. A user-defined storage pool can then be obtained by declaring an object of the type extension. 25 The writer of the user-defined allocation and deallocation procedures. If they are used inside protected objects. The storage pool used for an allocator of an anonymous access type should be determined as follows: • If the allocator is defining a coextension (see 3. a default storage pool should be created at the point where the anonymous access type is elaborated. Documentation Requirements 22 An implementation shall document the set of values that a user-defined Allocate procedure needs to accept for the Alignment parameter. and Storage_Size. Deallocate. Erroneous Execution 21 If Storage_Pool is specified for an access type.2/2 25. are responsible for dealing with any interactions with tasking. Storage_Error is raised at the point of the attribute_definition_clause. then the meaning of Storage_Size is implementation defined. • For other access discriminants and access parameters. and return the address of the first storage element in Storage_Address. For example.10. 19 20 If Storage_Pool is specified for an access type. and users of allocators for the associated access type. then the storage pool used for the outer allocator should also be used for the coextension. and how storage is allocated by standard storage pools.3/2 26 27 28 29 30 13. Finalize might reclaim blocks of storage that are allocated separately from the pool object itself. 24 25/2 25. they require mutual exclusion. A default (implementation-provided) storage pool for an access-to-constant type should not have overhead to support deallocation of individual objects. The block should contain Size_In_Storage_Elements storage elements. then if Allocate can satisfy the request. If the request cannot be satisfied. The allocated storage should not be used for any other purpose while the pool element remains in existence. 3 — Ada Reference Manual left. the storage pool should be created at the point of the allocator. then the specified pool is used. then Allocate should propagate an exception (such as Storage_Error). If they are used by interrupt handlers (see C.1/2 25.11 Storage Management 10 November 2006 292 . and overriding the primitive subprograms Allocate. they cannot block. If Allocate behaves in any other manner. In particular: • • • If the allocators are used in different tasks. • Otherwise.2) of an object being created by an outer allocator.3. Implementation Advice 23 An implementation should document any cases in which it dynamically allocates heap storage for a purpose other than the evaluation of an allocator. the mutual exclusion mechanism has to work properly in that context. The effect of calling Allocate and Deallocate for a standard storage pool directly (rather than implicitly via an allocator or an instance of Unchecked_Deallocation) is unspecified. If neither Storage_Pool nor Storage_Size are specified. “Interrupt Support”). it should allocate a contiguous block of memory. An implementation shall document how the standard storage pool is chosen. and should be aligned according to Alignment. such a storage pool need not support deallocation of individual objects.

presuming that Mark_Release_Pool_Type has two additional operations. MR_Pool : Mark_Release_Pool_Type (Pool_Size => 2000. 35 36 37 38 The semantics of this is implementation defined for a standard storage pool. for Acc'Storage_Pool use MR_Pool. the user first declares a pool object of some type derived from Root_Storage_Pool. 3 — Ada Reference Manual 26 The primitives Allocate. the user defines its Storage_Pool attribute. Then. As usual.11 .Reclaim the storage. via: for T2'Storage_Pool use T'Storage_Pool. then this accounts for any calls on Allocate that could be performed to provide space for such coextensions....Storage_Count) is new Root_Storage_Pool with private. and Storage_Size are declared as abstract (see 3. -. 39/1 40 41 42 43 13. Block_Size : Storage_Elements.Allocate objects using “new Designated(.)”. the following attribute is defined: S'Max_Size_In_Storage_Elements Denotes the maximum value for Size_In_Storage_Elements that could be requested by the implementation via Allocate for an access type whose designated subtype is S. -. if the implementation allocates space for a coextension in the same pool as that of the object having the access discriminant. Mark and Release. type Acc is access . Static Semantics 1 For every subtype S.... 32 33 34 Another access type may be added to an existing storage pool.. . and therefore they have to be overridden when a new (non-abstract) storage pool type is declared.. .. the following is a possible use: type Mark_Release_Pool_Type (Pool_Size : Storage_Elements. Mark(MR_Pool). Block_Size => 100).3).Storage_Count. Deallocate.9.1 The Max_Size_In_Storage_Elements Attribute The Max_Size_In_Storage_Elements attribute is useful in writing user-defined pool types. For example. 2 3/2 293 10 November 2006 Storage Management 13. a derivative of Root_Storage_Pool may define additional operations. as follows: Pool_Object : Some_Storage_Pool_Type.11. For a type with access discriminants.ISO/IEC 8652:2007(E) Ed. The value of this attribute is of type universal_integer.. Release(MR_Pool). Examples 31 To associate an access type with a storage pool object. for T'Storage_Pool use Pool_Object.. . type T is access Designated.

their storage can be reused for other purposes.10. has no effect. If the storage pool is a user-defined object.2). It then deallocates the storage occupied by the object designated by X (and any coextensions). The possible consequences are: • No exception is raised.6. the storage for the discriminants (and for any enclosing object if it is designated by an access discriminant of the task) is not reclaimed prior to task termination. Static Semantics 2 3 The following language-defined generic library procedure exists: generic type Object(<>) is limited private. the object designated by X. Storage_Address is the value returned in the Storage_Address parameter of the corresponding Allocate call.2 Unchecked Storage Deallocation 10 November 2006 294 . Erroneous Execution 15 16 Evaluating a name that denotes a nonexistent object is erroneous. 13. Ada. unterminated task object.Unchecked_Deallocation). After executing Free(X). 3 — Ada Reference Manual 13. In the first two cases. Free(X). the value of X is null.1. passing access_to_variable_subtype_name'Storage_Pool as the Pool parameter. 3. when X is already equal to null. After Free(X).Unchecked_Deallocation(X : in out Name). • Program_Error or Tasking_Error is raised in the task the next time it references any of the discriminants. pragma Convention(Intrinsic. Size_In_Storage_Elements and Alignment are the same values passed to the corresponding Allocate call.11. The execution of a call to an instance of Unchecked_Deallocation is erroneous if the object was created other than by an allocator for an access type whose pool is Name'Storage_Pool. 6 7 8 9/2 Procedure Free has the following effect: 1. access_to_variable_subtype_name).Unchecked_Deallocation).ISO/IEC 8652:2007(E) Ed. the object might not be deallocated.2 Unchecked Storage Deallocation 1 Unchecked storage deallocation of an object designated by a value of an access type is achieved by a call to an instance of the generic procedure Unchecked_Deallocation. as described in 7. when X is not equal to null first performs finalization of the object designated by X (and any coextensions of the object — see 3. 2.Unchecked_Deallocation( object_subtype_name. type Name is access Object. Bounded (Run-Time) Errors 10/2 11 12 13 14 It is a bounded error to free a discriminated. Free(X). • Program_Error or Tasking_Error is raised at the point of the deallocation. There is one exception: if the object being freed contains tasks. pragma Preelaborate(Ada. procedure Ada.11. then the storage is deallocated by calling Deallocate. and any subcomponents (and coextensions) thereof. Dynamic Semantics 4 5 Given an instance of Unchecked_Deallocation declared as follows: procedure Free is new Ada. no longer exist.

and its value shall be nonnegative. Legality Rules 5 Unless otherwise specified for a particular restriction.ISO/IEC 8652:2007(E) Ed. 17 18 19 13. a pragma Controlled has no effect.3 Pragma Controlled Pragma Controlled is used to prevent any automatic reclamation of storage (garbage collection) for the objects created by allocators of a given access type. Free should actually reclaim the storage. Legality Rules 2 3 The first_subtype_local_name of a pragma Controlled shall denote a non-derived access subtype.1/2 Unless otherwise specified for a particular restriction. the expression is expected to be of any integer type. 3 — Ada Reference Manual Implementation Advice For a standard storage pool. 8 13. restriction}). 6 295 10 November 2006 Unchecked Storage Deallocation 13.5. NOTES 27 The rules here that refer to Free apply to any instance of Unchecked_Deallocation. while the objects still exist. This is implied by the rules of 12. Garbage collection is a process that automatically reclaims storage. This may facilitate the construction of simpler run-time environments. Syntax 1 The form of a pragma Restrictions is as follows: pragma Restrictions(restriction{. restriction ::= restriction_identifier | restriction_parameter_identifier => restriction_parameter_argument restriction_parameter_argument ::= name | expression Name Resolution Rules 2 3 4/2 4.11. in which case.12 Pragma Restrictions A pragma Restrictions expresses the user's intent to abide by certain restrictions. Static Semantics 4 A pragma Controlled is a representation pragma that specifies the controlled aspect of representation. Syntax 1 The form of a pragma Controlled is as follows: pragma Controlled(first_subtype_local_name).11. or moves objects to a different address. the expression shall be static.4. 28 Unchecked_Deallocation cannot be instantiated for an access-to-constant type.2 . Implementation Permissions 5 6 7 An implementation need not support garbage collection. then garbage collection is not performed for objects in that pool. If a pragma Controlled is specified for an access type with a standard storage pool.

The consequences of violating such limitations are implementation defined. This restriction applies only to the current compilation or environment.1 are detected by this restriction. 3 — Ada Reference Manual Static Semantics 7/2 The set of restrictions is implementation defined.3/1 8. not the entire partition.ISO/IEC 8652:2007(E) Ed. Whenever enforcement of a restriction is not required prior to execution. • If an object of a type is declared or allocated and not explicitly initialized. For the purpose of checking whether a partition contains constructs that violate any restriction (unless specified otherwise for a particular restriction): • Generic instances are logically expanded at the point of instantiation.12.4. Implementation Permissions 8.12 Pragma Restrictions 10 November 2006 296 . No_Implementation_Pragmas There are no implementation-defined pragmas or pragma arguments. even if it chooses not to take advantage of the restrictions in terms of efficiency. It is implementation-defined if uses of the renamings of J.1 Language-Defined Restrictions Static Semantics 1/2 The following restriction_identifiers are language-defined (additional restrictions are defined in the Specialized Needs Annexes): No_Implementation_Attributes There are no implementation-defined attributes. not the entire partition. This restriction applies only to the current compilation or environment. 2/2 3/2 4/2 13. not the entire partition. unless otherwise specified for a particular restriction. Restrictions intended for use when constructing high integrity systems are defined in H. 30 An implementation has to enforce the restrictions in cases where enforcement is required.2/1 10/2 11 13. then all expressions appearing in the definition for the type and any of its ancestors are presumed to be used. NOTES 29 Restrictions intended to facilitate the construction of efficient tasking run-time systems are defined in D. 9.4/1 9 An implementation may place limitations on the values of the expression that are supported.2/1 8. and limitations on the supported combinations of restrictions. This restriction applies only to the current compilation or environment. an implementation may nevertheless enforce the restriction prior to execution of a partition to which the restriction applies. No_Obsolescent_Features There is no use of language features defined in Annex J.1/1 9. • A default_expression for a formal parameter or a generic formal object is considered to be used if and only if the corresponding actual parameter is not provided in a given call or instantiation. a partition shall obey the restriction if a pragma Restrictions applies to any compilation unit included in the partition. Post-Compilation Rules 8 A pragma Restrictions is a configuration pragma.1/1 8. provided that every execution of the partition would violate the restriction. An implementation is permitted to omit restriction checks for code that is recognized at compile time to be unreachable and for which no code is generated.7.

procedure Read( Stream : in out Root_Stream_Type.. Last : out Stream_Element_Offset) is abstract..13 Streams A stream is a sequence of elements comprising values from possibly different types and allowing sequential access to these values. -. Post-Compilation Rules 7/2 No compilation unit included in the partition shall depend semantically on the library unit identified by the name. private . type Stream_Element_Offset is range implementation-defined. Legality Rules 5/2 6/2 The restriction_parameter_argument of a No_Dependence restriction shall be a name. or a network channel. The predefined streamoriented attributes like T'Read and T'Write make dispatching calls on the Read and Write procedures of the Root_Stream_Type. and optionally defining additional primitive subprograms. the name shall have the form of a full expanded name of a library unit. A new stream type is defined by extending the root type (or some other stream type).ISO/IEC 8652:2007(E) Ed. such as an external sequential file. A stream type may be implemented in various ways. pragma Preelaborable_Initialization(Root_Stream_Type). 1 2 3/2 4/1 5 6 7 297 10 November 2006 Language-Defined Restrictions 13. overriding the Read and Write operations. 3 — Ada Reference Manual The following restriction_parameter_identifier is language defined: No_Dependence Specifies a library unit on which there are no semantic dependences..1 The Package Streams Static Semantics The abstract type Root_Stream_Type is the root type of the class of stream types.not specified by the language end Ada. but need not denote a unit present in the environment.1 . type Root_Stream_Type is abstract tagged limited private.13.12. procedure Write( Stream : in out Root_Stream_Type. A stream type is a type in the class whose root type is Streams. or can call the Read and Write attributes of other types. (User-defined T'Read and T'Write attributes can also make such calls. Item : in Stream_Element_Array) is abstract. type Stream_Element_Array is array(Stream_Element_Offset range <>) of aliased Stream_Element. subtype Stream_Element_Count is Stream_Element_Offset range 0. 1 13. an internal buffer. type Stream_Element is mod implementation-defined. 8/2 13.) package Ada.Streams is pragma Pure(Streams).Streams.Root_Stream_Type. The types in this class represent different kinds of streams. Item : out Stream_Element_Array.Stream_Element_Offset'Last. according to the requirements of the particular kind of stream.

“The Package Streams. Item'First . The Write operation appends Item to the specified stream. nonnegative. NOTES 31 See A. If any elements are transferred. Implementation Advice 1. Last is less than Item'Last only if the end of the stream is reached.7/2 1.13. the index of the last stream element transferred is returned in Last.12. the value of Stream_Size for an elementary type should be the number of bits that corresponds to the minimum number of stream elements required by the first subtype of the type. the number of stream elements required per item of elementary type T is: 1. The recommended level of support for the Stream_Size attribute is: • A Stream_Size clause should be supported for a discrete or fixed point type T if the specified Stream_Size is a multiple of Stream_Element'Size and is no less than the size of the first subtype of T. 10 11/2 13.ISO/IEC 8652:2007(E) Ed.4/2 T'Stream_Size / Ada.Stream_IO” for an example of extending type Root_Stream_Type.Streams. enumeration. Static Semantics 1.6/2 If not specified. the following representation attribute is defined: S'Stream_Size Denotes the number of bits occupied in a stream by items of subtype S. then the components of Stream_Element_Array need not be aliased. Elements are transferred until Item'Length elements have been transferred. rounded up to the nearest factor or multiple of the word size that is also a multiple of the stream element size. and Input convert values to a stream of elements and reconstruct values from a stream. Otherwise.2 Stream-Oriented Attributes 1/1 The operational attributes Write. ordinary fixed point.2/2 For every subtype S of an elementary type T. 32 If the end of stream has been reached.13.Stream_Element'Size The value of this attribute is of type universal_integer and is a multiple of Stream_Element'Size. or decimal fixed point). the expression of such a clause shall be static.Storage_Unit. Output. Read. and no greater than the size of the largest type of the same elementary class (signed integer. 1.8/2 13. Read will raise Constraint_Error. modular integer.1. Stream_Size may be specified for first subtypes via an attribute_definition_clause.1 The Package Streams 10 November 2006 298 . and Item'First is Stream_Element_Offset'First. 3 — Ada Reference Manual 8/2 The Read operation transfers stream elements from the specified stream to fill the array Item.1/2 1. and a multiple of Stream_Element'Size.1/1 If Stream_Element'Size is not a multiple of System. Implementation Permissions 9 9.3/2 1.1 is returned in Last. Hence.5/2 1. or until the end of the stream is reached.

For type extensions. For a limited type extension. Bounds are not included in the stream if T is an array type. and the attribute of the parent type or the type of any of the extension components is not available at the freezing point of T.13. the representation of those stream elements is implementation defined.2 . If T is a discriminated type. or a fixed point type.Streams. where available.1/2 10 11 12/2 Dispatches to the subprogram denoted by the Write attribute of the specific type identified by the tag of Item. the Write or Read attribute for each component is called in canonical order.1 if the attribute is available for the parent type at the point where T is declared. these attributes are not inherited. then the attribute of T shall be directly specified. if the attribute of the parent type or any progenitor type of T is available anywhere within the immediate scope of T.ISO/IEC 8652:2007(E) Ed. S'Class'Read S'Class'Read denotes a procedure with the following specification: procedure S'Class'Read( Stream : not null access Ada. in canonical order. For composite types. an enumeration type. discriminants are included only if they have defaults. For a signed integer type. the Write (resp. Item : out T'Class) 13 14 15/2 299 10 November 2006 Stream-Oriented Attributes 13. which is last dimension varying fastest for an array.Root_Stream_Type'Class. Item : in T) 2 3 4/2 S'Write writes the value of Item to Stream. but rather the default implementations are used. Item : out T) 5 6 7/2 S'Read reads the value of Item from Stream. the tag is not included.Streams. 3 — Ada Reference Manual Static Semantics For every subtype S of a specific type T. the Write or Read attribute for the parent type is called. Constraint_Error is raised by the predefined Write attribute if the value of the elementary item is outside the range of values representable using Stream_Size bits.Root_Stream_Type'Class. S'Write S'Write denotes a procedure with the following specification: procedure S'Write( Stream : not null access Ada. the range is unsigned only if the integer code for the lower bound of the first subtype is nonnegative. Read reads (and Write writes) the number of stream elements implied by the Stream_Size for the type T. otherwise the range is signed. execute as follows: For elementary types. For every subtype S'Class of a class-wide type T'Class: S'Class'Write S'Class'Write denotes a procedure with the following specification: procedure S'Class'Write( Stream : not null access Ada. The default implementations of the Write and Read attributes.Streams. S'Read S'Read denotes a procedure with the following specification: procedure S'Read( Stream : not null access Ada. and positional aggregate order for a record. Read) attribute is inherited according to the rules given in 13. and a (symmetric) signed range that covers all values of the first subtype would require more than Stream_Size bits. the following attributes are defined. If T is a tagged type.2/2 9/2 9.1/2 8. For a tagged derived type. For an untagged derived type.Streams.Root_Stream_Type'Class.Root_Stream_Type'Class. Item : in T'Class) 8 8. followed by the Write or Read attribute of each component of the extension part.

1/2 28 29 30/2 31/2 First writes the external tag of Item to Stream (by calling String'Output(Stream. Implementation Advice 17/2 This paragraph was deleted. Item : in T) 21 22 23/2 S'Output writes the value of Item to Stream.1/2 26 27/2 27. where available. Static Semantics 18 19 20/2 For every subtype S of a specific type T. For every subtype S'Class of a class-wide type T'Class: S'Class'Output S'Class'Output denotes a procedure with the following specification: procedure S'Class'Output( Stream : not null access Ada.Streams.Root_Stream_Type'Class.Streams.Streams. if any. Item : in T'Class) 25/2 25. S'Input S'Input denotes a function with the following specification: function S'Input( Stream : not null access Ada. S'Output S'Output denotes a procedure with the following specification: procedure S'Output( Stream : not null access Ada. the following attributes are defined.3.Streams.2 Stream-Oriented Attributes 10 November 2006 300 . and 7. and S'Input first reads the bounds.6. S'Output first writes the bounds. then S'Input is an abstract function. Tags. including any bounds or discriminants. and S'Input first reads the discriminants (using S'Read for each). If T has discriminants without defaults. S'Input then creates an object (with the bounds or discriminants.9) and then dispatches to the subprogram denoted by the Output attribute of the specific type identified by the tag. taken from the stream). using any bounds or discriminants written by a corresponding S'Output to determine how much to read.External_Tag(Item'Tag)) — see 3.Root_Stream_Type'Class. passes it to S'Read.1 if the attribute is available for the parent type at the point where T is declared. 7. S'Class'Input S'Class'Input denotes a function with the following specification: function S'Class'Input( Stream : not null access Ada.ISO/IEC 8652:2007(E) Ed.Root_Stream_Type'Class) return T 24 S'Input reads and returns one value from Stream. these attributes are not inherited.1.Root_Stream_Type'Class) return T'Class 32 33/2 13. 3 — Ada Reference Manual 16 Dispatches to the subprogram denoted by the Read attribute of the specific type identified by the tag of Item.1). the Output (resp. Normal default initialization and finalization take place for this object (see 3. execute as follows: • If T is an array type. S'Output first writes the discriminants (using S'Write for each).6. The default implementations of the Output and Input attributes. • S'Output then calls S'Write to write the value of Item to the stream. Input) attribute is inherited according to the rules given in 13. For a tagged derived type. and returns the value of the object. Tag_Error is raised if the tag of Item identifies a type declared at an accessibility level deeper than that of S. but rather the default implementations are used.13. For an untagged derived type. If T is an abstract type.

Write) is available for the parent type of T and for the types of all of the extension components. if the actual parameter of Read is constrained. or • the corresponding attribute of T is available. • The attribute_designator is Read (resp. If the specific type identified by the internal tag is not covered by T'Class or is abstract. the corresponding attribute is available at the end of the visible part where T is declared. Write) is available for T. A stream-oriented attribute for a subtype of a class-wide type T'Class is available at places where one of the following conditions is true: • T is nonlimited. Furthermore. If the value is not a value of its subtype and this error is not detected. In the default implementation of Read for a composite type with defaulted discriminants.2 . Constraint_Error is raised. 48/2 301 10 November 2006 Stream-Oriented Attributes 13. The stream-oriented attributes may be specified for any type via an attribute_definition_clause. In the default implementation of Read and Input for a composite type. For each component that is of an access type. and the attribute Read (resp. • T is a limited untagged derived type. S'Tag) which might raise Tag_Error — see 3. and erroneous execution can result (see 13.ISO/IEC 8652:2007(E) Ed. Write) and T is a limited record extension. It is unspecified at which point and in which order these checks are performed. it is unspecified how many stream elements have been read from the stream. Output). for each scalar component that is a discriminant or whose component_declaration includes a default_expression. Constraint_Error is raised if this check fails. • the attribute has been specified via an attribute_definition_clause. the component has an abnormal value.Descendant_Tag(String'Input(Stream). provided that if T has a partial view.1). 34/2 35/2 36/2 37/1 38/2 39/2 40/2 41/2 42/2 43/2 and the 44/2 attribute_definition_clause is visible. and the attribute Read (resp. Constraint_Error is raised. and T is a limited type. and the attribute was inherited for the type. if a stream-oriented attribute is specified for an interface type by an attribute_definition_clause. if Constraint_Error is raised due to the failure of one of these checks. • The attribute_designator is Input (resp. 45/2 46/2 and the 47/2 attribute_definition_clause is visible.9) and then dispatches to the subprogram denoted by the Input attribute of the specific type identified by the internal tag.9. the subprogram name given in the clause shall statically denote a null procedure. In the default implementation of Read and Input for a type. a check is made that the value returned by Read for the component belongs to its subtype. 3 — Ada Reference Manual First reads the external tag from Stream and determines the corresponding internal tag (by calling Tags. returns that result. In particular. a check is made that the discriminants read from the stream are equal to those of the actual parameter. Constraint_Error is raised if this check fails.13. For other scalar components. no check is made. The subprogram name given in such a clause shall not denote an abstract subprogram. • The attribute has been specified via an attribute_definition_clause. A stream-oriented attribute for a subtype of a specific type T is available at places where one of the following conditions is true: • T is nonlimited. End_Error is raised if the end of the stream is reached before the reading of a value of the type is completed. if the implementation can detect that the value returned by Read for the component is not a value of its subtype.

13. Furthermore.ISO/IEC 8652:2007(E) Ed. an attribute_reference for T'Input is illegal if T is an abstract type. Implementation Permissions 55/2 56/2 The number of calls performed by the predefined implementation of the stream-oriented attributes on the Read and Write operations of the stream type is unspecified. or tags. If Constraint_Error is raised during a call to Read because of failure of one the above checks. T'Output and T'Input will normally be needed. respectively. possibly through a generic instantiation (see 12. This rule applies across partitions if the implementation conforms to the Distributed Systems Annex. An anonymous access type does not support external streaming. All other types support external streaming. and the first subtype otherwise. the implementation must ensure that the discriminants of the actual parameter of Read are not modified. the output generated by S'Output or S'Write shall be readable by S'Input or S'Read. 34 User-specified attributes of S'Class are not inherited by other class-wide types descended from S. An explicit invocation is one appearing explicitly in the program text. the subtype of the Item parameter shall be the base subtype if scalar. For an indefinite subtype S of a type T. A limited type supports external streaming only if it has available Read and Write attributes.3). with Write marshalling the representation. or does not exist in the partition at the time of the call. and that attribute_definition_clause is visible. In the parameter_and_result_profiles for the stream-oriented attributes. has Read and Write attributes that have been specified via an attribute_definition_clause. The same rule applies to the result of the Input attribute. and the first subtype otherwise. The same rule applies to the result of the Input function. and Read unmarshalling the representation. A type with a part that is of an access type supports external streaming only if that access type or the type of some part that includes the access type component. For an attribute_definition_clause specifying one of these attributes. However. since T'Write and T'Read do not pass bounds. A type is said to support external streaming if Read and Write attributes are provided for sending values of such a type between active partitions. all the calls on the Read and Write operations of the stream type needed to implement an explicit invocation of a stream-oriented attribute must take place before this invocation returns. discriminants. Implementation Requirements 54/1 For every subtype S of a language-defined nonlimited specific type T. the subtype of the Item parameter is the base subtype of T if T is a scalar type. Erroneous Execution 50/2 51/2 52/2 53/2 If the internal tag returned by Descendant_Tag to T'Class'Input identifies a type that is not library-level and whose tag has not been created. execution is erroneous. NOTES 33 For a definite subtype S of a type T. An implementation may take advantage of this permission to perform internal buffering.2 Stream-Oriented Attributes 10 November 2006 302 . 3 — Ada Reference Manual 49/2 An attribute_reference for one of the stream-oriented attributes is illegal unless the attribute is available at the place of the attribute_reference. 57 58 13. only T'Write and T'Read are needed to pass an arbitrary value of the subtype through a stream.

unless the name or expression is part of a default_expression.1/1 8. • The occurrence of an object_declaration that has no corresponding completion causes freezing. causes freezing of each entity declared within it. as described below. causes freezing of the entity in some contexts. protected_body. the freezing occurs later as part of another construct. At the place where a construct causes freezing.Streams. The following rules define which entities are frozen at the place where a construct causes freezing: • At the place where an expression causes freezing. in which case. If an expression is implicitly converted to a type or subtype T. if a parameter of the instantiation is defaulted. 59 60/2 13. for My_Integer'Write use My_Write.4). or protected unit causes freezing of any progenitor types specified in the declaration. T is frozen. also. expression.ISO/IEC 8652:2007(E) Ed. A noninstance body other than a renames-as-body causes freezing of each entity declared before it within the same declarative_part.1/2 8/1 8. unless the expression is an enumeration literal used as a discrete_choice of the array_aggregate of an enumeration_representation_clause. The Legality Rules forbid certain kinds of uses of an entity in the region of text where it is frozen. • The declaration of a record extension. the type of the expression is frozen. A static expression causes freezing where it occurs.” A use of an entity. • The declaration of a record extension causes freezing of the parent subtype. 1 2 3/1 4/1 5 6 7 7. Each entity is frozen from its first freezing point to the end of the program text (given the ordering of compilation units defined in 10. except for incomplete types. task unit. 3 — Ada Reference Manual Examples Example of user-defined Write attribute: procedure My_Write( Stream : not null access Ada. Item : My_Integer'Base). The freezing of an entity occurs at one or more places (freezing points) in the program text where the representation for the entity has to be fully determined.2 . such as a reference to it by name. implicit_dereference. or (for a type) an expression of the type. A construct that (explicitly or implicitly) references an entity can cause the freezing of the entity.2/1 9 10 303 10 November 2006 Stream-Oriented Attributes 13. interface type. or a declaration of a library package or generic library package.14 Freezing Rules This clause defines a place in the program text where each declared entity becomes “frozen. a default_name. The end of a declarative_part.13. then at the place where the expression causes freezing.Root_Stream_Type'Class. or range within the construct causes freezing: • The occurrence of a generic_instantiation causes freezing. or a per-object expression of a component's constraint. This is true even if the implicit call is removed via implementation permissions. the default_expression or default_name for that parameter causes freezing. An object name or nonstatic expression causes freezing where it occurs.1. An implicit call freezes the same entities that would be frozen by an explicit call. as defined by subsequent paragraphs. each name.

the nominal subtype associated with the name is frozen. index subtypes. the type of the range is frozen. An operational or representation item that directly specifies an aspect of an entity shall appear before the entity is frozen (see 13. Dynamic Semantics 17 18 19/1 20/2 The tag (see 3. its type is frozen. For a specific tagged type. and parent subtype of the type are frozen as well. and any component subtypes. any expressions or names within the full type definition cause freezing.14 Freezing Rules 10 November 2006 304 .1). If the callable entity is a member of an entry family. the designated subtype of its type is frozen. For a class-wide type. 13. • At the place where a callable entity is frozen. the first subtype. Legality Rules 16 The explicit declaration of a primitive subprogram of a tagged type shall occur before the type is frozen (see 3.1/1 12 13 14 15 15.4). the entity denoted by the name is frozen.3). • At the place where a specific tagged type is frozen.2). at the place where an object name causes freezing. • At the place where an implicit_dereference causes freezing. the index subtype of the family is frozen. A type shall be completely defined before it is frozen (see 3. At the place where a function call causes freezing. each subtype of its profile is frozen. • At the place where an allocator causes freezing. The completion of a deferred constant declaration shall occur before the constant is frozen (see 7.1 and 7. • At the place where a subtype is frozen. • At the place where a range causes freezing. the default_expression for that parameter causes freezing. At the place where a type is frozen.1/2 • At the place where a name causes freezing.9) of a tagged type T is created at the point where T is frozen. then all ancestor types are also frozen. the primitive subprograms of the type are frozen. unless the name is a prefix of an expanded name. if a parameter of the call is defaulted. the corresponding class-wide type is frozen as well. the nominal subtype associated with the implicit_dereference is frozen.11. If the type of the allocator is a derived type.ISO/IEC 8652:2007(E) Ed. 3 — Ada Reference Manual 11 11.9. the corresponding specific type is frozen as well.

3 — Ada Reference Manual The Standard Libraries 305 10 November 2006 The Standard Libraries .ISO/IEC 8652:2007(E) Ed.

.

3 Generic_Array_Sort — A.1 Doubly_Linked_Lists — A.12 Indefinite_Hashed_Sets — A.1 Time_Zones — 9.2 Names — C.1 Stream_IO — A.3. There are three root library units: Ada.10.18.6.4 Handling — A.10 Ordered_Maps — A.8 Timing_Events — D.1.8 Indefinite_Doubly_Linked_Lists — A.6.14.3.13 Numerics — A.5.5 Hashed_Sets — A.1 Characters — A.1.18.13 Indefinite_Ordered_Sets — A.1 Discrete_Random — A.2 Generic_Complex_Arrays — G..2 Generic_Complex_Elementary_Functions — G. 3 — Ada Reference Manual Annex A (normative) Predefined Language Environment This Annex contains the specifications of library units that shall be provided by every implementation.11 Interrupts — C.3.5 Complex_Arrays — G.2 Decimal — F.6 Arithmetic — 9.1 Conversions — A.5 Dynamic_Priorities — D.1 EDF — D.5.2.8.1.18.3.12.1 Real_Time — D.1 Generic_Real_Arrays — G.1 Real_Arrays — G.2 Elementary_Functions — A.18.3 Command_Line — A.6 Ordered_Sets — A.2.14.18.continued) Environment_Variables — A.15 Sequential_IO — A.3 Containers — A.3.13.6.18.2 Assertions — 11.1 Finalization — 7.17 Exceptions — 11.11 Integer_Text_IO — A.2 Timers — D.1.1 Ada — A.. other library units are children of these: 1 2/2 Standard — A.11 Calendar — 9.8.18.1 307 10 November 2006 Predefined Language Environment A .3.15 Complex_Text_IO — G.2 Latin_1 — A.2 Asynchronous_Task_Control — D.4 Directories — A. and System.1 Float_Random — A.1 Formatting — 9.2 Complex_Types — G..18.8 Integer_Wide_Text_IO — A.18.5.10.15 Indefinite_Vectors — A.9 Vectors — A.6 Float_Text_IO — A.18.continued) Ada (.18. Interfaces.18.16 Generic_Constrained_Array_Sort — A.11 Indefinite_Hashed_Maps — A.2 IO_Exceptions — A.5 Standard (.4.6 Round_Robin — D.11 Integer_Wide_Wide_Text_IO — A.14 Indefinite_Ordered_Maps — A.18.2 Generic_Complex_Types — G.3.5.16 Dispatching — D.9 Streams — 13.2.3.2 Complex_Elementary_Functions — G.14 Group_Budgets — D.3.16 Hashed_Maps — A.1 Execution_Time — D.1.2 Direct_IO — A.4..1 Storage_IO — A.18.1 Generic_Elementary_Functions — A.9 Float_Wide_Text_IO — A.18.3.11 Float_Wide_Wide_Text_IO — A.16 Information — A.ISO/IEC 8652:2007(E) Ed.

1 Bounded — A.8 Wide_Wide_Fixed — A.5 Text_Streams — A.4 Editing — F.1.6 Unbounded — A.7 Wide_Hash — A.11 Wide_Wide_Characters — A.11.3 Hash — A.3.10.4.11 Interfaces — B.11 Complex_IO — G..12.7 Address_To_Access_Conversions — 13.8 Wide_Wide_Hash — A. A Predefined Language Environment 10 November 2006 308 .4.3 Pointers — B.4..4..7 Wide_Hash — A.2 Task_Identification — C.4.3 Standard (.11 Complex_IO — G.4.4.continued) Ada (.2 Unbounded_IO — A.10.8 Wide_Wide_Maps — A.11 Wide_Wide_Unbounded_IO — A.4.9 Maps — A.12 Unchecked_Conversion — 13..4.continued) Strings — A.4.10 Tags — 3.8 RPC — E.2 Strings — B.4.5 Editing — F.3.3 Wide_Bounded_IO — A.4 Hash — A.2 Wide_Characters — A.7 Wide_Hash — A. so long as all parameters that could be passed by reference denote nonoverlapping objects.8 Wide_Wide_Unbounded — A.7 Wide_Hash — A.7.2 Machine_Code — 13.4.continued) Ada (.12.5 System — 13.3.7.4.3.4.4.1 Wide_Text_IO — A.4.3.4.11 Complex_IO — G.9 Fixed — A.11 Wide_Unbounded_IO — A.1.3 Text_Streams — A.8 Wide_Wide_Hash — A.2 Constants — A.8 Synchronous_Task_Control — D.3.11 Implementation Requirements 3/2 The implementation shall ensure that each language-defined subprogram is reentrant in the sense that concurrent calls on the same subprogram perform as specified.4.4.7. 3 — Ada Reference Manual Standard (.4.7 Wide_Maps — A.7 Wide_Unbounded — A.4.continued) Text_IO — A.7.7.5 Storage_Elements — 13..3.4..9 Wide_Bounded — A.1 Bounded_IO — A.4 Text_Streams — A.8 Wide_Wide_Constants — A.1 Wide_Wide_Text_IO — A.8 Wide_Wide_Hash — A.4.4 Fortran — B..12. The implementation may restrict children of language-defined library units (other than Standard).4 Wide_Wide_Bounded_IO — A.4.4.4.9 Task_Attributes — C.8 Wide_Wide_Hash — A.1 COBOL — B.5 Hash — A.9 Hash — A.ISO/IEC 8652:2007(E) Ed.7 Wide_Constants — A.1 Task_Termination — C.9 Unchecked_Deallocation — 13.2 C — B.1. Implementation Permissions 4 The implementation may restrict the replacement of language-defined compilation units.4.10.9 Generic_Dispatching_Constructor — 3.4.1 Storage_Pools — 13..7 Wide_Fixed — A.3 Editing — F.7 Wide_Wide_Bounded — A.

. -. (Left. -. Integer'Base. subtype Positive is Integer range 1 . (Left. 18 309 10 November 2006 The Package Standard A. (Left. subtype Natural is Integer range 0 . -. Right : Boolean'Base) return Boolean'Base.function "abs" (Right : Integer'Base) return Integer'Base. Boolean. Boolean. (Left. The operators that are predefined for the types declared in the package Standard are given in comments since they are implicitly declared. -. Integer'Last. -.corresponding universal type universal_integer are predefined.function "**" -- (Left : Integer'Base. Right Right Right Right Right Right : : : : : : Boolean'Base) Boolean'Base) Boolean'Base) Boolean'Base) Boolean'Base) Boolean'Base) return return return return return return Boolean. Boolean. Italics are used for pseudo-names of anonymous types (such as root_real) and for undefined information (such as implementation-defined). Boolean. Integer'Last.1 The Package Standard This clause outlines the specification of the package Standard containing all predefined identifiers in the language. (Left. Right Right Right Right Right Right : : : : : : Integer'Base) Integer'Base) Integer'Base) Integer'Base) Integer'Base) Integer'Base) return return return return return return Boolean. Right : Natural) return Integer'Base. Integer'Base. 16 17 -. (Left.function "and" (Left.function "-" (Right : Integer'Base) return Integer'Base. (Left. -.negation operator are as follows: -. (Left. ------function function function function function function "+" "-" "*" "/" "rem" "mod" (Left. (Left.. The corresponding package body is not specified by the language. 3 4 5 6 7/1 -.The predefined relational operators for this type are as follows: ------function function function function function function "=" "/=" "<" "<=" ">" ">=" (Left.function "+" (Right : Integer'Base) return Integer'Base. (Left. Boolean. Boolean.function "or" (Left.The integer type root_integer and the -. (Left. Integer'Base. -. Static Semantics 1 2 The library package Standard has the following declaration: package Standard is pragma Pure(Standard). Boolean. type Boolean is (False. Boolean. Integer'Base. Right : Boolean'Base) return Boolean'Base. -.The predefined operators for type Integer are as follows: ------function function function function function function "=" "/=" "<" "<=" ">" ">=" (Left. (Left.function "xor" (Left. Right : Boolean'Base) return Boolean'Base. (Left. 3 — Ada Reference Manual A. (Left.function "not" (Right : Boolean'Base) return Boolean'Base.ISO/IEC 8652:2007(E) Ed.The predefined logical operators and the predefined logical -.1 . 8 9/1 10/1 11/2 12 13 14 15 -. Boolean. Right Right Right Right Right Right : : : : : : Integer'Base) Integer'Base) Integer'Base) Integer'Base) Integer'Base) Integer'Base) return return return return return return Integer'Base. type Integer is range implementation-defined. (Left. True). Boolean. Integer'Base.

The specification of each operator for the type root_real. Boolean. The right operand of the exponentiation operator -.corresponding operator of the type Float.The specification of each operator for the type -. (Left. Right : universal_fixed) return universal_fixed. or for any additional predefined integer -. 3 — Ada Reference Manual 19 -.1/2 34.The only multiplying operators defined between -.The floating point type root_real and the -. Boolean. (Left.root_integer. (Left. type Float is digits implementation-defined.2/2 A. 33 34 34. ----function function function function "+" "-" "*" "/" (Left. Right : Integer'Base) return Float.corresponding universal type universal_real are predefined. Right Right Right Right Right Right : : : : : : Float) Float) Float) Float) Float) Float) return return return return return return Boolean.1 The Package Standard 10 November 2006 310 . Boolean. Float.The predefined operators for this type are as follows: ------function function function function function function "=" "/=" "<" "<=" ">" ">=" (Left. or for -. Right : universal_fixed) return universal_fixed. (Left.In addition. -. Float.any additional predefined floating point type.numeric types: function "*" (Left : root_integer. is obtained by replacing Integer by the name of the type -. function "/" (Left : universal_fixed. (Left.remains as subtype Natural. Right : root_integer) Right : root_integer) 28 29 30 31 32 -. the following operators are predefined for the root -.function "abs" (Right : Float) return Float.The type universal_access is predefined. (Left.function "+" (Right : Float) return Float. function "*" (Left : root_real. -. -. Boolean. -. -.function "-" (Right : Float) return Float. Right: universal_access) return Boolean. 25 26 27 -. -. -. return root_real. return root_real. function "/=" (Left.The type universal_fixed is predefined.Integer. -. Boolean. Right Right Right Right : : : : Float) Float) Float) Float) return return return return Float. 20/2 21 22 23 24 -.type. Right: universal_access) return Boolean. is obtained by -. function "/" (Left : root_real.ISO/IEC 8652:2007(E) Ed.in the specification of the corresponding operator of the type -.The following equality operators are predefined: function "=" (Left.replacing Float by the name of the type in the specification of the -. (Left. Float. Right : root_real) return root_real. (Left.fixed point types are function "*" (Left : universal_fixed.function "**" (Left : Float. -.

etx. '&'. 'ª'.. 'î'. 'J'. 'f'. gs. 'Þ'. 'Ù'. 'y'. 223 (16#DF#) 'ç'. 'ó'.. 'Y'. 'q'. dc1.'. 'å'. Hex_0000FFFE.. 'r'. '½'. --192 (16#C0#) . 'F'. ')'. '. 'j'. '$'. type Character is (nul.'. 'Ó'. '´'. 'K'.. 131 (16#83#) --132 (16#84#) . '4'. reserved_153. '1'. 'â'. 'ñ'. 'Ð'. 'l'. -. 71 (16#47#) 'O'. 135 (16#87#) --136 (16#88#) . reserved_129. --208 (16#D0#) . '-'. --240 (16#F0#) . --184 (16#B8#) . -. ssa. sci.. esa. rs. stx... '®'. 'ø'..'. 'æ'. 'Q'. --160 (16#A0#) . 'Æ'. '['. 'I'. 'ö'. dc2. '5'.. 255 (16#FF#) 36 '¥'. em. hts.set. 'n'. 'Í'. 'i'. 'A'.The declaration of type Character is based on the standard ISO 8859-1 character set. The first 256 positions have the same contents as type Character. '²'. 'ò'. 'a'.. '±'. '¤'.. --64 (16#40#) . 'E'. 'Ê'.The declaration of type Wide_Character is based on the standard ISO/IEC 10646:2003 BMP character -. 'Ã'. 'm'. 143 (16#8F#) reserved_128. 'h'. 'À'. nbh. 215 (16#D7#) 'ß'. '<'. --104 (16#68#) . cch. '. 183 (16#B7#) '¿'. 'õ'. htj. '>'. 'C'. --32 (16#20#) . 'Ú'. '8'. '³'. 'Ä'. ff. 'B'. 199 (16#C7#) 'Ï'. nel. osc.5. 36. pld. '*'.. 247 (16#F7#) 'ÿ'). sub. 'x'. 'Ý'.. 63 (16#3F#) 'G'. '¡'.. ss2. '¬'. 'v'. st. '»'.. bs. '2'. 'c'. dc4. 'Å'. '¼'. 'D'.. --200 (16#C8#) . 159 (16#9F#) '§'. pm. --96 (16#60#) .2. 'Á'. ' '. --120 (16#78#) . 'ú'. --0 (16#00#) . 151 (16#97#) --152 (16#98#) .2. --224 (16#E0#) . vts.1/2 311 10 November 2006 The Package Standard A..5. 103 (16#67#) 'o'. 'U'.any enumeration type.ISO/IEC 8652:2007(E) Ed. 111 (16#6F#) 'w'. -. spa. type Wide_Character is (nul. soh . ']'. See 3. '!'. --216 (16#D8#) ..There are no character literals corresponding to the positions for control characters. See 3. 'X'. 'b'. --176 (16#B0#) .. 'ì'. '^'. --232 (16#E8#) . '¨'. 7 (16#07#) --8 (16#08#) . sts. 3 — Ada Reference Manual -. ack. 'V'. 'M'. 'ë'. 'Û'. Hex_0000FFFF). '~'. cr. '¦'.. soh. ht. '¶'. 15 (16#0F#) --16 (16#10#) . 'e'. ' '. '0'. bph.. 'Ü'. can. 167 (16#A7#) '¯'. etb. '('. '#'. '«'.. '¸'. eot. 's'. --72 (16#48#) . 23 (16#17#) --24 (16#18#) . sos. 127 (16#7F#) --128 (16#80#) . '3'. 'ô'. '£'. 'Ô'. pu1. 31 (16#1F#) 35/2 '''.. 'È'. 'á'. si. '`'. nak. --56 (16#38#) . --40 (16#28#) .. '¢'. 'ê'.--248 (16#F8#) . fs. reserved_132. '¹'.. 39 (16#27#) '/'. 87 (16#57#) '_'. 191 (16#BF#) 'Ç'. 119 (16#77#) del.. 'µ'. 'ù'. apc. 'Ì'.. 155 (16#9B#) --156 (16#9C#) . 'é'.. 55 (16#37#) '?'.They are indicated in italics in this definition. 'ð'. bel. 'H'.1 .. -. enq.. 'ý'. '%'. '@'. 'Ò'. ss3.. pu2. --112 (16#70#) . 'z'. 'Z'. 'Ë'. 'è'. esc. 'L'. --144 (16#90#) . 79 (16#4F#) 'W'. 207 (16#CF#) '×'. '¾'. --168 (16#A8#) . 'Õ'. 'T'. --88 (16#58#) . 'Â'. 'Ø'. 'Ö'. 'P'. 'É'. '{'. '='. us. dle. '°'. --48 (16#30#) . mw. '+'.. 'þ'. 95 (16#5F#) 'g'. csi. 'k'. '-'. 'Ñ'. 'd'. dc3. 'R'. 'ä'. so.. ':'.The predefined operators for the type Character are the same as for -. 'í'. 'Î'. plu. --80 (16#50#) . '"'. 'N'. vt. 'ü'. 't'... '6'. '}'. '©'. dcs. '\'. 'u'. 'ã'. '|'. 47 (16#2F#) '7'. lf. 'º'.. 231 (16#E7#) 'ï'. 'S'. 'û'. 'p'. syn. ri. '9'. 'à'. epa. 239 (16#EF#) '÷'. 175 (16#AF#) '·'. '.

soh . end ASCII. 3 — Ada Reference Manual 36. for Wide_Wide_Character'Size use 32. Character. (Left. Boolean. (Left. String.2/2 43 44 45 46 47 48 49/2 Standard has no private part. Hex_7FFFFFFE.any fixed point type. 36.2. Similarly. exception.The predefined operators for this type correspond to those for String. 42.. A. In each of the types Character.Predefined string types: type String is array(Positive range <>) of Character.2/2 -. each occurrence of the character literal ' ' in this International Standard refers to the space character.The predefined operators for this type are as follows: ----------function function function function function function function function function function "=" "/=" "<" "<=" ">" ">=" "&" "&" "&" "&" (Left. -. pragma Pack(String). -. Unless indicated otherwise. 40 String. --Obsolescent. -. See 3.3/2 package ASCII is . Unless indicated otherwise. Boolean. Hex_7FFFFFFF). String. (Left.. type Duration is delta implementation-defined range implementation-defined. pragma Pack(Wide_String). see J. type Wide_Wide_String is array (Positive range <>) of Wide_Wide_Character. each occurrence of the character literal '–' in this International Standard refers to the hyphen character. the character literals for hyphen (position 45) and soft hyphen (position 173) correspond to different values. Not all of these types need have names. and Wide_Wide_Character. (Left. (Left. type Wide_Wide_Character is (nul. Boolean. Implementation Permissions 51 An implementation may provide additional predefined integer types and additional predefined floating point types.. The first 65536 positions have the -.same contents as type Wide_Character. Dynamic Semantics 50 Elaboration of the body of Standard has no effect.5 37 -. String.1/2 type Wide_String is array(Positive range <>) of Wide_Character.ISO/IEC 10646:2003 character set. pragma Pack (Wide_Wide_String).5. (Left: (Left: (Left: (Left: Right: Right: Right: Right: Right: Right: String) String) String) String) String) String) return return return return return return Boolean. Wide_Character. 38 39 -. the character literals for the space character (position 32) and the non-breaking space character (position 160) correspond to different values.The predefined operators for this type correspond to those for String. String. Boolean.ISO/IEC 8652:2007(E) Ed.The predefined exceptions: Constraint_Error: Program_Error : Storage_Error : Tasking_Error : end Standard. exception. Character. -.1 The Package Standard 10 November 2006 312 .. return return return return String. exception. Boolean.The declaration of type Wide_Wide_Character is based on the full -.The predefined operators for the type Duration are the same as for -. Right: Right: Right: Right: String) String) Character) Character) 41 42 42. exception.

1 2 Ada serves as the parent of most of the other language-defined library units. 52 53 54 55 56 A. it is illegal to compile a child of package Ada. the declarative region of the package Standard encloses every library unit and consequently the main subprogram. The name of a library unit cannot be a homograph of a name (such as Integer) that is already declared in Standard. If an implementation provides additional named predefined floating point types. its declaration is empty (except for the pragma Pure).Handling provides classification and conversion functions for Character data. 2 As explained in 8.2 The Package Ada Static Semantics The following language-defined library package exists: package Ada is pragma Pure(Ada). 3 — Ada Reference Manual Implementation Advice If an implementation provides additional named predefined integer types.1.ISO/IEC 8652:2007(E) Ed.3. then the names should end with “Integer” as in “Long_Integer”.4.Numeric_Error is defined in J. and moreover. that library unit itself. 1/2 313 10 November 2006 The Package Standard A.6. and some simple functions for dealing with Wide_Character and Wide_Wide_Character data. The package Characters. “The Compilation Process”.1 . 4 A. The child package Characters. Library_items are assumed to be ordered in such a way that there are no forward semantic dependences. However.Latin_1 declares a set of constants initialized to values of type Character. the declaration of every library unit is assumed to occur within this declarative region. as explained in 8. For example. although the enumeration type Boolean can be written showing the two enumeration literals False and True.Latin_1.Handling and Characters. 4 The exception Standard. NOTES 1 Certain aspects of the predefined entities cannot be completely described in the language itself. “Visibility”. Legality Rules 3 In the standard mode. 3 If all block_statements of a program are named. the short-circuit control forms cannot be expressed in the language.3 Character Handling This clause presents the packages related to character processing: an empty pure package Characters and child packages Characters. the only library units that are visible within a given compilation unit are the library units named by all with_clauses that apply to the given unit. then the names should end with “Float” as in “Long_Float”.1. within the declarative region of a given library unit. “Declarative Region” and 10. end Ada. then the name of each program unit can always be written as an expanded name starting with Standard (unless Standard is itself hidden).

ISO/IEC 8652:2007(E) Ed. end Ada. Wide_Characters. Boolean. function To_Upper (Item : in String) return String. classification. collating and sorting.) it should do so by providing child units of Wide_Characters. Boolean.1 The Packages Characters.Handling is pragma Pure(Handling).2 The Package Characters.Characters is pragma Pure(Characters). Wide_Characters.Wide_Characters.Characters.1 The Packages Characters. end Ada. function Is_Hexadecimal_Digit (Item : function Is_Alphanumeric (Item : function Is_Special (Item : --Conversion functions for Character and String function To_Lower (Item : in Character) return Character.Handling has the following declaration: with Ada.Characters.3.Handling Static Semantics 1 2/2 The library package Characters. Boolean. --Character classification functions Is_Control (Item : Is_Graphic (Item : Is_Letter (Item : Is_Lower (Item : Is_Upper (Item : Is_Basic (Item : Is_Digit (Item : Is_Decimal_Digit (Item : renames Is_Digit. function To_Basic (Item : in String) return String. Similarly if it chooses to provide implementation-defined operations on Wide_Wide_Character or Wide_Wide_String it should do so by providing child units of Wide_Wide_Characters. 5/2 6/2 The library package Wide_Wide_Characters has the following declaration: package Ada. 5 6 7 A.3. Boolean. A. function To_Lower (Item : in String) return String. and Wide_Wide_Characters Static Semantics 1 2 The library package Characters has the following declaration: package Ada.Conversions. 3 — Ada Reference Manual A. Implementation Advice 7/2 If an implementation chooses to provide implementation-defined operations on Wide_Character or Wide_String (such as case mapping. Boolean. in Character) return Boolean. and Wide_Wide_Characters 10 November 2006 314 . function function function function function function function function in in in in in in in in Character) Character) Character) Character) Character) Character) Character) Character) return return return return return return return return Boolean.Characters. function To_Upper (Item : in Character) return Character. in Character) return Boolean. etc.3. end Ada. Boolean 3 4 in Character) return Boolean.Wide_Wide_Characters. Boolean. package Ada. function To_Basic (Item : in Character) return Character. 3/2 4/2 The library package Wide_Characters has the following declaration: package Ada.Wide_Characters is pragma Pure(Wide_Characters).Wide_Wide_Characters is pragma Pure(Wide_Wide_Characters).

Is_Hexadecimal_Digit True if Item is a hexadecimal digit.'z'.'9'. True if Item is a letter..3. and returns a Boolean result. 3 — Ada Reference Manual --Classifications of and conversions between Character and ISO 646 subtype ISO_646 is Character range Character'Val(0) .Handling. True if Item is a basic letter.. or 248. Is_String. 'Ð'.246. -. Is_Alphanumeric True if Item is an alphanumeric character. Character'Val(127). True if Item is a decimal digit. 19 20 In the description below for each function that returns a Boolean result. 222..ISO/IEC 8652:2007(E) Ed. its formal Character 315 10 November 2006 The Package Characters. An upper-case letter is a character that is in the range 'A'. To_String.246 or 248. and the other that converts from String to String.255..255.'z'. 'þ'... A lower-case letter is a character that is in the range 'a'.. -..Handling A.. 'æ'. function Is_ISO_646 (Item : in Character) return Boolean. To_Character.214 or 216. function Is_ISO_646 (Item : in String) return Boolean. the effect is described in terms of the conditions under which the value True is returned. function To_ISO_646 (Item : in Character.'Z' and 'a'..31 or 127. True if Item is a graphic character.159. True if Item is an upper-case letter. or whose position is in one of the ranges 192. 21 22 23 24 25 26 27 28 29 Is_Decimal_Digit A renaming of Is_Digit.. 216. then the function returns False. or whose position is in one of the ranges 223. A basic letter is a character that is in one of the ranges 'A'. and To_Basic refers to two functions: one that converts from Character to Character. An alphanumeric character is a character that is either a letter or a decimal digit. Paragraphs 14 through 18 were deleted.'z'... 'Þ'. A special graphic character is a graphic character that is not alphanumeric. or that is one of the following: 'Æ'.. Substitute : in ISO_646 := ' ') return ISO_646.214. Is_Control Is_Graphic Is_Letter Is_Lower Is_Upper Is_Basic Is_Digit True if Item is a control character.Characters. The result of each Character-toCharacter function is described below. A decimal digit is a character in the range '0'..and To_Wide_String are obsolescent. A control character is a character whose position is in one of the ranges 0... 'ð'.14.'Z' or whose position is in one of the ranges 192.. 'f'. function To_ISO_646 (Item : in String. To_Upper. Item. A letter is a character that is in one of the ranges 'A'. To_Wide_Character. A hexadecimal digit is a character that is either a decimal digit or that is in one of the ranges 'A' .The functions Is_Character. Substitute : in ISO_646 := ' ') return String... in terms of the conversion applied to Item. 30 31 32 Each of the names To_Lower. 8 9 10 11 12 13/2 end Ada. or 'ß'. If these conditions are not met.2 33 .. 'F' or 'a' . see J. A graphic character is a character whose position is in one of the ranges 32.255.'Z' or 'a'. Each of the following classification functions has a formal Character parameter. True if Item is a lower-case letter.126 or 160. Is_Special True if Item is a special graphic character.

Item. 34 To_Lower To_Upper Returns the corresponding lower-case value for Item if Is_Upper(Item). Item. if Item is a letter but not a basic letter. The function whose formal parameter. Is_ISO_646 Is_ISO_646 To_ISO_646 The function whose first formal parameter.Handling 10 November 2006 316 . The result of each String-to-String conversion is obtained by applying to each element of the function's String parameter the corresponding Character-to-Character conversion. the result is the null String if the value of the formal parameter is the null String. Returns the corresponding upper-case value for Item if Is_Lower(Item) and Item has an upper-case form. Item. 35 36 To_Basic 37 The following set of functions test for membership in the ISO 646 character range. and returns Item otherwise. is of type String returns the String whose Range is 1. 38 39 40 41 To_ISO_646 The function whose first formal parameter. is of type Character returns True if Item is in the subtype ISO_646. Implementation Advice 49/2 This paragraph was deleted. returns Item otherwise.2 The Package Characters.Item'Length and each of whose elements is given by To_ISO_646 of the corresponding element in Item. the categories identified in the classification functions form a strict hierarchy: — Control characters — Graphic characters — Alphanumeric characters — Letters — Upper-case letters — Lower-case letters — Decimal digits — Special graphic characters 50 51 52 53 54 55 56 57 58 59 A.ISO/IEC 8652:2007(E) Ed. NOTES 5 A basic letter is a letter without a diacritical mark. and ISO_646 characters. Item. The lower bound of the result String is 1. is of type Character returns Item if Is_ISO_646(Item). The lower case letters 'ß' and 'ÿ' do not have upper case forms. and returns Item otherwise. is of type String returns True if Is_ISO_646(Item(I)) is True for each I in Item'Range. Paragraphs 42 through 48 were deleted. The function whose formal parameter. 3 — Ada Reference Manual parameter. Returns the letter corresponding to Item but with no diacritical mark. 6 Except for the hexadecimal digits. and returns the Substitute ISO_646 character otherwise.3. basic letters.. or convert between ISO 646 and Character.

Control characters: NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US -. Character'Val(21).Characters. constant Character := '. Character'Val(16). Character'Val(17). constant Character := '"'. Character'Val(8). Character'Val(18).3.ISO/IEC 8652:2007(E) Ed.Character'Val(43) -.Character'Val(38) -. Character'Val(3). constant Character := '+'.Character'Val(35) -. Character'Val(20).Character'Val(45) -.Character'Val(40) -. 2 3 4 5 6 7 8 317 10 November 2006 The Package Characters. constant Character := '.'.Character'Val(41) -. Character'Val(6). Character renames Hyphen. Character'Val(30).Character'Val(32) -. constant Character := ')'. 3 — Ada Reference Manual A. Character'Val(28).Latin_1 A.Character'Val(39) -. Character'Val(12). Character'Val(15). constant Character := '!'.Character'Val(47) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := Character'Val(0). Character'Val(27).Character'Val(33) -. constant Character := '('. Character'Val(31). Character'Val(7). Character'Val(19).Latin_1 has the following declaration: package Ada.'.3.Character'Val(46) -.Character'Val(37) -. constant Character := '-'.Latin_1 The package Characters. constant Character := '''. -. Character'Val(1).Latin_1 is pragma Pure(Latin_1). -. Character'Val(29).3 . constant Character := '%'. Character'Val(26).Latin_1 declares constants for characters in ISO 8859-1.Character'Val(42) -. constant Character := '#'. Character'Val(22).3 The Package Characters. Character'Val(9). constant Character := '/'. Character'Val(5).Character'Val(36) -. Character'Val(25). Character'Val(14). constant Character := '$'. Character'Val(13). Character'Val(23). constant Character := '*'.ISO 646 graphic characters: Space Exclamation Quotation Number_Sign Dollar_Sign Percent_Sign Ampersand Apostrophe Left_Parenthesis Right_Parenthesis Asterisk Plus_Sign Comma Hyphen Minus_Sign Full_Stop Solidus : : : : : : : : : : : : : : : : : constant Character := ' '. Character'Val(11). constant Character := '&'. Character'Val(4). Character'Val(24). Static Semantics 1 The library package Characters. Character'Val(10).Character'Val(44) -.Character'Val(34) -. Character'Val(2).

'_'.Character'Val(106) -. 'j'.Character'Val(105) -.Character'Val(63) -.3.Character'Val(124) '}'.Character'Val(104) -.Character'Val(111) 11 12 -.Decimal digits '0' though '9' are at positions 48 through 57 Colon Semicolon Less_Than_Sign Equals_Sign Greater_Than_Sign Question Commercial_At Left_Square_Bracket Reverse_Solidus Right_Square_Bracket Circumflex Low_Line Grave LC_A LC_B LC_C LC_D LC_E LC_F LC_G LC_H LC_I LC_J LC_K LC_L LC_M LC_N LC_O LC_P LC_Q LC_R LC_S LC_T LC_U LC_V LC_W LC_X LC_Y LC_Z Left_Curly_Bracket Vertical_Line Right_Curly_Bracket Tilde DEL -. -.Character'Val(101) -.Character'Val(119) 'x'. 'e'.Character'Val(96) -.ISO 6429 control characters: IS4 IS3 IS2 IS1 : : : : Character Character Character Character renames renames renames renames FS. 15 16 A.Character'Val(113) 'r'.Character'Val(117) 'v'. '>'.'. '`'. '. ']'. RS.Character'Val(120) 'y'.Character'Val(59) -. 'b'.Character'Val(114) 's'. -.Character'Val(61) -.Character'Val(97) -. -.Character'Val(122) '{'.Character'Val(121) 'z'.Character'Val(103) -. -.Character'Val(58) -.Character'Val(95) -. 'f'. 'g'.Character'Val(100) -. 'c'.Character'Val(115) 't'.Character'Val(64) -. 'h'. '='.Character'Val(98) -.Character'Val(118) 'w'. -. GS. 'm'.Character'Val(94) -. -. 'd'.Character'Val(107) -. -.Character'Val(93) -.Character'Val(108) -. 'l'.Character'Val(123) '|'. 'n'.Character'Val(102) -. -. '?'. '['. -.Latin_1 10 November 2006 318 . 'i'.Character'Val(109) -. -.Letters 'A' through 'Z' are at positions 65 through 90 13 14 'p'. -. '^'.Character'Val(62) -.Character'Val(126) Character'Val(127).Character'Val(91) -. 3 — Ada Reference Manual 9 10 -. '<'.Character'Val(60) -.Character'Val(99) -. US. -.3 The Package Characters. -. '\'. 'o'.ISO/IEC 8652:2007(E) Ed.Character'Val(112) 'q'.Character'Val(92) -. -.Character'Val(116) 'u'.Character'Val(110) -. : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := ':'. -.Character'Val(125) '~'. '@'. -. 'a'. 'k'.

--Character'Val(162) Pound_Sign : constant Character := '£'. Character'Val(135). Character'Val(148). Character'Val(154). Character'Val(159). Character'Val(142). Character'Val(143). Character'Val(130). Character'Val(157). --Character'Val(160) NBSP : Character renames No_Break_Space. Character'Val(141). --Character'Val(175) : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant constant Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := Character'Val(128). Character'Val(140).. Character'Val(149). Character'Val(151). Character'Val(138). --Character'Val(174) Macron : constant Character := '¯'. Character'Val(156). 175 (16#AF#): No_Break_Space : constant Character := ' '. Character'Val(147). --Character'Val(163) Currency_Sign : constant Character := '¤'. --Character'Val(168) Copyright_Sign : constant Character := '©'. --Character'Val(172) Soft_Hyphen : constant Character := '-'. Character'Val(158).3. --Character'Val(171) Not_Sign : constant Character := '¬'. Inverted_Exclamation : constant Character := '¡'. Character'Val(153).Other graphic characters: -. --Character'Val(170) Left_Angle_Quotation : constant Character := '«'. Character'Val(155). --Character'Val(173) Registered_Trade_Mark_Sign : constant Character := '®'. --Character'Val(165) Broken_Bar : constant Character := '¦'. Character'Val(134). --Character'Val(169) Feminine_Ordinal_Indicator : constant Character := 'ª'. Character'Val(139). Character'Val(136). 3 — Ada Reference Manual Reserved_128 Reserved_129 BPH NBH Reserved_132 NEL SSA ESA HTS HTJ VTS PLD PLU RI SS2 SS3 DCS PU1 PU2 STS CCH MW SPA EPA SOS Reserved_153 SCI CSI ST OSC PM APC -. Character'Val(152). Character'Val(137). --Character'Val(161) Cent_Sign : constant Character := '¢'. --Character'Val(167) Diaeresis : constant Character := '¨'. 17 18 19 20 21 319 10 November 2006 The Package Characters. Character'Val(146). Character'Val(132). --Character'Val(164) Yen_Sign : constant Character := '¥'. Character'Val(144). Character'Val(150). Character'Val(131). Character'Val(129).Latin_1 A.Character positions 160 (16#A0#) . Character'Val(145). Character'Val(133).ISO/IEC 8652:2007(E) Ed. --Character'Val(166) Section_Sign : constant Character := '§'.3 .

ISO/IEC 8652:2007(E) Ed. --Character'Val(183) Cedilla : constant Character := '¸'. --Character'Val(189) Fraction_Three_Quarters : constant Character := '¾'. 'Þ'. 3 — Ada Reference Manual 22 -. --Character'Val(188) Fraction_One_Half : constant Character := '½'. Middle_Dot : constant Character := '·'.Character positions 208 (16#D0#) .3. 'Ú'. Plus_Minus_Sign : constant Character := '±'.Latin_1 10 November 2006 320 . --Character'Val(177) Superscript_Two : constant Character := '²'. 'Ñ'. 'Ä'. 'ß'. 'Ð'.. 'Ü'. 'Ö'. 'È'. 'Á'. 'Ï'. --Character'Val(186) Right_Angle_Quotation : constant Character := '»'. --Character'Val(184) Superscript_One : constant Character := '¹'. 'Õ'. 'Ø'. --Character'Val(178) Superscript_Three : constant Character := '³'. 'Ë'. 'Ê'.3 The Package Characters. 'Ý'. 'Å'. 'Û'. 223 (16#DF#): UC_Icelandic_Eth : constant UC_N_Tilde : constant UC_O_Grave : constant UC_O_Acute : constant UC_O_Circumflex : constant UC_O_Tilde : constant UC_O_Diaeresis : constant Multiplication_Sign : constant UC_O_Oblique_Stroke : constant UC_U_Grave : constant UC_U_Acute : constant UC_U_Circumflex : constant UC_U_Diaeresis : constant UC_Y_Acute : constant UC_Icelandic_Thorn : constant LC_German_Sharp_S : constant Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := 'À'. '×'. 'Ô'.Character positions 176 (16#B0#) . --Character'Val(191) -. --Character'Val(182) Paragraph_Sign : Character renames Pilcrow_Sign. 'Ç'. 191 (16#BF#): Degree_Sign : constant Character := '°'. 'Ò'. 207 (16#CF#): UC_A_Grave : constant UC_A_Acute : constant UC_A_Circumflex : constant UC_A_Tilde : constant UC_A_Diaeresis : constant UC_A_Ring : constant UC_AE_Diphthong : constant UC_C_Cedilla : constant UC_E_Grave : constant UC_E_Acute : constant UC_E_Circumflex : constant UC_E_Diaeresis : constant UC_I_Grave : constant UC_I_Acute : constant UC_I_Circumflex : constant UC_I_Diaeresis : constant -. 'Í'. 'É'. --Character'Val(190) Inverted_Question : constant Character := '¿'. 'Ã'.. 'Î'. 'Â'. --Character'Val(176) Ring_Above : Character renames Degree_Sign. --Character'Val(179) Acute : constant Character := '´'. --Character'Val(192) --Character'Val(193) --Character'Val(194) --Character'Val(195) --Character'Val(196) --Character'Val(197) --Character'Val(198) --Character'Val(199) --Character'Val(200) --Character'Val(201) --Character'Val(202) --Character'Val(203) --Character'Val(204) --Character'Val(205) --Character'Val(206) --Character'Val(207) --Character'Val(208) --Character'Val(209) --Character'Val(210) --Character'Val(211) --Character'Val(212) --Character'Val(213) --Character'Val(214) --Character'Val(215) --Character'Val(216) --Character'Val(217) --Character'Val(218) --Character'Val(219) --Character'Val(220) --Character'Val(221) --Character'Val(222) --Character'Val(223) 23 24 A. 'Ó'. --Character'Val(185) Masculine_Ordinal_Indicator: constant Character := 'º'. 'Æ'. --Character'Val(187) Fraction_One_Quarter : constant Character := '¼'. 'Ì'. --Character'Val(180) Micro_Sign : constant Character := 'µ'. --Character'Val(181) Pilcrow_Sign : constant Character := '¶'. 'Ù'.Character positions 192 (16#C0#) ..

Characters. 'õ'.. 'ÿ'. 239 (16#EF#): LC_A_Grave : constant LC_A_Acute : constant LC_A_Circumflex : constant LC_A_Tilde : constant LC_A_Diaeresis : constant LC_A_Ring : constant LC_AE_Diphthong : constant LC_C_Cedilla : constant LC_E_Grave : constant LC_E_Acute : constant LC_E_Circumflex : constant LC_E_Diaeresis : constant LC_I_Grave : constant LC_I_Acute : constant LC_I_Circumflex : constant LC_I_Diaeresis : constant -.Latin_1.3. 'ç'. 'â'. --Character'Val(224) --Character'Val(225) --Character'Val(226) --Character'Val(227) --Character'Val(228) --Character'Val(229) --Character'Val(230) --Character'Val(231) --Character'Val(232) --Character'Val(233) --Character'Val(234) --Character'Val(235) --Character'Val(236) --Character'Val(237) --Character'Val(238) --Character'Val(239) 26 --Character'Val(240) --Character'Val(241) --Character'Val(242) --Character'Val(243) --Character'Val(244) --Character'Val(245) --Character'Val(246) --Character'Val(247) --Character'Val(248) --Character'Val(249) --Character'Val(250) --Character'Val(251) --Character'Val(252) --Character'Val(253) --Character'Val(254) --Character'Val(255) Implementation Permissions An implementation may provide additional packages as children of Ada. 'á'.. 'ñ'. 'î'. 'û'. 3 — Ada Reference Manual -. 'þ'. 'ã'. 'æ'.3 . 'ö'. 'ê'.ISO/IEC 8652:2007(E) Ed. 'ð'. 'ë'.Character positions 224 (16#E0#) . 'ó'. 'í'.Latin_1 A.Characters. 'ú'. 'ò'. 'ý'.Character positions 240 (16#F0#) . 25 Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character Character := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := := 'à'. 'ø'. 27 321 10 November 2006 The Package Characters. 'ï'. 255 (16#FF#): LC_Icelandic_Eth : constant LC_N_Tilde : constant LC_O_Grave : constant LC_O_Acute : constant LC_O_Circumflex : constant LC_O_Tilde : constant LC_O_Diaeresis : constant Division_Sign : constant LC_O_Oblique_Stroke : constant LC_U_Grave : constant LC_U_Acute : constant LC_U_Circumflex : constant LC_U_Diaeresis : constant LC_Y_Acute : constant LC_Icelandic_Thorn : constant LC_Y_Diaeresis : constant end Ada. '÷'. 'é'. 'ü'. 'ì'. 'è'. to declare names for the symbols of the local character set or other character sets. 'ä'. 'ù'. 'å'. 'ô'.

Boolean. Substitute : in Character := ' ') return Character. function To_Wide_Character (Item : in Wide_Wide_Character. function To_Wide_Wide_String (Item return Wide_Wide_String.Conversions 10 November 2006 322 . or convert between corresponding characters of Wide_Wide_Character.4 The Package Characters. Substitute : in Character := ' ') return String. Returns True if Wide_Wide_Character'Pos(Item) <= Wide_Character'Pos(Wide_Character'Last). A.4 The Package Characters. 4/2 function To_Wide_Character (Item : in function To_Wide_String (Item : in function To_Wide_Wide_Character (Item return Wide_Wide_Character. String) return Wide_String. function To_Wide_Wide_String (Item return Wide_Wide_String. 5/2 function To_Character (Item : in Wide_Character.3. function Is_Character (Item : in function Is_String (Item : in function Is_Character (Item : in function Is_String (Item : in function Is_Wide_Character (Item return Boolean.Conversions has the following declaration: package Ada.Conversions is pragma Pure(Conversions). function To_Wide_String (Item : in Wide_Wide_String. function Is_Wide_Character (Item : in Wide_Wide_Character) return Boolean. function To_String (Item : in Wide_String. Substitute : in Wide_Character := ' ') return Wide_Character. function Is_Character (Item : in Wide_Wide_Character) return Boolean. function Is_Character (Item : in Wide_Character) return Boolean. function To_Wide_Wide_Character (Item return Wide_Wide_Character.Conversions test Wide_Wide_Character or Wide_Character values for membership in Wide_Character or Character. 6/2 7/2 The functions in package Characters.ISO/IEC 8652:2007(E) Ed.Conversions Static Semantics 1/2 2/2 3/2 The library package Characters. 3 — Ada Reference Manual A. Returns True if Wide_Wide_Character'Pos(Item) <= Character'Pos(Character'Last). Wide_Character. 8/2 9/2 10/2 11/2 12/2 13/2 Returns True if Wide_Character'Pos(Item) <= Character'Pos(Character'Last). end Ada. Wide_Character) return Wide_String) return Wide_Wide_Character) return Wide_Wide_String) return : in Wide_Wide_Character) : in Wide_Wide_String) Character) return Wide_Character. Substitute : in Wide_Character := ' ') return Wide_String.Characters. Boolean.3. Substitute : in Character := ' ') return String. and Character. Substitute : in Character := ' ') return Character. function Is_Wide_String (Item return Boolean.Characters. function To_Character (Item : in Wide_Wide_Character. : in Character) : in String) : in Wide_Character) : in Wide_String) Boolean.Conversions. function To_String (Item : in Wide_Wide_String. Boolean.

function To_Wide_String (Item : in String) return Wide_String. and returns the Substitute Character otherwise. 32/2 Returns the Wide_String whose range is 1.Item'Length and each of whose elements is given by To_Wide_Character of the corresponding element in Item with the given Substitute Wide_Character.ISO/IEC 8652:2007(E) Ed.Item'Length and each of whose elements is given by To_Wide_Character of the corresponding element in Item. Substitute : in Character := ' ') return String. function To_String (Item : in Wide_Wide_String. function Is_Wide_String (Item : in Wide_Wide_String) return Boolean. 28/2 Returns the String whose range is 1. function To_Wide_Character (Item : in Character) return Wide_Character. 3 — Ada Reference Manual function Is_String (Item : in Wide_String) return Boolean. Substitute : in Character := ' ') return String. X such that Character'Pos(Item) = 25/2 function To_Wide_Wide_Character (Item : in Wide_Character) return Wide_Wide_Character.3. 19/2 20/2 21/2 22/2 Returns the Wide_Character X such that Character'Pos(Item) = Wide_Character'Pos (X). function To_Wide_Character (Item : in Wide_Wide_Character..4 . function To_Character (Item : in Wide_Wide_Character. Substitute : in Wide_Character := ' ') return Wide_Character.. 14/2 Returns True if Is_Character(Item(I)) is True for each I in Item'Range. function Is_String (Item : in Wide_Wide_String) return Boolean. 23/2 24/2 Returns the Wide_Wide_Character Wide_Wide_Character'Pos (X). X such that Wide_Character'Pos(Item) = 27/2 function To_String (Item : in Wide_String. and returns the Substitute Wide_Character otherwise. function To_Wide_Wide_Character (Item : in Character) return Wide_Wide_Character. Substitute : in Character := ' ') return Character. Substitute : in Character := ' ') return Character. Substitute : in Wide_Character := ' ') return Wide_String. Returns the Wide_Character corresponding to Item if Is_Wide_Character(Item)..Item'Length and each of whose elements is given by To_Character of the corresponding element in Item.Conversions A. Returns the Character corresponding to Item if Is_Character(Item). 15/2 16/2 17/2 18/2 Returns True if Is_Wide_Character(Item(I)) is True for each I in Item'Range. 33/2 323 10 November 2006 The Package Characters. 26/2 Returns the Wide_Wide_Character Wide_Wide_Character'Pos (X). 29/2 30/2 31/2 Returns the Wide_String whose range is 1. function To_Wide_String (Item : in Wide_Wide_String. function To_Character (Item : in Wide_Character.

Right.2 The Package Strings. 3 — Ada Reference Manual 34/2 function To_Wide_Wide_String (Item : in String) return Wide_Wide_String. Outside).Strings is pragma Pure(Strings). Center). overwriting. Static Semantics 2 3/2 4/2 The library package Strings. and transformation (replacing. (Inside. Pattern_Error. Error). -. bounded-length. and unbounded-length strings are supported.4. translation (via a character-tocharacter mapping). Right. Wide_Wide_Space : constant Wide_Wide_Character := ' '.Maps has the following declaration: package Ada.Representation for a set of character values: type Character_Set is private. for String. function To_Wide_Wide_String (Item : in Wide_String) return Wide_Wide_String. (Left. Index_Error. A. and other entities needed for character sets and character-to-character mappings. Null_Set : constant Character_Set. Static Semantics 2 3 4/2 The library package Strings has the following declaration: package Ada.. Backward). (Forward. operations. Fixed-length.Strings. type Alignment type Truncation type Membership type Direction type Trim_End end Ada.High 5 6 A.Maps defines the types. Translation_Error : exception. High : Character. which provide facilities for dealing with string data.Represents Character range Low. type Character_Range is record Low : Character. inserting. 5 6 A.4 String Handling 1/2 This clause presents the specifications of the package Strings and several child packages.Conversions 10 November 2006 324 . and Wide_Wide_String. Both). Length_Error.. pragma Preelaborable_Initialization(Character_Set). 35/2 Returns the Wide_Wide_String whose range is 1. -.4 The Package Characters.ISO/IEC 8652:2007(E) Ed. The string-handling subprograms include searches for pattern strings and for characters in program-specified sets.1 The Package Strings 1 The package Strings provides declarations common to the string handling packages.Maps 1 The package Strings.Strings. end record. is is is is is (Left. A. Wide_Space : constant Wide_Character := ' '.Maps is pragma Pure(Maps). Space : constant Character := ' '. Right.3.Item'Length and each of whose elements is given by To_Wide_Wide_Character of the corresponding element in Item.4. and deleting of substrings). Wide_String. (Left.

function To_Range (Map : in Character_Mapping) return Character_Sequence. An object Obj of type Character_Range represents the set of characters in the range Obj.Maps. (Left. Character_Set. Character_Set.Low . type Character_Mapping_Function is access function (From : in Character) return Character. : in Character_Set) return Character_Sequence. 3 — Ada Reference Manual type Character_Ranges is array (Positive range <>) of Character_Range. Set : in Character_Set) return Boolean. Right : in Character_Set) return Boolean. function To_Domain (Map : in Character_Mapping) return Character_Sequence. An object Obj of type Character_Ranges represents the union of the sets corresponding to Obj(I) for I in Obj'Range..Maps A. Character_Set. pragma Preelaborable_Initialization(Character_Mapping). 325 10 November 2006 The Package Strings. private . (Span : in Character_Range)return Character_Set. Character_Set.High. (Left. function To_Set function To_Set function "=" function function function function function "not" "and" "or" "xor" "-" (Ranges : in Character_Ranges)return Character_Set. (Left. -. function To_Set (Sequence function To_Sequence (Set : in Character_Sequence)return Character_Set. function To_Mapping (From.Representation for a character to character mapping: type Character_Mapping is private. Null_Set represents the set containing no characters. -.ISO/IEC 8652:2007(E) Ed. 7 8 9 10 11 12 function To_Ranges (Set (Right (Left. function To_Set (Ranges : in Character_Ranges) return Character_Set. function Is_Subset (Elements : in Character_Set. (Left.. return Character_Set.2 . Right : in Character_Set) return Boolean renames Is_Subset. To : in Character_Sequence) return Character_Mapping. function To_Set (Singleton : in Character) 13 14 15 16 17 18 19 20/2 -. Element : in Character) return Character. : in Character_Set) Right : in Character_Set) Right : in Character_Set) Right : in Character_Set) Right : in Character_Set) function Is_In (Element : in Character. Identity : constant Character_Mapping.. otherwise the returned value represents the set corresponding to Ranges.Alternative representation for a set of character values: subtype Character_Sequence is String. return return return return return Character_Set. 21 22 23 24 25 26 An object of type Character_Set represents a set of characters. function "<=" (Left : in Character_Set.Strings. : in Character_Set) return Character_Ranges. function Value (Map : in Character_Mapping. 27 28 29 30 31 32 If Ranges'Length=0 then Null_Set is returned. Obj. Set : in Character_Set) return Boolean.not specified by the language end Ada.4.

function "=" (Left. in increasing order of Low. A string S matches a pattern string P with respect to a given Character_Mapping if their lengths are the same and if each character in S matches its corresponding character in the pattern string P. subtype Character_Sequence is String. 40 41 42 Is_In returns True if Element is in Set. 37 38 39 The function "=" returns True if Left and Right represent identical sets. and "xor" returns a Character_Set value that represents the set obtained by applying the corresponding operation to the set(s) represented by the parameter(s) of the operator. "or". C) = P.4. is returned. Element : in Character) return Character. If Set = Null_Set then an empty Character_Ranges array is returned. Each of the To_Set functions returns a Character_Set value that represents the set portrayed by Sequence or Singleton. 43 44 45 Is_Subset returns True if Elements is a subset of Set. A character C matches a pattern character P with respect to a given Character_Mapping value Map if Value(Map. Singleton portrays the set comprising a single Character. Right) is equivalent to "and"(Left. Each of the logical operators "not". Set : in Character_Set). function To_Sequence (Set : in Character_Set) return Character_Sequence.Maps 10 November 2006 326 . and False otherwise. function Is_In (Element : in Character. 46 function To_Set (Singleton : in Character) 47 Sequence portrays the set of character values that it explicitly contains (ignoring duplicates).2 The Package Strings. function To_Ranges (Set : in Character_Set) return Character_Ranges. and False otherwise. The Character_Sequence subtype is used to portray a set of character values and also to identify the domain and range of a character mapping. "not"(Right)). otherwise the shortest array of contiguous ranges of Character values in Set. function To_Set (Sequence : in Character_Sequence) return Character_Set. "–"(Left. "and". 48 49 The function To_Sequence returns a Character_Sequence value containing each of the characters in the set represented by Set.ISO/IEC 8652:2007(E) Ed. Right : in Character_Set) return Boolean. function Value (Map : in Character_Mapping. 3 — Ada Reference Manual 33 34 35 36 function To_Set (Span : in Character_Range) return Character_Set. function Is_Subset (Elements : in Character_Set. 53 The function Value returns the Character value to which Element maps with respect to the mapping represented by Map. The returned value represents the set containing each character in Span. type Character_Mapping is private. Set : in Character_Set) return Boolean. return Boolean. and False otherwise. 50 51 52 An object of type Character_Mapping represents a Character-to-Character mapping. in ascending order with no duplicates. 54 A. return Character_Set.

or if some character is repeated in From.Fixed. Identity : constant Character_Mapping. 'C' to 'A'. 'D' to 'B'. and such that the characters in D are in ascending order. each has additional parameters to control the effect when the logical length of the result differs from the parameter's length. padding is stripped. then Translation_Error is propagated. "ZZAB") returns a Character_Mapping that maps 'A' and 'B' to 'Z'. Examples 64 65 66 To_Mapping("ABCD". If From'Length /= To'Length. 3 — Ada Reference Manual String handling subprograms that deal with character mappings have parameters whose type is Character_Mapping. allows the programmer to control these effects. such that if D = To_Domain(Map). Several of these subprograms are procedures that modify the contents of a String that is passed as an out or an in out parameter. which takes a String as an out parameter. Similar control is provided by the string transformation procedures. function To_Mapping (From.2 . that is. and D(I) maps to R(I) for each I in D'Range.4. which is said to match C with respect to mapping function F. and each other Character to itself. the lower bound of the returned value is 1.all(C). For each function that returns a String.ISO/IEC 8652:2007(E) Ed. The lower bound of D is 1.Maps A. and each other character maps to itself. 67 A. for values of type Standard. To_Mapping produces a Character_Mapping such that each element of From maps to the corresponding element of To. 59 60 61 To_Domain returns the shortest Character_Sequence value D such that each character not in D maps to itself. The Move procedure in Strings.Fixed provides string-handling subprograms for fixed-length strings. then R has the same bounds as D. The basic model embodied in the package is that a fixed-length string comprises significant characters and possibly padding (with space characters) on either or both ends. and when a longer string is copied to a shorter one. 55 56 57 58 Identity maps each Character to itself. function To_Range (Map : in Character_Mapping) return Character_Sequence. function To_Domain (Map : in Character_Mapping) return Character_Sequence. NOTES 7 Character_Mapping and Character_Mapping_Function are used both for character equivalence mappings in the search subprograms (such as for case insensitivity) and as transformational mappings in the Translate subprograms. 62 63/1 To_Range returns the Character_Sequence value R. 1 2 3 327 10 November 2006 The Package Strings. 8 To_Domain(Identity) and To_Range(Identity) each returns the null string.4.String. When a shorter string is copied to a longer string. To : in Character_Sequence) return Character_Mapping.3 Fixed-Length String Handling The language-defined package Strings. An object F of type Character_Mapping_Function maps a Character value C to the Character value F. padding is inserted.

Character_Mapping_Function) String.1/2 8. Direction := Forward. function Index (Source Pattern From Going Mapping return Natural.Fixed has the following declaration: with Ada. Membership := Inside. Direction := Forward. String. Positive. function Index (Source Set Test Going return Natural. Membership := Inside. -.1/2 11 in in in in 11. Maps.Strings. Alignment := Left. Positive. Direction := Forward) String. Maps. function Index_Non_Blank (Source : in String. function Index (Source Set From Test Going return Natural.3 Fixed-Length String Handling 10 November 2006 328 .Character_Mapping_Function) String.2/2 9 10 function Index (Source Pattern Going Mapping return Natural. 6 7 8 8.ISO/IEC 8652:2007(E) Ed. Positive. function Index (Source Pattern Going Mapping return Natural.Character_Set. : : : : : : : : : : : : : : in in in in in in in in in in in in in in String. Maps. Direction := Forward. : in String. package Ada. From : in Positive. : in String.Character_Set. Direction := Forward.Fixed is pragma Preelaborate(Fixed). Going : in Direction := Forward) return Natural. 3 — Ada Reference Manual Static Semantics 4 5 The library package Strings.1/2 function Index_Non_Blank (Source : in String. String.Character_Mapping := Maps. Truncation := Error. : : : : : : : : : : : : : in in in in in in in in in 10.Search subprograms function Index (Source Pattern From Going Mapping return Natural.Identity) String.Identity) 12 13 A. String.Maps.4. : in Maps.Strings.Character_Mapping := Maps. String.Identity) String. String. Going : in Direction := Forward) return Natural. Direction := Forward) : : : : : in out in in in String. function Count (Source Pattern Mapping return Natural. Maps.Character_Mapping := Maps."Copy" procedure for strings of possibly different lengths procedure Move (Source Target Drop Justify Pad -. Maps. Maps. Character := Space).

String. : in Maps. New_Item : in String) return String. String. : in String. 3 — Ada Reference Manual function Count (Source Pattern Mapping return Natural.ISO/IEC 8652:2007(E) Ed. procedure Translate (Source : in out String. 19 20 21 22 23 24 function Insert (Source : in String. New_Item : in String) return String. in Membership. Position : in Positive. Truncation := Error). Positive. procedure Insert (Source Before New_Item Drop : : : : in in in in out String. Truncation := Error. Through : in Natural) return String.String translation subprograms 16 17 18 function Translate (Source : in String. String. Character := Space). Positive. Truncation := Right). Positive. : in Maps. procedure Overwrite (Source Position New_Item Drop : : : : in in in in out String. Before : in Positive.Character_Mapping) return String. procedure Translate (Source : in out String. Natural.Character_Mapping).Character_Mapping_Function) : in String. Mapping : in Maps.4. 27 28 function Delete (Source : in String. -. 25 26 function Overwrite (Source : in String. String) out String.Character_Mapping_Function) return String.Character_Set) : : : : : in String. out Natural). in Maps. Mapping : in Maps. 14 15 procedure Find_Token (Source Set Test First Last -. function Count (Source Set return Natural. : in String.Character_Mapping_Function).3 . 29 329 10 November 2006 Fixed-Length String Handling A. Positive. Alignment := Left. From : in Positive. function Translate (Source : in String. out Positive. Natural. procedure Replace_Slice (Source Low High By Drop Justify Pad : : : : : : : : : : : in in in in in in in in in in in String. Mapping : in Maps.Character_Set. Mapping : in Maps.String transformation subprograms function Replace_Slice (Source Low High By return String.

Character_Set. Natural. 31 --String selector subprograms function Trim (Source : in String. procedure Tail (Source Count Justify Pad --String constructor functions function "*" (Left : in Natural. • If Justify=Right.Character_Set. Right : in String) return String. end Ada. Character := Space). procedure Move (Source Target Drop Justify Pad : : : : : in out in in in String. procedure Trim (Source Side Justify Pad : : : : in in in in out String. Truncation := Error. procedure Head (Source Count Justify Pad : : : : in in in in out String. then Source is copied into the first Source'Length characters of Target. 32 33 function Trim (Source : in String. Natural. Right : in Maps. 3 — Ada Reference Manual 30 procedure Delete (Source From Through Justify Pad : : : : : in in in in in out String. Character := Space). 36 37 function Tail (Source : in String. String. If Source has the same length as Target. Maps. Pad : in Character := Space) return String. Character := Space). Alignment := Left.4. 46 47 A. function "*" (Left : in Natural. Trim_End. then the effect is to assign Source to Target. Alignment := Left. If Source is shorter than Target then: • If Justify=Left. Left : in Maps. Character := Space). Alignment := Left. then Source is copied into the last Source'Length characters of Target.Fixed. 45 The Move procedure copies characters from Source to Target. Pad : in Character := Space) return String. Alignment := Strings. Alignment := Left. Count : in Natural.Character_Set) return String. procedure Trim (Source Left Right Justify Pad : : : : : in in in in in out String.3 Fixed-Length String Handling 10 November 2006 330 . Positive.Strings. Character := Space).Character_Set. Count : in Natural. Natural.ISO/IEC 8652:2007(E) Ed. 34 35 function Head (Source : in String.Left. Alignment := Left. : : : : in in in in out String. 38 39 40 41 42 43 44 The effects of the above subprograms are as follows. Side : in Trim_End) return String. Maps. Right : in Character) return String. Character := Space).

Positive. then the rightmost Target'Length characters of Source are copied into Target.Character_Mapping_Function) 54 • 55 • 56 56. and if each of the leftmost Source'Length-Target'Length characters in Source is Pad.2/2 331 10 November 2006 Fixed-Length String Handling A. and if each of the rightmost Source'Length-Target'Length characters in Source is Pad. If Going = Forward. If Going = Backward. then 0 is returned. the parameter Going indicates the direction of the lookup. Maps.Identity) String. Length_Error is propagated. If Justify=Right.4. • Pad is copied to each Target character not otherwise assigned. Maps. Direction := Forward. then the rightmost Target'Length characters of Source are copied to Target. • If Drop=Right. then the effect is based on Drop. Each Index function searches.ISO/IEC 8652:2007(E) Ed. if the difference in length between Target and Source is odd. with length Pattern'Length. Otherwise. that matches Pattern with respect to Mapp