Recent from talks
Nothing was collected or created yet.
Ada (programming language)
View on Wikipedia| Ada | |
|---|---|
| Paradigm | Multi-paradigm: structured, imperative, object-oriented, aspect-oriented,[1] concurrent, array, distributed, generic, procedural, meta |
| Family | Pascal |
| Designed by |
|
| First appeared | February 1980 |
| Stable release | Ada 2022
/ May 2023 |
| Typing discipline | static, strong, safe, nominal |
| OS | Multi- or cross-platform |
| Filename extensions | .adb, .ads |
| Website | adaic.org |
| Major implementations | |
| AdaCore GNAT,[2] Green Hills Software Optimising Ada 95 compiler, PTC ApexAda and ObjectAda,[3] MapuSoft Ada-C/C++ changer,[4] formerly known as "AdaMagic with C Intermediate",[5] DDC-I Score | |
| Dialects | |
| SPARK, Ravenscar profile | |
| Influenced by | |
| ALGOL 68, Pascal, Simula 67,[6] C++ (Ada 95), Smalltalk (Ada 95), Modula-2 (Ada 95) Java (Ada 2005), Eiffel (Ada 2012) | |
| Influenced | |
| C++, Chapel,[7] Drago,[8] D, Eiffel, Griffin,[9] Java, Nim, ParaSail, PL/SQL, PL/pgSQL, Python, Ruby, SPARforte,[10] Sparkel, SQL/PSM, VHDL | |
| |

Ada is a structured, statically typed, imperative, and object-oriented high-level programming language, inspired by Pascal and other languages. It has built-in language support for design by contract (DbC), extremely strong typing, explicit concurrency, tasks, synchronous message passing, protected objects, and non-determinism. Ada improves code safety and maintainability by using the compiler to find errors in favor of runtime errors. Ada is an international technical standard, jointly defined by the International Organization for Standardization (ISO), and the International Electrotechnical Commission (IEC). As of May 2023[update], the standard, ISO/IEC 8652:2023, is called Ada 2022 informally.[11]
Ada was originally designed by a team led by French computer scientist Jean Ichbiah of Honeywell under contract to the United States Department of Defense (DoD) from 1977 to 1983 to supersede over 450 programming languages then used by the DoD.[12] Ada was named after Ada Lovelace (1815–1852), who has been credited as the first computer programmer.[13]
Features
[edit]Ada was originally designed for embedded and real-time systems. The Ada 95 revision, designed by S. Tucker Taft of Intermetrics between 1992 and 1995, improved support for systems, numerical, financial, and object-oriented programming (OOP).
Features of Ada include: strong typing, modular programming mechanisms (packages), run-time checking, parallel processing (tasks, synchronous message passing, protected objects, and nondeterministic select statements), exception handling, and generics. Ada 95 added support for object-oriented programming, including dynamic dispatch.
The syntax of Ada minimizes choices of ways to perform basic operations, and prefers English keywords (such as or else and and then) to symbols (such as || and &&). Ada uses the basic arithmetical operators +, -, *, and /, but avoids using other symbols. Code blocks are delimited by words such as 'declare', 'begin', and 'end', where the 'end' (in most cases) is followed by the keyword of the block that it closes (e.g., if ... end if, loop ... end loop). In the case of conditional blocks this avoids a dangling else that could pair with the wrong nested 'if'-expression in other languages such as C or Java.
Ada is designed for developing very large software systems. Ada packages can be compiled separately. Ada package specifications (the package interface) can also be compiled separately without the implementation to check for consistency. This makes it possible to detect problems early during the design phase, before implementation starts.
A large number of compile-time checks are supported to help avoid bugs that would not be detectable until run-time in some other languages or would require explicit checks to be added to the source code. For example, the syntax requires explicitly named closing of blocks to prevent errors due to mismatched end tokens. The adherence to strong typing allows detecting many common software errors (wrong parameters, range violations, invalid references, mismatched types, etc.) either during compile-time, or otherwise during run-time. As concurrency is part of the language specification, the compiler can in some cases detect potential deadlocks.[14] Compilers also commonly check for misspelled identifiers, visibility of packages, redundant declarations, etc. and can provide warnings and useful suggestions on how to fix the error.
Ada also supports run-time checks to protect against access to unallocated memory, buffer overflow errors, range violations, off-by-one errors, array access errors, and other detectable bugs. These checks can be disabled in the interest of runtime efficiency, but can often be compiled efficiently. It also includes facilities to help program verification. For these reasons, Ada is sometimes used in critical systems, where any anomaly might lead to very serious consequences, e.g., accidental death, injury or severe financial loss. Examples of systems where Ada is used include avionics, air traffic control, railways, banking, military and space technology.[15][16]
Ada's dynamic memory management is high-level and type-safe. Ada has no generic or untyped pointers; nor does it implicitly declare any pointer type. Instead, all dynamic memory allocation and deallocation must occur via explicitly declared access types. Each access type has an associated storage pool that handles the low-level details of memory management; the programmer can either use the default storage pool or define new ones (this is particularly relevant for Non-Uniform Memory Access). It is even possible to declare several different access types that all designate the same type but use different storage pools. Also, the language provides for accessibility checks, both at compile time and at run time, that ensures that an access value cannot outlive the type of the object it points to.[17]
Though the semantics of the language allow automatic garbage collection of inaccessible objects, most implementations do not support it by default, as it would cause unpredictable behaviour in real-time systems. Ada supports a limited form of region-based memory management, and in Ada, destroying a storage pool also destroys all the objects in the pool.
A double-dash (--), resembling an em dash, denotes comment text. Comments stop at end of line; there is intentionally no way to make a comment span multiple lines, to prevent unclosed comments from accidentally voiding whole sections of source code. Disabling a whole block of code therefore requires the prefixing of each line (or column) individually with --. While this clearly denotes disabled code by creating a column of repeated '--' down the page, it also renders the experimental dis/re-enablement of large blocks a more drawn-out process in editors without block commenting support.
The semicolon (;) is a statement terminator, and the null or no-operation statement is null;. A single ; without a statement to terminate is not allowed.
Unlike most ISO standards, the Ada language definition (known as the Ada Reference Manual or ARM, or sometimes the Language Reference Manual or LRM) is free content. Thus, it is a common reference for Ada programmers, not only programmers implementing Ada compilers. Apart from the reference manual, there is also an extensive rationale document which explains the language design and the use of various language constructs. This document is also widely used by programmers. When the language was revised, a new rationale document was written.
One notable free software tool that is used by many Ada programmers to aid them in writing Ada source code is the GNAT Programming Studio, and GNAT which is part of the GNU Compiler Collection.
Alire is a package and toolchain management tool for Ada.[18]
History
[edit]In the 1970s the US Department of Defense (DoD) became concerned by the number of different programming languages being used for its embedded computer system projects, many of which were obsolete or hardware-dependent, and none of which supported safe modular programming. In 1975, a working group, the High Order Language Working Group (HOLWG), was formed with the intent to reduce this number by finding or creating a programming language generally suitable for the department's and the UK Ministry of Defence's requirements. After many iterations beginning with an original straw-man proposal[19] the eventual programming language was named Ada. The total number of high-level programming languages in use for such projects fell from over 450 in 1983 to 37 by 1996.
HOLWG crafted the Steelman language requirements , a series of documents stating the requirements they felt a programming language should satisfy. Many existing languages were formally reviewed, but the team concluded in 1977 that no existing language met the specifications. The requirements were created by the United States Department of Defense in The Department of Defense Common High Order Language program in 1978. The predecessors of this document were called, in order, "Strawman", "Woodenman", "Tinman" and "Ironman".[20] The requirements focused on the needs of embedded computer applications, and emphasised reliability, maintainability, and efficiency. Notably, they included exception handling facilities, run-time checking, and parallel computing.
It was concluded that no existing language met these criteria to a sufficient extent,[21] so a contest was called to create a language that would be closer to fulfilling them. The design that won this contest became the Ada programming language. The resulting language followed the Steelman requirements closely, though not exactly.

