From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b3edde39ad90f1b7,start X-Google-Attributes: gid103376,public From: Florian Weimer Subject: Representation clauses and streams Date: 1999/12/29 Message-ID: #1/1 X-Deja-AN: 566112820 Sender: rusfw@mercury.rus.uni-stuttgart.de Organization: Comp.Center (RUS), U of Stuttgart, FRG Content-Type: text/plain; charset=us-ascii User-Agent: Gnus/5.0803 (Gnus v5.8.3) Emacs/20.5 Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-29T00:00:00+00:00 List-Id: 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;