@smallexample @c ada
type Rb1 is array (1 .. 13) of Boolean;
- pragma Pack (rb1);
+ pragma Pack (Rb1);
type Rb2 is array (1 .. 65) of Boolean;
- pragma Pack (rb2);
+ pragma Pack (Rb2);
type AF is new Float with Atomic;
- type x2 is record
- l1 : Boolean;
- l2 : Duration;
- l3 : AF;
- l4 : Boolean;
- l5 : Rb1;
- l6 : Rb2;
+ type X2 is record
+ L1 : Boolean;
+ L2 : Duration;
+ L3 : AF;
+ L4 : Boolean;
+ L5 : Rb1;
+ L6 : Rb2;
end record;
- pragma Pack (x2);
+ pragma Pack (X2);
@end smallexample
@noindent
-The representation for the record x2 is as follows:
+The representation for the record X2 is as follows:
@smallexample @c ada
-for x2'Size use 224;
-for x2 use record
- l1 at 0 range 0 .. 0;
- l2 at 0 range 1 .. 64;
- l3 at 12 range 0 .. 31;
- l4 at 16 range 0 .. 0;
- l5 at 16 range 1 .. 13;
- l6 at 18 range 0 .. 71;
+for X2'Size use 224;
+for X2 use record
+ L1 at 0 range 0 .. 0;
+ L2 at 0 range 1 .. 64;
+ L3 at 12 range 0 .. 31;
+ L4 at 16 range 0 .. 0;
+ L5 at 16 range 1 .. 13;
+ L6 at 18 range 0 .. 71;
end record;
@end smallexample
@noindent
-Studying this example, we see that the packable fields @code{l1}
-and @code{l2} are
+Studying this example, we see that the packable fields @code{L1}
+and @code{L2} are
of length equal to their sizes, and placed at specific bit boundaries (and
not byte boundaries) to
-eliminate padding. But @code{l3} is of a non-packable float type (because
+eliminate padding. But @code{L3} is of a non-packable float type (because
it is aliased), so it is on the next appropriate alignment boundary.
-The next two fields are fully packable, so @code{l4} and @code{l5} are
+The next two fields are fully packable, so @code{L4} and @code{L5} are
minimally packed with no gaps. However, type @code{Rb2} is a packed
array that is longer than 64 bits, so it is itself non-packable. Thus
-the @code{l6} field is aligned to the next byte boundary, and takes an
+the @code{L6} field is aligned to the next byte boundary, and takes an
integral number of bytes, i.e.@: 72 bits.
@node Record Representation Clauses
@item ^-R^-R^
@cindex @option{^-R^-R^} (@command{gnatbind})
-Output closure source list.
+Output closure source list, which includes all non-time-units that are
+included in the bind.
+
+@item ^-Ra^-Ra^
+@cindex @option{^-Ra^-Ra^} (@command{gnatbind})
+Like @option{-R} but the list includes run-time units.
@item ^-s^/READ_SOURCES=ALL^
@cindex @option{^-s^/READ_SOURCES=ALL^} (@command{gnatbind})
@c *********************************
@node Performing Dimensionality Analysis in GNAT
@chapter Performing Dimensionality Analysis in GNAT
+@cindex Dimensionality analysis
+
@noindent
The GNAT compiler now supports dimensionality checking. The user can
specify physical units for objects, and the compiler will verify that uses
(including powers with static exponents) are computed from their consistuents.
This feature depends on Ada 2012 aspect specifications, and is available from
-version 7.0.1 of GNAT onwards. The GNAT-specific aspect Dimension_System allows
-you to define a system of units; the aspect Dimension then allows the user
-to declare dimensioned quantities within a given system.
+version 7.0.1 of GNAT onwards.
+The GNAT-specific aspect @code{Dimension_System}
+@cindex @code{Dimension_System} aspect
+allows you to define a system of units; the aspect @code{Dimension}
+@cindex @code{Dimension} aspect
+then allows the user to declare dimensioned quantities within a given system.
+(These aspects are described in the @i{Implementation Defined Aspects}
+chapter of the @i{GNAT Reference Manual}).
The major advantage of this model is that it does not require the declaration of
multiple operators for all possible combinations of types: it is only necessary
to use the proper subtypes in object declarations.
The simplest way to impose dimensionality checking on a computation is to make
-use of the package System.Dim.Mks, which is part of the GNAT library. This
-package defines a floating-point type MKS_Type, for which a sequence of
+use of the package @code{System.Dim.Mks},
+@cindex @code{System.Dim.Mks} package (GNAT library)
+which is part of the GNAT library. This
+package defines a floating-point type @code{MKS_Type},
+@cindex @code{MKS_Type} type
+for which a sequence of
dimension names are specified, together with their conventional abbreviations.
The following should be read together with the full specification of the
-package, in file s-dimmks.ads.
+package, in file @file{s-dimmks.ads}.
+@cindex @file{s-dimmks.ads} file
@smallexample @c ada
+@group
type Mks_Type is new Long_Long_Float
with
Dimension_System => (
(Unit_Name => Kelvin, Unit_Symbol => 'K', Dim_Symbol => "Theta"),
(Unit_Name => Mole, Unit_Symbol => "mol", Dim_Symbol => 'N'),
(Unit_Name => Candela, Unit_Symbol => "cd", Dim_Symbol => 'J'));
+@end group
@end smallexample
@noindent
The package then defines a series of subtypes that correspond to these
conventional units. For example:
+
@smallexample @c ada
+@group
subtype Length is Mks_Type
with
Dimension => (Symbol => 'm', Meter => 1, others => 0);
+@end group
@end smallexample
+
@noindent
-and similarly for Mass, Time, Electric_Current, Thermodynamic_Temperature,
-Amount_Of_Substance, and Luminous_Intensity (the standard set of units of
-the SI system).
+and similarly for @code{Mass}, @code{Time}, @code{Electric_Current},
+@code{Thermodynamic_Temperature}, @code{Amount_Of_Substance}, and
+@code{Luminous_Intensity} (the standard set of units of the SI system).
The package also defines conventional names for values of each unit, for
example:
@smallexample @c ada
+@group
m : constant Length := 1.0;
kg : constant Mass := 1.0;
s : constant Time := 1.0;
A : constant Electric_Current := 1.0;
+@end group
@end smallexample
@noindent
as well as useful multiples of these units:
@smallexample @c ada
+@group
cm : constant Length := 1.0E-02;
g : constant Mass := 1.0E-03;
min : constant Time := 60.0;
- day : constant TIme := 60.0 * 24.0 * min;
+ day : constant Time := 60.0 * 24.0 * min;
...
+@end group
@end smallexample
@noindent
be used for output of a value of that unit:
@smallexample @c ada
+@group
subtype Acceleration is Mks_Type
with Dimension => ("m/sec^^^2",
Meter => 1,
Second => -2,
others => 0);
+@end group
@end smallexample
@noindent
Here is a complete example of use:
@smallexample @c ada
+@group
with System.Dim.MKS; use System.Dim.Mks;
with System.Dim.Mks_IO; use System.Dim.Mks_IO;
with Text_IO; use Text_IO;
G : constant acceleration := 9.81 * m / (s ** 2);
T : Time := 10.0*s;
Distance : Length;
+@end group
+@group
begin
Put ("Gravitational constant: ");
Put (G, Aft => 2, Exp => 0); Put_Line ("");
Put (Distance, Aft => 2, Exp => 0);
Put_Line ("");
end Free_Fall;
+@end group
@end smallexample
@noindent
Execution of this program yields:
@smallexample
+@group
Gravitational constant: 9.81 m/sec^^^2
distance travelled in 10 seconds of free fall 490.50 m
+@end group
@end smallexample
@noindent
However, incorrect assignments such as:
@smallexample @c ada
+@group
Distance := 5.0;
Distance := 5.0 * kg:
+@end group
@end smallexample
@noindent
are rejected with the following diagnoses:
@smallexample
+@group
Distance := 5.0;
>>> dimensions mismatch in assignment
>>> left-hand side has dimension [L]
>>> right-hand side is dimensionless
+@end group
+@group
Distance := 5.0 * kg:
>>> dimensions mismatch in assignment
>>> left-hand side has dimension [L]
>>> right-hand side has dimension [M]
+@end group
@end smallexample
@noindent
no explicit subtype for it. If we add to the program:
@smallexample @c ada
+@group
Put ("Final velocity: ");
Put (G * T, Aft =>2, Exp =>0);
Put_Line ("");
+@end group
@end smallexample
@noindent
Final velocity: 98.10 m.s**(-1)
@end smallexample
+
@c *********************************
@node Generating Ada Bindings for C and C++ headers
@chapter Generating Ada Bindings for C and C++ headers