comp.lang.ada
 help / color / mirror / Atom feed
From: Florian Weimer <Florian.Weimer@rus.uni-stuttgart.de>
Subject: Representation clauses and streams
Date: 1999/12/29
Date: 1999-12-29T00:00:00+00:00	[thread overview]
Message-ID: <tgso0lg67p.fsf@mercury.rus.uni-stuttgart.de> (raw)

I understand that, according to the ARM, record representation clauses
have to be ignored by the default implementations for 'Read and 'Write
(13.13.2(9)).  But representation clauses are ignored for discrete
types as well (at least by GNAT 3.12p on x86).  For example, the type

   Bits_Per_Octet : constant := 8;

   type One_Octet_Type   is range 0 .. 2**(1*Bits_Per_Octet) - 1;
   for One_Octet_Type'Size use Bits_Per_Octet;

is written as a two-octet value to a stream (Stream_Element'Size is,
of course, 8).  One_Octet_Type'Object_Size and One_Octet_Type'Value_Size
(the non-standard GNAT pragmas) are 8 as well; so I'm pretty sure that
a value of type One_Octet_Type should fit into one Stream_Element.

Well, I don't like this behavior at all.  Is there any reason why GNAT
ignores the implementation advice 13.13.2(17)?  What are other compilers
doing here?

A short package for testing (of course, it doesn't run, you have to
look at the machine code to see which of the predefined write operations
is performed):

with Ada.Streams;
package Test_Rep is
   
   Bits_Per_Octet : constant := 8;
   
   type One_Octet_Type is range 0 .. 2**(1*Bits_Per_Octet) - 1;
   for One_Octet_Type'Size use 1*Bits_Per_Octet;
   
   procedure Write
     (Stream : access Ada.Streams.Root_Stream_Type'Class;
      Item   : in One_Octet_Type);
   
end Test_Rep;

package body Test_Rep is

   procedure Write
     (Stream : access Ada.Streams.Root_Stream_Type'Class;
      Item   : in One_Octet_Type)
   is
   begin
      One_Octet_Type'Write (Stream, Item);
   end Write;

end Test_Rep;




             reply	other threads:[~1999-12-29  0:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-29  0:00 Florian Weimer [this message]
1999-12-29  0:00 ` Representation clauses and streams Ted Dennison
1999-12-29  0:00   ` Florian Weimer
1999-12-29  0:00 ` Robert Dewar
1999-12-30  0:00   ` Florian Weimer
2000-01-02  0:00     ` Tucker Taft
2000-01-03  0:00       ` Robert Dewar
2000-01-03  0:00         ` Robert A Duff
2000-01-03  0:00           ` Robert Dewar
2000-01-04  0:00       ` Florian Weimer
2000-01-04  0:00         ` Robert Dewar
replies disabled

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