Articles


Declaring subtypes of private types

Sometimes, you want to declare a subtype for a subset of the possible values of a private type. You might for example want a subtype of Ada.Calendar.Time, which only can include times in the past. If Ada.Calendar.Time was a numeric type, we could declare a subset …

Building a VCS status package with Gprbuild

Would you like your executable files to be able to tell which commit in your version control system it corresponds to? You can do it by: Creating a program (in this example a shell script), which generates Ada source files reporting the version control status. Defining a "language" in Gprbuild …

Using Ada.Sequential_IO to create simple hexdump utility

There is every now and then need for viewing the file contents as "raw" bytes shown as hex numbers. Usually, operating systems have tool 'hexdump' to do this. But it is not hard to create one from scratch. Here is one example how to create a simple hexdump utility in …


Create multiple instances of same package using parameterless generics

There are some cases when you want to create and use multiple instances of same package. This is easily done by creating a generic package which does not take any parameters: generic package Counter is function Get_Number return Natural; end Counter; package body Counter is Counter_Value : Natural := 0; function Get_Number …

Use Ada 2012 aspects to specify variable locations

Earlier with Ada 95 and Ada 2005, if you wanted to put a variable to some specific memory location, you had to use 'for Variable'Address use X' statement and Volatile pragma for that: My_Var : Unsigned_32; for My_Var'Address use System'To_Address (16#FF00#); pragma Volatile (My_Var); With Ada 2012 this becomes simpler …


Self-referencing Objects

One may in some cases want an object to contain a reference ('Access) to itself. The package Self_Referencing_Objects shows how one can implement (consistently) self-referencing objects using limited records and discriminants. type Instance is limited private; ... type Holder (Reference : access Instance) is limited null record; type Instance is limited record …