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,fe1de79a099115c5 X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: 16 bit integers in streams Date: 1997/09/25 Message-ID: #1/1 X-Deja-AN: 275466610 Sender: news@inmet.camb.inmet.com (USENET news) References: <342A57CC.2553@gsfc.nasa.gov> X-Nntp-Posting-Host: houdini.camb.inmet.com Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1997-09-25T00:00:00+00:00 List-Id: Stephen Leake (Stephen.Leake@gsfc.nasa.gov) wrote: : ... Here's an attempt to force ObjectAda to read a 16 bit integer: : with Ada.Streams; : package Interface_Streams is : type Integer_16 is range -32768 .. 32767; : for Integer_16'Size use 16; : procedure Read_16 : (Stream : access Ada.Streams.Root_Stream_Type'Class; : Item : out Integer_16); : subtype Integer_16_Base is Integer_16'base; : for Integer_16_Base'Read use Read_16; : procedure Write_16 : (Stream : access Ada.Streams.Root_Stream_Type'Class; : Item : in Integer_16); : for Integer_16'Write use Write_16; : end Interface_Streams; : For both attribute definition clauses, ObjectAda 7.1 gives the error: : interface_streams.ads: Error: line 18 col 33 LRM:13.13.2(36), For an : attribute definition clause specifying a stream attribute for a scalar : type, the subtype for the Item parameter must be the base subtype : Apparently ObjectAda uses a 32 bit base integer type, even when only 16 : bits are requested. What is the rationale for this? The rationale is that the most efficient arithmetic is 32-bits. Even though you ask for only 16 bits, and memory-resident variables will only take up 16 bits, the base "value" size is 32 bits, and the compiler will use 32-bit registers and 32-bit arithmetic for computations. Note that this is similar to declaring a 6 bit integer type. You presumably would not be surprised if the compiler used a base subtype of larger than 6 bits. On most modern processors, the efficient arithmetic size is 32 or 64 bits, so less and less should you expect the base subtypes to be anything shorter than 32. : ... Is it legal for : ObjectAda to reject these attribute definition clauses? It is *required* to reject them, given that Integer_16'Base is not the same subtype as Integer_16. In fact, even if Integer_16'Base'Size were 16, it would still be required to reject the above, since you didn't use Integer_16'Base. If you want to specify a stream attribute for a discrete subtype, you have to use the 'Base attribute, since any other subtype will be constrained (even if the constraints happen to match the base range), and the stream attributes require the (unconstrained) base subtype for scalars. : ... What is the base type of Integer_16? ^^^^ "subtype" Integer_16'Base. : I hope this issue can be addressed by the Uniformity Rapporteur Group; : it would be very nice if streams generated by one compiler/run-time : could be read by another. It would also be nice if a 16 bit integer : would read and write just 16 bits. The fact that 'Read and 'Write use the base subtype rather than the first subtype for a scalar type is a bit problematic, but there are good reasons for it (of course ;-). Basically you get only one 'Read attribute per *type*, and there is nothing prohibiting someone from declaring a variable using the 'Base subtype, so if the stream attributes are going to work for all subtypes of the type, they need to accommodate the 'Base subtype as well. One possibility is to "pretend" the base subtype is only 16 bits, even though 32-bit arithmetic and 32-bit registers are used for all calculations. This would bring the stream behavior back to where it only wrote 16 bits per item, but the meaning of 'Base would be somewhat muddied. : I just looked (on AdaHome) for the commentaries produced by the URG; I : found a bunch of AI's, but no UI's. Can someone point me to where the : URG output is? The URG is no longer an active group. The ARG is taking up the slack, and there will probably be AIs that address implementation advice, as opposed to implementation requirements. : -- : - Stephe -- -Tucker Taft stt@inmet.com http://www.inmet.com/~stt/ Intermetrics, Inc. Burlington, MA USA