comp.lang.ada
 help / color / mirror / Atom feed
From: "Robert C. Leif" <rleif@rleif.com>
To: "Comp. Lang. Ada" <comp.lang.ada@ada-france.org>
Subject: for Object_Size use 0
Date: Tue, 12 Apr 2005 18:52:07 -0700
Date: 2005-04-12T18:52:07-07:00	[thread overview]
Message-ID: <mailman.18.1113357147.24457.comp.lang.ada@ada-france.org> (raw)

      To: the Readers of Comp.Lang.Ada 
      I have been working for about two years to produce a program that
stores the values of one or more selected parameters of a group of
parameters.  This work has been published (R. C. Leif, CytometryML, Binary
Data Standards,  in Manipulation and Analysis of Biomolecules, Cells, and
Tissues II, D. V. Nicolau, J. Enderlein, R. C. Leif, and D. Farkas, Editors,
SPIE Proceeding Vol. 5699 pp. 325-333 (2005).(Preprint at
http://newportinstruments.com/cytometryml/pdf/CytometryML_Bin_Data_Stds28Jan
05.pdf) 
      Since Ada was new to this audience and this was not a software
engineering paper, I limited the amount of Ada source.  Therefore, it might
be desirable to submit a paper on this use of Ada to SIGAda 2005.  However,
the software in this paper would have been much simpler and more reliable,
if a variant record with a discriminant set to false resulted in an object
that used no storage space.  This peculiar requirement for the use of 0
storage space is based on the creation of a binary data standard that
produces files that can be read and written by multiple programming
languages.  
      One way to facilitate testing of this software is to create files that
are based on arrays of records with a fixed simple, constant format.   A
simple efficient fixed format is to have the data from each parameter in a
fixed sequence without any spaces. Thus, a record containing multiple
selected parameters would look like the binary representation of the
following with the spaces omitted: 1 500 25_000 1.0 10_000 0.5 
      The number of elements in the data array or file ranges between 5,000
and 100 million.
      The example below includes a variant record with a single parameter.
The actual usage would have between 1 and 100 parameters.
      I specifically need to know if it is possible to create a zero sized
type in Ada 95 or the updated standard, which is to be released in the near
future.
      Thank you.
      Bob Leif 
      ---------------------------------------------------------
      --  This is a test of whether Ada can have a type with a size of 0
bits.
      --  This type is needed to permit the use of a variant record
      --  as a means of not including a parameter.
      with Ada.Text_IO;
      procedure Empty_Pkg is
         package T_IO renames Ada.Text_IO;
         type Empty_Type is (Empty);
         for Empty_Type'Object_Size use 0;
         Empty_Var : Empty_Type := Empty;
         type Byte_Type is mod 256; -- an unsigned byte
         for Byte_Type'Object_Size use 8;
         Byte : Byte_Type := 255;
         subtype Fl_520_540_Type is Natural;
         -- Fl_520_540 is the fluorescence emission between 520 and 540
         -- nanometers.
         type Fl_520_540_Or_Null_Rec_Type (Stored : Boolean := False) is
         record
            case Stored is
               when True =>
                  Fl_520_540_Part : Fl_520_540_Type  := 0;
               when False =>
                  null;
            end case;
         end record;
      
         Fl_520_540_Or_Null_Rec : Fl_520_540_Or_Null_Rec_Type 
             (Stored => False);
      
         type Fl_520_540_Or_Empty_Rec_Type (Stored : Boolean := False) is
         record
            case Stored is
               when True =>
                  Fl_520_540_Part : Fl_520_540_Type  := 0;
               when False =>
                  Empty_Part : Empty_Type := Empty;
            end case;
         end record;
         Fl_520_540_Or_Empty_Rec : Fl_520_540_Or_Empty_Rec_Type (Stored =>
False);
      
         type Fl_520_540_Or_Byte_Rec_Type (Stored : Boolean := False) is
         record
            case Stored is
               when True =>
                  Fl_520_540_Part : Fl_520_540_Type  := 0;
               when False =>
                  Byte_Part : Byte_Type := 255;
            end case;
         end record;
         Fl_520_540_Or_Byte_Rec : Fl_520_540_Or_Byte_Rec_Type (Stored =>
False);
      
         function Size (
               Empty : Empty_Type)
           return Integer is
         begin
            return Empty'Size;
         end Size;
      
         function Size (
               Byte : Byte_Type)
           return Integer is
         begin
            return Byte'Size;
         end Size;
      
         function Size (Fl_520_540_Or_Null_Rec :
Fl_520_540_Or_Null_Rec_Type)
               return Integer is
         begin
            return Fl_520_540_Or_Null_Rec'Size;
         end Size;
      
      
      begin
         --  T_Io.Put_Line("The size of null is " &
Integer'Image(null'Size));
         T_IO.Put_Line ("The Empty'Size is " & Integer'Image
(Empty_Var'Size));
         T_IO.Put_Line ("The Byte'Size  is " & Integer'Image (Byte'Size));
         T_IO.Put_Line (" ");
      
         T_IO.Put_Line ("The Size(Empty) is " & Integer'Image (Size
(Empty)));
         T_IO.Put_Line ("The Size(Byte) is " & Integer'Image (Size (Byte)));
         T_IO.Put_Line (" ");
      
      
         T_IO.Put_Line ("The size of the Fl_520_540_or_Empty_Rec is " &
Integer'Image(Fl_520_540_Or_Empty_Rec'Size));
      
         T_IO.Put_Line ("The size of the Fl_520_540_or_Null_Rec is " &
Integer'Image (Fl_520_540_Or_Null_Rec'Size));
      
      T_IO.Put_Line ("The Size (Fl_520_540_or_Null_Rec) is " & Integer'Image
            (size(Fl_520_540_Or_Null_Rec)));
      
         T_IO.Put_Line ("The size of the Fl_520_540_or_Byte_Rec is " &
Integer'Image (Fl_520_540_Or_Byte_Rec'Size));
      
         T_IO.Put_Line (" ");
      end Empty_Pkg;
      ---------------------------------------------------------------
      Output of GNAT compiled with -gnatR0 -O2	(or O3) 1
      AD: executable=.\Empty_Pkg.exe
      
      The Empty'Size is  8
      The Byte'Size  is  8
      
      The Size(Empty) is  8
      The Size(Byte) is  8
      
      The size of the Fl_520_540_or_Empty_Rec is  64
      The size of the Fl_520_540_or_Null_Rec is  32
      The Size (Fl_520_540_or_Null_Rec) is  32
      The size of the Fl_520_540_or_Byte_Rec is  64
      
      
      Program exited normally.




             reply	other threads:[~2005-04-13  1:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-13  1:52 Robert C. Leif [this message]
2005-04-13  7:58 ` for Object_Size use 0 Martin Dowie
2005-04-13 15:51 ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
2005-04-13 12:02 Robert C. Leif
2005-04-14  5:20 Christoph Grein
2005-04-14 14:48 ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox