Your browser does not support JavaScript! Skip to main content
Free 30-day trial DO-178C Handbook RapiCoupling Preview DO-178C Multicore Training Multicore Resources
Rapita Systems
 

Industry leading verification tools & services

Rapita Verification Suite (RVS)

  RapiTest - Unit/system testing  RapiCover - Structural coverage analysis  RapiTime - Timing analysis (inc. WCET)  RapiTask - Scheduling visualization  RapiCoverZero - Zero footprint coverage analysis  RapiTimeZero - Zero footprint timing analysis  RapiTaskZero - Zero footprint scheduling analysis  RapiCouplingPreview - DCCC analysis

Multicore Verification

  MACH178  MACH178 Foundations  Multicore Timing Solution  RapiDaemons

Engineering Services

  V&V Services  Data Coupling & Control Coupling  Object code verification  Qualification  Training  Consultancy  Tool Integration  Support

Industries

  Civil Aviation (DO-178C)   Automotive (ISO 26262)   Military & Defense   Space

Other

RTBx Mx-Suite Software licensing Product life cycle policy RVS Assurance issue policy RVS development roadmap

Latest from Rapita HQ

Latest news

SAIF Autonomy to use RVS to verify their groundbreaking AI platform
RVS 3.22 Launched
Hybrid electric pioneers, Ascendance, join Rapita Systems Trailblazer Partnership Program
Magline joins Rapita Trailblazer Partnership Program to support DO-178 Certification
View News

Latest from the Rapita blog

How to certify multicore processors - what is everyone asking?
Data Coupling Basics in DO-178C
Control Coupling Basics in DO-178C
Components in Data Coupling and Control Coupling
View Blog

Latest discovery pages

control_tower DO-278A Guidance: Introduction to RTCA DO-278 approval
Picture of a car ISO 26262
DCCC Image Data Coupling & Control Coupling
Additional Coe verification thumb Verifying additional code for DO-178C
View Discovery pages

Upcoming events

Avionics and Testing Innovations 2025
2025-05-20
DASC 2025
2025-09-14
DO-178C Multicore In-person Training (Fort Worth, TX)
2025-10-01
DO-178C Multicore In-person Training (Toulouse)
2025-11-04
View Events

Technical resources for industry professionals

Latest White papers

Mitigation of interference in multicore processors for A(M)C 20-193
Sysgo WP
Developing DO-178C and ED-12C-certifiable multicore software
DO178C Handbook
Efficient Verification Through the DO-178C Life Cycle
View White papers

Latest Videos

Rapita Systems - Safety Through Quality
Simulation for the Motorola 68020 microprocessor with Sim68020
AI-driven Requirements Traceability for Faster Testing and Certification
Multicore software verification with RVS 3.22
View Videos

Latest Case studies

GMV case study front cover
GMV verify ISO26262 automotive software with RVS
Kappa: Verifying Airborne Video Systems for Air-to-Air Refueling using RVS
Supporting DanLaw with unit testing and code coverage analysis for automotive software
View Case studies

Other Resources

 Webinars

 Brochures

 Product briefs

 Technical notes

 Research projects

 Multicore resources

Discover Rapita

Who we are

The company menu

  • About us
  • Customers
  • Distributors
  • Locations
  • Partners
  • Research projects
  • Contact us

US office

+1 248-957-9801
info@rapitasystems.com
Rapita Systems, Inc.
41131 Vincenti Ct.
Novi
MI 48375
USA

UK office

+44 (0)1904 413945
info@rapitasystems.com
Rapita Systems Ltd.
Atlas House
Osbaldwick Link Road
York, YO10 3JB
UK

Spain office

+34 93 351 02 05
info@rapitasystems.com
Rapita Systems S.L.
Parc UPC, Edificio K2M
c/ Jordi Girona, 1-3
Barcelona 08034
Spain

Working at Rapita

Careers

Careers menu

  • Current opportunities & application process
  • Working at Rapita
Back to Top Contact Us

Ada enumerations are sometimes functions

Breadcrumb

  1. Home
2016-04-18

In Ada, you declare a new enumeration type by providing a list of literals:

type Position is ( Left, Middle, Right );

Ada also lets you use character literals in an enumeration:

type Calc_Op is ( '*', '/', '+', '-' );

or even:

type DNACode is ( 'A', 'C', 'G', 'T', Unknown );

Once you have an enumeration type, you can use these literals just as you would other literals:

op: Calc_Op := '*';
...
case op
is
when '*' => ...

In Ada, each literal is technically the name of a function taking no arguments and returning the corresponding value. However, these functions are not generated in the object code unless they are actually needed. When such a function is needed, the compiler generates additional object code that does not correspond directly to the source code. For example, the "return" of the generated function does not correspond to a "return" statement in the source text. At DO-178B and DO-178C level A, it is important to analyse cases where the compiler introduces additional object code in this way (DO-178B 6.4.4.2(b)). Here are two straightforward cases that will cause this to happen.

Explicit renaming

The most direct way this happens is when you create a function that renames a literal:

function make_times return Calc_Op renames '*';

