comp.lang.ada
 help / color / mirror / Atom feed
* 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

* Re: for Object_Size use 0
  2005-04-13  1:52 for Object_Size use 0 Robert C. Leif
@ 2005-04-13  7:58 ` Martin Dowie
  2005-04-13 15:51 ` Robert A Duff
  1 sibling, 0 replies; 6+ messages in thread
From: Martin Dowie @ 2005-04-13  7:58 UTC (permalink / raw)


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

* 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

* Re: for Object_Size use 0
  2005-04-13  1:52 for Object_Size use 0 Robert C. Leif
  2005-04-13  7:58 ` Martin Dowie
@ 2005-04-13 15:51 ` Robert A Duff
  1 sibling, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2005-04-13 15:51 UTC (permalink / raw)


"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.

An implementation must support "for Empty_Type'Size use 0;",
but that's not necessary -- it must be 0 by default.

I think GNAT does this wrong.  That's a bug in GNAT,
but I don't think they consider it important enough to fix.

'Object_Size is a GNAT-specific attribute, so its semantics
are defined by AdaCore.  AI-319 proposed to add this attribute
to the language, but I believe it was not approved for Ada 2005.

There are no requirements on Size for record types.
It would be nice if compilers could avoid storing the
discriminants with the record, which seems to be what you want,
but I don't know of any compilers that do that.

Also, if the discriminant has a default, and the record is not limited,
then most compilers will store the maximum size, because the
discriminants can change in that case.  Some compilers instead
use a level of indirection, which is still not zero size.

I don't think this changed in Ada 2005.

So for discriminated records, you're out of luck.

- Bob



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

* 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-14  5:20 Christoph Grein
@ 2005-04-14 14:48 ` Robert A Duff
  0 siblings, 0 replies; 6+ messages in thread
From: Robert A Duff @ 2005-04-14 14:48 UTC (permalink / raw)


Christoph Grein <Christoph.Grein@eurocopter.com> writes:

> 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".

Yes, but C.2(2) turns that Advice into hard requirements.  So any
compiler that claims to support Annex C (which GNAT does) must obey that
advice.

So what I said is not entirely correct, since an implementation need not
support Annex C.  But in practise, what I said is true, since pretty
much all Ada implementations (claim to) support this Annex.

Anyway, even for Implementation Advice that is not covered by C.2,
implementations really ought to obey, unless they have good reason not
to.  So it's often legitimate to complain to your compiler vendor if
they don't obey Advice.  In retrospect, I think perhaps we should not
have called it "Implementation Advice".  Perhaps "Informal Rules" or
"Untestable Requirements" would be better.  Most of these really ought
to be language rules; it's just that there's no way to formalize them,
and therefore no way to test them in an ACATS-style test suite.

> But you're the language lawyer...

;-)  ...which is why I know about C.2.

- Bob



^ 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-13  1:52 for Object_Size use 0 Robert C. Leif
2005-04-13  7:58 ` 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

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