comp.lang.ada
 help / color / mirror / Atom feed
* Re: for Object_Size use 0
@ 2005-04-14  5:20 Christoph Grein
  2005-04-14 14:48 ` Robert A Duff
  0 siblings, 1 reply; 6+ messages in thread
From: Christoph Grein @ 2005-04-14  5:20 UTC (permalink / raw)
  To: CLA

Robert A Duff wrote:

> "Robert C. Leif" <rleif@rleif.com> writes:
>
>  
>
>>      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.
>>   
>
>
> For a discrete type, Size can be zero.  So in your example:
>
>    type Empty_Type is (Empty);
>
> Empty_Type'Size must be zero (if there is no Size clause).
> This follows from RM-13.3(55).  The same is true of
> "subtype S is Integer range 0..0;" -- S'Size = 0 by default.
> See also para 55.b in the AARM.
>
But this is only "Implementation Advice". Consequently RM-13.3(55) uses 
the word "should".

But you're the language lawyer...




^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: for Object_Size use 0
@ 2005-04-13 12:02 Robert C. Leif
  0 siblings, 0 replies; 6+ messages in thread
From: Robert C. Leif @ 2005-04-13 12:02 UTC (permalink / raw)
  To: Comp. Lang. Ada

   I changed Martin Dowie's example below to
      
      type Fl_520_540_Rec_Type is null record;
            for Fl_520_540_Rec_Type'Size use 0;
         Fl_520_540_Rec : Fl_520_540_Rec_Type;
      
      I also changed 'Object_Size to 'Size.
      The results with GNAT are essentially the same as previously.
      The size of Fl_520_540_Rec is  8
      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
      
      Is this truly a GNAT problem or is the standard ambiguous?  If the Ada
standard is ambiguous, should it be clarified?
      Bob Leif 
      -------------------------------------
      Message: 5
      Date: Wed, 13 Apr 2005 08:58:43 +0100
      From: "Martin Dowie" <martin.dowie@baesystems.com>
      Subject: Re: for Object_Size use 0
      To: comp.lang.ada@ada-france.org
      Message-ID: <425ccf77_1@glkas0286.greenlnk.net>
      
      Robert C. Leif wrote:
      >       --  This is a test of whether Ada can have a type with a size
      
      You're program isn't Ada it's GNAT.
      
      I think the answer is "depends on your compiler", e.g.
      
         type Foo is null record;
         for Foo'Size use 0;
      
         Bar : Foo;
      
      GNAT:        Bar'Size => 8
      ObjectAda:  Bar'Size => 0
      
      Cheers
      
      -- Martin
      




^ permalink raw reply	[flat|nested] 6+ messages in thread
* for Object_Size use 0
@ 2005-04-13  1:52 Robert C. Leif
  2005-04-13  7:58 ` Martin Dowie
  2005-04-13 15:51 ` Robert A Duff
  0 siblings, 2 replies; 6+ messages in thread
From: Robert C. Leif @ 2005-04-13  1:52 UTC (permalink / raw)
  To: Comp. Lang. Ada

      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.




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-04-14 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-14  5:20 for Object_Size use 0 Christoph Grein
2005-04-14 14:48 ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
2005-04-13 12:02 Robert C. Leif
2005-04-13  1:52 Robert C. Leif
2005-04-13  7:58 ` Martin Dowie
2005-04-13 15:51 ` Robert A Duff

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