Requests for proposals for a new programming language were issued and four contractors were hired to develop their proposals under the names of Red (Intermetrics led by Benjamin Brosgol), Green (Honeywell, led by Jean Ichbiah), Blue (SofTech, led by John Goodenough)[22] and Yellow (SRI International, led by Jay Spitzen). In April 1978, after public scrutiny, the Red and Green proposals passed to the next phase. In May 1979, the Green proposal, designed by Jean Ichbiah at Honeywell, was chosen and given the name Ada—after Augusta Ada King, Countess of Lovelace, usually known as Ada Lovelace. This proposal was influenced by the language LIS that Ichbiah and his group had developed in the 1970s. The preliminary Ada reference manual was published in ACM SIGPLAN Notices in June 1979. The Military Standard reference manual was approved on December 10, 1980 (Ada Lovelace's birthday), and given the number MIL-STD-1815 in honor of Ada Lovelace's birth year. In 1981, Tony Hoare took advantage of his Turing Award speech to criticize Ada for being overly complex and hence unreliable,[23] but subsequently seemed to recant in the foreword he wrote for an Ada textbook.[24]
Ada attracted much attention from the programming community as a whole during its early days. Its backers and others predicted that it might become a dominant language for general purpose programming and not only defense-related work.[25] Ichbiah publicly stated that within ten years, only two programming languages would remain: Ada and Lisp.[26] Early Ada compilers struggled to implement the large, complex language, and both compile-time and run-time performance tended to be slow and tools primitive.[25] Compiler vendors expended most of their efforts in passing the massive, language-conformance-testing, government-required Ada Compiler Validation Capability (ACVC) validation suite that was required in another novel feature of the Ada language effort.[26]
The first validated Ada implementation was the NYU Ada/Ed translator,[27] certified on April 11, 1983. NYU Ada/Ed is implemented in the high-level set language SETL.[28] Several commercial companies began offering Ada compilers and associated development tools, including Alsys, TeleSoft, DDC-I, Advanced Computer Techniques, Tartan Laboratories, Irvine Compiler, TLD Systems, and Verdix.[29] Computer manufacturers who had a significant business in the defense, aerospace, or related industries, also offered Ada compilers and tools on their platforms; these included Concurrent Computer Corporation, Cray Research, Inc., Digital Equipment Corporation, Harris Computer Systems, and Siemens Nixdorf Informationssysteme AG.[29]
In 1991, the US Department of Defense began to require the use of Ada (the Ada mandate) for all software,[30] though exceptions to this rule were often granted.[25] The Department of Defense Ada mandate was effectively removed in 1997, as the DoD began to embrace commercial off-the-shelf (COTS) technology.[25] Similar requirements existed in other NATO countries: Ada was required for NATO systems involving command and control and other functions, and Ada was the mandated or preferred language for defense-related applications in countries such as Sweden, Germany, and Canada.[31]
By the late 1980s and early 1990s, Ada compilers had improved in performance, but there were still barriers to fully exploiting Ada's abilities, including a tasking model that was different from what most real-time programmers were used to.[26]
Because of Ada's safety-critical support features, it is now used not only for military applications, but also in commercial projects where a software bug can have severe consequences, e.g., avionics and air traffic control, commercial rockets such as the Ariane 4 and 5, satellites and other space systems, railway transport and banking.[16] For example, the Primary Flight Control System, the fly-by-wire system software in the Boeing 777, was written in Ada, as were the fly-by-wire systems for the aerodynamically unstable Eurofighter Typhoon,[32] Saab Gripen,[33] Lockheed Martin F-22 Raptor and the DFCS replacement flight control system for the Grumman F-14 Tomcat. The Canadian Automated Air Traffic System was written in 1 million lines of Ada (SLOC count). It featured advanced distributed processing, a distributed Ada database, and object-oriented design. Ada is also used in other air traffic systems, e.g., the UK's next-generation Interim Future Area Control Tools Support (iFACTS) air traffic control system is designed and implemented using SPARK Ada.[34] It is also used in the French TVM in-cab signalling system on the TGV high-speed rail system, and the metro suburban trains in Paris, London, Hong Kong and New York City.[16][35]
The Ada 95 revision of the language went beyond the Steelman requirements, targeting general-purpose systems in addition to embedded ones, and adding features supporting object-oriented programming.[36]
Standardization
[edit]| Year | Informal name | Official Standard |
|---|---|---|
| 1980 | Ada | ANSI MIL-STD 1815 |
| 1983 | Ada 83/87 | ANSI MIL-STD 1815A ISO/IEC 8652:1987 |
| 1995 | Ada 95 | ISO/IEC 8652:1995 |
| 2007 | Ada 2005 | ISO/IEC 8652:1995/Amd 1:2007 |
| 2012 | Ada 2012 | ISO/IEC 8652:2012 |
| 2023 | Ada 2022 | ISO/IEC 8652:2023 |
Preliminary Ada can be found in ACM Sigplan Notices Vol 14, No 6, June 1979[37]
Ada was first published in 1980 as an ANSI standard ANSI/MIL-STD 1815. As this very first version held many errors and inconsistencies,[a] the revised edition was published in 1983 as ANSI/MIL-STD 1815A. Without any further changes, it became an ISO standard in 1987.[39] This version of the language is commonly known as Ada 83, from the date of its adoption by ANSI, but is sometimes referred to also as Ada 87, from the date of its adoption by ISO.[40] There is also a French translation; DIN translated it into German as DIN 66268 in 1988.
Ada 95, the joint ISO/IEC/ANSI standard ISO/IEC 8652:1995[41][42] was published in February 1995, making it the first ISO standard object-oriented programming language. To help with the standard revision and future acceptance, the US Air Force funded the development of the GNAT Compiler. Presently, the GNAT Compiler is part of the GNU Compiler Collection.
Work has continued on improving and updating the technical content of the Ada language. A Technical Corrigendum to Ada 95 was published in October 2001,[43][44] and a major Amendment, ISO/IEC 8652:1995/Amd 1:2007 [45][46] was published on March 9, 2007, commonly known as Ada 2005 because work on the new standard was finished that year.
At the Ada-Europe 2012 conference in Stockholm, the Ada Resource Association (ARA) and Ada-Europe announced the completion of the design of the latest version of the Ada language and the submission of the reference manual to the ISO/IEC JTC 1/SC 22/WG 9 of the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC) for approval. ISO/IEC 8652:2012[47] (see Ada 2012 RM) was published in December 2012, known as Ada 2012. A technical corrigendum, ISO/IEC 8652:2012/COR 1:2016, was published [48] (see RM 2012 with TC 1).
On May 2, 2023, the Ada community saw the formal approval of publication of the Ada 2022 edition of the programming language standard.[11]
Despite the names Ada 83, 95 etc., legally there is only one Ada standard, the last ISO/IEC standard: with the acceptance of a new standard version, the previous one becomes withdrawn. The other names are just informal ones referencing a certain edition.
Other related standards include ISO/IEC 8651-3:1988 Information processing systems—Computer graphics—Graphical Kernel System (GKS) language bindings—Part 3: Ada.
Language constructs
[edit]Ada is an ALGOL-like programming language featuring control structures with reserved words such as if, then, else, while, for, and so on. However, Ada also has many data structuring facilities and other abstractions which were not included in the original ALGOL 60, such as type definitions, records, pointers, enumerations. Such constructs were in part inherited from or inspired by Pascal.
"Hello, world!" in Ada
[edit]A common example of a language's syntax is the "Hello, World!" program: (hello.adb)
with Ada.Text_IO;
procedure Hello is
begin
Ada.Text_IO.Put_Line ("Hello, world!");
end Hello;
This program can be compiled by using the freely available open source compiler GNAT, by executing
gnatmake hello.adb
Data types
[edit]Ada's type system is not based on a set of predefined primitive types but allows users to declare their own types. This declaration in turn is not based on the internal representation of the type but on describing the goal which should be achieved. This allows the compiler to determine a suitable memory size for the type, and to check for violations of the type definition at compile time and run time (i.e., range violations, buffer overruns, type consistency, etc.). Ada supports numerical types defined by a range, modulo types, aggregate types (records and arrays), and enumeration types. Access types define a reference to an instance of a specified type; untyped pointers are not permitted. Special types provided by the language are task types and protected types.
For example, a date might be represented as:
type Day_type is range 1 .. 31;
type Month_type is range 1 .. 12;
type Year_type is range 1800 .. 2100;
type Hours is mod 24;
type Weekday is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
type Date is
record
Day : Day_type;
Month : Month_type;
Year : Year_type;
end record;
Important to note: Day_type, Month_type, Year_type, Hours are incompatible types, meaning that for instance the following expression is illegal:
Today: Day_type := 4;
Current_Month: Month_type := 10;
... Today + Current_Month ... -- illegal
The predefined plus-operator can only add values of the same type, so the expression is illegal.
Types can be refined by declaring subtypes:
subtype Working_Hours is Hours range 0 .. 12; -- at most 12 Hours to work a day
subtype Working_Day is Weekday range Monday .. Friday; -- Days to work
Work_Load: constant array(Working_Day) of Working_Hours -- implicit type declaration
:= (Friday => 6, Monday => 4, others => 10); -- lookup table for working hours with initialization
Types can have modifiers such as limited, abstract, private etc. Private types do not show their inner structure; objects of limited types cannot be copied.[49] Ada 95 adds further features for object-oriented extension of types.
Control structures
[edit]Ada is a structured programming language, meaning that the flow of control is structured into standard statements. All standard constructs and deep-level early exit are supported, so the use of the also supported "go to" commands is seldom needed.
-- while a is not equal to b, loop.
while a /= b loop
Ada.Text_IO.Put_Line ("Waiting");
end loop;
if a > b then
Ada.Text_IO.Put_Line ("Condition met");
else
Ada.Text_IO.Put_Line ("Condition not met");
end if;
for i in 1 .. 10 loop
Ada.Text_IO.Put ("Iteration: ");
Ada.Text_IO.Put (i);
Ada.Text_IO.Put_Line;
end loop;
loop
a := a + 1;
exit when a = 10;
end loop;
case i is
when 0 => Ada.Text_IO.Put ("zero");
when 1 => Ada.Text_IO.Put ("one");
when 2 => Ada.Text_IO.Put ("two");
-- case statements have to cover all possible cases:
when others => Ada.Text_IO.Put ("none of the above");
end case;
for aWeekday in Weekday'Range loop -- loop over an enumeration
Put_Line ( Weekday'Image(aWeekday) ); -- output string representation of an enumeration
if aWeekday in Working_Day then -- check of a subtype of an enumeration
Put_Line ( " to work for " &
Working_Hours'Image (Work_Load(aWeekday)) ); -- access into a lookup table
end if;
end loop;
Packages, procedures and functions
[edit]Among the parts of an Ada program are packages, procedures and functions.
Functions differ from procedures in that they must return a value. Function calls cannot be used "as a statement", and their result must be assigned to a variable. However, since Ada 2012, functions are not required to be pure and may mutate their suitably declared parameters or the global state.[50]
Example: Package specification (example.ads)
package Example is
type Number is range 1 .. 11;
procedure Print_and_Increment (j: in out Number);
end Example;
Package body (example.adb)
with Ada.Text_IO;
package body Example is
i : Number := Number'First;
procedure Print_and_Increment (j: in out Number) is
function Next (k: in Number) return Number is
begin
return k + 1;
end Next;
begin
Ada.Text_IO.Put_Line ( "The total is: " & Number'Image(j) );
j := Next (j);
end Print_and_Increment;
-- package initialization executed when the package is elaborated
begin
while i < Number'Last loop
Print_and_Increment (i);
end loop;
end Example;
This program can be compiled, e.g., by using the freely available open-source compiler GNAT, by executing
gnatmake -z example.adb
Packages, procedures and functions can nest to any depth, and each can also be the logical outermost block.
Each package, procedure or function can have its own declarations of constants, types, variables, and other procedures, functions and packages, which can be declared in any order.
Pragmas
[edit]A pragma is a compiler directive that conveys information to the compiler to allow specific manipulating of compiled output.[51] Certain pragmas are built into the language,[52] while others are implementation-specific.
Examples of common usage of compiler pragmas would be to disable certain features, such as run-time type checking or array subscript boundary checking, or to instruct the compiler to insert object code instead of a function call (as C/C++ does with inline functions).
Generics
[edit]Ada has had generics since it was first designed in 1977–1980. The standard library uses generics to provide many services. Ada 2005 adds a comprehensive generic container library to the standard library, which was inspired by C++'s Standard Template Library.[53][54]
A generic unit is a package or a subprogram that takes one or more generic formal parameters.[55]
A generic formal parameter is a value, a variable, a constant, a type, a subprogram, or even an instance of another, designated, generic unit. For generic formal types, the syntax distinguishes between discrete, floating-point, fixed-point, access (pointer) types, etc. Some formal parameters can have default values.[56]
To instantiate a generic unit, the programmer passes actual parameters for each formal. The generic instance then behaves just like any other unit. It is possible to instantiate generic units at run-time, for example inside a loop.[56]See also
[edit]- Ada compilers
- ALGOL 68 – Programming language
- APSE – Programming environment specification
- List of Ada software and tools
- Pascal – Programming language
- Ravenscar profile – Feature of the Ada programming language
- Smalltalk – Object-oriented programming language
- SPARK – Programming language
- VHDL – Hardware description language
- Ada Programming on Wikibooks
Notes
[edit]- ^ "Ada2012 Rationale" (PDF). adacore.com. Archived (PDF) from the original on 18 April 2016. Retrieved 5 May 2018.
- ^ "Commercial software solutions for Ada, C and C++". AdaCore. Retrieved Apr 4, 2023.
- ^ "PTC ObjectAda". PTC.com. Retrieved 2014-01-27.
- ^ "MapuSoft Ada-C/C++ changer". 16 April 2019.
- ^ "Ada 95 Certified Processors List – Details". ada-auth.org. Retrieved Apr 4, 2023.
- ^ Ada Rationale, 1986, pp. 23, 70, 110–114, 137, 165, 236
- ^ "Chapel spec (Acknowledgements)" (PDF). Cray Inc. 2015-10-01. Archived (PDF) from the original on 2022-10-09. Retrieved 2016-01-14.
- ^ "Drago". Archived from the original on 2020-09-14. Retrieved 2018-08-06.
- ^ "The Griffin Project". cs.nyu.edu. Retrieved Apr 4, 2023.
- ^ "SparForte Programming Language". www.sparforte.com. Retrieved Apr 4, 2023.
- ^ a b Pinho, Luis Miguel (June 2023). "From the Editor's Desk". Ada Letters. XLIII (1). Association for Computing Machinery: 3. doi:10.1145/3631483 (inactive 1 July 2025).
{{cite journal}}: CS1 maint: DOI inactive as of July 2025 (link) - ^ "The Ada Programming Language". University of Mich. Archived from the original on 2016-05-22. Retrieved 27 May 2016.
- ^ Fuegi, J; Francis, J (2003). "Lovelace & Babbage and the creation of the 1843 'notes'". IEEE Annals of the History of Computing. 25 (4): 16–26. doi:10.1109/MAHC.2003.1253887. S2CID 40077111.
- ^ "Concurrency". Ada 95 Quality and Style Guide. Ada Information Clearinghouse. Retrieved November 5, 2021.
- ^ Taft, S. Tucker; Olsen, Florence (1999-06-30). "Ada helps churn out less-buggy code". Government Computer News. pp. 2–3. Archived from the original on 2015-08-31. Retrieved 2010-09-14.
- ^ a b c Feldman, Michael. "Who's Using Ada? Real-World Projects Powered by the Ada Programming Language November 2014". SIGAda Education Working Group.
- ^ no safe dynamic memory management in ADA, in: Writing Linux Kernel Modules in Safe Rust – Geoffrey Thomas & Alex Gaynor, The Linux Foundation, 2019-10-02
- ^ "Alire - Homepage". Adacore. Retrieved 2024-12-09.
- ^ "DoD – Strawman Requirements – April 1975". iment.com. Retrieved Apr 4, 2023.
- ^ Department of Defense (June 1978), Requirements for High Order Computer Programming Languages: "Steelman"
- ^ SoftTech Inc. (1976), "Evaluation of ALGOL 68, Jovial J3B, Pascal, Simula 67, and TACPOL Versus TINMAN - Requirements for a Common High Order Programming Language." - See also: ALGOL 68, JOVIAL J3B, Pascal, Simula 67, and TACPOL (Defense Technical Information Center - DTIC ADA037637, Report Number 1021-14)
- ^ "John Goodenough | SEI Staff Profile". Sei.cmu.edu. Retrieved 2014-01-27.
- ^ C.A.R., Hoare (1981). "The Emperor's Old Clothes" (PDF). Communications of the ACM. 24 (2). Association for Computing Machinery: 75–83. doi:10.1145/358549.358561. S2CID 97895. Archived (PDF) from the original on 2016-03-04.
- ^ Watt, D.A.; Wichmann, B.A.; Findlay, W. (1987). Ada: Language and Methodology. Prentice-Hall.
- ^ a b c d Sward, Ricky E. (November 2010). "The rise, fall and persistence of Ada". SIGAda '10: Proceedings of the ACM SIGAda annual international conference on SIGAda. pp. 71–74. doi:10.1145/1879063.1879081. ISBN 978-1-4503-0027-8.
- ^ a b c Rosen, J-P. (August 2009). "The Ada Paradox(es)". Ada Letters. 24 (2). ACM SIGAda: 28–35. doi:10.1145/1620593.1620597. S2CID 608405.
- ^ SofTech Inc. (1983-04-11). "Ada Compiler Validation Summary Report: NYU Ada/ED, Version 19.7 V-001". Waltham, MA. Archived from the original on 2012-03-12. Retrieved 2010-12-16.
- ^ Dewar, Robert B. K.; Fisher, Gerald A. Jr.; Schonberg, Edmond; Froelich, Robert; Bryant, Stephen; Goss, Clinton F.; Burke, Michael (November 1980). "The NYU Ada translator and interpreter". Proceeding of the ACM-SIGPLAN symposium on Ada programming language – SIGPLAN '80. Vol. 15. pp. 194–201. doi:10.1145/948632.948659. ISBN 0-89791-030-3. S2CID 10586359.
- ^ a b "Ada Validated Compilers List". Ada Information Clearinghouse. July 1, 1992. pp. 1–36.
- ^ Ada Information Clearinghouse (1994). "The Congressional Ada Mandate". Archived from the original on 2016-03-04. Retrieved 2015-06-07.
- ^ Babiak, Nicholas J. (1989). Ada, the New DoD Weapon System Computer Language – Panacea or Calamity (PDF). Air University (United States Air Force). pp. 39–40. Archived (PDF) from the original on December 15, 2019.
- ^ "Agile thinking". FlightGlobal. 16 June 1999. Archived from the original on 15 April 2021. Retrieved 13 Feb 2024.
- ^ Frisberg, Bo. "Usage of Ada in the Gripen Flight Control System" (PDF). The Special Interest Group on Ada. Archived (PDF) from the original on 15 Jan 2024. Retrieved 13 Feb 2024.
- ^ AdaCore. "GNAT Pro Chosen for UK's Next Generation ATC System". Archived from the original on 2010-12-24. Retrieved 2011-03-01.
- ^ AdaCore. "Look Who's Using Ada". Archived from the original on 2010-12-24. Retrieved 2011-03-01.
- ^ David A. Wheeler (1997), "Ada, C, C++, and Java vs. The Steelman". Originally published in Ada Letters July/August 1997
- ^ Ichbiah, J. D. (June 1979). "ACM Sigplan Notices". pp. 1–145. doi:10.1145/956650.956651.
- ^ Summary of Ada Language Changes
- ^ "ISO 8652:1987". ISO. 2013-02-21. Retrieved 2024-01-19.
- ^ "Ada 83 LRM, Front Page". archive.adaic.com. Retrieved 2024-01-19.
- ^ "ISO/IEC 8652:1995". ISO. Retrieved 2024-01-19.
- ^ "Ada 95 Language Reference Manual (original) – Ada Resource Association". www.adaic.org. Retrieved 2024-01-19.
- ^ ISO/IEC 8652:1995/Corr 1:2001
- ^ Ada 95 RM with TC 1
- ^ "ISO/IEC 8652:1995/Amd 1:2007". ISO. Retrieved 2024-01-19.
- ^ "Ada Reference Manual, ISO/IEC 8652:2007(E) Ed. 3". www.adaic.org. Retrieved 2024-01-19.
- ^ "ISO/IEC 8652:2012". ISO. 2013-03-28. Retrieved 2024-01-19.
- ^ "ISO/IEC 8652:2012/Cor 1:2016". ISO. Retrieved 2024-01-19.
- ^ "Ada Syntax Card" (PDF). Archived from the original (PDF) on 6 July 2011. Retrieved 28 February 2011.
- ^ "Subprograms". learn.adacore.com. AdaCore. Retrieved 14 April 2024.
- ^ "Ada 83 LRM, Sec 2.8: Pragmas". Archive.adaic.com. Retrieved 2014-01-27.
- ^ "Ada 83 LRM, Appendix/Annex B: Predefined Language Pragmas". Archive.adaic.com. Archived from the original on 2012-02-06. Retrieved 2014-01-27.
- ^ "Ada 2005 Overview - Ada Resource Association". www.adaic.org. Retrieved 2025-10-06.
- ^ "Overview: Exceptions, numerics, generics etc". www.adaic.org. Retrieved 2025-10-06.
- ^ "Generic Units". www.adaic.org. Retrieved 2024-04-25.
- ^ a b ""learn.adacore.com"". learn.adacore.com. Retrieved 2025-10-06.
References
[edit]International standards
[edit]- ISO/IEC 8652: Information technology—Programming languages—Ada
- ISO/IEC 15291: Information technology—Programming languages—Ada Semantic Interface Specification (ASIS)
- ISO/IEC 18009: Information technology—Programming languages—Ada: Conformity assessment of a language processor (ACATS)
- IEEE Standard 1003.5b-1996, the POSIX Ada binding
- Ada Language Mapping Specification, the CORBA interface description language (IDL) to Ada mapping
Rationale
[edit]These documents have been published in various forms, including print.
- Ichbiah, Jean D.; Barnes, John G. P.; Firth, Robert J.; Woodger, Mike (1986), Rationale for the Design of the Ada Programming Language, archived from the original on 2007-02-02 Also available apps.dtic.mil, pdf
- Barnes, John G. P. (1995), Ada 95 rationale: the language: the standard libraries
- Barnes, John (2006) [2005], Rationale for Ada 2005
Books
[edit]- Booch, Grady (1987). Software Engineering with Ada. California: The Benjamin/Cummings Publishing Company. ISBN 0-8053-0604-8.
- Skansholm, Jan (1996). Ada 95 From the Beginning. Addison-Wesley. ISBN 0-201-40376-5.
- Gilpin, Geoff (1985). Ada: A Guided Tour and Tutorial. Prentice hall. ISBN 978-0-13-004045-9.
- Beidler, John (1997). Data Structures and Algorithms: An Object-Oriented Approach Using Ada 95. Springer-Verlag. ISBN 0-387-94834-1.
- Gonzalez, Dean W. (1991). Ada Programmer's Handbook. Benjamin-Cummings Publishing Company. ISBN 0-8053-2529-8.
- Ben-Ari, M. (1998). Ada for Software Engineers. John Wiley & Sons. ISBN 0-471-97912-0.
- Cohen, Norman (1996). Ada as a Second Language. McGraw-Hill Science/Engineering/Math. ISBN 0-07-011607-5.
- Burns, Alan; Wellings, Andy (2001). Real-Time Systems and Programming Languages. Ada 95, Real-Time Java and Real-Time POSIX. Addison-Wesley. ISBN 0-201-72988-1.
- Burns, Alan; Wellings, Andy (1995). Concurrency in Ada. Cambridge University Press. ISBN 0-521-62911-X.
- Atkinson, Colin (1991). Object-Oriented Reuse, Concurrency and Distribution: An Ada-Based Approach. Addison-Wesley. ISBN 0-201-56527-7.
- Booch, Grady; Bryan, Doug (1994). Software Engineering with Ada. Addison-Wesley. ISBN 0-8053-0608-0.
- Jones, Do-While (1989). Ada in Action: With Practical Programming Examples. John Wiley & Sons. ISBN 0-471-60708-8.
- Stubbs, Daniel; Webre, Neil W. (1993). Data Structures with Abstract Data Types and Ada. Brooks Cole. ISBN 0-534-14448-9.
- Ledru, Pascal (December 1998). Distributed Programming in Ada with Protected Objects. Dissertation.com. ISBN 1-58112-034-6.
- Culwin, Fintan (1997). Ada, a Developmental Approach. Prentice Hall. ISBN 0-13-264680-3.
- English, John; Culwin, Fintan (January 1997). Ada 95 the Craft of Object-Oriented Programming. Prentice Hall. ISBN 0-13-230350-7.
- Musser, David R.; Stepanov, Alexander (24 October 1989). The Ada Generic Library: Linear List Processing Packages. Springer-Verlag. ISBN 0-387-97133-5.
- Feldman, Michael B. (1997). Software Construction and Data Structures with Ada 95. Addison-Wesley. ISBN 0-201-88795-9.
- Johnston, Simon (1997). Ada 95 for C and C++ Programmers. Addison-Wesley. ISBN 0-201-40363-3.
- Feldman, Michael B.; Koffman, Elliot B. (1992–1993). Ada: Problem Solving and Program Design. Addison-Wesley. ISBN 0-201-52279-9. 795 pages.
- Feldman, Michael B.; Koffman, Elliot B. (1999). Ada 95. Addison-Wesley. ISBN 0-201-36123-X.
- Dale, Nell B.; Weems, Chip; McCormick, John (August 1996). Programming and Problem Solving with Ada 95. Jones & Bartlett Publishers. ISBN 0-7637-0293-5.
- Dale, Nell B.; McCormick, John (2007). Ada Plus Data Structures: An Object-Oriented Approach, 2nd edition. Jones & Bartlett Publishers. ISBN 978-0-7637-3794-8.
- Krell, Bruce C. (1992). Developing With Ada: Life-Cycle Methods. Bantam Dell Pub Group. ISBN 0-553-09102-6.
- Bishop, Judy (10 May 1990). Distributed Ada: Developments and Experiences. Cambridge University Press. ISBN 0-521-39251-9.
- Sanden, Bo (1994). Software Systems Construction With Examples in Ada. Prentice Hall. ISBN 0-13-030834-X.
- Hillam, Bruce (1994). Introduction to Abstract Data Types Using Ada. Prentice Hall. ISBN 0-13-045949-6.
- Rudd, David (1994). Introduction to Software Design and Development With Ada. Brooks Cole. ISBN 0-314-02829-3.
- Pyle, Ian C. (1991). Developing Safety Systems: A Guide Using Ada. Prentice Hall. ISBN 0-13-204298-3.
- Baker, Louis (1989). Artificial Intelligence With Ada. McGraw-Hill. ISBN 0-07-003350-1.
- Burns, Alan; Wellings, Andy (1995). HRT-HOOD: A Structured Design Method for Hard Real-Time Ada Systems. North-Holland. ISBN 0-444-82164-3.
- Savitch, Walter; Peterson, Charles (1992). Ada: An Introduction to the Art and Science of Programming. Benjamin-Cummings Publishing Company. ISBN 0-8053-7070-6.
- Weiss, Mark Allen (1993). Data Structures and Algorithm Analysis in Ada. Benjamin-Cummings Publishing Company. ISBN 0-8053-9055-3.
- Ledgard, Henry (1983). Ada: An Introduction (second ed.). Springer-Verlag. ISBN 0-387-90814-5.
- Bjørner, Dines; Oest, Ole N., eds. (1980). Towards a Formal Description of Ada. London: Springer-Verlag. ISBN 3-540-10283-3.
Further reading
[edit]- Barnes, John (2024). Programming in Ada 2022. Cambridge University Press. ISBN 978-1-009-56477-9.
- Barnes, John (2014). Programming in Ada 2012 with a Preview of Ada 2022. Cambridge University Press. ISBN 978-1-009-18134-1.
- Barnes, John (2014). Programming in Ada 2012. Cambridge University Press. ISBN 978-1-107-42481-4.
- Barnes, John (2006). Programming in Ada 2005. Addison-Wesley. ISBN 0-321-34078-7.
- Barnes, John (1991). Programming in Ada plus Language Reference Manual. Addison-Wesley. ISBN 0-201-56539-0.
- Barnes, John (1998). Programming in Ada 95. Addison-Wesley. ISBN 0-201-34293-6.
- Barnes, John (1997). High Integrity Ada: The SPARK Approach. Addison-Wesley. ISBN 0-201-17517-7.
- Barnes, John (2003). High Integrity Software: The SPARK Approach to Safety and Security. Addison-Wesley. ISBN 0-321-13616-0.
External links
[edit]- Ada Resource Association
- DOD Ada programming language (ANSI/MIL STD 1815A-1983) specification
- JTC1/SC22/WG9 ISO home of Ada Standards
- Ada Programming Language Materials, 1981–1990. Charles Babbage Institute, University of Minnesota.
- Department of Defense (June 1978), Requirements for High Order Computer Programming Languages: "Steelman"
- David A. Wheeler (1996), Introduction to Steelman On-Line (version 1.2).
- SoftTech Inc. (1976), "Evaluation of ALGOL 68, JOVIAL J3B, Pascal, Simula 67, and TACPOL Versus TINMAN - Requirements for a Common High Order Programming Language." - See also: ALGOL 68, JOVIAL J3B, Pascal, Simula 67, and TACPOL (Defense Technical Information Center - DTIC ADA037637, Report Number 1021-14).
- David A. Wheeler (1997), "Ada, C, C++, and Java vs. The Steelman". Originally published in Ada Letters July/August 1997.
Ada (programming language)
View on GrokipediaHistory
Origins and Development
In the mid-1970s, the U.S. Department of Defense (DoD) grappled with the inefficiency caused by over 450 specialized programming languages and dialects used across its embedded computer systems, leading to significant maintenance challenges and costs.[4] To address this, the DoD's High Order Language Working Group (HOLWG) launched an initiative to define requirements for a single, standardized high-order language suitable for real-time and embedded applications.[8] This effort progressed through iterative requirements documents: the initial Strawman in April 1975, followed by Woodenman in August 1975, Tinman in January 1976, and Ironman in January 1977 (revised in July 1977), each refining the specifications based on expert feedback.[9] These culminated in the Steelman document in June 1978, which served as the comprehensive blueprint for the language design.[10] In April 1977, the DoD issued a Request for Proposals (RFP) to solicit designs meeting the Steelman requirements, sparking a competitive process among industry teams.[8] Sixteen proposals were submitted, with four selected for initial funding: the Green team from CII-Honeywell-Bull, led by French computer scientist Jean Ichbiah; the Red team from Intermetrics; the Blue team from SofTech; and the Yellow team from SRI International.[9] In early 1978, the Green and Red proposals advanced to a second phase for further refinement, where the Green language—developed as a prototype emphasizing modularity, type safety, and concurrency—emerged as the frontrunner.[11] In April 1979, the DoD awarded the contract to Honeywell's team under Ichbiah, tasking them with finalizing the design.[4] The design process concluded with the publication of the Ada 80 Reference Manual (MIL-STD-1815) in July 1980, marking the completion of the initial language specification.[4] To validate early compiler implementations, the DoD conducted pilot projects from 1981 to 1982, testing Ada in real-world scenarios and identifying refinements needed for practical deployment.[4] In 1983, the DoD issued a mandate requiring Ada for all new software development in weapons systems, embedding the language as a cornerstone of defense computing to promote reliability and reduce long-term costs.[12]Initial Adoption and Naming
The name "Ada" was selected in May 1979 to honor Augusta Ada Lovelace (1815–1852), a mathematician and the daughter of Lord Byron, who is widely recognized as the world's first computer programmer for her work on Charles Babbage's Analytical Engine in the 1840s.[4] This choice symbolized the language's emphasis on structured, systematic programming practices, distinguishing it from the ad hoc dialects proliferating in military software development at the time.[1] The name is not an acronym, a deliberate decision to avoid the connotations of contrived abbreviations common in technical nomenclature.[1] Following the language's initial specification in 1980 and its standardization as MIL-STD-1815 (Ada 83) in February 1983, the U.S. Department of Defense (DoD) issued its first official policy mandating Ada use for mission-critical embedded computer systems in June 1983, aiming to consolidate over 450 disparate languages into a single, reliable standard.[13] The Ada Joint Program Office (AJPO), established in December 1980 under the direction of the DoD, coordinated these efforts, overseeing compiler validation, training, and policy enforcement to facilitate widespread adoption.[4] The first validated Ada compilers emerged shortly thereafter, with New York University's Ada/Ed implementation achieving validation in 1983 and Digital Equipment Corporation's VAX/VMS compiler following in 1984, enabling initial pilots and prototypes in defense projects.[4] Early adoption encountered significant hurdles, including immature toolsets and resistance from developers accustomed to legacy languages, as highlighted in a 1989 U.S. Government Accountability Office (GAO) report that documented delays in compiler availability and support environments during the mandate's initial years.[14] Despite these challenges, the DoD mandate spurred commercial interest, prompting vendors like DEC and Honeywell to invest in Ada-compatible products, with the AJPO playing a key role in validating over a dozen compilers by the mid-1980s.[15] By the late 1980s, Ada had gained traction in the defense sector, with the first operational deployments in military systems such as avionics and command-and-control applications, marking a shift toward its intended role in high-reliability embedded software.[16]Standardization
Evolution of Standards
The Ada programming language was initially standardized in the United States as ANSI/MIL-STD-1815A in 1983, commonly referred to as Ada 83, before being adopted internationally as ISO/IEC 8652:1987.[4] This standard established the foundational syntax, type system, and concurrency model for Ada, emphasizing portability and reliability for safety-critical systems.[17] Subsequent revisions to the standard follow a structured process managed by ISO/IEC JTC1/SC22/WG9, which conducts five-year review cycles to assess the language's evolution, incorporate feedback from defect reports, and facilitate public reviews through the Ada Rapporteur Group (ARG).[18] The ARG drafts proposed changes, ensuring compatibility with prior versions while addressing emerging needs in software engineering.[19] The first significant revision, Ada 95 (ISO/IEC 8652:1995), expanded the language's capabilities to support modern programming paradigms, including object-oriented programming through tagged types enabling inheritance and dynamic polymorphism, as well as child packages for improved modularity and library organization.[20] These additions were motivated by the need to enhance reusability and maintainability in large-scale developments, building on Ada 83's strong typing without sacrificing safety.[21] Tasking facilities, a core concurrency feature from Ada 83, underwent substantial refinement in Ada 95 with the introduction of protected objects to provide more efficient mutual exclusion and interrupt handling, addressing performance concerns from earlier implementations while preserving the overall model.[22] Ada 2005 (ISO/IEC 8652:2005) further advanced object-oriented features by introducing interfaces, which support multiple inheritance-like behavior for abstract types, and synchronized interfaces tailored for task and protected implementations to unify concurrency with OOP.[23] These enhancements aimed to increase flexibility in designing extensible systems, particularly for real-time applications, while maintaining Ada's emphasis on verifiable behavior.[24] In Ada 2012 (ISO/IEC 8652:2012), contract-based programming was introduced via preconditions, postconditions, and type invariants, allowing developers to specify behavioral contracts directly in the language to facilitate static analysis and formal verification.[25] This revision responded to demands for better support in high-assurance software, integrating seamlessly with existing type safety mechanisms to reduce runtime errors.[26] The most recent revision, Ada 2022 (ISO/IEC 8652:2023), incorporates parallel constructs such as parallel loops and blocks to leverage multicore processors efficiently, alongside improvements to generics including contract aspects for formal parameters.[27] These updates were driven by the growing prevalence of parallel computing in embedded and high-performance systems, enhancing scalability without compromising Ada's reliability guarantees.[28]Governing Organizations
The primary international body responsible for the maintenance and evolution of the Ada programming language standard is ISO/IEC JTC1/SC22/WG9, established in 1983 to oversee the standardization of Ada under ISO/IEC 8652.[29] This working group coordinates the technical development, review, and approval of revisions to the Ada standard, ensuring global consistency and interoperability across implementations. Within WG9, the Ada Rapporteur Group (ARG) serves as the key technical subgroup, tasked with interpreting the standard, evaluating public comments, resolving defects, and proposing amendments based on community input and emerging requirements.[30] The ARG operates through structured procedures, including the preparation of Ada Issues (AIs) to document and address technical decisions, supporting WG9's broader standardization efforts.[19] Complementing the formal standardization process, organizations such as Ada-Europe and ACM SIGAda play crucial roles in advocacy, education, and community engagement for Ada. Ada-Europe, founded in 1987, promotes the adoption and correct use of Ada in Europe by organizing annual international conferences, publishing the Ada User Journal, and representing European interests in global standardization discussions.[31] Similarly, ACM SIGAda, established in 1983 under the Association for Computing Machinery, fosters Ada's advancement through technical conferences like the annual SIGAda Summit, advocacy for its application in high-reliability domains, and recognition of contributions via awards such as the SIGAda Distinguished Service Award. These groups facilitate knowledge dissemination and collaboration, bridging the gap between standards bodies and practitioners without direct authority over the language specification. Historically, the U.S. Department of Defense's Ada Joint Program Office (AJPO), operational from 1980 until its closure in 1998, managed Ada's validation and certification processes to ensure compliance in defense systems.[32] The AJPO oversaw the Ada Validation Organization (AVO), which tested and certified compilers starting in 1984, enforcing the DoD's mandate for Ada in embedded and real-time applications. Following the AJPO's dissolution, responsibilities transitioned to the Ada Conformity Assessment Authority (ACAA), established in 1999 under ISO/IEC JTC1/SC22/WG9 to administer conformity assessments using the Ada Conformity Assessment Test Suite (ACATS).[33] The ACAA maintains an independent, international framework for verifying processor compliance, issuing certificates that support Ada's use in regulated environments. Current governance processes emphasize ongoing maintenance and reliability. WG9 convenes semi-annual meetings, often aligned with Ada-Europe or SIGAda conferences, to review progress, assign action items, and plan future work items such as amendments or technical reports.[34] Defect reporting and community feedback are handled through the ARG's structured system, including the Ada Issues database for tracking interpretations and corrections, accessible via official submission forms and GitHub repositories for public input.[35] For safety-critical applications, Ada implementations achieve certification under standards like DO-178C for airborne systems, with the ACAA's conformity assessments providing foundational evidence of language-level reliability, complemented by tool qualification and domain-specific verification.[36]Design Principles
Safety and Reliability Objectives
Ada was developed in response to the U.S. Department of Defense's (DoD) need for a standardized high-order programming language suitable for embedded real-time systems, with primary objectives drawn from the 1978 Steelman requirements document. These objectives included promoting program readability to aid comprehension and maintenance, ensuring efficiency in generating object code while allowing recognition of costly constructs, achieving machine independence through avoidance of hardware-specific features and provision of configuration query mechanisms, and supporting the development of large-scale, long-lived programs that could evolve over decades. A core focus of Ada's design is the prevention of common programming errors to enhance safety and reliability in high-stakes environments, such as avionics and defense systems. This is achieved through strong static typing, which enforces type compatibility at compile time to eliminate mismatches that could lead to subtle runtime failures, and comprehensive run-time checks for array bounds, arithmetic overflows, and other potential violations, enabling early detection of anomalies during execution. These mechanisms align with Steelman's mandate to maximize error detection and minimize error-prone language features, thereby reducing the risk of catastrophic failures in mission-critical applications.[37] To support maintainability in collaborative and extended-lifecycle projects, Ada's architecture emphasizes modularity through packages, which encapsulate related declarations and bodies, promoting information hiding, reusability, and team-based development without compromising system integrity. This structured approach facilitates the management of complex software by allowing independent compilation and verification of modules, essential for large programs developed by distributed teams over prolonged periods. The 1983 Ada Rationale document, prepared by the language's design team, provides detailed justification for these choices, highlighting how the absence of unrestricted goto statements—replaced by structured control flows like loops with exit conditions—improves code predictability and reliability by discouraging unstructured branching that often leads to maintenance challenges. Later standards annexes, such as those in Ada 95, further refined these objectives to address evolving needs in safety-critical domains while preserving the foundational emphasis on verifiable and robust software construction.[38]Influences and Comparisons
Ada's development was driven by the U.S. Department of Defense's (DoD) need to consolidate a fragmented landscape of over 450 programming languages and dialects used across military systems, including JOVIAL for the Air Force, CMS-2 for the Navy, TACPOL for the Army, and SPL for space and missile systems (Air Force), which led to high maintenance costs and portability issues.[39][40][41] The language was intended to unify these efforts into a single, standardized high-level language for embedded and real-time applications, promoting reliability and reducing the proliferation of proprietary dialects.[15] Key influences on Ada's design included Pascal, which provided the foundation for strong typing and modular structures through its block-based organization and data abstraction features.[42] ALGOL 68 contributed concepts of orthogonality, enabling independent language features without unintended interactions, and a robust type system that emphasized flexibility in expression.[43] Concurrent Pascal inspired Ada's tasking model for concurrency, introducing monitors and processes to manage parallel execution safely within a structured framework. Ada's designers rejected the C preprocessor due to its potential for introducing errors through macro expansions and conditional compilation, opting instead for pragmas as a controlled mechanism to convey compiler directives while maintaining type safety and readability.[44] This choice underscored Ada's emphasis on abstraction and high-level constructs over low-level control, prioritizing verifiable correctness in complex systems rather than unrestricted hardware access.[38] In comparison to C, Ada offers superior safety through enforced type checking and exception handling, avoiding C's vulnerability to buffer overflows and undefined behavior, while providing built-in concurrency via tasks and protected objects absent in standard C.[45] Versus Modula-2, Ada extends modularity with parametric generics for reusable components and support for distributed systems through remote calls, enabling larger-scale applications beyond Modula-2's single-address-space focus.[46] Although predating Rust by decades, Ada shares a commitment to memory safety and reliability but achieves it through compile-time constraints and optional formal verification rather than Rust's runtime borrow checker, which enforces ownership rules dynamically.[47]Core Features
Type Safety and Checking
Ada features a strong, static type system that enforces type compatibility at compile time, preventing unintended type conversions and promoting early error detection. This system distinguishes between types and subtypes, where subtypes impose additional constraints on base types without altering their underlying representation. For instance, the predefined subtypePositive is declared as a constrained range of Integer from 1 to Integer'Last, ensuring that variables of this subtype cannot hold zero or negative values, thus catching range violations during compilation.[48][49] Such subtypes enhance safety by allowing programmers to express domain-specific invariants, like positive indices or non-negative counts, while maintaining compatibility with the parent type for operations.[48]
To complement static checks, Ada mandates run-time checks for dynamic properties that cannot be fully verified at compile time, including array index bounds, division by zero, and dereferencing of invalid access values. These checks are enabled by default in conforming implementations, raising predefined exceptions such as Constraint_Error if violated, which helps prevent undefined behavior in safety-critical applications.[50] Programmers can suppress specific checks using the pragma Suppress, such as pragma Suppress (Overflow_Check);, to optimize performance in verified code sections, though this requires careful justification to avoid introducing latent errors.[51][52]
Ada addresses the risks of unions through discriminated types and variant records, which provide a safe alternative to unchecked unions in other languages. A discriminated record includes a discriminant field—typically an enumeration or integer—that determines the validity of conditional components, with the compiler generating run-time checks to ensure only appropriate parts are accessed based on the current discriminant value.[53] For example:
type Shape_Tag is (Circle, Rectangle);
type Shape (Tag : Shape_Tag) is record
case Tag is
when Circle =>
Radius : Float;
when Rectangle =>
Width, Height : Float;
end case;
end record;
type Shape_Tag is (Circle, Rectangle);
type Shape (Tag : Shape_Tag) is record
case Tag is
when Circle =>
Radius : Float;
when Rectangle =>
Width, Height : Float;
end case;
end record;
Constraint_Error for mismatches and eliminating common errors like accessing uninitialized union members.[54]
Private types further bolster Ada's safety by enabling information hiding, where the package specification declares a type as private, revealing only its existence and essential operations to clients while concealing the full implementation details in the package body. This opaque view prevents clients from directly manipulating internal components, reducing the risk of errors stemming from assumptions about the type's structure and allowing implementation changes without affecting dependent code.[55] For instance, a private type might abstract a stack as type Stack is private;, exposing only push and pop operations, which shields users from representation-specific bugs like buffer overflows.[56]
Modularity with Packages
Ada packages serve as the primary mechanism for achieving modularity in the language, enabling developers to organize related declarations and subprograms into reusable units that promote encapsulation and maintainability.[57] A package is divided into two main parts: the package specification, which declares the public interface visible to clients, and the package body, which provides the implementation details.[57] The specification is typically stored in a file with a.ads extension, while the body uses .adb, allowing for separate compilation of each part.[58]
The package specification includes a visible part for client-accessible entities and an optional private part for internal details that should remain hidden from direct client use.[57] For example, a simple stack package might declare a Stack_Type and operations like Push and Pop in the visible part, while implementation details such as internal arrays are confined to the private part.
package Stack is
type Stack_Type is private;
procedure Push (S : in out Stack_Type; Item : in Integer);
procedure Pop (S : in out Stack_Type; Item : out Integer);
private
type Stack_Type is record
Items : array (1 .. 100) of Integer;
Top : Integer := 0;
end record;
end Stack;
package Stack is
type Stack_Type is private;
procedure Push (S : in out Stack_Type; Item : in Integer);
procedure Pop (S : in out Stack_Type; Item : out Integer);
private
type Stack_Type is record
Items : array (1 .. 100) of Integer;
Top : Integer := 0;
end record;
end Stack;
Math parent package might have a public child Math.Vectors for general operations and a private child Math.Internal for low-level utilities visible only to other Math children.[59]
To handle inter-package dependencies without circularity, Ada provides limited views through incomplete type declarations and limited with clauses, allowing a package to reference types from another as incomplete views without full visibility.[61] This declares an incomplete view of the type, sufficient for pointers or access types but deferring full details until the referenced package is compiled.[62] Such mechanisms enhance modularity by enabling forward references in large systems.
Generic packages offer a brief extension for parameterized modularity, allowing a package to be instantiated with specific types or values, though detailed instantiation is covered elsewhere.[63] For example, a generic stack could be parameterized over an item type like Integer or String.
Overall, these features support separate compilation, as clients need only the specification to use a package, while bodies can be compiled independently and linked later.[57] Packages may contain subprograms, providing a namespace for related functions and procedures.[57] This design fosters large-scale software engineering by enforcing boundaries and reusability.[60]
Concurrency and Tasks
Ada's concurrency model is built around tasks, which represent independent threads of execution, and protected objects, which manage shared data access to prevent race conditions. Tasks enable parallel execution of program components, allowing separable activities to proceed concurrently while interacting through well-defined synchronization mechanisms. This design emphasizes safety by integrating concurrency primitives directly into the language, avoiding low-level threading APIs common in other languages.[64] A task is declared using a task type or single task declaration, specifying entry points as interfaces for communication, followed by a task body that defines its executable statements. Tasks begin in an inactive state upon declaration and are activated collectively by the activator task—typically the enclosing declarative part—before the activator proceeds. Activation involves elaborating the task body and starting the task's execution, with tasks competing for processor resources once ready. For synchronization, tasks use rendezvous, a synchronous mechanism where a calling task invokes an entry call on a called task, blocking until the called task accepts the call via an accept statement, executes the associated handler, and completes the rendezvous to resume both tasks. This ensures coordinated interaction without shared mutable state during the rendezvous.[64][65] Protected objects address mutual exclusion for shared data, declared as a protected type or object with visible protected operations (procedures, functions, or entries) that encapsulate the data. Access to a protected object is serialized: procedures provide exclusive read-write access, while functions allow concurrent read-only access by multiple tasks, ensuring atomicity without explicit locking. Entries within protected objects function similarly to task entries but support conditional waiting via barriers, suspending callers until a condition holds, thus facilitating efficient synchronization for resources like buffers or semaphores.[66] Tasking was introduced in Ada 83 as the language's foundational concurrency feature, relying on rendezvous for inter-task communication and delays for timing. Ada 95 enhanced this with protected objects for lighter-weight synchronization and asynchronous transfer of control (ATC), allowing selective statements to handle external events like timeouts or signals without aborting entire tasks, alongside the Real-Time Systems Annex for priority-based scheduling. Further refinements appeared in Ada 2005 with synchronized interfaces for abstract concurrency, the Ravenscar profile, and pragmas like Partition_Elaboration_Policy(Concurrent) to enable parallel elaboration of library units. Ada 2012 added multiprocessor support, including task affinities to specific CPUs and enhancements to dispatching domains.[67][22][65] Ada 2022 further improved concurrency with nonblocking aspects, global data annotations for race prevention, parallel loops and blocks, and CPU affinity for protected objects.[27] The Ravenscar profile, formalized in Ada 2005 and extended in Ada 2012, defines a deterministic subset of tasking features tailored for safety-critical real-time systems, restricting dynamic task creation, entry queues (to zero or one), and abort statements to enable static schedulability analysis and bounded execution times. By prohibiting features like ATC and dynamic priorities, it ensures predictability on single- or multiprocessor platforms, widely adopted in avionics and space applications for certification under standards like DO-178C.[68][69]Language Constructs
Basic Syntax and Programs
Ada programs are structured as sequences of lexical elements, including identifiers, literals, operators, and delimiters, formed from characters in the ISO/IEC 10646 Universal Coded Character Set.[70] The language is case-insensitive, meaning that identifiers and reserved words can be written in any combination of upper and lower case letters without affecting their meaning.[70] Reserved words, which have special syntactic roles, include abort, abs, abstract, accept, access, aliased, all, and, array, at, begin, body, case, constant, declare, delay, delta, digits, do, else, elsif, end, entry, except, exit, for, function, generic, goto, if, in, is, limited, loop, mod, new, not, null, of, or, others, out, package, pragma, private, procedure, protected, raise, range, record, rem, renames, requeue, return, reverse, select, separate, some, subtype, synchronized, tagged, task, terminate, then, type, until, use, when, while, with, xor, and parallel.[71] Comments begin with two adjacent hyphens (-- ) and extend to the end of the line, serving to document the code without impacting its semantics; they can appear anywhere in the source text and may span multiple lines if continued accordingly.[72] The basic skeleton of an Ada program centers on a main procedure, which serves as the entry point and is declared as a library unit.[73] It typically includes with clauses to import packages from the standard library or other units, followed optionally by use clauses to allow unqualified access to entities within those packages. The procedure body is enclosed in begin and end blocks, containing declarative regions for variables and statements for execution. For instance, a simple main program might import theAda.Text_IO package for input/output operations and invoke its procedures within the statement sequence.
A canonical "Hello, world!" program illustrates this structure:
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line ("Hello, world!");
end Hello;
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line ("Hello, world!");
end Hello;
Ada.Text_IO via the with clause, uses it directly due to the use clause, declares a main procedure named Hello, and executes the Put_Line procedure to output the message followed by a newline.[74] The program is compiled and linked into an executable, which upon running produces the specified output.
Ada organizes code into compilation units for separate compilation and modularity. A compilation unit is either a library unit—such as a package, subprogram, or generic unit that stands alone and can be referenced by other units—or a subunit, which implements a body of a library unit.[75] Library subprogram units, including procedures and functions declared at the library level, form the basis for main programs and reusable components, while nested subprograms reside within declarative regions of other units without being separately compilable.[75] This separation enables incremental development and maintenance of large systems.
Data Types and Declarations
Ada's type system is built around explicit declarations that define both new types and objects such as variables and constants, ensuring strong static typing from the outset. A type declaration introduces a new type name and specifies its structure, while an object declaration names a variable or constant, associates it with a type, and optionally provides an initial value.[76] For instance, the syntax for a variable declaration isName : Type_Name [:= Initial_Value];, and for a constant, it is Name : constant Type_Name [:= Initial_Value];.[76] This declarative approach allows programmers to precisely control the properties of data, promoting reliability in safety-critical applications.
Scalar types form the foundation of Ada's data model and include enumeration types, integer types, and real types, where real types encompass both floating-point and fixed-point varieties.[77] Enumeration types are discrete scalar types declared by listing their literal values, such as type Day is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);, which defines an ordered set of named constants. Integer types, also discrete, can be predefined like Integer or user-defined with a range constraint, for example, type Count is range 0 .. 1_000_000;, allowing customization of the value set while inheriting operations from the base type. Real types support approximate representation of continuous values; floating-point types like Float provide variable precision based on the machine, whereas fixed-point types specify exact decimal scaling, declared as type Money is delta 0.01 range 0.0 .. 1_000.0;, which ensures predictable precision for financial or embedded applications. Subtypes can further constrain these scalar types to enhance safety by limiting ranges or values, as detailed in the core features of the language.
Composite types in Ada aggregate multiple components into a single unit, enabling the modeling of complex structures like arrays and records.[78] Array types are declared with an index range and component type, such as type Vector is [array](/page/Array)(Positive range <>) of [Integer](/page/Integer);, where the components are homogeneous and accessed via indexing (e.g., V(1) := 42;). Multidimensional arrays follow similarly, like type Matrix is [array](/page/Array)(1 .. 10, 1 .. 10) of Float;. Record types group heterogeneous components, declared as type Person is record Name : [String](/page/String)(1 .. 50); Age : Positive; end record;, with access to fields via selection (e.g., P.Age := 30;). Records support discriminants for variant structures, where a parameter like type [Shape](/page/Shape)(D : [Dimension](/page/Dimension)) is record ... end record; allows the record's layout to vary based on the discriminant value at declaration.
Access types provide pointer-like functionality for dynamic memory management, designating objects or subprograms while maintaining type safety.[79] Access-to-object types are declared with a designated type, for example, type Node_Ptr is access Node;, where Node is the type of the object being pointed to.[79] Objects must be allocated dynamically using new, such as Ptr := new [Integer](/page/Integer)'(10);, which creates an anonymous object on the heap and returns an access value; deallocation is handled explicitly via unchecked deallocation to prevent leaks. This mechanism supports structures like linked lists, with null as a valid uninitialized value.[79]
Control Structures
Ada provides structured control mechanisms for conditional execution and iteration, designed to promote reliability by enforcing explicit coverage of cases and avoiding unstructured jumps. These include if statements for boolean-based branching, case statements for multi-way selection on discrete values, loop statements for repetition, and block statements for defining local scopes. Goto statements exist but are heavily restricted to prevent violations of scoping rules, encouraging the use of higher-level constructs instead.[73]Conditionals
The if statement enables selective execution based on a boolean condition, with all variants fully delimited by keywords to ensure clarity and prevent errors from implicit fall-through. Its basic syntax is:if condition then
sequence_of_statements
end if;
if condition then
sequence_of_statements
end if;
if condition then
sequence_of_statements
elsif condition then
sequence_of_statements
[elsif ...]
[else
sequence_of_statements]
end if;
if condition then
sequence_of_statements
elsif condition then
sequence_of_statements
[elsif ...]
[else
sequence_of_statements]
end if;
case selecting_expression is
when choice_list => sequence_of_statements
[when ...]
[when others => sequence_of_statements]
end case;
case selecting_expression is
when choice_list => sequence_of_statements
[when ...]
[when others => sequence_of_statements]
end case;
Loops
Ada's loop statements provide flexible iteration, categorized by their optional iteration_scheme: while for condition-based repetition, for for quantified traversal, and unconditional loops ended by explicit exit. The general form is:[loop_name:] [iteration_scheme]
loop
sequence_of_statements
end loop [loop_name];
[loop_name:] [iteration_scheme]
loop
sequence_of_statements
end loop [loop_name];
parallel for I in 1 .. 100 loop
-- Process I independently
end loop;
parallel for I in 1 .. 100 loop
-- Process I independently
end loop;
while condition loop
sequence_of_statements
end loop;
while condition loop
sequence_of_statements
end loop;
for loop_parameter in discrete_range loop
sequence_of_statements
end loop;
for loop_parameter in discrete_range loop
sequence_of_statements
end loop;
exit [loop_name] [when condition];
exit [loop_name] [when condition];
Block Statements
Block statements define a local declarative region and handled sequence, useful for encapsulating temporary variables or exception handlers without subprogram overhead. The syntax is:[label:] declare
declarative_part
begin
handled_sequence_of_statements
end [label];
[label:] declare
declarative_part
begin
handled_sequence_of_statements
end [label];
declare
Temp : [Integer](/page/Integer);
begin
Temp := A;
A := B;
B := Temp;
end;
declare
Temp : [Integer](/page/Integer);
begin
Temp := A;
A := B;
B := Temp;
end;
goto label;
<<label>>
goto label;
<<label>>
Subprograms and Functions
In Ada, subprograms provide the mechanism for defining reusable blocks of code that encapsulate specific operations or computations. They are essential for promoting modularity and abstraction in programs, allowing developers to break down complex tasks into manageable units. There are two primary forms of subprograms: procedures, which execute a sequence of statements to perform actions without producing a return value, and functions, which compute a result and return it to the caller. Subprograms can be declared locally within other constructs or globally, and their interfaces are defined separately from their implementations to support separate compilation.[83] Procedures are declared using the keywordprocedure followed by the procedure name, a parameter profile in parentheses (which may be empty), the reserved word is, an optional declarative region, the reserved word begin, a sequence of statements, and the reserved word end followed by the procedure name. For example, a simple procedure to print a message might be written as:
procedure Print_Message (Text : in String) is
begin
Put_Line (Text);
end Print_Message;
procedure Print_Message (Text : in String) is
begin
Put_Line (Text);
end Print_Message;
Text of type String and outputs it using the Put_Line procedure from the standard library. Procedure calls appear as statements and invoke the associated body to execute its actions.[83][84]
Functions, in contrast, are declared using the keyword function followed by the function name, a parameter profile, the reserved word return specifying the result type, is, an optional declarative region, begin, statements, and end followed by the function name. The body must include at least one return statement that provides a value of the specified return type. An example function to compute the sum of two integers is:
function Add (Left, Right : Integer) return Integer is
begin
return Left + Right;
end Add;
function Add (Left, Right : Integer) return Integer is
begin
return Left + Right;
end Add;
- in: The actual value is copied into the formal parameter at the start of the call; the formal cannot be updated, ensuring read-only access. This is the default mode if none is specified.
- out: The formal parameter is an output-only entity; any initial value from the actual is discarded, and the subprogram must assign a value before completion, which is then copied back to the actual.
- in out: The actual value is copied into the formal at the start; the subprogram may read and update it, with the final value copied back to the actual upon return.
Add procedures could exist for [Integer](/page/Integer) and Float parameters. Overloading applies to both procedures and functions but requires all overloaded entities to be of the same kind (all procedures or all functions).[83]
Recursion is fully supported in Ada, allowing subprograms to invoke themselves directly or mutually, which is useful for algorithms like tree traversals or factorial computations. The language's strong typing and stack management ensure safe recursive calls, with no special syntax required beyond a standard subprogram call. An example recursive function for factorial is:
function Factorial (N : [Natural](/page/The_Natural)) return [Natural](/page/The_Natural) is
begin
if N <= 1 then
return 1;
else
return N * Factorial (N - 1);
end if;
end Factorial;
function Factorial (N : [Natural](/page/The_Natural)) return [Natural](/page/The_Natural) is
begin
if N <= 1 then
return 1;
else
return N * Factorial (N - 1);
end if;
end Factorial;
N! by recursively multiplying N with Factorial(N-1) until the base case. Mutual recursion is also possible, where two or more subprograms call each other.[84]
Advanced Constructs
Generics and Parameterization
Ada's generics provide a mechanism for parametric polymorphism, allowing developers to define reusable units such as packages and subprograms that operate on unspecified types or values until instantiation. This feature supports code reuse by creating templates that can be specialized for different types, promoting modularity without sacrificing type safety.[86] A generic unit is declared using the keywordgeneric, followed by a list of formal parameters enclosed in parentheses, and then the specification or body of the package, procedure, or function. For example, a generic stack package might be declared as:
generic
type Element is private;
with function "=" (Left, Right : Element) return Boolean is <>;
package Stack is
type Stack_Type is private;
procedure Push (S : in out Stack_Type; Item : Element);
-- Other operations...
private
-- Implementation details
end Stack;
generic
type Element is private;
with function "=" (Left, Right : Element) return Boolean is <>;
package Stack is
type Stack_Type is private;
procedure Push (S : in out Stack_Type; Item : Element);
-- Other operations...
private
-- Implementation details
end Stack;
Element is a formal type parameter that can be any private type, and the equality function is a formal subprogram parameter with a box <> indicating it defaults to a predefined operator if available. Formal parameters can include types (with or without constraints like range <> for discrete types or digits <> for floating-point), values (e.g., Max_Size : Positive := 100;), and subprograms, each supporting default values to allow optional specification during instantiation.[63][87]
Instantiation creates a non-generic unit by binding actual parameters to the formals of a generic declaration, producing a specialized version of the template. The syntax is package Instance_Name is new Generic_Name (Actual_Parameters);, where actuals match the formals positionally or by named association. Continuing the stack example:
package Float_Stack is new Stack (Element => Float);
package Float_Stack is new Stack (Element => Float);
Float elements, using the default equality. If defaults are provided, some actuals can be omitted, and the resulting instance behaves as a regular package with the substituted types and values, ensuring compile-time type checking. Instantiations can occur at the library level or nested within other units.
Formal type parameters support constraints to restrict possible actual types, such as type Index is range <>; for discrete types or type Elem is digits <>; for decimal fixed-point, which are verified at instantiation to prevent mismatches. Value parameters, like constants, must be static expressions and can have defaults (e.g., Limit : [Integer](/page/Integer) := 0;, where 0 means unbounded), allowing flexible reuse. Subprogram formals declare interfaces that actual subprograms must conform to, enhancing abstraction.[87]
Child units of generic packages can themselves be generic, extending the parameterization hierarchically while inheriting visibility of the parent's formals. For instance, a generic parent package Parent with formal type T; can have a child Parent.Child declared as generic package Child is ... end Child;, where T is directly usable in Child. This supports complex library structures, such as generic containers with specialized child operations.
Nested instantiation allows generics to be instantiated within the body of another generic, using the enclosing generic's formals as actuals to build layered abstractions. For example, inside a generic container's body, a generic list might be instantiated with the container's element type, enabling compositional reuse without premature commitment to specific types. This technique is particularly useful for implementing advanced data structures like generic graphs or trees.[63]
Pragmas and Compiler Directives
In Ada, pragmas serve as compiler directives that provide supplementary information or instructions to the compiler without affecting the semantics of the program during execution. They are non-executable statements that can influence aspects such as optimization, error checking, and representation. The general syntax for a pragma ispragma pragma_name ( [pragma_argument_associations] );, where the pragma name is an identifier, and argument associations may include positional or named parameters. Pragmas can appear in declarative regions or as configuration pragmas affecting entire compilation units, but their exact placement and effects are governed by the specific pragma definition.[88]
Ada distinguishes between language-defined pragmas, which are specified in the ISO/IEC 8652 standard and must be supported by all conforming implementations, and implementation-defined pragmas, which are extensions provided by specific compilers such as GNAT or ObjectAda. Language-defined pragmas include those for controlling optimizations and checks, while implementation-defined ones may address vendor-specific features like additional debugging or linking options. The Ada 2022 standard (ISO/IEC 8652:2022) maintains this distinction, with Annex L summarizing all language-defined pragmas.[88][80]
One common language-defined pragma is Suppress, which permits the compiler to omit specific run-time checks to improve performance, such as range or overflow verification, though implementations may still perform them if deemed necessary for safety. For example, pragma Suppress (Range_Check); disables range checks from the point of the pragma to the end of the enclosing declarative region or until revoked by Unsuppress. This pragma is particularly useful in performance-critical sections where the programmer has verified the safety of omitting checks.[89][90]
The Pack pragma specifies that components of a composite type should be packed as tightly as possible at the bit level to minimize storage, equivalent to setting the Pack aspect to True. Applied as pragma Pack (Type_Name); to an array or record type, it influences layout decisions but may increase access overhead due to bit operations. In Ada 2022, Pack is obsolescent in favor of the aspect specification, though it remains supported for compatibility.[91][92]
For debugging and verification, the Assert pragma evaluates a Boolean expression at compile time if possible or run time otherwise, raising Assertion_Error if false, with an optional message parameter. Syntax is pragma Assert (Check [, Message => string_expression]);, and its behavior is controlled globally by Assertion_Policy, which can enable, disable, or handle assertions in implementation-specific ways. This supports contract-based programming without runtime overhead in production builds.[93][94]
Optimization-related pragmas include Pure, which declares a library unit as having no observable side effects outside its visible state, allowing aggressive compiler optimizations and enabling its use in pure contexts like generic formal packages. Applied as pragma Pure (Library_Unit_Name);, it sets the Pure aspect to True and is required for certain standard library units. Similarly, Inline requests that calls to denoted subprograms be expanded inline for potential performance gains, using pragma Inline (Subprogram_Name); to set the Inline aspect, though the compiler may ignore it based on complexity or other factors.[95][96]
In Ada 2022, new language-defined pragmas support parallelism features introduced for lightweight concurrent programming. The Conflict_Check_Policy pragma establishes policies for detecting data races in parallel constructs, such as sequential checks by default or parallel-specific policies like Known or Concurrent to ensure safe shared access. For instance, pragma Conflict_Check_Policy (Parallel => Known); informs the compiler that the programmer guarantees no conflicts in parallel loops or blocks, enabling optimizations while tying into run-time checks for safety. These pragmas complement aspects like Parallel on loop statements, facilitating scalable parallelism without full tasking overhead.[27]
Exception Handling
Ada's exception handling mechanism provides a structured way to detect, signal, and recover from runtime errors, enhancing program reliability by separating error detection from normal execution flow.[97] Exceptions in Ada are named entities that represent error conditions, allowing developers to declare custom exceptions and handle both predefined and user-defined ones explicitly.[98] This approach promotes robust software, particularly in safety-critical systems, by enabling precise control over error propagation and recovery.[99] Exceptions are declared using the syntaxdefining_identifier_list : exception;, which introduces one or more names for exceptions within the declarative region of a package, subprogram, or block. For example:
package My_Package is
My_Error : exception;
end My_Package;
package My_Package is
My_Error : exception;
end My_Package;
Ada.Exceptions, such as Constraint_Error for violations of type constraints and Storage_Error for memory exhaustion, which are raised automatically by the runtime system.[97]
To signal an exception, a raise statement is used, either naming a specific exception with raise Exception_Name; or re-raising the current exception with raise;.[101] The former explicitly raises a new occurrence of the named exception, abandoning normal execution, while the latter, usable only within a handler, propagates the existing exception occurrence.[101] For instance, within a subprogram, raise My_Error; can indicate an invalid input after validation.[98]
Handling occurs within a handled_sequence_of_statements, structured as:
begin
-- executable statements
exception
when Exception_Choice_1 => -- handled statements
when Exception_Choice_2 => -- handled statements
when others => -- catch-all for unlisted exceptions
end;
begin
-- executable statements
exception
when Exception_Choice_1 => -- handled statements
when Exception_Choice_2 => -- handled statements
when others => -- catch-all for unlisted exceptions
end;
Exception_Choice can specify a single exception, a list (E1 | E2), a range (E1 .. E2), or others for any unhandled exception. Handlers execute the associated statements if the raised exception matches the choice, after which control resumes after the end keyword; non-matching handlers are skipped.[97] This block can enclose any sequence of statements, allowing localized error recovery.[98]
If no applicable handler exists in the current scope, the exception propagates outward to enclosing handled blocks, subprograms, or tasks until handled or reaching the environment task.[97] Unhandled exceptions in the environment task terminate the partition, invoking finalization for the master and potentially calling the default exception handler if defined.[102] In concurrent programs, an unhandled exception in a task terminates that task and may propagate to the parent task or environment.[97]
Introduced in Ada 95, exception renaming allows an existing exception to be given an alternative name via exception_renaming_declaration, such as EOF : exception renames Ada.IO_Exceptions.End_Of_File;, facilitating clearer code without creating new exceptions.[103] Additionally, Ada 95 added controlled types, which support user-defined finalization through the Finalize procedure of the Ada.Finalization.Controlled limited interface.[104] When an exception propagates and causes a master to complete, objects of controlled types are finalized in reverse declaration order, ensuring resource cleanup even during error paths; exceptions raised in Finalize are ignored unless they occur in the outermost master.[105] This feature integrates exception handling with automatic resource management, reducing leaks in erroneous executions.[106]