misc 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 …

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 …

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 …



Redirecting Text_IO output to a file

One, probably not so often used, feature of Ada.Text_IO is an ability to redirect output (Put, Put_Line, Newline) to a file. It happens simply by opening a file where you want to redirect the output and then calling Set_Output procedure. Example below shows how it is done: with Ada …