comp.lang.ada
 help / color / mirror / Atom feed
* Representation clauses and streams
@ 1999-12-29  0:00 Florian Weimer
  1999-12-29  0:00 ` Ted Dennison
  1999-12-29  0:00 ` Robert Dewar
  0 siblings, 2 replies; 11+ messages in thread
From: Florian Weimer @ 1999-12-29  0:00 UTC (permalink / 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;




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

end of thread, other threads:[~2000-01-04  0:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-29  0:00 Representation clauses and streams Florian Weimer
1999-12-29  0:00 ` 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

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