This causes the GNAT expander (we use gnatmake options -gnatDGL for this) to emit this definition:

function lee__make_times return lee__calc_op is
begin
return '*';
end lee__make_times;

If the renamed function is not called, later optimisation stages remove it. Otherwise, you get object code as follows (on a standard host platform):

00401510 <_lee__make_times.2282>:
401510:   55                      push   %ebp
401511:   89 e5                   mov    %esp,%ebp
401513:   83 ec 18                sub    $0x18,%esp
401516:   89 4d f4                mov    %ecx,-0xc(%ebp)
401519:   b8 00 00 00 00          mov    $0x0,%eax
40151e:   c9                      leave
40151f:   c3                      ret

Note here that the internal representation of '*' is not its ASCII code; it's allocated as per any other enumeration, starting from 0. Ada lets you take an access to such a function, but does not allow an access directly to the corresponding literal.

Generic parameters

If a parameter to a generic is a function of no arguments returning an enumeration value, a literal may be supplied directly without any need for renaming. In this example, the user can instantiate an evaluate function based on a Calc_Op :

generic
with function get_op return Calc_Op;
function evaluate( L, R: Integer )
return Integer;
function evaluate( L, R: Integer )
return Integer
is
begin
case get_op is
when '*' => return L * R;
when '/' => return L / R;
when '+' => return L + R;
when '-' => return L - R;
end case;
end evaluate;
function multiply is new evaluate( '*' );

In the expanded code, among the other package creation and expansion, GNAT provides a function for '*' . In the start of the new instance of evaluate, it creates a call to get_op :

function lee__multiply (l : integer; r : integer) return integer is
begin
R31b : constant lee__calc_op := lee__multiplyGP644__get_op;
...

and then later on, it creates a body for lee__multiplyGP644__get_op :

function lee__multiplyGP644__get_op return lee__calc_op is
begin
return '*';
end lee__multiplyGP644__get_op;

This makes some kind of sense: from the point of view of the code within the generic, whatever is supplied for get_op must behave exactly like a function, including taking an access to that function. The same thing happens with default values. Here is the same code with a default for get_op :

generic
with function get_op return Calc_Op is '+';
function evaluate( L, R: Integer )
return Integer;

Instantiating this without providing anything for get_op leads to a new function in the expander:

function multiply2 is new evaluate;
function lee__multiply2GP1096__get_op return lee__calc_op is
begin
return '+';
end lee__multiply2GP1096__get_op;

Function coverage and literals

If using this feature of the Ada language, we recommend analysing the generated object code on your platform to investigate how these implicit functions are generated. The intermediate view from the expander is helpful in explaining the intent of the additional object code. DO-178B and DO-178C structural coverage is assessed at the source level. You need to decide whether you want to treat functions that rename literals - directly or via generic formal functions - as source-level functions for which coverage should be demonstrated, or as compiler-added object code for which additional review is needed. Or, as with a lot of convenient features, impose a coding standard that forbids the use of these features in your critical code.

DO-178C webinars

DO178C webinars

White papers

Mitigation of interference in multicore processors for A(M)C 20-193
Sysgo WP Developing DO-178C and ED-12C-certifiable multicore software
DO178C Handbook Efficient Verification Through the DO-178C Life Cycle
A Commercial Solution for Safety-Critical Multicore Timing Analysis

Related blog posts

Evolving language support in RVS: Libadalang

.
2020-04-09

Test your Ada skills with our puzzle

.
2019-06-18

Highlights from Ada-Europe 2018

.
2018-07-03

Highlights from Ada Europe 2016

.
2016-07-06

Pagination

  • Current page 1
  • Page 2
  • Page 3
  • Page 4
  • Page 5
  • Next page Next ›
  • Last page Last »
  • Solutions
    • Rapita Verification Suite
    • RapiTest
    • RapiCover
    • RapiTime
    • RapiTask
    • MACH178

    • Verification and Validation Services
    • Qualification
    • Training
    • Integration
  • Latest
  • Latest menu

    • News
    • Blog
    • Events
    • Videos
  • Downloads
  • Downloads menu

    • Brochures
    • Webinars
    • White Papers
    • Case Studies
    • Product briefs
    • Technical notes
    • Software licensing
  • Company
  • Company menu

    • About Rapita
    • Careers
    • Customers
    • Distributors
    • Industries
    • Locations
    • Partners
    • Research projects
    • Contact
  • Discover
    • Multicore Timing Analysis
    • Embedded Software Testing Tools
    • Worst Case Execution Time
    • WCET Tools
    • Code coverage for Ada, C & C++
    • MC/DC Coverage
    • Verifying additional code for DO-178C
    • Timing analysis (WCET) & Code coverage for MATLAB® Simulink®
    • Data Coupling & Control Coupling
    • Aerospace Software Testing
    • Automotive Software Testing
    • Certifying eVTOL
    • DO-178C
    • AC 20-193 and AMC 20-193
    • ISO 26262
    • What is CAST-32A?

All materials © Rapita Systems Ltd. 2025 - All rights reserved | Privacy information | Trademark notice Subscribe to our newsletter